author | zecke <zecke> | 2004-12-30 14:07:11 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-30 14:07:11 (UTC) |
commit | 8467a23d6a7f4b52619b60462c8ba80d8a736a9e (patch) (unidiff) | |
tree | b2ee7da7ee41cd4b3aab4215cddfcfaebd7c72e0 /library/resource.cpp | |
parent | e3fa443e845e76707171c6fae79125892a369b75 (diff) | |
download | opie-8467a23d6a7f4b52619b60462c8ba80d8a736a9e.zip opie-8467a23d6a7f4b52619b60462c8ba80d8a736a9e.tar.gz opie-8467a23d6a7f4b52619b60462c8ba80d8a736a9e.tar.bz2 |
Remove the 'namespacing' of global and app icons in the PixmapCache
as it didn't utilize the embedded pixmaps anymore.
Revert of the last commit
-rw-r--r-- | library/resource.cpp | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index 43fdc60..cfa0d26 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -17,125 +17,100 @@ | |||
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 <qpixmapcache.h> | 26 | #include <qpixmapcache.h> |
27 | 27 | ||
28 | // this namespace is just a workaround for a gcc bug | 28 | // this namespace is just a workaround for a gcc bug |
29 | // gcc exports inline functions in the generated file | 29 | // gcc exports inline functions in the generated file |
30 | // inlinepics_p.h | 30 | // inlinepics_p.h |
31 | 31 | ||
32 | namespace { | 32 | namespace { |
33 | #include "inlinepics_p.h" | 33 | #include "inlinepics_p.h" |
34 | } | 34 | } |
35 | 35 | ||
36 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | 36 | static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); |
37 | 37 | ||
38 | /*! | 38 | /*! |
39 | \class Resource resource.h | 39 | \class Resource resource.h |
40 | \brief The Resource class provides access to named resources. | 40 | \brief The Resource class provides access to named resources. |
41 | 41 | ||
42 | The resources may be provided from files or other sources. | 42 | The resources may be provided from files or other sources. |
43 | 43 | ||
44 | The allSounds() function returns a list of all the sounds available. | 44 | The allSounds() function returns a list of all the sounds available. |
45 | A particular sound can be searched for using findSound(). | 45 | A particular sound can be searched for using findSound(). |
46 | 46 | ||
47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
48 | and loadIconSet(). | 48 | and loadIconSet(). |
49 | 49 | ||
50 | \ingroup qtopiaemb | 50 | \ingroup qtopiaemb |
51 | */ | 51 | */ |
52 | 52 | ||
53 | /*! | 53 | /*! |
54 | \fn Resource::Resource() | 54 | \fn Resource::Resource() |
55 | \internal | 55 | \internal |
56 | */ | 56 | */ |
57 | 57 | ||
58 | /*! | 58 | /*! |
59 | Returns the QPixmap called \a pix. You should avoid including | 59 | Returns the QPixmap called \a pix. You should avoid including |
60 | any filename type extension (e.g. .png, .xpm). | 60 | any filename type extension (e.g. .png, .xpm). |
61 | */ | 61 | */ |
62 | QPixmap Resource::loadPixmap( const QString &pix ) | 62 | QPixmap Resource::loadPixmap( const QString &pix ) |
63 | { | 63 | { |
64 | QPixmap pm; | 64 | QPixmap pm; |
65 | 65 | QString key="QPE_"+pix; | |
66 | // Give the pixmaps some kind of namespace in the pixmapcache | 66 | if ( !QPixmapCache::find(key,pm) ) { |
67 | int index = pix.find('/'); | 67 | pm.convertFromImage(loadImage(pix)); |
68 | QString appName1 = qApp->argv()[0]; | 68 | QPixmapCache::insert(key,pm); |
69 | appName1 = appName1.replace(QRegExp(".*/"),""); | ||
70 | QString appName2 = pix.left(index); | ||
71 | |||
72 | if ( appName2 == "" || appName2 == pix || appName2 == "icons" ) | ||
73 | appName2 = "Global"; | ||
74 | |||
75 | QString appKey1 = "_QPE_" + appName1 + "_" + pix; | ||
76 | QString appKey2 = "_QPE_" + appName2 + "_" + pix.mid(index+1); | ||
77 | |||
78 | if ( !QPixmapCache::find(appKey1, pm) ) { | ||
79 | if ( !QPixmapCache::find(appKey2, pm) ) { | ||
80 | QImage img; | ||
81 | QString f = findPixmap( pix ); | ||
82 | if ( !f.isEmpty() ) { | ||
83 | img.load(f); | ||
84 | if ( !img.isNull() ) { | ||
85 | pm.convertFromImage(img); | ||
86 | if ( f.contains(appName1) ) { | ||
87 | QPixmapCache::insert( appKey1, pm); | ||
88 | } else { | ||
89 | QPixmapCache::insert( appKey2, pm); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | 69 | } |
95 | return pm; | 70 | return pm; |
96 | } | 71 | } |
97 | 72 | ||
98 | /*! | 73 | /*! |
99 | Returns the QBitmap called \a pix. You should avoid including | 74 | Returns the QBitmap called \a pix. You should avoid including |
100 | any filename type extension (e.g. .png, .xpm). | 75 | any filename type extension (e.g. .png, .xpm). |
101 | */ | 76 | */ |
102 | QBitmap Resource::loadBitmap( const QString &pix ) | 77 | QBitmap Resource::loadBitmap( const QString &pix ) |
103 | { | 78 | { |
104 | QBitmap bm; | 79 | QBitmap bm; |
105 | bm = loadPixmap(pix); | 80 | bm = loadPixmap(pix); |
106 | return bm; | 81 | return bm; |
107 | } | 82 | } |
108 | 83 | ||
109 | /*! | 84 | /*! |
110 | Returns the filename of a pixmap called \a pix. You should avoid including | 85 | Returns the filename of a pixmap called \a pix. You should avoid including |
111 | any filename type extension (e.g. .png, .xpm). | 86 | any filename type extension (e.g. .png, .xpm). |
112 | 87 | ||
113 | Normally you will use loadPixmap() rather than this function. | 88 | Normally you will use loadPixmap() rather than this function. |
114 | */ | 89 | */ |
115 | QString Resource::findPixmap( const QString &pix ) | 90 | QString Resource::findPixmap( const QString &pix ) |
116 | { | 91 | { |
117 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 92 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
118 | 93 | ||
119 | QString f; | 94 | QString f; |
120 | 95 | ||
121 | // Common case optimizations... | 96 | // Common case optimizations... |
122 | f = picsPath + pix + ".png"; | 97 | f = picsPath + pix + ".png"; |
123 | if ( QFile( f ).exists() ) | 98 | if ( QFile( f ).exists() ) |
124 | return f; | 99 | return f; |
125 | f = picsPath + pix + ".xpm"; | 100 | f = picsPath + pix + ".xpm"; |
126 | if ( QFile( f ).exists() ) | 101 | if ( QFile( f ).exists() ) |
127 | return f; | 102 | return f; |
128 | 103 | ||
129 | 104 | ||
130 | // All formats... | 105 | // All formats... |
131 | QStrList fileFormats = QImageIO::inputFormats(); | 106 | QStrList fileFormats = QImageIO::inputFormats(); |
132 | QString ff = fileFormats.first(); | 107 | QString ff = fileFormats.first(); |
133 | while ( fileFormats.current() ) { | 108 | while ( fileFormats.current() ) { |
134 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 109 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
135 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 110 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
136 | QString f = picsPath + pix + "." + *it; | 111 | QString f = picsPath + pix + "." + *it; |
137 | if ( QFile(f).exists() ) | 112 | if ( QFile(f).exists() ) |
138 | return f; | 113 | return f; |
139 | } | 114 | } |
140 | ff = fileFormats.next(); | 115 | ff = fileFormats.next(); |
141 | } | 116 | } |