-rw-r--r-- | library/resource.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index 4108883..f70658d 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -1,86 +1,88 @@ | |||
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 <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qregexp.h> | 27 | #include <qregexp.h> |
28 | #include <qpixmapcache.h> | 28 | #include <qpixmapcache.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | 30 | ||
31 | // this namespace is just a workaround for a gcc bug | 31 | // this namespace is just a workaround for a gcc bug |
32 | // gcc exports inline functions in the generated file | 32 | // gcc exports inline functions in the generated file |
33 | // inlinepics_p.h | 33 | // inlinepics_p.h |
34 | 34 | ||
35 | namespace { | 35 | namespace { |
36 | #include "inlinepics_p.h" | 36 | #include "inlinepics_p.h" |
37 | } | 37 | } |
38 | 38 | ||
39 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | ||
40 | |||
39 | /*! | 41 | /*! |
40 | \class Resource resource.h | 42 | \class Resource resource.h |
41 | \brief The Resource class provides access to named resources. | 43 | \brief The Resource class provides access to named resources. |
42 | 44 | ||
43 | The resources may be provided from files or other sources. | 45 | The resources may be provided from files or other sources. |
44 | 46 | ||
45 | The allSounds() function returns a list of all the sounds available. | 47 | The allSounds() function returns a list of all the sounds available. |
46 | A particular sound can be searched for using findSound(). | 48 | A particular sound can be searched for using findSound(). |
47 | 49 | ||
48 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 50 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
49 | and loadIconSet(). | 51 | and loadIconSet(). |
50 | 52 | ||
51 | \ingroup qtopiaemb | 53 | \ingroup qtopiaemb |
52 | */ | 54 | */ |
53 | 55 | ||
54 | /*! | 56 | /*! |
55 | \fn Resource::Resource() | 57 | \fn Resource::Resource() |
56 | \internal | 58 | \internal |
57 | */ | 59 | */ |
58 | 60 | ||
59 | /*! | 61 | /*! |
60 | Returns the QPixmap called \a pix. You should avoid including | 62 | Returns the QPixmap called \a pix. You should avoid including |
61 | any filename type extension (e.g. .png, .xpm). | 63 | any filename type extension (e.g. .png, .xpm). |
62 | */ | 64 | */ |
63 | QPixmap Resource::loadPixmap( const QString &pix ) | 65 | QPixmap Resource::loadPixmap( const QString &pix ) |
64 | { | 66 | { |
65 | QPixmap pm; | 67 | QPixmap pm; |
66 | QString key="QPE_"+pix; | 68 | QString key="QPE_"+pix; |
67 | if ( !QPixmapCache::find(key,pm) ) { | 69 | if ( !QPixmapCache::find(key,pm) ) { |
68 | pm.convertFromImage(loadImage(pix)); | 70 | pm.convertFromImage(loadImage(pix)); |
69 | QPixmapCache::insert(key,pm); | 71 | QPixmapCache::insert(key,pm); |
70 | } | 72 | } |
71 | return pm; | 73 | return pm; |
72 | } | 74 | } |
73 | 75 | ||
74 | /*! | 76 | /*! |
75 | Returns the QBitmap called \a pix. You should avoid including | 77 | Returns the QBitmap called \a pix. You should avoid including |
76 | any filename type extension (e.g. .png, .xpm). | 78 | any filename type extension (e.g. .png, .xpm). |
77 | */ | 79 | */ |
78 | QBitmap Resource::loadBitmap( const QString &pix ) | 80 | QBitmap Resource::loadBitmap( const QString &pix ) |
79 | { | 81 | { |
80 | QBitmap bm; | 82 | QBitmap bm; |
81 | bm = loadPixmap(pix); | 83 | bm = loadPixmap(pix); |
82 | return bm; | 84 | return bm; |
83 | } | 85 | } |
84 | 86 | ||
85 | /*! | 87 | /*! |
86 | Returns the filename of a pixmap called \a pix. You should avoid including | 88 | Returns the filename of a pixmap called \a pix. You should avoid including |
@@ -114,104 +116,117 @@ QString Resource::findPixmap( const QString &pix ) | |||
114 | return f; | 116 | return f; |
115 | } | 117 | } |
116 | ff = fileFormats.next(); | 118 | ff = fileFormats.next(); |
117 | } | 119 | } |
118 | 120 | ||
119 | // Finally, no (or existing) extension... | 121 | // Finally, no (or existing) extension... |
120 | if ( QFile( picsPath + pix ).exists() ) | 122 | if ( QFile( picsPath + pix ).exists() ) |
121 | return picsPath + pix; | 123 | return picsPath + pix; |
122 | 124 | ||
123 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 125 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
124 | return QString(); | 126 | return QString(); |
125 | } | 127 | } |
126 | 128 | ||
127 | /*! | 129 | /*! |
128 | Returns a sound file for a sound called \a name. | 130 | Returns a sound file for a sound called \a name. |
129 | 131 | ||
130 | You should avoid including any filename type extension (e.g. .wav), | 132 | You should avoid including any filename type extension (e.g. .wav), |
131 | as the system will search for only those fileformats which are supported | 133 | as the system will search for only those fileformats which are supported |
132 | by the library. | 134 | by the library. |
133 | 135 | ||
134 | Currently, only WAV files are supported. | 136 | Currently, only WAV files are supported. |
135 | */ | 137 | */ |
136 | QString Resource::findSound( const QString &name ) | 138 | QString Resource::findSound( const QString &name ) |
137 | { | 139 | { |
138 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 140 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
139 | 141 | ||
140 | QString result; | 142 | QString result; |
141 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 143 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
142 | return result; | 144 | return result; |
143 | 145 | ||
144 | return QString(); | 146 | return QString(); |
145 | } | 147 | } |
146 | 148 | ||
147 | /*! | 149 | /*! |
148 | Returns a list of all sound names. | 150 | Returns a list of all sound names. |
149 | */ | 151 | */ |
150 | QStringList Resource::allSounds() | 152 | QStringList Resource::allSounds() |
151 | { | 153 | { |
152 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 154 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
153 | QStringList entries = resourcedir.entryList(); | 155 | QStringList entries = resourcedir.entryList(); |
154 | QStringList result; | 156 | QStringList result; |
155 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 157 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
156 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 158 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
157 | return result; | 159 | return result; |
158 | } | 160 | } |
159 | 161 | ||
160 | static QImage load_image(const QString &name) | 162 | static QImage load_image(const QString &name) |
161 | { | 163 | { |
162 | QImage img = qembed_findImage(name.latin1()); | 164 | if (g_notUseSet ) { |
163 | if ( img.isNull() ) { | 165 | // try file |
164 | // No inlined image, try file | 166 | QImage img; |
165 | QString f = Resource::findPixmap(name); | 167 | QString f = Resource::findPixmap(name); |
166 | if ( !f.isEmpty() ) | 168 | if ( !f.isEmpty() ) |
167 | img.load(f); | 169 | img.load(f); |
170 | if (img.isNull() ) | ||
171 | img = qembed_findImage(name.latin1() ); | ||
172 | return img; | ||
173 | } | ||
174 | else{ | ||
175 | QImage img = qembed_findImage(name.latin1()); | ||
176 | |||
177 | if ( img.isNull() ) { | ||
178 | // No inlined image, try file | ||
179 | QString f = Resource::findPixmap(name); | ||
180 | if ( !f.isEmpty() ) | ||
181 | img.load(f); | ||
182 | } | ||
183 | return img; | ||
168 | } | 184 | } |
169 | return img; | ||
170 | } | 185 | } |
171 | 186 | ||
172 | /*! | 187 | /*! |
173 | Returns the QImage called \a name. You should avoid including | 188 | Returns the QImage called \a name. You should avoid including |
174 | any filename type extension (e.g. .png, .xpm). | 189 | any filename type extension (e.g. .png, .xpm). |
175 | */ | 190 | */ |
176 | QImage Resource::loadImage( const QString &name) | 191 | QImage Resource::loadImage( const QString &name) |
177 | { | 192 | { |
178 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 193 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
179 | static QImage last_enabled; | 194 | static QImage last_enabled; |
180 | static QString last_enabled_name; | 195 | static QString last_enabled_name; |
181 | if ( name == last_enabled_name ) | 196 | if ( name == last_enabled_name ) |
182 | return last_enabled; | 197 | return last_enabled; |
183 | #endif | 198 | #endif |
184 | QImage img = load_image(name); | 199 | QImage img = load_image(name); |
185 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 200 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
186 | if ( img.isNull() ) { | 201 | if ( img.isNull() ) { |
187 | // No file, try generating | 202 | // No file, try generating |
188 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 203 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
189 | last_enabled_name = name.left(name.length()-9); | 204 | last_enabled_name = name.left(name.length()-9); |
190 | last_enabled = load_image(last_enabled_name); | 205 | last_enabled = load_image(last_enabled_name); |
191 | if ( last_enabled.isNull() ) { | 206 | if ( last_enabled.isNull() ) { |
192 | last_enabled_name = QString::null; | 207 | last_enabled_name = QString::null; |
193 | } else { | 208 | } else { |
194 | img.detach(); | 209 | img.detach(); |
195 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 210 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
196 | for ( int y = 0; y < img.height(); y++ ) { | 211 | for ( int y = 0; y < img.height(); y++ ) { |
197 | for ( int x = 0; x < img.width(); x++ ) { | 212 | for ( int x = 0; x < img.width(); x++ ) { |
198 | QRgb p = last_enabled.pixel( x, y ); | 213 | QRgb p = last_enabled.pixel( x, y ); |
199 | int a = qAlpha(p)/3; | 214 | int a = qAlpha(p)/3; |
200 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 215 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
201 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 216 | img.setPixel( x, y, qRgba(g,g,g,a) ); |
202 | } | 217 | } |
203 | } | 218 | } |
204 | img.setAlphaBuffer( TRUE ); | 219 | img.setAlphaBuffer( TRUE ); |
205 | } | 220 | } |
206 | } | 221 | } |
207 | } | 222 | } |
208 | #endif | 223 | #endif |
209 | return img; | 224 | return img; |
210 | } | 225 | } |
211 | 226 | ||
212 | /*! | 227 | /*! |
213 | \fn QIconSet Resource::loadIconSet( const QString &name ) | 228 | \fn QIconSet Resource::loadIconSet( const QString &name ) |
214 | 229 | ||
215 | Returns a QIconSet for the pixmap named \a name. A disabled icon is | 230 | Returns a QIconSet for the pixmap named \a name. A disabled icon is |
216 | generated that conforms to the Qtopia look & feel. You should avoid | 231 | generated that conforms to the Qtopia look & feel. You should avoid |
217 | including any filename type extension (eg. .png, .xpm). | 232 | including any filename type extension (eg. .png, .xpm). |