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,88 +1,104 @@
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() )
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 */