summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp16
-rw-r--r--noncore/multimedia/opieplayer2/skin.h16
2 files changed, 16 insertions, 16 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 9ad5f3f..06453f9 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -1,190 +1,206 @@
1/* 1/*
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 25
25#include <qpe/resource.h> 26#include <qpe/resource.h>
26#include <qpe/config.h> 27#include <qpe/config.h>
27 28
28#include <assert.h> 29#include <assert.h>
29 30
30struct SkinData 31struct SkinData
31{ 32{
32 typedef QMap<QString, QImage> ButtonMaskImageMap; 33 typedef QMap<QString, QImage> ButtonMaskImageMap;
33 34
34 QImage backgroundImage; 35 QImage backgroundImage;
35 QImage buttonUpImage; 36 QImage buttonUpImage;
36 QImage buttonDownImage; 37 QImage buttonDownImage;
37 QImage buttonMask; 38 QImage buttonMask;
38 ButtonMaskImageMap buttonMasks; 39 ButtonMaskImageMap buttonMasks;
39}; 40};
40 41
42class SkinCache : public Singleton<SkinCache>
43{
44public:
45 SkinCache();
46
47 QImage loadImage( const QString &name );
48
49private:
50 typedef QDict<QImage> ImageCache;
51
52 ImageCache m_cache;
53
54 ThreadUtil::Mutex m_cacheGuard;
55};
56
41Skin::Skin( const QString &name, const QString &fileNameInfix ) 57Skin::Skin( const QString &name, const QString &fileNameInfix )
42 : m_fileNameInfix( fileNameInfix ) 58 : m_fileNameInfix( fileNameInfix )
43{ 59{
44 init( name ); 60 init( name );
45} 61}
46 62
47Skin::Skin( const QString &fileNameInfix ) 63Skin::Skin( const QString &fileNameInfix )
48 : m_fileNameInfix( fileNameInfix ) 64 : m_fileNameInfix( fileNameInfix )
49{ 65{
50 init( defaultSkinName() ); 66 init( defaultSkinName() );
51} 67}
52 68
53Skin::~Skin() 69Skin::~Skin()
54{ 70{
55 delete d; 71 delete d;
56} 72}
57 73
58void Skin::init( const QString &name ) 74void Skin::init( const QString &name )
59{ 75{
60 m_skinPath = "opieplayer2/skins/" + name; 76 m_skinPath = "opieplayer2/skins/" + name;
61 d = new SkinData; 77 d = new SkinData;
62} 78}
63 79
64void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) 80void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount )
65{ 81{
66 backgroundImage(); 82 backgroundImage();
67 buttonUpImage(); 83 buttonUpImage();
68 buttonDownImage(); 84 buttonDownImage();
69 ( void )buttonMask( skinButtonInfo, buttonCount ); 85 ( void )buttonMask( skinButtonInfo, buttonCount );
70} 86}
71 87
72QImage Skin::backgroundImage() const 88QImage Skin::backgroundImage() const
73{ 89{
74 if ( d->backgroundImage.isNull() ) 90 if ( d->backgroundImage.isNull() )
75 d->backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 91 d->backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) );
76 return d->backgroundImage; 92 return d->backgroundImage;
77} 93}
78 94
79QImage Skin::buttonUpImage() const 95QImage Skin::buttonUpImage() const
80{ 96{
81 if ( d->buttonUpImage.isNull() ) 97 if ( d->buttonUpImage.isNull() )
82 d->buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 98 d->buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
83 return d->buttonUpImage; 99 return d->buttonUpImage;
84} 100}
85 101
86QImage Skin::buttonDownImage() const 102QImage Skin::buttonDownImage() const
87{ 103{
88 if ( d->buttonDownImage.isNull() ) 104 if ( d->buttonDownImage.isNull() )
89 d->buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 105 d->buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
90 return d->buttonDownImage; 106 return d->buttonDownImage;
91} 107}
92 108
93QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const 109QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const
94{ 110{
95 if ( !d->buttonMask.isNull() ) 111 if ( !d->buttonMask.isNull() )
96 return d->buttonMask; 112 return d->buttonMask;
97 113
98 QSize buttonAreaSize = buttonUpImage().size(); 114 QSize buttonAreaSize = buttonUpImage().size();
99 115
100 d->buttonMask = QImage( buttonAreaSize, 8, 255 ); 116 d->buttonMask = QImage( buttonAreaSize, 8, 255 );
101 d->buttonMask.fill( 0 ); 117 d->buttonMask.fill( 0 );
102 118
103 for ( uint i = 0; i < buttonCount; ++i ) 119 for ( uint i = 0; i < buttonCount; ++i )
104 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); 120 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) );
105 121
106 return d->buttonMask; 122 return d->buttonMask;
107} 123}
108 124
109void Skin::addButtonToMask( int tag, const QImage &maskImage ) const 125void Skin::addButtonToMask( int tag, const QImage &maskImage ) const
110{ 126{
111 if ( maskImage.isNull() ) 127 if ( maskImage.isNull() )
112 return; 128 return;
113 129
114 uchar **dest = d->buttonMask.jumpTable(); 130 uchar **dest = d->buttonMask.jumpTable();
115 for ( int y = 0; y < d->buttonMask.height(); y++ ) { 131 for ( int y = 0; y < d->buttonMask.height(); y++ ) {
116 uchar *line = dest[y]; 132 uchar *line = dest[y];
117 for ( int x = 0; x < d->buttonMask.width(); x++ ) 133 for ( int x = 0; x < d->buttonMask.width(); x++ )
118 if ( !qRed( maskImage.pixel( x, y ) ) ) 134 if ( !qRed( maskImage.pixel( x, y ) ) )
119 line[x] = tag; 135 line[x] = tag;
120 } 136 }
121} 137}
122 138
123QImage Skin::buttonMaskImage( const QString &fileName ) const 139QImage Skin::buttonMaskImage( const QString &fileName ) const
124{ 140{
125 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); 141 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName );
126 if ( it == d->buttonMasks.end() ) { 142 if ( it == d->buttonMasks.end() ) {
127 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); 143 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
128 QString path = prefix + fileName + ".png"; 144 QString path = prefix + fileName + ".png";
129 it = d->buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); 145 it = d->buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) );
130 } 146 }
131 return *it; 147 return *it;
132} 148}
133 149
134QString Skin::defaultSkinName() 150QString Skin::defaultSkinName()
135{ 151{
136 Config cfg( "OpiePlayer" ); 152 Config cfg( "OpiePlayer" );
137 cfg.setGroup( "Options" ); 153 cfg.setGroup( "Options" );
138 return cfg.readEntry( "Skin", "default" ); 154 return cfg.readEntry( "Skin", "default" );
139} 155}
140 156
141SkinCache::SkinCache() 157SkinCache::SkinCache()
142{ 158{
143 m_cache.setAutoDelete( true ); 159 m_cache.setAutoDelete( true );
144} 160}
145 161
146QImage SkinCache::loadImage( const QString &name ) 162QImage SkinCache::loadImage( const QString &name )
147{ 163{
148 ThreadUtil::AutoLock lock( m_cacheGuard ); 164 ThreadUtil::AutoLock lock( m_cacheGuard );
149 165
150 QImage *image = m_cache.find( name ); 166 QImage *image = m_cache.find( name );
151 if ( image ) { 167 if ( image ) {
152 qDebug( "cache hit for %s", name.ascii() ); 168 qDebug( "cache hit for %s", name.ascii() );
153 return *image; 169 return *image;
154 } 170 }
155 171
156 image = new QImage( Resource::findPixmap( name ) ); 172 image = new QImage( Resource::findPixmap( name ) );
157 m_cache.insert( name, image ); 173 m_cache.insert( name, image );
158 return *image; 174 return *image;
159} 175}
160 176
161SkinLoader::SkinLoader() 177SkinLoader::SkinLoader()
162{ 178{
163} 179}
164 180
165void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, 181void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix,
166 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) 182 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount )
167{ 183{
168 assert( isRunning() == false ); 184 assert( isRunning() == false );
169 185
170 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); 186 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount );
171} 187}
172 188
173void SkinLoader::run() 189void SkinLoader::run()
174{ 190{
175 qDebug( "SkinLoader::run()" ); 191 qDebug( "SkinLoader::run()" );
176 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) 192 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it )
177 load( *it ); 193 load( *it );
178 qDebug( "SkinLoader is done." ); 194 qDebug( "SkinLoader is done." );
179} 195}
180 196
181void SkinLoader::load( const Info &nfo ) 197void SkinLoader::load( const Info &nfo )
182{ 198{
183 qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); 199 qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() );
184 200
185 Skin skin( nfo.skinName, nfo.fileNameInfix ); 201 Skin skin( nfo.skinName, nfo.fileNameInfix );
186 skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); 202 skin.preload( nfo.skinButtonInfo, nfo.buttonCount );
187} 203}
188 204
189/* vim: et sw=4 ts=4 205/* vim: et sw=4 ts=4
190 */ 206 */
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index 5ab6574..060ff73 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -1,121 +1,105 @@
1/* 1/*
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#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> 28#include <qmap.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "mediawidget.h" 31#include "mediawidget.h"
32#include "threadutil.h" 32#include "threadutil.h"
33#include "singleton.h"
34 33
35struct SkinData; 34struct SkinData;
36 35
37class Skin 36class Skin
38{ 37{
39public: 38public:
40 Skin( const QString &name, const QString &fileNameInfix ); 39 Skin( const QString &name, const QString &fileNameInfix );
41 Skin( const QString &fileNameInfix ); 40 Skin( const QString &fileNameInfix );
42 ~Skin(); 41 ~Skin();
43 42
44 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); 43 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
45 44
46 QImage backgroundImage() const; 45 QImage backgroundImage() const;
47 QImage buttonUpImage() const; 46 QImage buttonUpImage() const;
48 QImage buttonDownImage() const; 47 QImage buttonDownImage() const;
49 48
50 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 49 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
51 50
52 QImage buttonMaskImage( const QString &fileName ) const; 51 QImage buttonMaskImage( const QString &fileName ) const;
53 52
54 static QString defaultSkinName(); 53 static QString defaultSkinName();
55 54
56private: 55private:
57 void init( const QString &name ); 56 void init( const QString &name );
58 57
59 void addButtonToMask( int tag, const QImage &maskImage ) const; 58 void addButtonToMask( int tag, const QImage &maskImage ) const;
60 59
61 QString m_fileNameInfix; 60 QString m_fileNameInfix;
62 QString m_skinPath; 61 QString m_skinPath;
63 62
64 SkinData *d; 63 SkinData *d;
65 64
66 Skin( const Skin & ); 65 Skin( const Skin & );
67 Skin &operator=( const Skin & ); 66 Skin &operator=( const Skin & );
68}; 67};
69 68
70class SkinCache : public Singleton<SkinCache>
71{
72public:
73 SkinCache();
74
75 QImage loadImage( const QString &name );
76
77private:
78 typedef QDict<QImage> ImageCache;
79
80 ImageCache m_cache;
81
82 ThreadUtil::Mutex m_cacheGuard;
83};
84
85class SkinLoader : public ThreadUtil::Thread 69class SkinLoader : public ThreadUtil::Thread
86{ 70{
87public: 71public:
88 SkinLoader(); 72 SkinLoader();
89 73
90 void schedule( const QString &skinName, const QString &fileNameInfix, 74 void schedule( const QString &skinName, const QString &fileNameInfix,
91 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); 75 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount );
92 76
93protected: 77protected:
94 virtual void run(); 78 virtual void run();
95 79
96private: 80private:
97 struct Info 81 struct Info
98 { 82 {
99 Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} 83 Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {}
100 Info( const QString &_skinName, const QString &_fileNameInfix, 84 Info( const QString &_skinName, const QString &_fileNameInfix,
101 const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) 85 const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount )
102 : skinName( _skinName ), fileNameInfix( _fileNameInfix ), 86 : skinName( _skinName ), fileNameInfix( _fileNameInfix ),
103 skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) 87 skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount )
104 {} 88 {}
105 89
106 const QString skinName; 90 const QString skinName;
107 const QString fileNameInfix; 91 const QString fileNameInfix;
108 const MediaWidget::SkinButtonInfo *skinButtonInfo; 92 const MediaWidget::SkinButtonInfo *skinButtonInfo;
109 const uint buttonCount; 93 const uint buttonCount;
110 }; 94 };
111 typedef QValueList<Info> InfoList; 95 typedef QValueList<Info> InfoList;
112 96
113 void load( const Info &nfo ); 97 void load( const Info &nfo );
114 98
115 InfoList pendingSkins; 99 InfoList pendingSkins;
116 ThreadUtil::Mutex guard; 100 ThreadUtil::Mutex guard;
117}; 101};
118 102
119#endif // SKIN_H 103#endif // SKIN_H
120/* vim: et sw=4 ts=4 104/* vim: et sw=4 ts=4
121 */ 105 */