author | mickeyl <mickeyl> | 2005-02-19 18:09:40 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-02-19 18:09:40 (UTC) |
commit | 5909f43e922a066637127e48c2e3d99685e4871a (patch) (unidiff) | |
tree | 9d87440d0494a52cc8314148e0994039a3856314 | |
parent | 112337f13c70f1266430f154d486b6f23ec18488 (diff) | |
download | opie-5909f43e922a066637127e48c2e3d99685e4871a.zip opie-5909f43e922a066637127e48c2e3d99685e4871a.tar.gz opie-5909f43e922a066637127e48c2e3d99685e4871a.tar.bz2 |
back out an unintentionally commited change
-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 | |||
@@ -1,259 +1,248 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | 21 | #define QTOPIA_INTERNAL_MIMEEXT |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include "resource.h" | 23 | #include "resource.h" |
24 | #include "mimetype.h" | 24 | #include "mimetype.h" |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qpixmapcache.h> | 26 | #include <qpixmapcache.h> |
27 | 27 | ||
28 | // this namespace is just a workaround for a gcc bug | 28 | // this namespace is just a workaround for a gcc bug |
29 | // gcc exports inline functions in the generated file | 29 | // gcc exports inline functions in the generated file |
30 | // inlinepics_p.h | 30 | // inlinepics_p.h |
31 | 31 | ||
32 | #ifndef LIBQPE_NO_INLINE_IMAGES | 32 | #ifndef LIBQPE_NO_INLINE_IMAGES |
33 | namespace { | 33 | namespace { |
34 | #include "inlinepics_p.h" | 34 | #include "inlinepics_p.h" |
35 | } | 35 | } |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | 38 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); |
39 | 39 | ||
40 | /*! | 40 | /*! |
41 | \class Resource resource.h | 41 | \class Resource resource.h |
42 | \brief The Resource class provides access to named resources. | 42 | \brief The Resource class provides access to named resources. |
43 | 43 | ||
44 | The resources may be provided from files or other sources. | 44 | The resources may be provided from files or other sources. |
45 | 45 | ||
46 | The allSounds() function returns a list of all the sounds available. | 46 | The allSounds() function returns a list of all the sounds available. |
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 |
186 | if (img.isNull() ) | 175 | if (img.isNull() ) |
187 | img = qembed_findImage(name.latin1() ); | 176 | img = qembed_findImage(name.latin1() ); |
188 | #endif | 177 | #endif |
189 | return img; | 178 | return img; |
190 | } | 179 | } |
191 | else{ | 180 | else{ |
192 | #ifndef LIBQPE_NO_INLINE_IMAGES | 181 | #ifndef LIBQPE_NO_INLINE_IMAGES |
193 | img = qembed_findImage(name.latin1()); | 182 | img = qembed_findImage(name.latin1()); |
194 | #else | 183 | #else |
195 | QString f = Resource::findPixmap( "/inline/" + name ); | 184 | QString f = Resource::findPixmap( "/inline/" + name ); |
196 | if ( !f.isEmpty() ) | 185 | if ( !f.isEmpty() ) |
197 | { | 186 | { |
198 | img.load(f); | 187 | img.load(f); |
199 | return img; | 188 | return img; |
200 | } | 189 | } |
201 | #endif | 190 | #endif |
202 | if ( img.isNull() ) | 191 | if ( img.isNull() ) |
203 | { | 192 | { |
204 | // No inlined image, try file | 193 | // No inlined image, try file |
205 | QString f = Resource::findPixmap(name); | 194 | QString f = Resource::findPixmap(name); |
206 | if ( !f.isEmpty() ) | 195 | if ( !f.isEmpty() ) |
207 | img.load(f); | 196 | img.load(f); |
208 | } | 197 | } |
209 | return img; | 198 | return img; |
210 | } | 199 | } |
211 | } | 200 | } |
212 | 201 | ||
213 | /*! | 202 | /*! |
214 | Returns the QImage called \a name. You should avoid including | 203 | Returns the QImage called \a name. You should avoid including |
215 | any filename type extension (e.g. .png, .xpm). | 204 | any filename type extension (e.g. .png, .xpm). |
216 | */ | 205 | */ |
217 | QImage Resource::loadImage( const QString &name) | 206 | QImage Resource::loadImage( const QString &name) |
218 | { | 207 | { |
219 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 208 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
220 | static QImage last_enabled; | 209 | static QImage last_enabled; |
221 | static QString last_enabled_name; | 210 | static QString last_enabled_name; |
222 | if ( name == last_enabled_name ) | 211 | if ( name == last_enabled_name ) |
223 | return last_enabled; | 212 | return last_enabled; |
224 | #endif | 213 | #endif |
225 | QImage img = load_image(name); | 214 | QImage img = load_image(name); |
226 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 215 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
227 | if ( img.isNull() ) { | 216 | if ( img.isNull() ) { |
228 | // No file, try generating | 217 | // No file, try generating |
229 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 218 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
230 | last_enabled_name = name.left(name.length()-9); | 219 | last_enabled_name = name.left(name.length()-9); |
231 | last_enabled = load_image(last_enabled_name); | 220 | last_enabled = load_image(last_enabled_name); |
232 | if ( last_enabled.isNull() ) { | 221 | if ( last_enabled.isNull() ) { |
233 | last_enabled_name = QString::null; | 222 | last_enabled_name = QString::null; |
234 | } else { | 223 | } else { |
235 | img.detach(); | 224 | img.detach(); |
236 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 225 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
237 | for ( int y = 0; y < img.height(); y++ ) { | 226 | for ( int y = 0; y < img.height(); y++ ) { |
238 | for ( int x = 0; x < img.width(); x++ ) { | 227 | for ( int x = 0; x < img.width(); x++ ) { |
239 | QRgb p = last_enabled.pixel( x, y ); | 228 | QRgb p = last_enabled.pixel( x, y ); |
240 | int a = qAlpha(p)/3; | 229 | int a = qAlpha(p)/3; |
241 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 230 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
242 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 231 | img.setPixel( x, y, qRgba(g,g,g,a) ); |
243 | } | 232 | } |
244 | } | 233 | } |
245 | img.setAlphaBuffer( TRUE ); | 234 | img.setAlphaBuffer( TRUE ); |
246 | } | 235 | } |
247 | } | 236 | } |
248 | } | 237 | } |
249 | #endif | 238 | #endif |
250 | return img; | 239 | return img; |
251 | } | 240 | } |
252 | 241 | ||
253 | /*! | 242 | /*! |
254 | \fn QIconSet Resource::loadIconSet( const QString &name ) | 243 | \fn QIconSet Resource::loadIconSet( const QString &name ) |
255 | 244 | ||
256 | Returns a QIconSet for the pixmap named \a name. A disabled icon is | 245 | Returns a QIconSet for the pixmap named \a name. A disabled icon is |
257 | generated that conforms to the Qtopia look & feel. You should avoid | 246 | generated that conforms to the Qtopia look & feel. You should avoid |
258 | including any filename type extension (eg. .png, .xpm). | 247 | including any filename type extension (eg. .png, .xpm). |
259 | */ | 248 | */ |