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 | |
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 | |||
@@ -88,4 +88,38 @@ QBitmap Resource::loadBitmap( const QString &pix ) | |||
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 |
@@ -108,14 +142,9 @@ QString Resource::findPixmap( const QString &pix ) | |||
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 | ||