-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 5d8929e..b2c1649 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp @@ -7,48 +7,49 @@ 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 <opie2/odebug.h> #include <qcache.h> #include <qtimer.h> #include <qpe/config.h> +#include <qpe/global.h> #include <assert.h> struct SkinData { typedef QMap<QString, QImage> ButtonMaskImageMap; QPixmap backgroundPixmap; QImage buttonUpImage; QImage buttonDownImage; QImage buttonMask; ButtonMaskImageMap buttonMasks; }; class SkinCache : public Singleton<SkinCache> { public: SkinCache(); SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); private: @@ -158,166 +159,166 @@ QString Skin::defaultSkinName() 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_backgroundPixmapCache.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 - odebug << "SkinCache: hit" << oendl; + odebug << "SkinCache: hit" << oendl; QPixmap *bgPixmap = m_backgroundPixmapCache.find( skinPath ); if ( bgPixmap ) { - odebug << "SkinCache: hit on bgpixmap" << oendl; + odebug << "SkinCache: hit on bgpixmap" << oendl; data->backgroundPixmap = *bgPixmap; } else data->backgroundPixmap = QPixmap(); return data; } void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) { QPixmap *backgroundPixmap = new QPixmap( data->backgroundPixmap ); data->backgroundPixmap = QPixmap(); QString key = skinPath + fileNameInfix; if ( m_cache.find( key, false /*ref*/ ) != 0 || !m_cache.insert( key, data ) ) delete data; if ( m_backgroundPixmapCache.find( skinPath, false /*ref*/ ) != 0 || !m_backgroundPixmapCache.insert( skinPath, backgroundPixmap ) ) delete backgroundPixmap; } SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) : m_skin( info.skinName, info.fileNameInfix ), m_info( info ) { m_currentState = LoadBackgroundPixmap; } SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() { switch ( m_currentState ) { case LoadBackgroundPixmap: - odebug << "load bgpixmap" << oendl; + odebug << "load bgpixmap" << oendl; m_skin.backgroundPixmap(); m_currentState = LoadButtonUpImage; break; case LoadButtonUpImage: - odebug << "load upimage" << oendl; + odebug << "load upimage" << oendl; m_skin.buttonUpImage(); m_currentState = LoadButtonDownImage; break; case LoadButtonDownImage: - odebug << "load downimage" << oendl; + odebug << "load downimage" << oendl; m_skin.buttonDownImage(); m_currentState = LoadButtonMasks; m_currentButton = 0; break; case LoadButtonMasks: - odebug << "load button masks " << m_currentButton << "" << oendl; + odebug << "load button masks " << m_currentButton << "" << oendl; m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName ); m_currentButton++; if ( m_currentButton >= m_info.buttonCount ) m_currentState = LoadButtonMask; break; case LoadButtonMask: - odebug << "load whole mask" << oendl; + odebug << "load whole mask" << oendl; m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount ); return LoadingCompleted; } return MoreToCome; } SkinLoader::SkinLoader() : m_currentLoader( 0 ), m_timerId( -1 ) { } SkinLoader::~SkinLoader() { - odebug << "SkinLoader::~SkinLoader()" << oendl; + Global::statusMessage( tr( "Loading of Skin finished" ) ); killTimers(); delete m_currentLoader; } void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo ) { schedule( Skin::defaultSkinName(), guiInfo ); } void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ) { pendingSkins << Info( skinName, guiInfo ); } void SkinLoader::start() { assert( m_timerId == -1 ); m_timerId = startTimer( 100 /* ms */ ); - odebug << "SkinLoader::start() " << pendingSkins.count() << " jobs" << oendl; + odebug << "SkinLoader::start() " << pendingSkins.count() << " jobs" << oendl; } void SkinLoader::timerEvent( QTimerEvent *ev ) { if ( ev->timerId() != m_timerId ) { QObject::timerEvent( ev ); return; } if ( !m_currentLoader ) { if ( pendingSkins.isEmpty() ) { - odebug << "all jobs done" << oendl; + odebug << "all jobs done" << oendl; 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 ); - odebug << "new loader " << pendingSkins.count() << " jobs left" << oendl; + odebug << "new loader " << pendingSkins.count() << " jobs left" << oendl; } if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) { delete m_currentLoader; m_currentLoader = 0; } - odebug << "finished step" << oendl; + odebug << "finished step" << oendl; } void SkinLoader::deleteMe() { delete this; } /* vim: et sw=4 ts=4 */ |