author | simon <simon> | 2002-12-11 17:18:17 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:18:17 (UTC) |
commit | 75f0ed4978579eb4b27cdece64c597741ed24b79 (patch) (unidiff) | |
tree | 6443323e08a9639ad0db7b5b1852d3804172e70a /noncore/multimedia/opieplayer2/skin.cpp | |
parent | 94461696cfdcf8cdbaabec1400300e546edc447e (diff) | |
download | opie-75f0ed4978579eb4b27cdece64c597741ed24b79.zip opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.gz opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.bz2 |
- added a skin cache and a threaded skin loader. looks like the latter
we have to disable though, because pure image loading with qt is
anything but threadsafe :(
Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 58 |
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 | |||
@@ -4,6 +4,8 @@ | |||
4 | #include <qpe/resource.h> | 4 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | 6 | ||
7 | #include <assert.h> | ||
8 | |||
7 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 9 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
8 | : m_fileNameInfix( fileNameInfix ) | 10 | : m_fileNameInfix( fileNameInfix ) |
9 | { | 11 | { |
@@ -32,21 +34,21 @@ void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint butt | |||
32 | QImage Skin::backgroundImage() const | 34 | QImage Skin::backgroundImage() const |
33 | { | 35 | { |
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; |
37 | } | 39 | } |
38 | 40 | ||
39 | QImage Skin::buttonUpImage() const | 41 | QImage Skin::buttonUpImage() const |
40 | { | 42 | { |
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; |
44 | } | 46 | } |
45 | 47 | ||
46 | QImage Skin::buttonDownImage() const | 48 | QImage Skin::buttonDownImage() const |
47 | { | 49 | { |
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; |
51 | } | 53 | } |
52 | 54 | ||
@@ -86,7 +88,7 @@ QImage Skin::buttonMaskImage( const QString &fileName ) const | |||
86 | if ( it == m_buttonMasks.end() ) { | 88 | if ( it == m_buttonMasks.end() ) { |
87 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 89 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
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 | } |
91 | return *it; | 93 | return *it; |
92 | } | 94 | } |
@@ -98,5 +100,53 @@ QString Skin::defaultSkinName() | |||
98 | return cfg.readEntry( "Skin", "default" ); | 100 | return cfg.readEntry( "Skin", "default" ); |
99 | } | 101 | } |
100 | 102 | ||
103 | SkinCache::SkinCache() | ||
104 | { | ||
105 | m_cache.setAutoDelete( true ); | ||
106 | } | ||
107 | |||
108 | QImage 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 | |||
123 | SkinLoader::SkinLoader() | ||
124 | { | ||
125 | } | ||
126 | |||
127 | void 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 | |||
135 | void 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 | |||
143 | void 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 |
102 | */ | 152 | */ |