summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-04-22 19:45:21 (UTC)
committer llornkcor <llornkcor>2003-04-22 19:45:21 (UTC)
commita4cbad5c0dece9af449a5a881973ce272208c1ba (patch) (unidiff)
tree851b17d12c1d9627514593dc62f167acd91aa6c6
parentc45bfc674b4ac3dcf13dca127f9f52a4f2641c03 (diff)
downloadopie-a4cbad5c0dece9af449a5a881973ce272208c1ba.zip
opie-a4cbad5c0dece9af449a5a881973ce272208c1ba.tar.gz
opie-a4cbad5c0dece9af449a5a881973ce272208c1ba.tar.bz2
remove qdebug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/resource.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/resource.cpp b/library/resource.cpp
index 6f164c7..80ce7a2 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -1,219 +1,220 @@
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
35namespace { 35namespace {
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*/
63QPixmap Resource::loadPixmap( const QString &pix ) 63QPixmap 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*/
78QBitmap Resource::loadBitmap( const QString &pix ) 78QBitmap 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*/
91QString Resource::findPixmap( const QString &pix ) 91QString 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()); 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??
106 107
107 // All formats... 108 // All formats...
108 QStrList fileFormats = QImageIO::inputFormats(); 109 QStrList fileFormats = QImageIO::inputFormats();
109 QString ff = fileFormats.first(); 110 QString ff = fileFormats.first();
110 while ( fileFormats.current() ) { 111 while ( fileFormats.current() ) {
111 QStringList exts = MimeType("image/"+ff.lower()).extensions(); 112 QStringList exts = MimeType("image/"+ff.lower()).extensions();
112 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { 113 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
113 QString f = picsPath + pix + "." + *it; 114 QString f = picsPath + pix + "." + *it;
114 if ( QFile(f).exists() ) 115 if ( QFile(f).exists() )
115 return f; 116 return f;
116 } 117 }
117 ff = fileFormats.next(); 118 ff = fileFormats.next();
118 } 119 }
119 120
120 // Finally, no (or existing) extension... 121 // Finally, no (or existing) extension...
121 if ( QFile( picsPath + pix ).exists() ) 122 if ( QFile( picsPath + pix ).exists() )
122 return picsPath + pix; 123 return picsPath + pix;
123 124
124 //qDebug("Cannot find pixmap: %s", pix.latin1()); 125 //qDebug("Cannot find pixmap: %s", pix.latin1());
125 return QString(); 126 return QString();
126} 127}
127 128
128/*! 129/*!
129 Returns a sound file for a sound called \a name. 130 Returns a sound file for a sound called \a name.
130 131
131 You should avoid including any filename type extension (e.g. .wav), 132 You should avoid including any filename type extension (e.g. .wav),
132 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
133 by the library. 134 by the library.
134 135
135 Currently, only WAV files are supported. 136 Currently, only WAV files are supported.
136*/ 137*/
137QString Resource::findSound( const QString &name ) 138QString Resource::findSound( const QString &name )
138{ 139{
139 QString picsPath = QPEApplication::qpeDir() + "sounds/"; 140 QString picsPath = QPEApplication::qpeDir() + "sounds/";
140 141
141 QString result; 142 QString result;
142 if ( QFile( (result = picsPath + name + ".wav") ).exists() ) 143 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
143 return result; 144 return result;
144 145
145 return QString(); 146 return QString();
146} 147}
147 148
148/*! 149/*!
149 Returns a list of all sound names. 150 Returns a list of all sound names.
150*/ 151*/
151QStringList Resource::allSounds() 152QStringList Resource::allSounds()
152{ 153{
153 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); 154 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
154 QStringList entries = resourcedir.entryList(); 155 QStringList entries = resourcedir.entryList();
155 QStringList result; 156 QStringList result;
156 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) 157 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
157 result.append((*i).replace(QRegExp("\\.wav"),"")); 158 result.append((*i).replace(QRegExp("\\.wav"),""));
158 return result; 159 return result;
159} 160}
160 161
161static QImage load_image(const QString &name) 162static QImage load_image(const QString &name)
162{ 163{
163 QImage img = qembed_findImage(name.latin1()); 164 QImage img = qembed_findImage(name.latin1());
164 if ( img.isNull() ) { 165 if ( img.isNull() ) {
165 // No inlined image, try file 166 // No inlined image, try file
166 QString f = Resource::findPixmap(name); 167 QString f = Resource::findPixmap(name);
167 if ( !f.isEmpty() ) 168 if ( !f.isEmpty() )
168 img.load(f); 169 img.load(f);
169 } 170 }
170 return img; 171 return img;
171} 172}
172 173
173/*! 174/*!
174 Returns the QImage called \a name. You should avoid including 175 Returns the QImage called \a name. You should avoid including
175 any filename type extension (e.g. .png, .xpm). 176 any filename type extension (e.g. .png, .xpm).
176*/ 177*/
177QImage Resource::loadImage( const QString &name) 178QImage Resource::loadImage( const QString &name)
178{ 179{
179 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 180 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
180 static QImage last_enabled; 181 static QImage last_enabled;
181 static QString last_enabled_name; 182 static QString last_enabled_name;
182 if ( name == last_enabled_name ) 183 if ( name == last_enabled_name )
183 return last_enabled; 184 return last_enabled;
184#endif 185#endif
185 QImage img = load_image(name); 186 QImage img = load_image(name);
186 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 187 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
187 if ( img.isNull() ) { 188 if ( img.isNull() ) {
188 // No file, try generating 189 // No file, try generating
189 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { 190 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
190 last_enabled_name = name.left(name.length()-9); 191 last_enabled_name = name.left(name.length()-9);
191 last_enabled = load_image(last_enabled_name); 192 last_enabled = load_image(last_enabled_name);
192 if ( last_enabled.isNull() ) { 193 if ( last_enabled.isNull() ) {
193 last_enabled_name = QString::null; 194 last_enabled_name = QString::null;
194 } else { 195 } else {
195 img.detach(); 196 img.detach();
196 img.create( last_enabled.width(), last_enabled.height(), 32 ); 197 img.create( last_enabled.width(), last_enabled.height(), 32 );
197 for ( int y = 0; y < img.height(); y++ ) { 198 for ( int y = 0; y < img.height(); y++ ) {
198 for ( int x = 0; x < img.width(); x++ ) { 199 for ( int x = 0; x < img.width(); x++ ) {
199 QRgb p = last_enabled.pixel( x, y ); 200 QRgb p = last_enabled.pixel( x, y );
200 int a = qAlpha(p)/3; 201 int a = qAlpha(p)/3;
201 int g = qGray(qRed(p),qGreen(p),qBlue(p)); 202 int g = qGray(qRed(p),qGreen(p),qBlue(p));
202 img.setPixel( x, y, qRgba(g,g,g,a) ); 203 img.setPixel( x, y, qRgba(g,g,g,a) );
203 } 204 }
204 } 205 }
205 img.setAlphaBuffer( TRUE ); 206 img.setAlphaBuffer( TRUE );
206 } 207 }
207 } 208 }
208 } 209 }
209#endif 210#endif
210 return img; 211 return img;
211} 212}
212 213
213/*! 214/*!
214 \fn QIconSet Resource::loadIconSet( const QString &name ) 215 \fn QIconSet Resource::loadIconSet( const QString &name )
215 216
216 Returns a QIconSet for the pixmap named \a name. A disabled icon is 217 Returns a QIconSet for the pixmap named \a name. A disabled icon is
217 generated that conforms to the Qtopia look & feel. You should avoid 218 generated that conforms to the Qtopia look & feel. You should avoid
218 including any filename type extension (eg. .png, .xpm). 219 including any filename type extension (eg. .png, .xpm).
219*/ 220*/