summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/skin.cpp
Side-by-side diff
Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp115
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
@@ -4,48 +4,49 @@
(C) 2002 L. Potter <ljp@llornkcor.com>
(C) 2002 Holger Freyther <zecke@handhelds.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#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>
struct SkinData
{
typedef QMap<QString, QImage> ButtonMaskImageMap;
QImage backgroundImage;
QImage buttonUpImage;
QImage buttonDownImage;
QImage buttonMask;
ButtonMaskImageMap buttonMasks;
};
class SkinCache : public Singleton<SkinCache>
{
public:
SkinCache();
SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
@@ -161,81 +162,167 @@ QString Skin::defaultSkinName()
cfg.setGroup( "Options" );
return cfg.readEntry( "Skin", "default" );
}
QImage Skin::loadImage( const QString &fileName )
{
return QImage( Resource::findPixmap( fileName ) );
}
SkinCache::SkinCache()
{
// let's say we cache two skins (audio+video) at maximum
m_cache.setMaxCost( 2 );
// ... and one background pixmap
m_backgroundImageCache.setMaxCost( 1 );
}
SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
{
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;
}
void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
{
QImage *backgroundImage = new QImage( data->backgroundImage );
data->backgroundImage = QImage();
QString key = skinPath + fileNameInfix;
if ( m_cache.find( key, false /*ref*/ ) != 0 ||
!m_cache.insert( key, data ) )
delete data;
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
*/