author | zecke <zecke> | 2005-02-22 23:06:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-02-22 23:06:10 (UTC) |
commit | ff2fdaf1a8e8a17ce756c0413102b37705e0c646 (patch) (unidiff) | |
tree | 654cf3e0322bab0594f15dc5b3e3ab704184b59f /library | |
parent | 9e755f078a806d6c81e1dbdbc54d12888041bbff (diff) | |
download | opie-ff2fdaf1a8e8a17ce756c0413102b37705e0c646.zip opie-ff2fdaf1a8e8a17ce756c0413102b37705e0c646.tar.gz opie-ff2fdaf1a8e8a17ce756c0413102b37705e0c646.tar.bz2 |
-Request Image Type extensions (e.g jpg, png, JPEG, PNG, tiff) from
MimeType only once (we need to see when and where to invalidate it)
-Create a method for it to parse it once and clean up at the end
-rw-r--r-- | library/resource.cpp | 49 |
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 | |||
@@ -86,8 +86,42 @@ QBitmap Resource::loadBitmap( const QString &pix ) | |||
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 | */ | ||
98 | QStringList *opie_image_extension_List = 0; | ||
99 | static void clean_opie_image_extension_List() { | ||
100 | delete opie_image_extension_List; | ||
101 | opie_image_extension_List = 0; | ||
102 | } | ||
103 | |||
104 | QStringList 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 | ||
@@ -106,18 +140,13 @@ QString Resource::findPixmap( const QString &pix ) | |||
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() ) |