-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 35 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 2 |
2 files changed, 17 insertions, 20 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index d2e3b00..5013bb4 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -14,76 +14,81 @@ | |||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | General Public License for more details. | 15 | General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; see the file COPYING. If not, write to | 18 | along with this program; see the file COPYING. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include "skin.h" | 23 | #include "skin.h" |
24 | #include "singleton.h" | 24 | #include "singleton.h" |
25 | 25 | ||
26 | #include <qcache.h> | ||
27 | #include <qmap.h> | ||
28 | |||
26 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
28 | 31 | ||
29 | #include <assert.h> | 32 | #include <assert.h> |
30 | 33 | ||
31 | struct SkinData | 34 | struct SkinData |
32 | { | 35 | { |
33 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 36 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
34 | 37 | ||
35 | QImage backgroundImage; | 38 | QImage backgroundImage; |
36 | QImage buttonUpImage; | 39 | QImage buttonUpImage; |
37 | QImage buttonDownImage; | 40 | QImage buttonDownImage; |
38 | QImage buttonMask; | 41 | QImage buttonMask; |
39 | ButtonMaskImageMap buttonMasks; | 42 | ButtonMaskImageMap buttonMasks; |
40 | }; | 43 | }; |
41 | 44 | ||
42 | class SkinCache : public Singleton<SkinCache> | 45 | class SkinCache : public Singleton<SkinCache> |
43 | { | 46 | { |
44 | public: | 47 | public: |
45 | SkinCache(); | 48 | SkinCache(); |
46 | 49 | ||
47 | QImage loadImage( const QString &name ); | 50 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); |
48 | 51 | ||
49 | private: | 52 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); |
50 | typedef QDict<QImage> ImageCache; | ||
51 | 53 | ||
52 | ImageCache m_cache; | 54 | private: |
55 | typedef QCache<SkinData> DataCache; | ||
56 | typedef QCache<QPixmap> BackgroundPixmapCache; | ||
53 | 57 | ||
54 | ThreadUtil::Mutex m_cacheGuard; | 58 | DataCache m_cache; |
59 | BackgroundPixmapCache m_backgroundPixmapCache; | ||
55 | }; | 60 | }; |
56 | 61 | ||
57 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 62 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
58 | : m_fileNameInfix( fileNameInfix ) | 63 | : m_fileNameInfix( fileNameInfix ) |
59 | { | 64 | { |
60 | init( name ); | 65 | init( name ); |
61 | } | 66 | } |
62 | 67 | ||
63 | Skin::Skin( const QString &fileNameInfix ) | 68 | Skin::Skin( const QString &fileNameInfix ) |
64 | : m_fileNameInfix( fileNameInfix ) | 69 | : m_fileNameInfix( fileNameInfix ) |
65 | { | 70 | { |
66 | init( defaultSkinName() ); | 71 | init( defaultSkinName() ); |
67 | } | 72 | } |
68 | 73 | ||
69 | Skin::~Skin() | 74 | Skin::~Skin() |
70 | { | 75 | { |
71 | delete d; | 76 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); |
72 | } | 77 | } |
73 | 78 | ||
74 | void Skin::init( const QString &name ) | 79 | void Skin::init( const QString &name ) |
75 | { | 80 | { |
76 | m_skinPath = "opieplayer2/skins/" + name; | 81 | m_skinPath = "opieplayer2/skins/" + name; |
77 | d = new SkinData; | 82 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); |
78 | } | 83 | } |
79 | 84 | ||
80 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 85 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) |
81 | { | 86 | { |
82 | backgroundImage(); | 87 | backgroundImage(); |
83 | buttonUpImage(); | 88 | buttonUpImage(); |
84 | buttonDownImage(); | 89 | buttonDownImage(); |
85 | ( void )buttonMask( skinButtonInfo, buttonCount ); | 90 | ( void )buttonMask( skinButtonInfo, buttonCount ); |
86 | } | 91 | } |
87 | 92 | ||
88 | QImage Skin::backgroundImage() const | 93 | QImage Skin::backgroundImage() const |
89 | { | 94 | { |
@@ -152,40 +157,34 @@ QString Skin::defaultSkinName() | |||
152 | Config cfg( "OpiePlayer" ); | 157 | Config cfg( "OpiePlayer" ); |
153 | cfg.setGroup( "Options" ); | 158 | cfg.setGroup( "Options" ); |
154 | return cfg.readEntry( "Skin", "default" ); | 159 | return cfg.readEntry( "Skin", "default" ); |
155 | } | 160 | } |
156 | 161 | ||
157 | QImage Skin::loadImage( const QString &fileName ) | 162 | QImage Skin::loadImage( const QString &fileName ) |
158 | { | 163 | { |
159 | return QImage( Resource::findPixmap( fileName ) ); | 164 | return QImage( Resource::findPixmap( fileName ) ); |
160 | } | 165 | } |
161 | 166 | ||
162 | SkinCache::SkinCache() | 167 | SkinCache::SkinCache() |
163 | { | 168 | { |
164 | m_cache.setAutoDelete( true ); | ||
165 | } | 169 | } |
166 | 170 | ||
167 | QImage SkinCache::loadImage( const QString &name ) | 171 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) |
168 | { | 172 | { |
169 | ThreadUtil::AutoLock lock( m_cacheGuard ); | 173 | return new SkinData; |
170 | |||
171 | QImage *image = m_cache.find( name ); | ||
172 | if ( image ) { | ||
173 | qDebug( "cache hit for %s", name.ascii() ); | ||
174 | return *image; | ||
175 | } | 174 | } |
176 | 175 | ||
177 | image = new QImage( Resource::findPixmap( name ) ); | 176 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) |
178 | m_cache.insert( name, image ); | 177 | { |
179 | return *image; | 178 | delete data; |
180 | } | 179 | } |
181 | 180 | ||
182 | SkinLoader::SkinLoader() | 181 | SkinLoader::SkinLoader() |
183 | { | 182 | { |
184 | } | 183 | } |
185 | 184 | ||
186 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, | 185 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, |
187 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) | 186 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) |
188 | { | 187 | { |
189 | assert( isRunning() == false ); | 188 | assert( isRunning() == false ); |
190 | 189 | ||
191 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); | 190 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); |
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index e55832c..9180067 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -16,26 +16,24 @@ | |||
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; see the file COPYING. If not, write to | 18 | along with this program; see the file COPYING. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #ifndef SKIN_H | 23 | #ifndef SKIN_H |
24 | #define SKIN_H | 24 | #define SKIN_H |
25 | 25 | ||
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qimage.h> | 27 | #include <qimage.h> |
28 | #include <qmap.h> | ||
29 | #include <qdict.h> | ||
30 | 28 | ||
31 | #include "mediawidget.h" | 29 | #include "mediawidget.h" |
32 | #include "threadutil.h" | 30 | #include "threadutil.h" |
33 | 31 | ||
34 | struct SkinData; | 32 | struct SkinData; |
35 | 33 | ||
36 | class Skin | 34 | class Skin |
37 | { | 35 | { |
38 | public: | 36 | public: |
39 | Skin( const QString &name, const QString &fileNameInfix ); | 37 | Skin( const QString &name, const QString &fileNameInfix ); |
40 | Skin( const QString &fileNameInfix ); | 38 | Skin( const QString &fileNameInfix ); |
41 | ~Skin(); | 39 | ~Skin(); |