summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.cpp7
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.h3
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h1
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp115
-rw-r--r--noncore/multimedia/opieplayer2/skin.h53
5 files changed, 148 insertions, 31 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp
index bbc60dd..963e783 100644
--- a/noncore/multimedia/opieplayer2/mediaplayer.cpp
+++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp
@@ -56,6 +56,11 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla
56 cfg.setGroup("PlayList"); 56 cfg.setGroup("PlayList");
57 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 57 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
58 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); 58 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() );
59
60 m_skinLoader = new SkinLoader;
61 m_skinLoader->schedule( AudioWidget::guiInfo() );
62 m_skinLoader->schedule( VideoWidget::guiInfo() );
63 m_skinLoader->start();
59} 64}
60 65
61MediaPlayer::~MediaPlayer() { 66MediaPlayer::~MediaPlayer() {
@@ -347,6 +352,8 @@ void MediaPlayer::cleanUp() {// this happens on closing
347 352
348void MediaPlayer::recreateAudioAndVideoWidgets() const 353void MediaPlayer::recreateAudioAndVideoWidgets() const
349{ 354{
355 delete m_skinLoader;
356
350 delete m_xineControl; 357 delete m_xineControl;
351 delete m_audioUI; 358 delete m_audioUI;
352 delete m_videoUI; 359 delete m_videoUI;
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.h b/noncore/multimedia/opieplayer2/mediaplayer.h
index 5975731..351c884 100644
--- a/noncore/multimedia/opieplayer2/mediaplayer.h
+++ b/noncore/multimedia/opieplayer2/mediaplayer.h
@@ -40,6 +40,7 @@
40#include "xinecontrol.h" 40#include "xinecontrol.h"
41 41
42#include "playlistwidget.h" 42#include "playlistwidget.h"
43#include "skin.h"
43 44
44class DocLnk; 45class DocLnk;
45class VolumeControl; 46class VolumeControl;
@@ -89,6 +90,8 @@ private:
89 mutable XineControl *m_xineControl; 90 mutable XineControl *m_xineControl;
90 mutable AudioWidget *m_audioUI; 91 mutable AudioWidget *m_audioUI;
91 mutable VideoWidget *m_videoUI; 92 mutable VideoWidget *m_videoUI;
93
94 QGuardedPtr<SkinLoader> m_skinLoader;
92}; 95};
93 96
94 97
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 40eb0af..45c46ea 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -91,6 +91,7 @@ public:
91 const SkinButtonInfo *buttonInfo; 91 const SkinButtonInfo *buttonInfo;
92 const uint buttonCount; 92 const uint buttonCount;
93 }; 93 };
94 typedef QValueList<GUIInfo> GUIInfoList;
94 95
95 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 96 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
96 virtual ~MediaWidget(); 97 virtual ~MediaWidget();
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
217SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info )
218 : m_skin( info.skinName, info.fileNameInfix ), m_info( info )
219{
220 m_currentState = LoadBackgroundImage;
221}
222
223SkinLoader::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
212SkinLoader::SkinLoader() 260SkinLoader::SkinLoader()
261 : m_currentLoader( 0 ), m_timerId( -1 )
213{ 262{
214} 263}
215 264
216void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, 265SkinLoader::~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 ); 272void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo )
273{
274 schedule( Skin::defaultSkinName(), guiInfo );
222} 275}
223 276
224void SkinLoader::run() 277void 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
232void SkinLoader::load( const Info &nfo ) 282void 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 ); 289void 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
322void SkinLoader::deleteMe()
323{
324 delete this;
238} 325}
239 326
240/* vim: et sw=4 ts=4 327/* vim: et sw=4 ts=4
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index 9180067..a43a1d0 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -25,9 +25,9 @@
25 25
26#include <qstring.h> 26#include <qstring.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qobject.h>
28 29
29#include "mediawidget.h" 30#include "mediawidget.h"
30#include "threadutil.h"
31 31
32struct SkinData; 32struct SkinData;
33 33
@@ -66,38 +66,57 @@ private:
66 Skin &operator=( const Skin & ); 66 Skin &operator=( const Skin & );
67}; 67};
68 68
69class SkinLoader : public ThreadUtil::Thread 69class SkinLoader : public QObject
70{ 70{
71 Q_OBJECT
71public: 72public:
72 SkinLoader(); 73 SkinLoader();
74 virtual ~SkinLoader();
73 75
74 void schedule( const QString &skinName, const QString &fileNameInfix, 76 void schedule( const MediaWidget::GUIInfo &guiInfo );
75 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); 77 void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo );
78
79 void start();
76 80
77protected: 81protected:
78 virtual void run(); 82 virtual void timerEvent( QTimerEvent *ev );
83
84private slots:
85 void deleteMe();
79 86
80private: 87private:
81 struct Info 88 struct Info : public MediaWidget::GUIInfo
82 { 89 {
83 Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} 90 Info() {}
84 Info( const QString &_skinName, const QString &_fileNameInfix, 91 Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo )
85 const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) 92 : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName )
86 : skinName( _skinName ), fileNameInfix( _fileNameInfix ),
87 skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount )
88 {} 93 {}
89 94
90 const QString skinName; 95 QString skinName;
91 const QString fileNameInfix;
92 const MediaWidget::SkinButtonInfo *skinButtonInfo;
93 const uint buttonCount;
94 }; 96 };
95 typedef QValueList<Info> InfoList; 97 typedef QValueList<Info> InfoList;
96 98
97 void load( const Info &nfo ); 99 class IncrementalLoader
100 {
101 public:
102 enum LoaderResult { LoadingCompleted, MoreToCome };
103
104 IncrementalLoader( const Info &info );
105
106 LoaderResult loadStep();
107
108 private:
109 enum State { LoadBackgroundImage, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask };
110
111 Skin m_skin;
112 Info m_info;
113 State m_currentState;
114 uint m_currentButton;
115 };
98 116
99 InfoList pendingSkins; 117 InfoList pendingSkins;
100 ThreadUtil::Mutex guard; 118 IncrementalLoader *m_currentLoader;
119 int m_timerId;
101}; 120};
102 121
103#endif // SKIN_H 122#endif // SKIN_H