-rw-r--r-- | library/resource.cpp | 11 |
1 files changed, 0 insertions, 11 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index 3b5e9ec..92d4b60 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -47,139 +47,128 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | |||
47 | A particular sound can be searched for using findSound(). | 47 | A particular sound can be searched for using findSound(). |
48 | 48 | ||
49 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 49 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
50 | and loadIconSet(). | 50 | and loadIconSet(). |
51 | 51 | ||
52 | \ingroup qtopiaemb | 52 | \ingroup qtopiaemb |
53 | */ | 53 | */ |
54 | 54 | ||
55 | /*! | 55 | /*! |
56 | \fn Resource::Resource() | 56 | \fn Resource::Resource() |
57 | \internal | 57 | \internal |
58 | */ | 58 | */ |
59 | 59 | ||
60 | /*! | 60 | /*! |
61 | Returns the QPixmap called \a pix. You should avoid including | 61 | Returns the QPixmap called \a pix. You should avoid including |
62 | any filename type extension (e.g. .png, .xpm). | 62 | any filename type extension (e.g. .png, .xpm). |
63 | */ | 63 | */ |
64 | #include <stdio.h> | 64 | #include <stdio.h> |
65 | QPixmap Resource::loadPixmap( const QString &pix ) | 65 | QPixmap Resource::loadPixmap( const QString &pix ) |
66 | { | 66 | { |
67 | QPixmap pm; // null pixmap | 67 | QPixmap pm; // null pixmap |
68 | QString key="QPE_"+pix; | 68 | QString key="QPE_"+pix; |
69 | if ( !QPixmapCache::find(key,pm) ) { | 69 | if ( !QPixmapCache::find(key,pm) ) { |
70 | QImage I = loadImage(pix); | 70 | QImage I = loadImage(pix); |
71 | if( I.isNull() ) { | 71 | if( I.isNull() ) { |
72 | qWarning( "Could not load %s", pix.latin1() ); | 72 | qWarning( "Could not load %s", pix.latin1() ); |
73 | } else { | 73 | } else { |
74 | pm.convertFromImage(I); | 74 | pm.convertFromImage(I); |
75 | QPixmapCache::insert(key,pm); | 75 | QPixmapCache::insert(key,pm); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | return pm; | 78 | return pm; |
79 | } | 79 | } |
80 | 80 | ||
81 | /*! | 81 | /*! |
82 | Returns the QBitmap called \a pix. You should avoid including | 82 | Returns the QBitmap called \a pix. You should avoid including |
83 | any filename type extension (e.g. .png, .xpm). | 83 | any filename type extension (e.g. .png, .xpm). |
84 | */ | 84 | */ |
85 | QBitmap Resource::loadBitmap( const QString &pix ) | 85 | QBitmap Resource::loadBitmap( const QString &pix ) |
86 | { | 86 | { |
87 | QBitmap bm; | 87 | QBitmap bm; |
88 | bm = loadPixmap(pix); | 88 | bm = loadPixmap(pix); |
89 | return bm; | 89 | return bm; |
90 | } | 90 | } |
91 | 91 | ||
92 | /*! | 92 | /*! |
93 | Returns the filename of a pixmap called \a pix. You should avoid including | 93 | Returns the filename of a pixmap called \a pix. You should avoid including |
94 | any filename type extension (e.g. .png, .xpm). | 94 | any filename type extension (e.g. .png, .xpm). |
95 | 95 | ||
96 | Normally you will use loadPixmap() rather than this function. | 96 | Normally you will use loadPixmap() rather than this function. |
97 | */ | 97 | */ |
98 | QString Resource::findPixmap( const QString &pix ) | 98 | QString Resource::findPixmap( const QString &pix ) |
99 | { | 99 | { |
100 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 100 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
101 | QString f; | 101 | QString f; |
102 | 102 | ||
103 | // Common case optimizations... | 103 | // Common case optimizations... |
104 | f = picsPath + pix + ".png"; | 104 | f = picsPath + pix + ".png"; |
105 | if ( QFile( f ).exists() ) | 105 | if ( QFile( f ).exists() ) |
106 | return f; | 106 | return f; |
107 | f = picsPath + pix + ".xpm"; | 107 | f = picsPath + pix + ".xpm"; |
108 | if ( QFile( f ).exists() ) | 108 | if ( QFile( f ).exists() ) |
109 | return f; | 109 | return f; |
110 | 110 | ||
111 | #ifdef LIBQPE_NO_INLINE_IMAGES | ||
112 | QString picsPathInline = picsPath + "inline/"; | ||
113 | // Common case optimizations... | ||
114 | f = picsPathInline + pix + ".png"; | ||
115 | if ( QFile( f ).exists() ) | ||
116 | return f; | ||
117 | f = picsPathInline + pix + ".xpm"; | ||
118 | if ( QFile( f ).exists() ) | ||
119 | return f; | ||
120 | #endif | ||
121 | |||
122 | // All formats... | 111 | // All formats... |
123 | QStrList fileFormats = QImageIO::inputFormats(); | 112 | QStrList fileFormats = QImageIO::inputFormats(); |
124 | QString ff = fileFormats.first(); | 113 | QString ff = fileFormats.first(); |
125 | while ( fileFormats.current() ) { | 114 | while ( fileFormats.current() ) { |
126 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 115 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
127 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 116 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
128 | QString f = picsPath + pix + "." + *it; | 117 | QString f = picsPath + pix + "." + *it; |
129 | if ( QFile(f).exists() ) | 118 | if ( QFile(f).exists() ) |
130 | return f; | 119 | return f; |
131 | } | 120 | } |
132 | ff = fileFormats.next(); | 121 | ff = fileFormats.next(); |
133 | } | 122 | } |
134 | 123 | ||
135 | // Finally, no (or existing) extension... | 124 | // Finally, no (or existing) extension... |
136 | if ( QFile( picsPath + pix ).exists() ) | 125 | if ( QFile( picsPath + pix ).exists() ) |
137 | return picsPath + pix; | 126 | return picsPath + pix; |
138 | 127 | ||
139 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 128 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
140 | return QString(); | 129 | return QString(); |
141 | } | 130 | } |
142 | 131 | ||
143 | /*! | 132 | /*! |
144 | Returns a sound file for a sound called \a name. | 133 | Returns a sound file for a sound called \a name. |
145 | 134 | ||
146 | You should avoid including any filename type extension (e.g. .wav), | 135 | You should avoid including any filename type extension (e.g. .wav), |
147 | as the system will search for only those fileformats which are supported | 136 | as the system will search for only those fileformats which are supported |
148 | by the library. | 137 | by the library. |
149 | 138 | ||
150 | Currently, only WAV files are supported. | 139 | Currently, only WAV files are supported. |
151 | */ | 140 | */ |
152 | QString Resource::findSound( const QString &name ) | 141 | QString Resource::findSound( const QString &name ) |
153 | { | 142 | { |
154 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 143 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
155 | 144 | ||
156 | QString result; | 145 | QString result; |
157 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 146 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
158 | return result; | 147 | return result; |
159 | 148 | ||
160 | return QString(); | 149 | return QString(); |
161 | } | 150 | } |
162 | 151 | ||
163 | /*! | 152 | /*! |
164 | Returns a list of all sound names. | 153 | Returns a list of all sound names. |
165 | */ | 154 | */ |
166 | QStringList Resource::allSounds() | 155 | QStringList Resource::allSounds() |
167 | { | 156 | { |
168 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 157 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
169 | QStringList entries = resourcedir.entryList(); | 158 | QStringList entries = resourcedir.entryList(); |
170 | QStringList result; | 159 | QStringList result; |
171 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 160 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
172 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 161 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
173 | return result; | 162 | return result; |
174 | } | 163 | } |
175 | 164 | ||
176 | static QImage load_image(const QString &name) | 165 | static QImage load_image(const QString &name) |
177 | { | 166 | { |
178 | QImage img; | 167 | QImage img; |
179 | 168 | ||
180 | if (g_notUseSet ) { | 169 | if (g_notUseSet ) { |
181 | // try file | 170 | // try file |
182 | QString f = Resource::findPixmap(name); | 171 | QString f = Resource::findPixmap(name); |
183 | if ( !f.isEmpty() ) | 172 | if ( !f.isEmpty() ) |
184 | img.load(f); | 173 | img.load(f); |
185 | #ifndef LIBQPE_NO_INLINE_IMAGES | 174 | #ifndef LIBQPE_NO_INLINE_IMAGES |