Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 115 |
1 files changed, 101 insertions, 14 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 0f49862..e9fb5a6 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <qcache.h> | 26 | #include <qcache.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | #include <qtimer.h> | ||
28 | 29 | ||
29 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
30 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
@@ -182,10 +183,14 @@ SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &file | |||
182 | SkinData *data = m_cache.take( key ); | 183 | SkinData *data = m_cache.take( key ); |
183 | if ( !data ) | 184 | if ( !data ) |
184 | data = new SkinData; | 185 | data = new SkinData; |
186 | else | ||
187 | qDebug( "SkinCache: hit" ); | ||
185 | 188 | ||
186 | QImage *bgImage = m_backgroundImageCache.find( skinPath ); | 189 | QImage *bgImage = m_backgroundImageCache.find( skinPath ); |
187 | if ( bgImage ) | 190 | if ( bgImage ) { |
191 | qDebug( "SkinCache: hit on bgimage" ); | ||
188 | data->backgroundImage = *bgImage; | 192 | data->backgroundImage = *bgImage; |
193 | } | ||
189 | else | 194 | else |
190 | data->backgroundImage = QImage(); | 195 | data->backgroundImage = QImage(); |
191 | 196 | ||
@@ -209,32 +214,114 @@ void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, Sk | |||
209 | delete backgroundImage; | 214 | delete backgroundImage; |
210 | } | 215 | } |
211 | 216 | ||
217 | SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) | ||
218 | : m_skin( info.skinName, info.fileNameInfix ), m_info( info ) | ||
219 | { | ||
220 | m_currentState = LoadBackgroundImage; | ||
221 | } | ||
222 | |||
223 | SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() | ||
224 | { | ||
225 | switch ( m_currentState ) { | ||
226 | case LoadBackgroundImage: | ||
227 | qDebug( "load bgimage" ); | ||
228 | m_skin.backgroundImage(); | ||
229 | m_currentState = LoadButtonUpImage; | ||
230 | break; | ||
231 | case LoadButtonUpImage: | ||
232 | qDebug( "load upimage" ); | ||
233 | m_skin.buttonUpImage(); | ||
234 | m_currentState = LoadButtonDownImage; | ||
235 | break; | ||
236 | case LoadButtonDownImage: | ||
237 | qDebug( "load downimage" ); | ||
238 | m_skin.buttonDownImage(); | ||
239 | m_currentState = LoadButtonMasks; | ||
240 | m_currentButton = 0; | ||
241 | break; | ||
242 | case LoadButtonMasks: | ||
243 | qDebug( "load button masks %i", m_currentButton ); | ||
244 | m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName ); | ||
245 | |||
246 | m_currentButton++; | ||
247 | if ( m_currentButton >= m_info.buttonCount ) | ||
248 | m_currentState = LoadButtonMask; | ||
249 | |||
250 | break; | ||
251 | case LoadButtonMask: | ||
252 | qDebug( "load whole mask" ); | ||
253 | m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount ); | ||
254 | return LoadingCompleted; | ||
255 | } | ||
256 | |||
257 | return MoreToCome; | ||
258 | } | ||
259 | |||
212 | SkinLoader::SkinLoader() | 260 | SkinLoader::SkinLoader() |
261 | : m_currentLoader( 0 ), m_timerId( -1 ) | ||
213 | { | 262 | { |
214 | } | 263 | } |
215 | 264 | ||
216 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, | 265 | SkinLoader::~SkinLoader() |
217 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) | ||
218 | { | 266 | { |
219 | assert( isRunning() == false ); | 267 | qDebug( "SkinLoader::~SkinLoader()" ); |
268 | killTimers(); | ||
269 | delete m_currentLoader; | ||
270 | } | ||
220 | 271 | ||
221 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); | 272 | void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo ) |
273 | { | ||
274 | schedule( Skin::defaultSkinName(), guiInfo ); | ||
222 | } | 275 | } |
223 | 276 | ||
224 | void SkinLoader::run() | 277 | void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ) |
225 | { | 278 | { |
226 | qDebug( "SkinLoader::run()" ); | 279 | pendingSkins << Info( skinName, guiInfo ); |
227 | for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) | ||
228 | load( *it ); | ||
229 | qDebug( "SkinLoader is done." ); | ||
230 | } | 280 | } |
231 | 281 | ||
232 | void SkinLoader::load( const Info &nfo ) | 282 | void SkinLoader::start() |
233 | { | 283 | { |
234 | qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); | 284 | assert( m_timerId == -1 ); |
285 | m_timerId = startTimer( 100 /* ms */ ); | ||
286 | qDebug( "SkinLoader::start() %d jobs", pendingSkins.count() ); | ||
287 | } | ||
235 | 288 | ||
236 | Skin skin( nfo.skinName, nfo.fileNameInfix ); | 289 | void SkinLoader::timerEvent( QTimerEvent *ev ) |
237 | skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); | 290 | { |
291 | if ( ev->timerId() != m_timerId ) { | ||
292 | QObject::timerEvent( ev ); | ||
293 | return; | ||
294 | } | ||
295 | |||
296 | if ( !m_currentLoader ) { | ||
297 | |||
298 | if ( pendingSkins.isEmpty() ) { | ||
299 | qDebug( "all jobs done" ); | ||
300 | killTimer( m_timerId ); | ||
301 | m_timerId = -1; | ||
302 | // ### qt3: use deleteLater(); | ||
303 | QTimer::singleShot( 0, this, SLOT( deleteMe() ) ); | ||
304 | return; | ||
305 | } | ||
306 | |||
307 | Info nfo = *pendingSkins.begin(); | ||
308 | pendingSkins.remove( pendingSkins.begin() ); | ||
309 | |||
310 | m_currentLoader = new IncrementalLoader( nfo ); | ||
311 | qDebug( "new loader %i jobs left", pendingSkins.count() ); | ||
312 | } | ||
313 | |||
314 | if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) { | ||
315 | delete m_currentLoader; | ||
316 | m_currentLoader = 0; | ||
317 | } | ||
318 | |||
319 | qDebug( "finished step" ); | ||
320 | } | ||
321 | |||
322 | void SkinLoader::deleteMe() | ||
323 | { | ||
324 | delete this; | ||
238 | } | 325 | } |
239 | 326 | ||
240 | /* vim: et sw=4 ts=4 | 327 | /* vim: et sw=4 ts=4 |