summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 44f5ca2..742e495 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -21,257 +21,257 @@
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> 26#include <qcache.h>
27#include <qmap.h> 27#include <qmap.h>
28#include <qtimer.h> 28#include <qtimer.h>
29 29
30#include <qpe/resource.h> 30#include <qpe/resource.h>
31#include <qpe/config.h> 31#include <qpe/config.h>
32 32
33#include <assert.h> 33#include <assert.h>
34 34
35struct SkinData 35struct SkinData
36{ 36{
37 typedef QMap<QString, QImage> ButtonMaskImageMap; 37 typedef QMap<QString, QImage> ButtonMaskImageMap;
38 38
39 QPixmap backgroundPixmap; 39 QPixmap backgroundPixmap;
40 QImage buttonUpImage; 40 QImage buttonUpImage;
41 QImage buttonDownImage; 41 QImage buttonDownImage;
42 QImage buttonMask; 42 QImage buttonMask;
43 ButtonMaskImageMap buttonMasks; 43 ButtonMaskImageMap buttonMasks;
44}; 44};
45 45
46class SkinCache : public Singleton<SkinCache> 46class SkinCache : public Singleton<SkinCache>
47{ 47{
48public: 48public:
49 SkinCache(); 49 SkinCache();
50 50
51 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); 51 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
52 52
53 void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); 53 void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data );
54 54
55private: 55private:
56 typedef QCache<SkinData> DataCache; 56 typedef QCache<SkinData> DataCache;
57 typedef QCache<QPixmap> BackgroundPixmapCache; 57 typedef QCache<QPixmap> BackgroundPixmapCache;
58 58
59 template <class CacheType> 59 template <class CacheType>
60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); 60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data );
61 61
62 DataCache m_cache; 62 DataCache m_cache;
63 BackgroundPixmapCache m_backgroundPixmapCache; 63 BackgroundPixmapCache m_backgroundPixmapCache;
64}; 64};
65 65
66Skin::Skin( const QString &name, const QString &fileNameInfix ) 66Skin::Skin( const QString &name, const QString &fileNameInfix )
67 : m_fileNameInfix( fileNameInfix ) 67 : m_fileNameInfix( fileNameInfix )
68{ 68{
69 init( name ); 69 init( name );
70} 70}
71 71
72Skin::Skin( const QString &fileNameInfix ) 72Skin::Skin( const QString &fileNameInfix )
73 : m_fileNameInfix( fileNameInfix ) 73 : m_fileNameInfix( fileNameInfix )
74{ 74{
75 init( defaultSkinName() ); 75 init( defaultSkinName() );
76} 76}
77 77
78Skin::~Skin() 78Skin::~Skin()
79{ 79{
80 if ( m_isCachable ) 80 if ( m_isCachable )
81 SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); 81 SkinCache::self().store( m_skinPath, m_fileNameInfix, d );
82 else 82 else
83 delete d; 83 delete d;
84} 84}
85 85
86void Skin::init( const QString &name ) 86void Skin::init( const QString &name )
87{ 87{
88 m_isCachable = true; 88 m_isCachable = true;
89 m_skinPath = "opieplayer2/skins/" + name; 89 m_skinPath = "opieplayer2/skins/" + name;
90 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); 90 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix );
91} 91}
92 92
93QPixmap Skin::backgroundPixmap() const 93QPixmap Skin::backgroundPixmap() const
94{ 94{
95 if ( d->backgroundPixmap.isNull() ) 95 if ( d->backgroundPixmap.isNull() )
96 d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 96 d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
97 return d->backgroundPixmap; 97 return d->backgroundPixmap;
98} 98}
99 99
100QImage Skin::buttonUpImage() const 100QImage Skin::buttonUpImage() const
101{ 101{
102 if ( d->buttonUpImage.isNull() ) 102 if ( d->buttonUpImage.isNull() )
103 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 103 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
104 return d->buttonUpImage; 104 return d->buttonUpImage;
105} 105}
106 106
107QImage Skin::buttonDownImage() const 107QImage Skin::buttonDownImage() const
108{ 108{
109 if ( d->buttonDownImage.isNull() ) 109 if ( d->buttonDownImage.isNull() )
110 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 110 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
111 return d->buttonDownImage; 111 return d->buttonDownImage;
112} 112}
113 113
114QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const 114QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const
115{ 115{
116 if ( !d->buttonMask.isNull() ) 116 if ( !d->buttonMask.isNull() )
117 return d->buttonMask; 117 return d->buttonMask;
118 118
119 QSize buttonAreaSize = buttonUpImage().size(); 119 QSize buttonAreaSize = buttonUpImage().size();
120 120
121 d->buttonMask = QImage( buttonAreaSize, 8, 255 ); 121 d->buttonMask = QImage( buttonAreaSize, 8, 255 );
122 d->buttonMask.fill( 0 ); 122 d->buttonMask.fill( 0 );
123 123
124 for ( uint i = 0; i < buttonCount; ++i ) 124 for ( uint i = 0; i < buttonCount; ++i )
125 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); 125 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) );
126 126
127 return d->buttonMask; 127 return d->buttonMask;
128} 128}
129 129
130void Skin::addButtonToMask( int tag, const QImage &maskImage ) const 130void Skin::addButtonToMask( int tag, const QImage &maskImage ) const
131{ 131{
132 if ( maskImage.isNull() ) 132 if ( maskImage.isNull() )
133 return; 133 return;
134 134
135 uchar **dest = d->buttonMask.jumpTable(); 135 uchar **dest = d->buttonMask.jumpTable();
136 for ( int y = 0; y < d->buttonMask.height(); y++ ) { 136 for ( int y = 0; y < d->buttonMask.height(); y++ ) {
137 uchar *line = dest[y]; 137 uchar *line = dest[y];
138 for ( int x = 0; x < d->buttonMask.width(); x++ ) 138 for ( int x = 0; x < d->buttonMask.width(); x++ )
139 if ( !qRed( maskImage.pixel( x, y ) ) ) 139 if ( !qRed( maskImage.pixel( x, y ) ) )
140 line[x] = tag; 140 line[x] = tag;
141 } 141 }
142} 142}
143 143
144QImage Skin::buttonMaskImage( const QString &fileName ) const 144QImage Skin::buttonMaskImage( const QString &fileName ) const
145{ 145{
146 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); 146 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName );
147 if ( it == d->buttonMasks.end() ) { 147 if ( it == d->buttonMasks.end() ) {
148 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); 148 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
149 QString path = prefix + fileName + ".png"; 149 QString path = prefix + fileName;
150 it = d->buttonMasks.insert( fileName, loadImage( path ) ); 150 it = d->buttonMasks.insert( fileName, loadImage( path ) );
151 } 151 }
152 return *it; 152 return *it;
153} 153}
154 154
155QString Skin::defaultSkinName() 155QString Skin::defaultSkinName()
156{ 156{
157 Config cfg( "OpiePlayer" ); 157 Config cfg( "OpiePlayer" );
158 cfg.setGroup( "Options" ); 158 cfg.setGroup( "Options" );
159 return cfg.readEntry( "Skin", "default" ); 159 return cfg.readEntry( "Skin", "default" );
160} 160}
161 161
162QImage Skin::loadImage( const QString &fileName ) 162QImage Skin::loadImage( const QString &fileName )
163{ 163{
164 return QImage( Resource::findPixmap( fileName ) ); 164 return QImage( Resource::findPixmap( fileName ) );
165} 165}
166 166
167SkinCache::SkinCache() 167SkinCache::SkinCache()
168{ 168{
169 // let's say we cache two skins (audio+video) at maximum 169 // let's say we cache two skins (audio+video) at maximum
170 m_cache.setMaxCost( 2 ); 170 m_cache.setMaxCost( 2 );
171 // ... and one background pixmap 171 // ... and one background pixmap
172 m_backgroundPixmapCache.setMaxCost( 1 ); 172 m_backgroundPixmapCache.setMaxCost( 1 );
173} 173}
174 174
175SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) 175SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
176{ 176{
177 QString key = skinPath + fileNameInfix; 177 QString key = skinPath + fileNameInfix;
178 178
179 SkinData *data = m_cache.take( key ); 179 SkinData *data = m_cache.take( key );
180 if ( !data ) 180 if ( !data )
181 data = new SkinData; 181 data = new SkinData;
182 else 182 else
183 qDebug( "SkinCache: hit" ); 183 qDebug( "SkinCache: hit" );
184 184
185 QPixmap *bgPixmap = m_backgroundPixmapCache.find( skinPath ); 185 QPixmap *bgPixmap = m_backgroundPixmapCache.find( skinPath );
186 if ( bgPixmap ) { 186 if ( bgPixmap ) {
187 qDebug( "SkinCache: hit on bgpixmap" ); 187 qDebug( "SkinCache: hit on bgpixmap" );
188 data->backgroundPixmap = *bgPixmap; 188 data->backgroundPixmap = *bgPixmap;
189 } 189 }
190 else 190 else
191 data->backgroundPixmap = QPixmap(); 191 data->backgroundPixmap = QPixmap();
192 192
193 return data; 193 return data;
194} 194}
195 195
196void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) 196void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
197{ 197{
198 QPixmap *backgroundPixmap = new QPixmap( data->backgroundPixmap ); 198 QPixmap *backgroundPixmap = new QPixmap( data->backgroundPixmap );
199 199
200 data->backgroundPixmap = QPixmap(); 200 data->backgroundPixmap = QPixmap();
201 201
202 QString key = skinPath + fileNameInfix; 202 QString key = skinPath + fileNameInfix;
203 203
204 if ( m_cache.find( key, false /*ref*/ ) != 0 || 204 if ( m_cache.find( key, false /*ref*/ ) != 0 ||
205 !m_cache.insert( key, data ) ) 205 !m_cache.insert( key, data ) )
206 delete data; 206 delete data;
207 207
208 if ( m_backgroundPixmapCache.find( skinPath, false /*ref*/ ) != 0 || 208 if ( m_backgroundPixmapCache.find( skinPath, false /*ref*/ ) != 0 ||
209 !m_backgroundPixmapCache.insert( skinPath, backgroundPixmap ) ) 209 !m_backgroundPixmapCache.insert( skinPath, backgroundPixmap ) )
210 delete backgroundPixmap; 210 delete backgroundPixmap;
211} 211}
212 212
213SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) 213SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info )
214 : m_skin( info.skinName, info.fileNameInfix ), m_info( info ) 214 : m_skin( info.skinName, info.fileNameInfix ), m_info( info )
215{ 215{
216 m_currentState = LoadBackgroundPixmap; 216 m_currentState = LoadBackgroundPixmap;
217} 217}
218 218
219SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() 219SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep()
220{ 220{
221 switch ( m_currentState ) { 221 switch ( m_currentState ) {
222 case LoadBackgroundPixmap: 222 case LoadBackgroundPixmap:
223 qDebug( "load bgpixmap" ); 223 qDebug( "load bgpixmap" );
224 m_skin.backgroundPixmap(); 224 m_skin.backgroundPixmap();
225 m_currentState = LoadButtonUpImage; 225 m_currentState = LoadButtonUpImage;
226 break; 226 break;
227 case LoadButtonUpImage: 227 case LoadButtonUpImage:
228 qDebug( "load upimage" ); 228 qDebug( "load upimage" );
229 m_skin.buttonUpImage(); 229 m_skin.buttonUpImage();
230 m_currentState = LoadButtonDownImage; 230 m_currentState = LoadButtonDownImage;
231 break; 231 break;
232 case LoadButtonDownImage: 232 case LoadButtonDownImage:
233 qDebug( "load downimage" ); 233 qDebug( "load downimage" );
234 m_skin.buttonDownImage(); 234 m_skin.buttonDownImage();
235 m_currentState = LoadButtonMasks; 235 m_currentState = LoadButtonMasks;
236 m_currentButton = 0; 236 m_currentButton = 0;
237 break; 237 break;
238 case LoadButtonMasks: 238 case LoadButtonMasks:
239 qDebug( "load button masks %i", m_currentButton ); 239 qDebug( "load button masks %i", m_currentButton );
240 m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName ); 240 m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName );
241 241
242 m_currentButton++; 242 m_currentButton++;
243 if ( m_currentButton >= m_info.buttonCount ) 243 if ( m_currentButton >= m_info.buttonCount )
244 m_currentState = LoadButtonMask; 244 m_currentState = LoadButtonMask;
245 245
246 break; 246 break;
247 case LoadButtonMask: 247 case LoadButtonMask:
248 qDebug( "load whole mask" ); 248 qDebug( "load whole mask" );
249 m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount ); 249 m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount );
250 return LoadingCompleted; 250 return LoadingCompleted;
251 } 251 }
252 252
253 return MoreToCome; 253 return MoreToCome;
254} 254}
255 255
256SkinLoader::SkinLoader() 256SkinLoader::SkinLoader()
257 : m_currentLoader( 0 ), m_timerId( -1 ) 257 : m_currentLoader( 0 ), m_timerId( -1 )
258{ 258{
259} 259}
260 260
261SkinLoader::~SkinLoader() 261SkinLoader::~SkinLoader()
262{ 262{
263 qDebug( "SkinLoader::~SkinLoader()" ); 263 qDebug( "SkinLoader::~SkinLoader()" );
264 killTimers(); 264 killTimers();
265 delete m_currentLoader; 265 delete m_currentLoader;
266} 266}
267 267
268void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo ) 268void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo )
269{ 269{
270 schedule( Skin::defaultSkinName(), guiInfo ); 270 schedule( Skin::defaultSkinName(), guiInfo );
271} 271}
272 272
273void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ) 273void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo )
274{ 274{
275 pendingSkins << Info( skinName, guiInfo ); 275 pendingSkins << Info( skinName, guiInfo );
276} 276}
277 277