summaryrefslogtreecommitdiff
path: root/library/resource.cpp
Unidiff
Diffstat (limited to 'library/resource.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/resource.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/library/resource.cpp b/library/resource.cpp
index cfa0d26..43fdc60 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -33,68 +33,93 @@ namespace {
33#include "inlinepics_p.h" 33#include "inlinepics_p.h"
34} 34}
35 35
36static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); 36static 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*/
62QPixmap Resource::loadPixmap( const QString &pix ) 62QPixmap Resource::loadPixmap( const QString &pix )
63{ 63{
64 QPixmap pm; 64 QPixmap pm;
65 QString key="QPE_"+pix; 65
66 if ( !QPixmapCache::find(key,pm) ) { 66 // Give the pixmaps some kind of namespace in the pixmapcache
67 pm.convertFromImage(loadImage(pix)); 67 int index = pix.find('/');
68 QPixmapCache::insert(key,pm); 68 QString appName1 = qApp->argv()[0];
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 }
69 } 94 }
70 return pm; 95 return pm;
71} 96}
72 97
73/*! 98/*!
74 Returns the QBitmap called \a pix. You should avoid including 99 Returns the QBitmap called \a pix. You should avoid including
75 any filename type extension (e.g. .png, .xpm). 100 any filename type extension (e.g. .png, .xpm).
76*/ 101*/
77QBitmap Resource::loadBitmap( const QString &pix ) 102QBitmap Resource::loadBitmap( const QString &pix )
78{ 103{
79 QBitmap bm; 104 QBitmap bm;
80 bm = loadPixmap(pix); 105 bm = loadPixmap(pix);
81 return bm; 106 return bm;
82} 107}
83 108
84/*! 109/*!
85 Returns the filename of a pixmap called \a pix. You should avoid including 110 Returns the filename of a pixmap called \a pix. You should avoid including
86 any filename type extension (e.g. .png, .xpm). 111 any filename type extension (e.g. .png, .xpm).
87 112
88 Normally you will use loadPixmap() rather than this function. 113 Normally you will use loadPixmap() rather than this function.
89*/ 114*/
90QString Resource::findPixmap( const QString &pix ) 115QString Resource::findPixmap( const QString &pix )
91{ 116{
92 QString picsPath = QPEApplication::qpeDir() + "pics/"; 117 QString picsPath = QPEApplication::qpeDir() + "pics/";
93 118
94 QString f; 119 QString f;
95 120
96 // Common case optimizations... 121 // Common case optimizations...
97 f = picsPath + pix + ".png"; 122 f = picsPath + pix + ".png";
98 if ( QFile( f ).exists() ) 123 if ( QFile( f ).exists() )
99 return f; 124 return f;
100 f = picsPath + pix + ".xpm"; 125 f = picsPath + pix + ".xpm";