summaryrefslogtreecommitdiff
path: root/noncore
authorsimon <simon>2002-12-11 19:34:20 (UTC)
committer simon <simon>2002-12-11 19:34:20 (UTC)
commitb3373b77e12e4b138848110884aedc37b56384e1 (patch) (unidiff)
tree7432537024816d316d05fdc364d26db73fae190b /noncore
parente59fabf981834292c2ed9b7192dd4f789cc4b7cb (diff)
downloadopie-b3373b77e12e4b138848110884aedc37b56384e1.zip
opie-b3373b77e12e4b138848110884aedc37b56384e1.tar.gz
opie-b3373b77e12e4b138848110884aedc37b56384e1.tar.bz2
- SkinCache now operates on SkinData instead of single images
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp37
-rw-r--r--noncore/multimedia/opieplayer2/skin.h2
2 files changed, 18 insertions, 21 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index d2e3b00..5013bb4 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -2,100 +2,105 @@
2 Copyright (C) 2002 Simon Hausmann <simon@lst.de> 2 Copyright (C) 2002 Simon Hausmann <simon@lst.de>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include "skin.h" 23#include "skin.h"
24#include "singleton.h" 24#include "singleton.h"
25 25
26#include <qcache.h>
27#include <qmap.h>
28
26#include <qpe/resource.h> 29#include <qpe/resource.h>
27#include <qpe/config.h> 30#include <qpe/config.h>
28 31
29#include <assert.h> 32#include <assert.h>
30 33
31struct SkinData 34struct SkinData
32{ 35{
33 typedef QMap<QString, QImage> ButtonMaskImageMap; 36 typedef QMap<QString, QImage> ButtonMaskImageMap;
34 37
35 QImage backgroundImage; 38 QImage backgroundImage;
36 QImage buttonUpImage; 39 QImage buttonUpImage;
37 QImage buttonDownImage; 40 QImage buttonDownImage;
38 QImage buttonMask; 41 QImage buttonMask;
39 ButtonMaskImageMap buttonMasks; 42 ButtonMaskImageMap buttonMasks;
40}; 43};
41 44
42class SkinCache : public Singleton<SkinCache> 45class SkinCache : public Singleton<SkinCache>
43{ 46{
44public: 47public:
45 SkinCache(); 48 SkinCache();
46 49
47 QImage loadImage( const QString &name ); 50 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
48 51
49private: 52 void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data );
50 typedef QDict<QImage> ImageCache;
51 53
52 ImageCache m_cache; 54private:
55 typedef QCache<SkinData> DataCache;
56 typedef QCache<QPixmap> BackgroundPixmapCache;
53 57
54 ThreadUtil::Mutex m_cacheGuard; 58 DataCache m_cache;
59 BackgroundPixmapCache m_backgroundPixmapCache;
55}; 60};
56 61
57Skin::Skin( const QString &name, const QString &fileNameInfix ) 62Skin::Skin( const QString &name, const QString &fileNameInfix )
58 : m_fileNameInfix( fileNameInfix ) 63 : m_fileNameInfix( fileNameInfix )
59{ 64{
60 init( name ); 65 init( name );
61} 66}
62 67
63Skin::Skin( const QString &fileNameInfix ) 68Skin::Skin( const QString &fileNameInfix )
64 : m_fileNameInfix( fileNameInfix ) 69 : m_fileNameInfix( fileNameInfix )
65{ 70{
66 init( defaultSkinName() ); 71 init( defaultSkinName() );
67} 72}
68 73
69Skin::~Skin() 74Skin::~Skin()
70{ 75{
71 delete d; 76 SkinCache::self().store( m_skinPath, m_fileNameInfix, d );
72} 77}
73 78
74void Skin::init( const QString &name ) 79void Skin::init( const QString &name )
75{ 80{
76 m_skinPath = "opieplayer2/skins/" + name; 81 m_skinPath = "opieplayer2/skins/" + name;
77 d = new SkinData; 82 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix );
78} 83}
79 84
80void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) 85void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount )
81{ 86{
82 backgroundImage(); 87 backgroundImage();
83 buttonUpImage(); 88 buttonUpImage();
84 buttonDownImage(); 89 buttonDownImage();
85 ( void )buttonMask( skinButtonInfo, buttonCount ); 90 ( void )buttonMask( skinButtonInfo, buttonCount );
86} 91}
87 92
88QImage Skin::backgroundImage() const 93QImage Skin::backgroundImage() const
89{ 94{
90 if ( d->backgroundImage.isNull() ) 95 if ( d->backgroundImage.isNull() )
91 d->backgroundImage = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 96 d->backgroundImage = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
92 return d->backgroundImage; 97 return d->backgroundImage;
93} 98}
94 99
95QImage Skin::buttonUpImage() const 100QImage Skin::buttonUpImage() const
96{ 101{
97 if ( d->buttonUpImage.isNull() ) 102 if ( d->buttonUpImage.isNull() )
98 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 103 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
99 return d->buttonUpImage; 104 return d->buttonUpImage;
100} 105}
101 106
@@ -140,64 +145,58 @@ QImage Skin::buttonMaskImage( const QString &fileName ) const
140{ 145{
141 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); 146 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName );
142 if ( it == d->buttonMasks.end() ) { 147 if ( it == d->buttonMasks.end() ) {
143 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); 148 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
144 QString path = prefix + fileName + ".png"; 149 QString path = prefix + fileName + ".png";
145 it = d->buttonMasks.insert( fileName, loadImage( path ) ); 150 it = d->buttonMasks.insert( fileName, loadImage( path ) );
146 } 151 }
147 return *it; 152 return *it;
148} 153}
149 154
150QString Skin::defaultSkinName() 155QString Skin::defaultSkinName()
151{ 156{
152 Config cfg( "OpiePlayer" ); 157 Config cfg( "OpiePlayer" );
153 cfg.setGroup( "Options" ); 158 cfg.setGroup( "Options" );
154 return cfg.readEntry( "Skin", "default" ); 159 return cfg.readEntry( "Skin", "default" );
155} 160}
156 161
157QImage Skin::loadImage( const QString &fileName ) 162QImage Skin::loadImage( const QString &fileName )
158{ 163{
159 return QImage( Resource::findPixmap( fileName ) ); 164 return QImage( Resource::findPixmap( fileName ) );
160} 165}
161 166
162SkinCache::SkinCache() 167SkinCache::SkinCache()
163{ 168{
164 m_cache.setAutoDelete( true );
165} 169}
166 170
167QImage SkinCache::loadImage( const QString &name ) 171SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
168{ 172{
169 ThreadUtil::AutoLock lock( m_cacheGuard ); 173 return new SkinData;
170 174}
171 QImage *image = m_cache.find( name );
172 if ( image ) {
173 qDebug( "cache hit for %s", name.ascii() );
174 return *image;
175 }
176 175
177 image = new QImage( Resource::findPixmap( name ) ); 176void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
178 m_cache.insert( name, image ); 177{
179 return *image; 178 delete data;
180} 179}
181 180
182SkinLoader::SkinLoader() 181SkinLoader::SkinLoader()
183{ 182{
184} 183}
185 184
186void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, 185void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix,
187 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) 186 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount )
188{ 187{
189 assert( isRunning() == false ); 188 assert( isRunning() == false );
190 189
191 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); 190 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount );
192} 191}
193 192
194void SkinLoader::run() 193void SkinLoader::run()
195{ 194{
196 qDebug( "SkinLoader::run()" ); 195 qDebug( "SkinLoader::run()" );
197 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) 196 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it )
198 load( *it ); 197 load( *it );
199 qDebug( "SkinLoader is done." ); 198 qDebug( "SkinLoader is done." );
200} 199}
201 200
202void SkinLoader::load( const Info &nfo ) 201void SkinLoader::load( const Info &nfo )
203{ 202{
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index e55832c..9180067 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -4,50 +4,48 @@
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef SKIN_H 23#ifndef SKIN_H
24#define SKIN_H 24#define SKIN_H
25 25
26#include <qstring.h> 26#include <qstring.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qmap.h>
29#include <qdict.h>
30 28
31#include "mediawidget.h" 29#include "mediawidget.h"
32#include "threadutil.h" 30#include "threadutil.h"
33 31
34struct SkinData; 32struct SkinData;
35 33
36class Skin 34class Skin
37{ 35{
38public: 36public:
39 Skin( const QString &name, const QString &fileNameInfix ); 37 Skin( const QString &name, const QString &fileNameInfix );
40 Skin( const QString &fileNameInfix ); 38 Skin( const QString &fileNameInfix );
41 ~Skin(); 39 ~Skin();
42 40
43 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); 41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
44 42
45 QImage backgroundImage() const; 43 QImage backgroundImage() const;
46 QImage buttonUpImage() const; 44 QImage buttonUpImage() const;
47 QImage buttonDownImage() const; 45 QImage buttonDownImage() const;
48 46
49 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
50 48
51 QImage buttonMaskImage( const QString &fileName ) const; 49 QImage buttonMaskImage( const QString &fileName ) const;
52 50
53 static QString defaultSkinName(); 51 static QString defaultSkinName();