00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define QTOPIA_INTERNAL_MIMEEXT
00022 #include <qpe/qpeapplication.h>
00023 #include "resource.h"
00024 #include "mimetype.h"
00025 #include <qdir.h>
00026 #include <qpixmapcache.h>
00027
00028
00029
00030
00031
00032 bool qpe_fast_findPixmap = false;
00033
00034
00035
00036
00037
00038 #ifndef LIBQPE_NO_INLINE_IMAGES
00039 namespace {
00040 #include "inlinepics_p.h"
00041 }
00042 #endif
00043
00068 #include <stdio.h>
00069 QPixmap Resource::loadPixmap( const QString &pix )
00070 {
00071 QPixmap pm;
00072 QString key="QPE_"+pix;
00073 if ( !QPixmapCache::find(key,pm) ) {
00074 QImage I = loadImage(pix);
00075 if( I.isNull() ) {
00076 qWarning( "Could not load %s", pix.latin1() );
00077 } else {
00078 pm.convertFromImage(I);
00079 QPixmapCache::insert(key,pm);
00080 }
00081 }else {
00082 qWarning("In Cache for %s pixmap %s", qApp->argv()[0], pix.local8Bit().data() );
00083 }
00084 return pm;
00085 }
00086
00091 QBitmap Resource::loadBitmap( const QString &pix )
00092 {
00093 QBitmap bm;
00094 bm = loadPixmap(pix);
00095 return bm;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 QStringList *opie_image_extension_List = 0;
00107 static void clean_opie_image_extension_List() {
00108 delete opie_image_extension_List;
00109 opie_image_extension_List = 0;
00110 }
00111
00112 QStringList opie_imageExtensions() {
00113
00114
00115
00116
00117 if ( !opie_image_extension_List ) {
00118 opie_image_extension_List = new QStringList();
00119 qAddPostRoutine( clean_opie_image_extension_List );
00120
00121 QStrList fileFormats = QImageIO::inputFormats();
00122 QString ff = fileFormats.first();
00123 while ( fileFormats.current() ) {
00124 *opie_image_extension_List += MimeType("image/"+ff.lower()).extensions();
00125 ff = fileFormats.next();
00126 }
00127 }
00128
00129 return *opie_image_extension_List;
00130 }
00131
00138 QString Resource::findPixmap( const QString &pix )
00139 {
00140 QString picsPath = QPEApplication::qpeDir() + "pics/";
00141 QString f;
00142
00143
00144 f = picsPath + pix + ".png";
00145 if ( QFile( f ).exists() )
00146 return f;
00147 f = picsPath + pix + ".xpm";
00148 if ( QFile( f ).exists() )
00149 return f;
00150
00151 if ( !qpe_fast_findPixmap ) {
00152 printf("Doing slow search for %s %s\n", qApp->argv()[0], pix.local8Bit().data() );
00153
00154 QStringList exts = opie_imageExtensions();
00155 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
00156 QString f = picsPath + pix + "." + *it;
00157 if ( QFile(f).exists() )
00158 return f;
00159 }
00160
00161
00162 if ( QFile( picsPath + pix ).exists() )
00163 return picsPath + pix;
00164 }
00165
00166
00167 return QString();
00168 }
00169
00179 QString Resource::findSound( const QString &name )
00180 {
00181 QString picsPath = QPEApplication::qpeDir() + "sounds/";
00182
00183 QString result;
00184 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
00185 return result;
00186
00187 return QString();
00188 }
00189
00193 QStringList Resource::allSounds()
00194 {
00195 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
00196 QStringList entries = resourcedir.entryList();
00197 QStringList result;
00198 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
00199 result.append((*i).replace(QRegExp("\\.wav"),""));
00200 return result;
00201 }
00202
00203 static QImage load_image(const QString &name)
00204 {
00205 QImage img;
00206
00207 #ifndef LIBQPE_NO_INLINE_IMAGES
00208 img = qembed_findImage(name.latin1());
00209 #endif
00210 if ( img.isNull() )
00211 {
00212
00213 QString f = Resource::findPixmap(name);
00214 if ( !f.isEmpty() )
00215 img.load(f);
00216 }
00217 return img;
00218 }
00219
00224 QImage Resource::loadImage( const QString &name)
00225 {
00226 #ifndef QT_NO_DEPTH_32 // have alpha-blended pixmaps
00227 static QImage last_enabled;
00228 static QString last_enabled_name;
00229 if ( name == last_enabled_name )
00230 return last_enabled;
00231 #endif
00232 QImage img = load_image(name);
00233 #ifndef QT_NO_DEPTH_32 // have alpha-blended pixmaps
00234 if ( img.isNull() ) {
00235
00236 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
00237 last_enabled_name = name.left(name.length()-9);
00238 last_enabled = load_image(last_enabled_name);
00239 if ( last_enabled.isNull() ) {
00240 last_enabled_name = QString::null;
00241 } else {
00242 img.detach();
00243 img.create( last_enabled.width(), last_enabled.height(), 32 );
00244 for ( int y = 0; y < img.height(); y++ ) {
00245 for ( int x = 0; x < img.width(); x++ ) {
00246 QRgb p = last_enabled.pixel( x, y );
00247 int a = qAlpha(p)/3;
00248 int g = qGray(qRed(p),qGreen(p),qBlue(p));
00249 img.setPixel( x, y, qRgba(g,g,g,a) );
00250 }
00251 }
00252 img.setAlphaBuffer( TRUE );
00253 }
00254 }
00255 }
00256 #endif
00257 return img;
00258 }
00259