summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 5013bb4..0f49862 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -55,6 +55,9 @@ private:
55 typedef QCache<SkinData> DataCache; 55 typedef QCache<SkinData> DataCache;
56 typedef QCache<QPixmap> BackgroundPixmapCache; 56 typedef QCache<QImage> BackgroundImageCache;
57
58 template <class CacheType>
59 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data );
57 60
58 DataCache m_cache; 61 DataCache m_cache;
59 BackgroundPixmapCache m_backgroundPixmapCache; 62 BackgroundImageCache m_backgroundImageCache;
60}; 63};
@@ -168,2 +171,6 @@ SkinCache::SkinCache()
168{ 171{
172 // let's say we cache two skins (audio+video) at maximum
173 m_cache.setMaxCost( 2 );
174 // ... and one background pixmap
175 m_backgroundImageCache.setMaxCost( 1 );
169} 176}
@@ -172,3 +179,15 @@ SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &file
172{ 179{
173 return new SkinData; 180 QString key = skinPath + fileNameInfix;
181
182 SkinData *data = m_cache.take( key );
183 if ( !data )
184 data = new SkinData;
185
186 QImage *bgImage = m_backgroundImageCache.find( skinPath );
187 if ( bgImage )
188 data->backgroundImage = *bgImage;
189 else
190 data->backgroundImage = QImage();
191
192 return data;
174} 193}
@@ -177,3 +196,15 @@ void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, Sk
177{ 196{
178 delete data; 197 QImage *backgroundImage = new QImage( data->backgroundImage );
198
199 data->backgroundImage = QImage();
200
201 QString key = skinPath + fileNameInfix;
202
203 if ( m_cache.find( key, false /*ref*/ ) != 0 ||
204 !m_cache.insert( key, data ) )
205 delete data;
206
207 if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 ||
208 !m_backgroundImageCache.insert( skinPath, backgroundImage ) )
209 delete backgroundImage;
179} 210}