-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 39 |
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 | |||
@@ -53,10 +53,13 @@ public: | |||
53 | 53 | ||
54 | private: | 54 | 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 | }; |
61 | 64 | ||
62 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 65 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
@@ -166,16 +169,44 @@ QImage Skin::loadImage( const QString &fileName ) | |||
166 | 169 | ||
167 | SkinCache::SkinCache() | 170 | 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 | } |
170 | 177 | ||
171 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) | 178 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) |
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 | } |
175 | 194 | ||
176 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) | 195 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) |
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 | } |
180 | 211 | ||
181 | SkinLoader::SkinLoader() | 212 | SkinLoader::SkinLoader() |