summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/resource.cpp49
1 files changed, 39 insertions, 10 deletions
diff --git a/library/resource.cpp b/library/resource.cpp
index a093e2f..18139b9 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -66,78 +66,107 @@ QPixmap Resource::loadPixmap( const QString &pix )
66 QString key="QPE_"+pix; 66 QString key="QPE_"+pix;
67 if ( !QPixmapCache::find(key,pm) ) { 67 if ( !QPixmapCache::find(key,pm) ) {
68 QImage I = loadImage(pix); 68 QImage I = loadImage(pix);
69 if( I.isNull() ) { 69 if( I.isNull() ) {
70 qWarning( "Could not load %s", pix.latin1() ); 70 qWarning( "Could not load %s", pix.latin1() );
71 } else { 71 } else {
72 pm.convertFromImage(I); 72 pm.convertFromImage(I);
73 QPixmapCache::insert(key,pm); 73 QPixmapCache::insert(key,pm);
74 } 74 }
75 } 75 }
76 return pm; 76 return pm;
77} 77}
78 78
79/*! 79/*!
80 Returns the QBitmap called \a pix. You should avoid including 80 Returns the QBitmap called \a pix. You should avoid including
81 any filename type extension (e.g. .png, .xpm). 81 any filename type extension (e.g. .png, .xpm).
82*/ 82*/
83QBitmap Resource::loadBitmap( const QString &pix ) 83QBitmap Resource::loadBitmap( const QString &pix )
84{ 84{
85 QBitmap bm; 85 QBitmap bm;
86 bm = loadPixmap(pix); 86 bm = loadPixmap(pix);
87 return bm; 87 return bm;
88} 88}
89 89
90/*
91 * @internal
92 * Parse the extensions only once. If the MimeType mapping
93 * changes we will still use the old extensions, applications
94 * will need to be restarted to be aware of new extensions...
95 * For now it seems ok to have that limitation, if that is a wrong
96 * assumption we will need to invalidate this list
97 */
98QStringList *opie_image_extension_List = 0;
99static void clean_opie_image_extension_List() {
100 delete opie_image_extension_List;
101 opie_image_extension_List = 0;
102}
103
104QStringList opie_imageExtensions() {
105 /*
106 * File extensions (e.g jpeg JPG jpg) are not
107 * parsed yet
108 */
109 if ( !opie_image_extension_List ) {
110 opie_image_extension_List = new QStringList();
111 qAddPostRoutine( clean_opie_image_extension_List );
112
113 QStrList fileFormats = QImageIO::inputFormats();
114 QString ff = fileFormats.first();
115 while ( fileFormats.current() ) {
116 *opie_image_extension_List += MimeType("image/"+ff.lower()).extensions();
117 ff = fileFormats.next();
118 }
119 }
120
121 return *opie_image_extension_List; // QShared so it should be efficient
122}
123
90/*! 124/*!
91 Returns the filename of a pixmap called \a pix. You should avoid including 125 Returns the filename of a pixmap called \a pix. You should avoid including
92 any filename type extension (e.g. .png, .xpm). 126 any filename type extension (e.g. .png, .xpm).
93 127
94 Normally you will use loadPixmap() rather than this function. 128 Normally you will use loadPixmap() rather than this function.
95*/ 129*/
96QString Resource::findPixmap( const QString &pix ) 130QString Resource::findPixmap( const QString &pix )
97{ 131{
98 QString picsPath = QPEApplication::qpeDir() + "pics/"; 132 QString picsPath = QPEApplication::qpeDir() + "pics/";
99 QString f; 133 QString f;
100 134
101 // Common case optimizations... 135 // Common case optimizations...
102 f = picsPath + pix + ".png"; 136 f = picsPath + pix + ".png";
103 if ( QFile( f ).exists() ) 137 if ( QFile( f ).exists() )
104 return f; 138 return f;
105 f = picsPath + pix + ".xpm"; 139 f = picsPath + pix + ".xpm";
106 if ( QFile( f ).exists() ) 140 if ( QFile( f ).exists() )
107 return f; 141 return f;
108 142
109 // All formats... 143 // All formats...
110 QStrList fileFormats = QImageIO::inputFormats(); 144 QStringList exts = opie_imageExtensions();
111 QString ff = fileFormats.first(); 145 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
112 while ( fileFormats.current() ) { 146 QString f = picsPath + pix + "." + *it;
113 QStringList exts = MimeType("image/"+ff.lower()).extensions(); 147 if ( QFile(f).exists() )
114 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { 148 return f;
115 QString f = picsPath + pix + "." + *it;
116 if ( QFile(f).exists() )
117 return f;
118 }
119 ff = fileFormats.next();
120 } 149 }
121 150
122 // Finally, no (or existing) extension... 151 // Finally, no (or existing) extension...
123 if ( QFile( picsPath + pix ).exists() ) 152 if ( QFile( picsPath + pix ).exists() )
124 return picsPath + pix; 153 return picsPath + pix;
125 154
126 //qDebug("Cannot find pixmap: %s", pix.latin1()); 155 //qDebug("Cannot find pixmap: %s", pix.latin1());
127 return QString(); 156 return QString();
128} 157}
129 158
130/*! 159/*!
131 Returns a sound file for a sound called \a name. 160 Returns a sound file for a sound called \a name.
132 161
133 You should avoid including any filename type extension (e.g. .wav), 162 You should avoid including any filename type extension (e.g. .wav),
134 as the system will search for only those fileformats which are supported 163 as the system will search for only those fileformats which are supported
135 by the library. 164 by the library.
136 165
137 Currently, only WAV files are supported. 166 Currently, only WAV files are supported.
138*/ 167*/
139QString Resource::findSound( const QString &name ) 168QString Resource::findSound( const QString &name )
140{ 169{
141 QString picsPath = QPEApplication::qpeDir() + "sounds/"; 170 QString picsPath = QPEApplication::qpeDir() + "sounds/";
142 171
143 QString result; 172 QString result;