author | simon <simon> | 2002-12-11 23:12:16 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 23:12:16 (UTC) |
commit | d4a0626f01fae21ed19d0eea88d8eca1935c6bc8 (patch) (unidiff) | |
tree | 9747bdd478c1bd93f46eaa49c95381404a6fd55b | |
parent | 8d5ae95e770bc387420fc094c54d8ac55e64e04b (diff) | |
download | opie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.zip opie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.tar.gz opie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.tar.bz2 |
- skins are now pre-loaded in the background (step by step)
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 115 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 53 |
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 | |||
@@ -57,4 +57,9 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla | |||
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 | ||
@@ -348,4 +353,6 @@ void MediaPlayer::cleanUp() {// this happens on closing | |||
348 | void MediaPlayer::recreateAudioAndVideoWidgets() const | 353 | void 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; |
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 | |||
@@ -41,4 +41,5 @@ | |||
41 | 41 | ||
42 | #include "playlistwidget.h" | 42 | #include "playlistwidget.h" |
43 | #include "skin.h" | ||
43 | 44 | ||
44 | class DocLnk; | 45 | class DocLnk; |
@@ -90,4 +91,6 @@ private: | |||
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 | ||
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 | |||
@@ -92,4 +92,5 @@ public: | |||
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 ); |
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 | |||
@@ -26,4 +26,5 @@ | |||
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> |
@@ -183,8 +184,12 @@ SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &file | |||
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(); |
@@ -210,30 +215,112 @@ void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, Sk | |||
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 | ||
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 | |||
@@ -26,7 +26,7 @@ | |||
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 | ||
32 | struct SkinData; | 32 | struct SkinData; |
@@ -67,36 +67,55 @@ private: | |||
67 | }; | 67 | }; |
68 | 68 | ||
69 | class SkinLoader : public ThreadUtil::Thread | 69 | class SkinLoader : public QObject |
70 | { | 70 | { |
71 | Q_OBJECT | ||
71 | public: | 72 | public: |
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 | ||
77 | protected: | 81 | protected: |
78 | virtual void run(); | 82 | virtual void timerEvent( QTimerEvent *ev ); |
83 | |||
84 | private slots: | ||
85 | void deleteMe(); | ||
79 | 86 | ||
80 | private: | 87 | private: |
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 | ||