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