summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/skin.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp58
1 files changed, 54 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 8281b20..0de3023 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -6,2 +6,4 @@
6 6
7#include <assert.h>
8
7Skin::Skin( const QString &name, const QString &fileNameInfix ) 9Skin::Skin( const QString &name, const QString &fileNameInfix )
@@ -34,3 +36,3 @@ QImage Skin::backgroundImage() const
34 if ( m_backgroundImage.isNull() ) 36 if ( m_backgroundImage.isNull() )
35 m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); 37 m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) );
36 return m_backgroundImage; 38 return m_backgroundImage;
@@ -41,3 +43,3 @@ QImage Skin::buttonUpImage() const
41 if ( m_buttonUpImage.isNull() ) 43 if ( m_buttonUpImage.isNull() )
42 m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); 44 m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
43 return m_buttonUpImage; 45 return m_buttonUpImage;
@@ -48,3 +50,3 @@ QImage Skin::buttonDownImage() const
48 if ( m_buttonDownImage.isNull() ) 50 if ( m_buttonDownImage.isNull() )
49 m_buttonDownImage = QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); 51 m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
50 return m_buttonDownImage; 52 return m_buttonDownImage;
@@ -88,3 +90,3 @@ QImage Skin::buttonMaskImage( const QString &fileName ) const
88 QString path = prefix + fileName + ".png"; 90 QString path = prefix + fileName + ".png";
89 it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); 91 it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) );
90 } 92 }
@@ -100,2 +102,50 @@ QString Skin::defaultSkinName()
100 102
103SkinCache::SkinCache()
104{
105 m_cache.setAutoDelete( true );
106}
107
108QImage SkinCache::loadImage( const QString &name )
109{
110 ThreadUtil::AutoLock lock( m_cacheGuard );
111
112 QImage *image = m_cache.find( name );
113 if ( image ) {
114 qDebug( "cache hit for %s", name.ascii() );
115 return *image;
116 }
117
118 image = new QImage( Resource::findPixmap( name ) );
119 m_cache.insert( name, image );
120 return *image;
121}
122
123SkinLoader::SkinLoader()
124{
125}
126
127void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix,
128 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount )
129{
130 assert( isRunning() == false );
131
132 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount );
133}
134
135void SkinLoader::run()
136{
137 qDebug( "SkinLoader::run()" );
138 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it )
139 load( *it );
140 qDebug( "SkinLoader is done." );
141}
142
143void SkinLoader::load( const Info &nfo )
144{
145 qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() );
146
147 Skin skin( nfo.skinName, nfo.fileNameInfix );
148 skin.preload( nfo.skinButtonInfo, nfo.buttonCount );
149}
150
101/* vim: et sw=4 ts=4 151/* vim: et sw=4 ts=4