author | zecke <zecke> | 2003-04-23 08:00:36 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-23 08:00:36 (UTC) |
commit | 7272fdfd7490b789d978f8d9822bdd899c660eb5 (patch) (unidiff) | |
tree | 62e122bb4616fc8ad0c65991a53fcc9ceb70dfec /library | |
parent | 2b7ee2f7df2f79bc016dd8185e314a3f5df1b07e (diff) | |
download | opie-7272fdfd7490b789d978f8d9822bdd899c660eb5.zip opie-7272fdfd7490b789d978f8d9822bdd899c660eb5.tar.gz opie-7272fdfd7490b789d978f8d9822bdd899c660eb5.tar.bz2 |
Better remove it once and for all... ( debug message )
-rw-r--r-- | library/resource.cpp | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index 80ce7a2..4108883 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -1,220 +1,218 @@ | |||
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 | /*! | 39 | /*! |
40 | \class Resource resource.h | 40 | \class Resource resource.h |
41 | \brief The Resource class provides access to named resources. | 41 | \brief The Resource class provides access to named resources. |
42 | 42 | ||
43 | The resources may be provided from files or other sources. | 43 | The resources may be provided from files or other sources. |
44 | 44 | ||
45 | The allSounds() function returns a list of all the sounds available. | 45 | The allSounds() function returns a list of all the sounds available. |
46 | A particular sound can be searched for using findSound(). | 46 | A particular sound can be searched for using findSound(). |
47 | 47 | ||
48 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 48 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
49 | and loadIconSet(). | 49 | and loadIconSet(). |
50 | 50 | ||
51 | \ingroup qtopiaemb | 51 | \ingroup qtopiaemb |
52 | */ | 52 | */ |
53 | 53 | ||
54 | /*! | 54 | /*! |
55 | \fn Resource::Resource() | 55 | \fn Resource::Resource() |
56 | \internal | 56 | \internal |
57 | */ | 57 | */ |
58 | 58 | ||
59 | /*! | 59 | /*! |
60 | Returns the QPixmap called \a pix. You should avoid including | 60 | Returns the QPixmap called \a pix. You should avoid including |
61 | any filename type extension (e.g. .png, .xpm). | 61 | any filename type extension (e.g. .png, .xpm). |
62 | */ | 62 | */ |
63 | QPixmap Resource::loadPixmap( const QString &pix ) | 63 | QPixmap Resource::loadPixmap( const QString &pix ) |
64 | { | 64 | { |
65 | QPixmap pm; | 65 | QPixmap pm; |
66 | QString key="QPE_"+pix; | 66 | QString key="QPE_"+pix; |
67 | if ( !QPixmapCache::find(key,pm) ) { | 67 | if ( !QPixmapCache::find(key,pm) ) { |
68 | pm.convertFromImage(loadImage(pix)); | 68 | pm.convertFromImage(loadImage(pix)); |
69 | QPixmapCache::insert(key,pm); | 69 | QPixmapCache::insert(key,pm); |
70 | } | 70 | } |
71 | return pm; | 71 | return pm; |
72 | } | 72 | } |
73 | 73 | ||
74 | /*! | 74 | /*! |
75 | Returns the QBitmap called \a pix. You should avoid including | 75 | Returns the QBitmap called \a pix. You should avoid including |
76 | any filename type extension (e.g. .png, .xpm). | 76 | any filename type extension (e.g. .png, .xpm). |
77 | */ | 77 | */ |
78 | QBitmap Resource::loadBitmap( const QString &pix ) | 78 | QBitmap Resource::loadBitmap( const QString &pix ) |
79 | { | 79 | { |
80 | QBitmap bm; | 80 | QBitmap bm; |
81 | bm = loadPixmap(pix); | 81 | bm = loadPixmap(pix); |
82 | return bm; | 82 | return bm; |
83 | } | 83 | } |
84 | 84 | ||
85 | /*! | 85 | /*! |
86 | Returns the filename of a pixmap called \a pix. You should avoid including | 86 | Returns the filename of a pixmap called \a pix. You should avoid including |
87 | any filename type extension (e.g. .png, .xpm). | 87 | any filename type extension (e.g. .png, .xpm). |
88 | 88 | ||
89 | Normally you will use loadPixmap() rather than this function. | 89 | Normally you will use loadPixmap() rather than this function. |
90 | */ | 90 | */ |
91 | QString Resource::findPixmap( const QString &pix ) | 91 | QString Resource::findPixmap( const QString &pix ) |
92 | { | 92 | { |
93 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 93 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
94 | 94 | ||
95 | QString f; | 95 | QString f; |
96 | 96 | ||
97 | // Common case optimizations... | 97 | // Common case optimizations... |
98 | f = picsPath + pix + ".png"; | 98 | f = picsPath + pix + ".png"; |
99 | if ( QFile( f ).exists() ) | 99 | if ( QFile( f ).exists() ) |
100 | return f; | 100 | return f; |
101 | f = picsPath + pix + ".xpm"; | 101 | f = picsPath + pix + ".xpm"; |
102 | if ( QFile( f ).exists() ) | 102 | if ( QFile( f ).exists() ) |
103 | return f; | 103 | return f; |
104 | 104 | ||
105 | //qDebug ( "\nLoading of image '%s' is not ideal (either it doesn't exist or an extension was specified)\n", pix.latin1()); | ||
106 | //is this really necessary?? | ||
107 | 105 | ||
108 | // All formats... | 106 | // All formats... |
109 | QStrList fileFormats = QImageIO::inputFormats(); | 107 | QStrList fileFormats = QImageIO::inputFormats(); |
110 | QString ff = fileFormats.first(); | 108 | QString ff = fileFormats.first(); |
111 | while ( fileFormats.current() ) { | 109 | while ( fileFormats.current() ) { |
112 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 110 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
113 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 111 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
114 | QString f = picsPath + pix + "." + *it; | 112 | QString f = picsPath + pix + "." + *it; |
115 | if ( QFile(f).exists() ) | 113 | if ( QFile(f).exists() ) |
116 | return f; | 114 | return f; |
117 | } | 115 | } |
118 | ff = fileFormats.next(); | 116 | ff = fileFormats.next(); |
119 | } | 117 | } |
120 | 118 | ||
121 | // Finally, no (or existing) extension... | 119 | // Finally, no (or existing) extension... |
122 | if ( QFile( picsPath + pix ).exists() ) | 120 | if ( QFile( picsPath + pix ).exists() ) |
123 | return picsPath + pix; | 121 | return picsPath + pix; |
124 | 122 | ||
125 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 123 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
126 | return QString(); | 124 | return QString(); |
127 | } | 125 | } |
128 | 126 | ||
129 | /*! | 127 | /*! |
130 | Returns a sound file for a sound called \a name. | 128 | Returns a sound file for a sound called \a name. |
131 | 129 | ||
132 | You should avoid including any filename type extension (e.g. .wav), | 130 | You should avoid including any filename type extension (e.g. .wav), |
133 | as the system will search for only those fileformats which are supported | 131 | as the system will search for only those fileformats which are supported |
134 | by the library. | 132 | by the library. |
135 | 133 | ||
136 | Currently, only WAV files are supported. | 134 | Currently, only WAV files are supported. |
137 | */ | 135 | */ |
138 | QString Resource::findSound( const QString &name ) | 136 | QString Resource::findSound( const QString &name ) |
139 | { | 137 | { |
140 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 138 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
141 | 139 | ||
142 | QString result; | 140 | QString result; |
143 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 141 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
144 | return result; | 142 | return result; |
145 | 143 | ||
146 | return QString(); | 144 | return QString(); |
147 | } | 145 | } |
148 | 146 | ||
149 | /*! | 147 | /*! |
150 | Returns a list of all sound names. | 148 | Returns a list of all sound names. |
151 | */ | 149 | */ |
152 | QStringList Resource::allSounds() | 150 | QStringList Resource::allSounds() |
153 | { | 151 | { |
154 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 152 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
155 | QStringList entries = resourcedir.entryList(); | 153 | QStringList entries = resourcedir.entryList(); |
156 | QStringList result; | 154 | QStringList result; |
157 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 155 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
158 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 156 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
159 | return result; | 157 | return result; |
160 | } | 158 | } |
161 | 159 | ||
162 | static QImage load_image(const QString &name) | 160 | static QImage load_image(const QString &name) |
163 | { | 161 | { |
164 | QImage img = qembed_findImage(name.latin1()); | 162 | QImage img = qembed_findImage(name.latin1()); |
165 | if ( img.isNull() ) { | 163 | if ( img.isNull() ) { |
166 | // No inlined image, try file | 164 | // No inlined image, try file |
167 | QString f = Resource::findPixmap(name); | 165 | QString f = Resource::findPixmap(name); |
168 | if ( !f.isEmpty() ) | 166 | if ( !f.isEmpty() ) |
169 | img.load(f); | 167 | img.load(f); |
170 | } | 168 | } |
171 | return img; | 169 | return img; |
172 | } | 170 | } |
173 | 171 | ||
174 | /*! | 172 | /*! |
175 | Returns the QImage called \a name. You should avoid including | 173 | Returns the QImage called \a name. You should avoid including |
176 | any filename type extension (e.g. .png, .xpm). | 174 | any filename type extension (e.g. .png, .xpm). |
177 | */ | 175 | */ |
178 | QImage Resource::loadImage( const QString &name) | 176 | QImage Resource::loadImage( const QString &name) |
179 | { | 177 | { |
180 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 178 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
181 | static QImage last_enabled; | 179 | static QImage last_enabled; |
182 | static QString last_enabled_name; | 180 | static QString last_enabled_name; |
183 | if ( name == last_enabled_name ) | 181 | if ( name == last_enabled_name ) |
184 | return last_enabled; | 182 | return last_enabled; |
185 | #endif | 183 | #endif |
186 | QImage img = load_image(name); | 184 | QImage img = load_image(name); |
187 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 185 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
188 | if ( img.isNull() ) { | 186 | if ( img.isNull() ) { |
189 | // No file, try generating | 187 | // No file, try generating |
190 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 188 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
191 | last_enabled_name = name.left(name.length()-9); | 189 | last_enabled_name = name.left(name.length()-9); |
192 | last_enabled = load_image(last_enabled_name); | 190 | last_enabled = load_image(last_enabled_name); |
193 | if ( last_enabled.isNull() ) { | 191 | if ( last_enabled.isNull() ) { |
194 | last_enabled_name = QString::null; | 192 | last_enabled_name = QString::null; |
195 | } else { | 193 | } else { |
196 | img.detach(); | 194 | img.detach(); |
197 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 195 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
198 | for ( int y = 0; y < img.height(); y++ ) { | 196 | for ( int y = 0; y < img.height(); y++ ) { |
199 | for ( int x = 0; x < img.width(); x++ ) { | 197 | for ( int x = 0; x < img.width(); x++ ) { |
200 | QRgb p = last_enabled.pixel( x, y ); | 198 | QRgb p = last_enabled.pixel( x, y ); |
201 | int a = qAlpha(p)/3; | 199 | int a = qAlpha(p)/3; |
202 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 200 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
203 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 201 | img.setPixel( x, y, qRgba(g,g,g,a) ); |
204 | } | 202 | } |
205 | } | 203 | } |
206 | img.setAlphaBuffer( TRUE ); | 204 | img.setAlphaBuffer( TRUE ); |
207 | } | 205 | } |
208 | } | 206 | } |
209 | } | 207 | } |
210 | #endif | 208 | #endif |
211 | return img; | 209 | return img; |
212 | } | 210 | } |
213 | 211 | ||
214 | /*! | 212 | /*! |
215 | \fn QIconSet Resource::loadIconSet( const QString &name ) | 213 | \fn QIconSet Resource::loadIconSet( const QString &name ) |
216 | 214 | ||
217 | Returns a QIconSet for the pixmap named \a name. A disabled icon is | 215 | Returns a QIconSet for the pixmap named \a name. A disabled icon is |
218 | generated that conforms to the Qtopia look & feel. You should avoid | 216 | generated that conforms to the Qtopia look & feel. You should avoid |
219 | including any filename type extension (eg. .png, .xpm). | 217 | including any filename type extension (eg. .png, .xpm). |
220 | */ | 218 | */ |