summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 23:12:16 (UTC)
committer simon <simon>2002-12-11 23:12:16 (UTC)
commitd4a0626f01fae21ed19d0eea88d8eca1935c6bc8 (patch) (side-by-side diff)
tree9747bdd478c1bd93f46eaa49c95381404a6fd55b
parent8d5ae95e770bc387420fc094c54d8ac55e64e04b (diff)
downloadopie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.zip
opie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.tar.gz
opie-d4a0626f01fae21ed19d0eea88d8eca1935c6bc8.tar.bz2
- skins are now pre-loaded in the background (step by step)
Diffstat (more/less context) (show 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
@@ -53,12 +53,17 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla
volControl = new VolumeControl;
Config cfg( "OpiePlayer" );
cfg.setGroup("PlayList");
QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() );
+
+ m_skinLoader = new SkinLoader;
+ m_skinLoader->schedule( AudioWidget::guiInfo() );
+ m_skinLoader->schedule( VideoWidget::guiInfo() );
+ m_skinLoader->start();
}
MediaPlayer::~MediaPlayer() {
delete m_xineControl;
delete m_audioUI;
delete m_videoUI;
@@ -344,12 +349,14 @@ void MediaPlayer::cleanUp() {// this happens on closing
// QPEApplication::grabKeyboard();
// QPEApplication::ungrabKeyboard();
}
void MediaPlayer::recreateAudioAndVideoWidgets() const
{
+ delete m_skinLoader;
+
delete m_xineControl;
delete m_audioUI;
delete m_videoUI;
m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" );
m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "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
@@ -37,12 +37,13 @@
#include <qmainwindow.h>
#include <qframe.h>
#include "xinecontrol.h"
#include "playlistwidget.h"
+#include "skin.h"
class DocLnk;
class VolumeControl;
class MediaPlayerState;
class AudioWidget;
class VideoWidget;
@@ -86,11 +87,13 @@ private:
void recreateAudioAndVideoWidgets() const;
mutable XineControl *m_xineControl;
mutable AudioWidget *m_audioUI;
mutable VideoWidget *m_videoUI;
+
+ QGuardedPtr<SkinLoader> m_skinLoader;
};
#endif // MEDIA_PLAYER_H
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
@@ -88,12 +88,13 @@ public:
{}
QString fileNameInfix;
const SkinButtonInfo *buttonInfo;
const uint buttonCount;
};
+ typedef QValueList<GUIInfo> GUIInfoList;
MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
virtual ~MediaWidget();
public slots:
virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 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
@@ -22,12 +22,13 @@
#include "skin.h"
#include "singleton.h"
#include <qcache.h>
#include <qmap.h>
+#include <qtimer.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <assert.h>
@@ -179,16 +180,20 @@ SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &file
{
QString key = skinPath + fileNameInfix;
SkinData *data = m_cache.take( key );
if ( !data )
data = new SkinData;
+ else
+ qDebug( "SkinCache: hit" );
QImage *bgImage = m_backgroundImageCache.find( skinPath );
- if ( bgImage )
+ if ( bgImage ) {
+ qDebug( "SkinCache: hit on bgimage" );
data->backgroundImage = *bgImage;
+ }
else
data->backgroundImage = QImage();
return data;
}
@@ -206,36 +211,118 @@ void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, Sk
if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 ||
!m_backgroundImageCache.insert( skinPath, backgroundImage ) )
delete backgroundImage;
}
+SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info )
+ : m_skin( info.skinName, info.fileNameInfix ), m_info( info )
+{
+ m_currentState = LoadBackgroundImage;
+}
+
+SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep()
+{
+ switch ( m_currentState ) {
+ case LoadBackgroundImage:
+ qDebug( "load bgimage" );
+ m_skin.backgroundImage();
+ m_currentState = LoadButtonUpImage;
+ break;
+ case LoadButtonUpImage:
+ qDebug( "load upimage" );
+ m_skin.buttonUpImage();
+ m_currentState = LoadButtonDownImage;
+ break;
+ case LoadButtonDownImage:
+ qDebug( "load downimage" );
+ m_skin.buttonDownImage();
+ m_currentState = LoadButtonMasks;
+ m_currentButton = 0;
+ break;
+ case LoadButtonMasks:
+ qDebug( "load button masks %i", m_currentButton );
+ m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName );
+
+ m_currentButton++;
+ if ( m_currentButton >= m_info.buttonCount )
+ m_currentState = LoadButtonMask;
+
+ break;
+ case LoadButtonMask:
+ qDebug( "load whole mask" );
+ m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount );
+ return LoadingCompleted;
+ }
+
+ return MoreToCome;
+}
+
SkinLoader::SkinLoader()
+ : m_currentLoader( 0 ), m_timerId( -1 )
{
}
-void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix,
- const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount )
+SkinLoader::~SkinLoader()
{
- assert( isRunning() == false );
+ qDebug( "SkinLoader::~SkinLoader()" );
+ killTimers();
+ delete m_currentLoader;
+}
- pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount );
+void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo )
+{
+ schedule( Skin::defaultSkinName(), guiInfo );
}
-void SkinLoader::run()
+void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo )
{
- qDebug( "SkinLoader::run()" );
- for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it )
- load( *it );
- qDebug( "SkinLoader is done." );
+ pendingSkins << Info( skinName, guiInfo );
}
-void SkinLoader::load( const Info &nfo )
+void SkinLoader::start()
{
- qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() );
+ assert( m_timerId == -1 );
+ m_timerId = startTimer( 100 /* ms */ );
+ qDebug( "SkinLoader::start() %d jobs", pendingSkins.count() );
+}
- Skin skin( nfo.skinName, nfo.fileNameInfix );
- skin.preload( nfo.skinButtonInfo, nfo.buttonCount );
+void SkinLoader::timerEvent( QTimerEvent *ev )
+{
+ if ( ev->timerId() != m_timerId ) {
+ QObject::timerEvent( ev );
+ return;
+ }
+
+ if ( !m_currentLoader ) {
+
+ if ( pendingSkins.isEmpty() ) {
+ qDebug( "all jobs done" );
+ killTimer( m_timerId );
+ m_timerId = -1;
+ // ### qt3: use deleteLater();
+ QTimer::singleShot( 0, this, SLOT( deleteMe() ) );
+ return;
+ }
+
+ Info nfo = *pendingSkins.begin();
+ pendingSkins.remove( pendingSkins.begin() );
+
+ m_currentLoader = new IncrementalLoader( nfo );
+ qDebug( "new loader %i jobs left", pendingSkins.count() );
+ }
+
+ if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) {
+ delete m_currentLoader;
+ m_currentLoader = 0;
+ }
+
+ qDebug( "finished step" );
+}
+
+void SkinLoader::deleteMe()
+{
+ delete this;
}
/* 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
@@ -22,15 +22,15 @@
#ifndef SKIN_H
#define SKIN_H
#include <qstring.h>
#include <qimage.h>
+#include <qobject.h>
#include "mediawidget.h"
-#include "threadutil.h"
struct SkinData;
class Skin
{
public:
@@ -63,43 +63,62 @@ private:
SkinData *d;
Skin( const Skin & );
Skin &operator=( const Skin & );
};
-class SkinLoader : public ThreadUtil::Thread
+class SkinLoader : public QObject
{
+ Q_OBJECT
public:
SkinLoader();
+ virtual ~SkinLoader();
- void schedule( const QString &skinName, const QString &fileNameInfix,
- const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount );
+ void schedule( const MediaWidget::GUIInfo &guiInfo );
+ void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo );
+
+ void start();
protected:
- virtual void run();
+ virtual void timerEvent( QTimerEvent *ev );
+
+private slots:
+ void deleteMe();
private:
- struct Info
+ struct Info : public MediaWidget::GUIInfo
{
- Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {}
- Info( const QString &_skinName, const QString &_fileNameInfix,
- const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount )
- : skinName( _skinName ), fileNameInfix( _fileNameInfix ),
- skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount )
+ Info() {}
+ Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo )
+ : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName )
{}
- const QString skinName;
- const QString fileNameInfix;
- const MediaWidget::SkinButtonInfo *skinButtonInfo;
- const uint buttonCount;
+ QString skinName;
};
typedef QValueList<Info> InfoList;
- void load( const Info &nfo );
+ class IncrementalLoader
+ {
+ public:
+ enum LoaderResult { LoadingCompleted, MoreToCome };
+
+ IncrementalLoader( const Info &info );
+
+ LoaderResult loadStep();
+
+ private:
+ enum State { LoadBackgroundImage, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask };
+
+ Skin m_skin;
+ Info m_info;
+ State m_currentState;
+ uint m_currentButton;
+ };
InfoList pendingSkins;
- ThreadUtil::Mutex guard;
+ IncrementalLoader *m_currentLoader;
+ int m_timerId;
};
#endif // SKIN_H
/* vim: et sw=4 ts=4
*/