-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.cpp | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 84f5f87..5d8929e 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,120 +1,121 @@ | |||
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 | #include "singleton.h" |
25 | #include <opie2/odebug.h> | ||
25 | 26 | ||
26 | #include <qcache.h> | 27 | #include <qcache.h> |
27 | #include <qtimer.h> | 28 | #include <qtimer.h> |
28 | 29 | ||
29 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
30 | 31 | ||
31 | #include <assert.h> | 32 | #include <assert.h> |
32 | 33 | ||
33 | struct SkinData | 34 | struct SkinData |
34 | { | 35 | { |
35 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 36 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
36 | 37 | ||
37 | QPixmap backgroundPixmap; | 38 | QPixmap backgroundPixmap; |
38 | QImage buttonUpImage; | 39 | QImage buttonUpImage; |
39 | QImage buttonDownImage; | 40 | QImage buttonDownImage; |
40 | QImage buttonMask; | 41 | QImage buttonMask; |
41 | ButtonMaskImageMap buttonMasks; | 42 | ButtonMaskImageMap buttonMasks; |
42 | }; | 43 | }; |
43 | 44 | ||
44 | class SkinCache : public Singleton<SkinCache> | 45 | class SkinCache : public Singleton<SkinCache> |
45 | { | 46 | { |
46 | public: | 47 | public: |
47 | SkinCache(); | 48 | SkinCache(); |
48 | 49 | ||
49 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); | 50 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); |
50 | 51 | ||
51 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); | 52 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); |
52 | 53 | ||
53 | private: | 54 | private: |
54 | typedef QCache<SkinData> DataCache; | 55 | typedef QCache<SkinData> DataCache; |
55 | typedef QCache<QPixmap> BackgroundPixmapCache; | 56 | typedef QCache<QPixmap> BackgroundPixmapCache; |
56 | 57 | ||
57 | template <class CacheType> | 58 | template <class CacheType> |
58 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); | 59 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); |
59 | 60 | ||
60 | DataCache m_cache; | 61 | DataCache m_cache; |
61 | BackgroundPixmapCache m_backgroundPixmapCache; | 62 | BackgroundPixmapCache m_backgroundPixmapCache; |
62 | }; | 63 | }; |
63 | 64 | ||
64 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 65 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
65 | : m_fileNameInfix( fileNameInfix ) | 66 | : m_fileNameInfix( fileNameInfix ) |
66 | { | 67 | { |
67 | init( name ); | 68 | init( name ); |
68 | } | 69 | } |
69 | 70 | ||
70 | Skin::Skin( const QString &fileNameInfix ) | 71 | Skin::Skin( const QString &fileNameInfix ) |
71 | : m_fileNameInfix( fileNameInfix ) | 72 | : m_fileNameInfix( fileNameInfix ) |
72 | { | 73 | { |
73 | init( defaultSkinName() ); | 74 | init( defaultSkinName() ); |
74 | } | 75 | } |
75 | 76 | ||
76 | Skin::~Skin() | 77 | Skin::~Skin() |
77 | { | 78 | { |
78 | if ( m_isCachable ) | 79 | if ( m_isCachable ) |
79 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); | 80 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); |
80 | else | 81 | else |
81 | delete d; | 82 | delete d; |
82 | } | 83 | } |
83 | 84 | ||
84 | void Skin::init( const QString &name ) | 85 | void Skin::init( const QString &name ) |
85 | { | 86 | { |
86 | m_isCachable = true; | 87 | m_isCachable = true; |
87 | m_skinPath = "opieplayer2/skins/" + name; | 88 | m_skinPath = "opieplayer2/skins/" + name; |
88 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); | 89 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); |
89 | } | 90 | } |
90 | 91 | ||
91 | QPixmap Skin::backgroundPixmap() const | 92 | QPixmap Skin::backgroundPixmap() const |
92 | { | 93 | { |
93 | if ( d->backgroundPixmap.isNull() ) | 94 | if ( d->backgroundPixmap.isNull() ) |
94 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); | 95 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
95 | return d->backgroundPixmap; | 96 | return d->backgroundPixmap; |
96 | } | 97 | } |
97 | 98 | ||
98 | QImage Skin::buttonUpImage() const | 99 | QImage Skin::buttonUpImage() const |
99 | { | 100 | { |
100 | if ( d->buttonUpImage.isNull() ) | 101 | if ( d->buttonUpImage.isNull() ) |
101 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 102 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
102 | return d->buttonUpImage; | 103 | return d->buttonUpImage; |
103 | } | 104 | } |
104 | 105 | ||
105 | QImage Skin::buttonDownImage() const | 106 | QImage Skin::buttonDownImage() const |
106 | { | 107 | { |
107 | if ( d->buttonDownImage.isNull() ) | 108 | if ( d->buttonDownImage.isNull() ) |
108 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 109 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
109 | return d->buttonDownImage; | 110 | return d->buttonDownImage; |
110 | } | 111 | } |
111 | 112 | ||
112 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 113 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
113 | { | 114 | { |
114 | if ( !d->buttonMask.isNull() ) | 115 | if ( !d->buttonMask.isNull() ) |
115 | return d->buttonMask; | 116 | return d->buttonMask; |
116 | 117 | ||
117 | QSize buttonAreaSize = buttonUpImage().size(); | 118 | QSize buttonAreaSize = buttonUpImage().size(); |
118 | 119 | ||
119 | d->buttonMask = QImage( buttonAreaSize, 8, 255 ); | 120 | d->buttonMask = QImage( buttonAreaSize, 8, 255 ); |
120 | d->buttonMask.fill( 0 ); | 121 | d->buttonMask.fill( 0 ); |
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp index d8b8abe..6ed9853 100644 --- a/noncore/multimedia/opieplayer2/threadutil.cpp +++ b/noncore/multimedia/opieplayer2/threadutil.cpp | |||
@@ -1,117 +1,118 @@ | |||
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "threadutil.h" | 20 | #include "threadutil.h" |
21 | 21 | ||
22 | #include <opie2/odebug.h> | ||
22 | #include <qsocketnotifier.h> | 23 | #include <qsocketnotifier.h> |
23 | 24 | ||
24 | #include <pthread.h> | 25 | #include <pthread.h> |
25 | #include <assert.h> | 26 | #include <assert.h> |
26 | #include <unistd.h> | 27 | #include <unistd.h> |
27 | #include <errno.h> | 28 | #include <errno.h> |
28 | 29 | ||
29 | using namespace ThreadUtil; | 30 | using namespace ThreadUtil; |
30 | 31 | ||
31 | struct Mutex::Data | 32 | struct Mutex::Data |
32 | { | 33 | { |
33 | Data() | 34 | Data() |
34 | { | 35 | { |
35 | pthread_mutex_init( &mutex, 0 ); | 36 | pthread_mutex_init( &mutex, 0 ); |
36 | } | 37 | } |
37 | ~Data() | 38 | ~Data() |
38 | { | 39 | { |
39 | pthread_mutex_destroy( &mutex ); | 40 | pthread_mutex_destroy( &mutex ); |
40 | } | 41 | } |
41 | 42 | ||
42 | pthread_mutex_t mutex; | 43 | pthread_mutex_t mutex; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | Mutex::Mutex() | 46 | Mutex::Mutex() |
46 | : d( new Data ) | 47 | : d( new Data ) |
47 | { | 48 | { |
48 | } | 49 | } |
49 | 50 | ||
50 | Mutex::~Mutex() | 51 | Mutex::~Mutex() |
51 | { | 52 | { |
52 | delete d; | 53 | delete d; |
53 | } | 54 | } |
54 | 55 | ||
55 | void Mutex::lock() | 56 | void Mutex::lock() |
56 | { | 57 | { |
57 | pthread_mutex_lock( &d->mutex ); | 58 | pthread_mutex_lock( &d->mutex ); |
58 | } | 59 | } |
59 | 60 | ||
60 | void Mutex::unlock() | 61 | void Mutex::unlock() |
61 | { | 62 | { |
62 | pthread_mutex_unlock( &d->mutex ); | 63 | pthread_mutex_unlock( &d->mutex ); |
63 | } | 64 | } |
64 | 65 | ||
65 | bool Mutex::tryLock() | 66 | bool Mutex::tryLock() |
66 | { | 67 | { |
67 | return pthread_mutex_trylock( &d->mutex ) == 0; | 68 | return pthread_mutex_trylock( &d->mutex ) == 0; |
68 | } | 69 | } |
69 | 70 | ||
70 | bool Mutex::isLocked() | 71 | bool Mutex::isLocked() |
71 | { | 72 | { |
72 | if ( !tryLock() ) | 73 | if ( !tryLock() ) |
73 | return true; | 74 | return true; |
74 | 75 | ||
75 | unlock(); | 76 | unlock(); |
76 | return false; | 77 | return false; |
77 | } | 78 | } |
78 | 79 | ||
79 | struct WaitCondition::Data | 80 | struct WaitCondition::Data |
80 | { | 81 | { |
81 | Data() | 82 | Data() |
82 | { | 83 | { |
83 | int result = pthread_cond_init( &waitCondition, 0 ); | 84 | int result = pthread_cond_init( &waitCondition, 0 ); |
84 | assert( result == 0 ); | 85 | assert( result == 0 ); |
85 | } | 86 | } |
86 | ~Data() | 87 | ~Data() |
87 | { | 88 | { |
88 | pthread_cond_destroy( &waitCondition ); | 89 | pthread_cond_destroy( &waitCondition ); |
89 | } | 90 | } |
90 | 91 | ||
91 | pthread_cond_t waitCondition; | 92 | pthread_cond_t waitCondition; |
92 | }; | 93 | }; |
93 | 94 | ||
94 | WaitCondition::WaitCondition() | 95 | WaitCondition::WaitCondition() |
95 | : d( new Data ) | 96 | : d( new Data ) |
96 | { | 97 | { |
97 | } | 98 | } |
98 | 99 | ||
99 | WaitCondition::~WaitCondition() | 100 | WaitCondition::~WaitCondition() |
100 | { | 101 | { |
101 | delete d; | 102 | delete d; |
102 | } | 103 | } |
103 | 104 | ||
104 | bool WaitCondition::wait() | 105 | bool WaitCondition::wait() |
105 | { | 106 | { |
106 | Mutex m; | 107 | Mutex m; |
107 | m.lock(); | 108 | m.lock(); |
108 | return wait( m ); | 109 | return wait( m ); |
109 | } | 110 | } |
110 | 111 | ||
111 | bool WaitCondition::wait( Mutex &mutex ) | 112 | bool WaitCondition::wait( Mutex &mutex ) |
112 | { | 113 | { |
113 | return pthread_cond_wait( &d->waitCondition, &mutex.d->mutex ); | 114 | return pthread_cond_wait( &d->waitCondition, &mutex.d->mutex ); |
114 | } | 115 | } |
115 | 116 | ||
116 | void WaitCondition::wakeOne() | 117 | void WaitCondition::wakeOne() |
117 | { | 118 | { |