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
@@ -35,48 +35,53 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla
35 m_videoUI = 0; 35 m_videoUI = 0;
36 m_xineControl = 0; 36 m_xineControl = 0;
37 37
38 fd=-1;fl=-1; 38 fd=-1;fl=-1;
39 playList.setCaption( tr( "OpiePlayer: Initializating" ) ); 39 playList.setCaption( tr( "OpiePlayer: Initializating" ) );
40 40
41 qApp->processEvents(); 41 qApp->processEvents();
42 // QPEApplication::grabKeyboard(); // EVIL 42 // QPEApplication::grabKeyboard(); // EVIL
43 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 43 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
44 44
45 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); 45 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
46 46
47// What is pauseCheck good for? (Simon) 47// What is pauseCheck good for? (Simon)
48// connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); 48// connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
49 49
50 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); 50 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
51 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); 51 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
52 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); 52 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) );
53 53
54 volControl = new VolumeControl; 54 volControl = new VolumeControl;
55 Config cfg( "OpiePlayer" ); 55 Config cfg( "OpiePlayer" );
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() {
62 delete m_xineControl; 67 delete m_xineControl;
63 delete m_audioUI; 68 delete m_audioUI;
64 delete m_videoUI; 69 delete m_videoUI;
65 delete volControl; 70 delete volControl;
66} 71}
67 72
68void MediaPlayer::pauseCheck( bool b ) { 73void MediaPlayer::pauseCheck( bool b ) {
69 if ( b && !mediaPlayerState.isPlaying() ) { 74 if ( b && !mediaPlayerState.isPlaying() ) {
70 mediaPlayerState.setPaused( FALSE ); 75 mediaPlayerState.setPaused( FALSE );
71 } 76 }
72} 77}
73 78
74void MediaPlayer::play() { 79void MediaPlayer::play() {
75 mediaPlayerState.setPlaying( FALSE ); 80 mediaPlayerState.setPlaying( FALSE );
76 mediaPlayerState.setPlaying( TRUE ); 81 mediaPlayerState.setPlaying( TRUE );
77} 82}
78 83
79void MediaPlayer::setPlaying( bool play ) { 84void MediaPlayer::setPlaying( bool play ) {
80 if ( !play ) { 85 if ( !play ) {
81 return; 86 return;
82 } 87 }
@@ -326,48 +331,50 @@ void MediaPlayer::keyReleaseEvent( QKeyEvent *e) {
326 case Key_F11: //menu 331 case Key_F11: //menu
327 break; 332 break;
328 case Key_F12: //home 333 case Key_F12: //home
329 qDebug("Blank here"); 334 qDebug("Blank here");
330// mediaPlayerState->toggleBlank(); 335// mediaPlayerState->toggleBlank();
331 break; 336 break;
332 case Key_F13: //mail 337 case Key_F13: //mail
333 qDebug("Blank here"); 338 qDebug("Blank here");
334 // mediaPlayerState->toggleBlank(); 339 // mediaPlayerState->toggleBlank();
335 break; 340 break;
336 } 341 }
337} 342}
338 343
339void MediaPlayer::cleanUp() {// this happens on closing 344void MediaPlayer::cleanUp() {// this happens on closing
340 Config cfg( "OpiePlayer" ); 345 Config cfg( "OpiePlayer" );
341 mediaPlayerState.writeConfig( cfg ); 346 mediaPlayerState.writeConfig( cfg );
342 playList.writeDefaultPlaylist( ); 347 playList.writeDefaultPlaylist( );
343 348
344// QPEApplication::grabKeyboard(); 349// QPEApplication::grabKeyboard();
345// QPEApplication::ungrabKeyboard(); 350// QPEApplication::ungrabKeyboard();
346} 351}
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;
353 m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); 360 m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" );
354 m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); 361 m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" );
355 362
356 connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); 363 connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
357 connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); 364 connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) );
358 connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); 365 connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
359 connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); 366 connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
360 367
361 connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); 368 connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
362 connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); 369 connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) );
363 connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); 370 connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
364 connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); 371 connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
365 372
366 m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState ); 373 m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState );
367} 374}
368 375
369AudioWidget *MediaPlayer::audioUI() const 376AudioWidget *MediaPlayer::audioUI() const
370{ 377{
371 if ( !m_audioUI ) 378 if ( !m_audioUI )
372 recreateAudioAndVideoWidgets(); 379 recreateAudioAndVideoWidgets();
373 return m_audioUI; 380 return 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
@@ -19,48 +19,49 @@
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef MEDIA_PLAYER_H 34#ifndef MEDIA_PLAYER_H
35#define MEDIA_PLAYER_H 35#define MEDIA_PLAYER_H
36 36
37#include <qmainwindow.h> 37#include <qmainwindow.h>
38#include <qframe.h> 38#include <qframe.h>
39 39
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;
46class MediaPlayerState; 47class MediaPlayerState;
47class AudioWidget; 48class AudioWidget;
48class VideoWidget; 49class VideoWidget;
49 50
50class MediaPlayer : public QObject { 51class MediaPlayer : public QObject {
51 Q_OBJECT 52 Q_OBJECT
52public: 53public:
53 MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ); 54 MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name );
54 ~MediaPlayer(); 55 ~MediaPlayer();
55 56
56public slots: 57public slots:
57 void reloadSkins(); 58 void reloadSkins();
58 59
59private slots: 60private slots:
60 void setPlaying( bool ); 61 void setPlaying( bool );
61 void pauseCheck( bool ); 62 void pauseCheck( bool );
62 void play(); 63 void play();
63 void next(); 64 void next();
64 void prev(); 65 void prev();
65 void startIncreasingVolume(); 66 void startIncreasingVolume();
66 void startDecreasingVolume(); 67 void startDecreasingVolume();
@@ -68,29 +69,31 @@ private slots:
68 void cleanUp(); 69 void cleanUp();
69 void blank( bool ); 70 void blank( bool );
70 71
71protected: 72protected:
72 void timerEvent( QTimerEvent *e ); 73 void timerEvent( QTimerEvent *e );
73 void keyReleaseEvent( QKeyEvent *e); 74 void keyReleaseEvent( QKeyEvent *e);
74 75
75private: 76private:
76 AudioWidget *audioUI() const; 77 AudioWidget *audioUI() const;
77 VideoWidget *videoUI() const; 78 VideoWidget *videoUI() const;
78 XineControl *xineControl() const; 79 XineControl *xineControl() const;
79 80
80 bool isBlanked, l, r; 81 bool isBlanked, l, r;
81 int fd, fl; 82 int fd, fl;
82 int volumeDirection; 83 int volumeDirection;
83 VolumeControl *volControl; 84 VolumeControl *volControl;
84 MediaPlayerState &mediaPlayerState; 85 MediaPlayerState &mediaPlayerState;
85 PlayListWidget &playList; 86 PlayListWidget &playList;
86 87
87 void recreateAudioAndVideoWidgets() const; 88 void recreateAudioAndVideoWidgets() const;
88 89
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
95#endif // MEDIA_PLAYER_H 98#endif // MEDIA_PLAYER_H
96 99
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
@@ -70,48 +70,49 @@ public:
70 // in the BAD_ALLOC macro it uses std::cerr and friends :-( 70 // in the BAD_ALLOC macro it uses std::cerr and friends :-(
71 typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; 71 typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector;
72#else 72#else
73 typedef std::vector<Button> ButtonVector; 73 typedef std::vector<Button> ButtonVector;
74#endif 74#endif
75 75
76 struct SkinButtonInfo 76 struct SkinButtonInfo
77 { 77 {
78 Command command; 78 Command command;
79 const char *fileName; 79 const char *fileName;
80 ButtonType type; 80 ButtonType type;
81 }; 81 };
82 82
83 struct GUIInfo 83 struct GUIInfo
84 { 84 {
85 GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} 85 GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {}
86 GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) 86 GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount )
87 : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) 87 : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount )
88 {} 88 {}
89 89
90 QString fileNameInfix; 90 QString fileNameInfix;
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();
97 98
98public slots: 99public slots:
99 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 100 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
100 virtual void setLength( long length ) = 0; 101 virtual void setLength( long length ) = 0;
101 virtual void setPlaying( bool playing ) = 0; 102 virtual void setPlaying( bool playing ) = 0;
102 103
103 virtual void loadSkin() = 0; 104 virtual void loadSkin() = 0;
104 105
105signals: 106signals:
106 void moreReleased(); 107 void moreReleased();
107 void lessReleased(); 108 void lessReleased();
108 void forwardReleased(); 109 void forwardReleased();
109 void backReleased(); 110 void backReleased();
110 void forwardClicked(); 111 void forwardClicked();
111 void backClicked(); 112 void backClicked();
112 void moreClicked(); 113 void moreClicked();
113 void lessClicked(); 114 void lessClicked();
114 115
115protected: 116protected:
116 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 117 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
117 const Skin &skin ); 118 const Skin &skin );
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
@@ -4,48 +4,49 @@
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
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 29
29#include <qpe/resource.h> 30#include <qpe/resource.h>
30#include <qpe/config.h> 31#include <qpe/config.h>
31 32
32#include <assert.h> 33#include <assert.h>
33 34
34struct SkinData 35struct SkinData
35{ 36{
36 typedef QMap<QString, QImage> ButtonMaskImageMap; 37 typedef QMap<QString, QImage> ButtonMaskImageMap;
37 38
38 QImage backgroundImage; 39 QImage backgroundImage;
39 QImage buttonUpImage; 40 QImage buttonUpImage;
40 QImage buttonDownImage; 41 QImage buttonDownImage;
41 QImage buttonMask; 42 QImage buttonMask;
42 ButtonMaskImageMap buttonMasks; 43 ButtonMaskImageMap buttonMasks;
43}; 44};
44 45
45class SkinCache : public Singleton<SkinCache> 46class SkinCache : public Singleton<SkinCache>
46{ 47{
47public: 48public:
48 SkinCache(); 49 SkinCache();
49 50
50 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); 51 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
51 52
@@ -161,81 +162,167 @@ QString Skin::defaultSkinName()
161 cfg.setGroup( "Options" ); 162 cfg.setGroup( "Options" );
162 return cfg.readEntry( "Skin", "default" ); 163 return cfg.readEntry( "Skin", "default" );
163} 164}
164 165
165QImage Skin::loadImage( const QString &fileName ) 166QImage Skin::loadImage( const QString &fileName )
166{ 167{
167 return QImage( Resource::findPixmap( fileName ) ); 168 return QImage( Resource::findPixmap( fileName ) );
168} 169}
169 170
170SkinCache::SkinCache() 171SkinCache::SkinCache()
171{ 172{
172 // let's say we cache two skins (audio+video) at maximum 173 // let's say we cache two skins (audio+video) at maximum
173 m_cache.setMaxCost( 2 ); 174 m_cache.setMaxCost( 2 );
174 // ... and one background pixmap 175 // ... and one background pixmap
175 m_backgroundImageCache.setMaxCost( 1 ); 176 m_backgroundImageCache.setMaxCost( 1 );
176} 177}
177 178
178SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) 179SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
179{ 180{
180 QString key = skinPath + fileNameInfix; 181 QString key = skinPath + fileNameInfix;
181 182
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
192 return data; 197 return data;
193} 198}
194 199
195void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) 200void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
196{ 201{
197 QImage *backgroundImage = new QImage( data->backgroundImage ); 202 QImage *backgroundImage = new QImage( data->backgroundImage );
198 203
199 data->backgroundImage = QImage(); 204 data->backgroundImage = QImage();
200 205
201 QString key = skinPath + fileNameInfix; 206 QString key = skinPath + fileNameInfix;
202 207
203 if ( m_cache.find( key, false /*ref*/ ) != 0 || 208 if ( m_cache.find( key, false /*ref*/ ) != 0 ||
204 !m_cache.insert( key, data ) ) 209 !m_cache.insert( key, data ) )
205 delete data; 210 delete data;
206 211
207 if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 || 212 if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 ||
208 !m_backgroundImageCache.insert( skinPath, backgroundImage ) ) 213 !m_backgroundImageCache.insert( skinPath, backgroundImage ) )
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
241 */ 328 */
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
@@ -4,102 +4,121 @@
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef SKIN_H 23#ifndef SKIN_H
24#define SKIN_H 24#define SKIN_H
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
34class Skin 34class Skin
35{ 35{
36public: 36public:
37 Skin( const QString &name, const QString &fileNameInfix ); 37 Skin( const QString &name, const QString &fileNameInfix );
38 Skin( const QString &fileNameInfix ); 38 Skin( const QString &fileNameInfix );
39 ~Skin(); 39 ~Skin();
40 40
41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); 41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
42 42
43 QImage backgroundImage() const; 43 QImage backgroundImage() const;
44 QImage buttonUpImage() const; 44 QImage buttonUpImage() const;
45 QImage buttonDownImage() const; 45 QImage buttonDownImage() const;
46 46
47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
48 48
49 QImage buttonMaskImage( const QString &fileName ) const; 49 QImage buttonMaskImage( const QString &fileName ) const;
50 50
51 static QString defaultSkinName(); 51 static QString defaultSkinName();
52 52
53private: 53private:
54 void init( const QString &name ); 54 void init( const QString &name );
55 55
56 void addButtonToMask( int tag, const QImage &maskImage ) const; 56 void addButtonToMask( int tag, const QImage &maskImage ) const;
57 57
58 static QImage loadImage( const QString &fileName ); 58 static QImage loadImage( const QString &fileName );
59 59
60 QString m_fileNameInfix; 60 QString m_fileNameInfix;
61 QString m_skinPath; 61 QString m_skinPath;
62 62
63 SkinData *d; 63 SkinData *d;
64 64
65 Skin( const Skin & ); 65 Skin( const Skin & );
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
104/* vim: et sw=4 ts=4 123/* vim: et sw=4 ts=4
105 */ 124 */