-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 115 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 53 |
5 files changed, 148 insertions, 31 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index bbc60dd..963e783 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp | |||
@@ -11,96 +11,101 @@ | |||
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | 12 | ||
13 | #include "mediaplayer.h" | 13 | #include "mediaplayer.h" |
14 | #include "playlistwidget.h" | 14 | #include "playlistwidget.h" |
15 | #include "audiowidget.h" | 15 | #include "audiowidget.h" |
16 | #include "videowidget.h" | 16 | #include "videowidget.h" |
17 | #include "volumecontrol.h" | 17 | #include "volumecontrol.h" |
18 | 18 | ||
19 | #include "mediaplayerstate.h" | 19 | #include "mediaplayerstate.h" |
20 | 20 | ||
21 | // for setBacklight() | 21 | // for setBacklight() |
22 | #include <linux/fb.h> | 22 | #include <linux/fb.h> |
23 | #include <sys/file.h> | 23 | #include <sys/file.h> |
24 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
25 | 25 | ||
26 | 26 | ||
27 | 27 | ||
28 | 28 | ||
29 | #define FBIOBLANK 0x4611 | 29 | #define FBIOBLANK 0x4611 |
30 | 30 | ||
31 | MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) | 31 | MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) |
32 | : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { | 32 | : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { |
33 | 33 | ||
34 | m_audioUI = 0; | 34 | m_audioUI = 0; |
35 | m_videoUI = 0; | 35 | m_videoUI = 0; |
36 | m_xineControl = 0; | 36 | m_xineControl = 0; |
37 | 37 | ||
38 | fd=-1;fl=-1; | 38 | fd=-1;fl=-1; |
39 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); | 39 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); |
40 | 40 | ||
41 | qApp->processEvents(); | 41 | qApp->processEvents(); |
42 | // QPEApplication::grabKeyboard(); // EVIL | 42 | // QPEApplication::grabKeyboard(); // EVIL |
43 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 43 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
44 | 44 | ||
45 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); | 45 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); |
46 | 46 | ||
47 | // What is pauseCheck good for? (Simon) | 47 | // What is pauseCheck good for? (Simon) |
48 | // connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); | 48 | // connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); |
49 | 49 | ||
50 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 50 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
51 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 51 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
52 | connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); | 52 | connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); |
53 | 53 | ||
54 | volControl = new VolumeControl; | 54 | volControl = new VolumeControl; |
55 | Config cfg( "OpiePlayer" ); | 55 | Config cfg( "OpiePlayer" ); |
56 | cfg.setGroup("PlayList"); | 56 | cfg.setGroup("PlayList"); |
57 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); | 57 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); |
58 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); | 58 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); |
59 | |||
60 | m_skinLoader = new SkinLoader; | ||
61 | m_skinLoader->schedule( AudioWidget::guiInfo() ); | ||
62 | m_skinLoader->schedule( VideoWidget::guiInfo() ); | ||
63 | m_skinLoader->start(); | ||
59 | } | 64 | } |
60 | 65 | ||
61 | MediaPlayer::~MediaPlayer() { | 66 | MediaPlayer::~MediaPlayer() { |
62 | delete m_xineControl; | 67 | delete m_xineControl; |
63 | delete m_audioUI; | 68 | delete m_audioUI; |
64 | delete m_videoUI; | 69 | delete m_videoUI; |
65 | delete volControl; | 70 | delete volControl; |
66 | } | 71 | } |
67 | 72 | ||
68 | void MediaPlayer::pauseCheck( bool b ) { | 73 | void MediaPlayer::pauseCheck( bool b ) { |
69 | if ( b && !mediaPlayerState.isPlaying() ) { | 74 | if ( b && !mediaPlayerState.isPlaying() ) { |
70 | mediaPlayerState.setPaused( FALSE ); | 75 | mediaPlayerState.setPaused( FALSE ); |
71 | } | 76 | } |
72 | } | 77 | } |
73 | 78 | ||
74 | void MediaPlayer::play() { | 79 | void MediaPlayer::play() { |
75 | mediaPlayerState.setPlaying( FALSE ); | 80 | mediaPlayerState.setPlaying( FALSE ); |
76 | mediaPlayerState.setPlaying( TRUE ); | 81 | mediaPlayerState.setPlaying( TRUE ); |
77 | } | 82 | } |
78 | 83 | ||
79 | void MediaPlayer::setPlaying( bool play ) { | 84 | void MediaPlayer::setPlaying( bool play ) { |
80 | if ( !play ) { | 85 | if ( !play ) { |
81 | return; | 86 | return; |
82 | } | 87 | } |
83 | 88 | ||
84 | if ( mediaPlayerState.isPaused() ) { | 89 | if ( mediaPlayerState.isPaused() ) { |
85 | mediaPlayerState.setPaused( FALSE ); | 90 | mediaPlayerState.setPaused( FALSE ); |
86 | return; | 91 | return; |
87 | } | 92 | } |
88 | 93 | ||
89 | QString tickerText, time, fileName; | 94 | QString tickerText, time, fileName; |
90 | if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { | 95 | if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { |
91 | //if playing in file list.. play in a different way | 96 | //if playing in file list.. play in a different way |
92 | // random and looping settings enabled causes problems here, | 97 | // random and looping settings enabled causes problems here, |
93 | // since there is no selected file in the playlist, but a selected file in the file list, | 98 | // since there is no selected file in the playlist, but a selected file in the file list, |
94 | // so we remember and shutoff | 99 | // so we remember and shutoff |
95 | l = mediaPlayerState.isLooping(); | 100 | l = mediaPlayerState.isLooping(); |
96 | if(l) { | 101 | if(l) { |
97 | mediaPlayerState.setLooping( false ); | 102 | mediaPlayerState.setLooping( false ); |
98 | } | 103 | } |
99 | r = mediaPlayerState.isShuffled(); | 104 | r = mediaPlayerState.isShuffled(); |
100 | mediaPlayerState.setShuffled( false ); | 105 | mediaPlayerState.setShuffled( false ); |
101 | } | 106 | } |
102 | 107 | ||
103 | PlayListWidget::Entry playListEntry = playList.currentEntry(); | 108 | PlayListWidget::Entry playListEntry = playList.currentEntry(); |
104 | fileName = playListEntry.name; | 109 | fileName = playListEntry.name; |
105 | xineControl()->play( playListEntry.file ); | 110 | xineControl()->play( playListEntry.file ); |
106 | 111 | ||
@@ -302,94 +307,96 @@ void MediaPlayer::blank( bool b ) { | |||
302 | ioctl( fd, FBIOBLANK, 0); | 307 | ioctl( fd, FBIOBLANK, 0); |
303 | #ifdef QT_QWS_EBX | 308 | #ifdef QT_QWS_EBX |
304 | if(fl != -1) { | 309 | if(fl != -1) { |
305 | ioctl( fl, 1); | 310 | ioctl( fl, 1); |
306 | ::close(fl); | 311 | ::close(fl); |
307 | } | 312 | } |
308 | #endif | 313 | #endif |
309 | isBlanked = FALSE; | 314 | isBlanked = FALSE; |
310 | } | 315 | } |
311 | close( fd ); | 316 | close( fd ); |
312 | } else { | 317 | } else { |
313 | qDebug("<< /dev/fb0 could not be opened >>"); | 318 | qDebug("<< /dev/fb0 could not be opened >>"); |
314 | } | 319 | } |
315 | } | 320 | } |
316 | 321 | ||
317 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 322 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
318 | switch ( e->key() ) { | 323 | switch ( e->key() ) { |
319 | ////////////////////////////// Zaurus keys | 324 | ////////////////////////////// Zaurus keys |
320 | case Key_Home: | 325 | case Key_Home: |
321 | break; | 326 | break; |
322 | case Key_F9: //activity | 327 | case Key_F9: //activity |
323 | break; | 328 | break; |
324 | case Key_F10: //contacts | 329 | case Key_F10: //contacts |
325 | break; | 330 | break; |
326 | case Key_F11: //menu | 331 | case Key_F11: //menu |
327 | break; | 332 | break; |
328 | case Key_F12: //home | 333 | case Key_F12: //home |
329 | qDebug("Blank here"); | 334 | qDebug("Blank here"); |
330 | // mediaPlayerState->toggleBlank(); | 335 | // mediaPlayerState->toggleBlank(); |
331 | break; | 336 | break; |
332 | case Key_F13: //mail | 337 | case Key_F13: //mail |
333 | qDebug("Blank here"); | 338 | qDebug("Blank here"); |
334 | // mediaPlayerState->toggleBlank(); | 339 | // mediaPlayerState->toggleBlank(); |
335 | break; | 340 | break; |
336 | } | 341 | } |
337 | } | 342 | } |
338 | 343 | ||
339 | void MediaPlayer::cleanUp() {// this happens on closing | 344 | void MediaPlayer::cleanUp() {// this happens on closing |
340 | Config cfg( "OpiePlayer" ); | 345 | Config cfg( "OpiePlayer" ); |
341 | mediaPlayerState.writeConfig( cfg ); | 346 | mediaPlayerState.writeConfig( cfg ); |
342 | playList.writeDefaultPlaylist( ); | 347 | playList.writeDefaultPlaylist( ); |
343 | 348 | ||
344 | // QPEApplication::grabKeyboard(); | 349 | // QPEApplication::grabKeyboard(); |
345 | // QPEApplication::ungrabKeyboard(); | 350 | // QPEApplication::ungrabKeyboard(); |
346 | } | 351 | } |
347 | 352 | ||
348 | void MediaPlayer::recreateAudioAndVideoWidgets() const | 353 | void MediaPlayer::recreateAudioAndVideoWidgets() const |
349 | { | 354 | { |
355 | delete m_skinLoader; | ||
356 | |||
350 | delete m_xineControl; | 357 | delete m_xineControl; |
351 | delete m_audioUI; | 358 | delete m_audioUI; |
352 | delete m_videoUI; | 359 | delete m_videoUI; |
353 | m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); | 360 | m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); |
354 | m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); | 361 | m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); |
355 | 362 | ||
356 | connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 363 | connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
357 | connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 364 | connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
358 | connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 365 | connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
359 | connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 366 | connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
360 | 367 | ||
361 | connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 368 | connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
362 | connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 369 | connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
363 | connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 370 | connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
364 | connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 371 | connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
365 | 372 | ||
366 | m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState ); | 373 | m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState ); |
367 | } | 374 | } |
368 | 375 | ||
369 | AudioWidget *MediaPlayer::audioUI() const | 376 | AudioWidget *MediaPlayer::audioUI() const |
370 | { | 377 | { |
371 | if ( !m_audioUI ) | 378 | if ( !m_audioUI ) |
372 | recreateAudioAndVideoWidgets(); | 379 | recreateAudioAndVideoWidgets(); |
373 | return m_audioUI; | 380 | return m_audioUI; |
374 | } | 381 | } |
375 | 382 | ||
376 | VideoWidget *MediaPlayer::videoUI() const | 383 | VideoWidget *MediaPlayer::videoUI() const |
377 | { | 384 | { |
378 | if ( !m_videoUI ) | 385 | if ( !m_videoUI ) |
379 | recreateAudioAndVideoWidgets(); | 386 | recreateAudioAndVideoWidgets(); |
380 | return m_videoUI; | 387 | return m_videoUI; |
381 | } | 388 | } |
382 | 389 | ||
383 | XineControl *MediaPlayer::xineControl() const | 390 | XineControl *MediaPlayer::xineControl() const |
384 | { | 391 | { |
385 | if ( !m_xineControl ) | 392 | if ( !m_xineControl ) |
386 | recreateAudioAndVideoWidgets(); | 393 | recreateAudioAndVideoWidgets(); |
387 | return m_xineControl; | 394 | return m_xineControl; |
388 | } | 395 | } |
389 | 396 | ||
390 | void MediaPlayer::reloadSkins() | 397 | void MediaPlayer::reloadSkins() |
391 | { | 398 | { |
392 | audioUI()->loadSkin(); | 399 | audioUI()->loadSkin(); |
393 | videoUI()->loadSkin(); | 400 | videoUI()->loadSkin(); |
394 | } | 401 | } |
395 | 402 | ||
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.h b/noncore/multimedia/opieplayer2/mediaplayer.h index 5975731..351c884 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.h +++ b/noncore/multimedia/opieplayer2/mediaplayer.h | |||
@@ -1,96 +1,99 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 LJP <> | 5 | Copyright (c) 2002 LJP <> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef MEDIA_PLAYER_H | 34 | #ifndef MEDIA_PLAYER_H |
35 | #define MEDIA_PLAYER_H | 35 | #define MEDIA_PLAYER_H |
36 | 36 | ||
37 | #include <qmainwindow.h> | 37 | #include <qmainwindow.h> |
38 | #include <qframe.h> | 38 | #include <qframe.h> |
39 | 39 | ||
40 | #include "xinecontrol.h" | 40 | #include "xinecontrol.h" |
41 | 41 | ||
42 | #include "playlistwidget.h" | 42 | #include "playlistwidget.h" |
43 | #include "skin.h" | ||
43 | 44 | ||
44 | class DocLnk; | 45 | class DocLnk; |
45 | class VolumeControl; | 46 | class VolumeControl; |
46 | class MediaPlayerState; | 47 | class MediaPlayerState; |
47 | class AudioWidget; | 48 | class AudioWidget; |
48 | class VideoWidget; | 49 | class VideoWidget; |
49 | 50 | ||
50 | class MediaPlayer : public QObject { | 51 | class MediaPlayer : public QObject { |
51 | Q_OBJECT | 52 | Q_OBJECT |
52 | public: | 53 | public: |
53 | MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ); | 54 | MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ); |
54 | ~MediaPlayer(); | 55 | ~MediaPlayer(); |
55 | 56 | ||
56 | public slots: | 57 | public slots: |
57 | void reloadSkins(); | 58 | void reloadSkins(); |
58 | 59 | ||
59 | private slots: | 60 | private slots: |
60 | void setPlaying( bool ); | 61 | void setPlaying( bool ); |
61 | void pauseCheck( bool ); | 62 | void pauseCheck( bool ); |
62 | void play(); | 63 | void play(); |
63 | void next(); | 64 | void next(); |
64 | void prev(); | 65 | void prev(); |
65 | void startIncreasingVolume(); | 66 | void startIncreasingVolume(); |
66 | void startDecreasingVolume(); | 67 | void startDecreasingVolume(); |
67 | void stopChangingVolume(); | 68 | void stopChangingVolume(); |
68 | void cleanUp(); | 69 | void cleanUp(); |
69 | void blank( bool ); | 70 | void blank( bool ); |
70 | 71 | ||
71 | protected: | 72 | protected: |
72 | void timerEvent( QTimerEvent *e ); | 73 | void timerEvent( QTimerEvent *e ); |
73 | void keyReleaseEvent( QKeyEvent *e); | 74 | void keyReleaseEvent( QKeyEvent *e); |
74 | 75 | ||
75 | private: | 76 | private: |
76 | AudioWidget *audioUI() const; | 77 | AudioWidget *audioUI() const; |
77 | VideoWidget *videoUI() const; | 78 | VideoWidget *videoUI() const; |
78 | XineControl *xineControl() const; | 79 | XineControl *xineControl() const; |
79 | 80 | ||
80 | bool isBlanked, l, r; | 81 | bool isBlanked, l, r; |
81 | int fd, fl; | 82 | int fd, fl; |
82 | int volumeDirection; | 83 | int volumeDirection; |
83 | VolumeControl *volControl; | 84 | VolumeControl *volControl; |
84 | MediaPlayerState &mediaPlayerState; | 85 | MediaPlayerState &mediaPlayerState; |
85 | PlayListWidget &playList; | 86 | PlayListWidget &playList; |
86 | 87 | ||
87 | void recreateAudioAndVideoWidgets() const; | 88 | void recreateAudioAndVideoWidgets() const; |
88 | 89 | ||
89 | mutable XineControl *m_xineControl; | 90 | mutable XineControl *m_xineControl; |
90 | mutable AudioWidget *m_audioUI; | 91 | mutable AudioWidget *m_audioUI; |
91 | mutable VideoWidget *m_videoUI; | 92 | mutable VideoWidget *m_videoUI; |
93 | |||
94 | QGuardedPtr<SkinLoader> m_skinLoader; | ||
92 | }; | 95 | }; |
93 | 96 | ||
94 | 97 | ||
95 | #endif // MEDIA_PLAYER_H | 98 | #endif // MEDIA_PLAYER_H |
96 | 99 | ||
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 40eb0af..45c46ea 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -46,96 +46,97 @@ namespace | |||
46 | class Skin; | 46 | class Skin; |
47 | 47 | ||
48 | class MediaWidget : public QWidget | 48 | class MediaWidget : public QWidget |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | public: | 51 | public: |
52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; | 52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; |
53 | enum ButtonType { NormalButton, ToggleButton }; | 53 | enum ButtonType { NormalButton, ToggleButton }; |
54 | 54 | ||
55 | struct Button | 55 | struct Button |
56 | { | 56 | { |
57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} | 57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} |
58 | 58 | ||
59 | Command command; | 59 | Command command; |
60 | 60 | ||
61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( | 61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( |
62 | bool isDown : 1; | 62 | bool isDown : 1; |
63 | 63 | ||
64 | QBitmap mask; | 64 | QBitmap mask; |
65 | QPixmap pixUp; | 65 | QPixmap pixUp; |
66 | QPixmap pixDown; | 66 | QPixmap pixDown; |
67 | }; | 67 | }; |
68 | #if defined( _CC_GNU_ ) | 68 | #if defined( _CC_GNU_ ) |
69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because | 69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because |
70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( | 70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( |
71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; | 71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; |
72 | #else | 72 | #else |
73 | typedef std::vector<Button> ButtonVector; | 73 | typedef std::vector<Button> ButtonVector; |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | struct SkinButtonInfo | 76 | struct SkinButtonInfo |
77 | { | 77 | { |
78 | Command command; | 78 | Command command; |
79 | const char *fileName; | 79 | const char *fileName; |
80 | ButtonType type; | 80 | ButtonType type; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | struct GUIInfo | 83 | struct GUIInfo |
84 | { | 84 | { |
85 | GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} | 85 | GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} |
86 | GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) | 86 | GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) |
87 | : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) | 87 | : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) |
88 | {} | 88 | {} |
89 | 89 | ||
90 | QString fileNameInfix; | 90 | QString fileNameInfix; |
91 | const SkinButtonInfo *buttonInfo; | 91 | const SkinButtonInfo *buttonInfo; |
92 | const uint buttonCount; | 92 | const uint buttonCount; |
93 | }; | 93 | }; |
94 | typedef QValueList<GUIInfo> GUIInfoList; | ||
94 | 95 | ||
95 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 96 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
96 | virtual ~MediaWidget(); | 97 | virtual ~MediaWidget(); |
97 | 98 | ||
98 | public slots: | 99 | public slots: |
99 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 100 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
100 | virtual void setLength( long length ) = 0; | 101 | virtual void setLength( long length ) = 0; |
101 | virtual void setPlaying( bool playing ) = 0; | 102 | virtual void setPlaying( bool playing ) = 0; |
102 | 103 | ||
103 | virtual void loadSkin() = 0; | 104 | virtual void loadSkin() = 0; |
104 | 105 | ||
105 | signals: | 106 | signals: |
106 | void moreReleased(); | 107 | void moreReleased(); |
107 | void lessReleased(); | 108 | void lessReleased(); |
108 | void forwardReleased(); | 109 | void forwardReleased(); |
109 | void backReleased(); | 110 | void backReleased(); |
110 | void forwardClicked(); | 111 | void forwardClicked(); |
111 | void backClicked(); | 112 | void backClicked(); |
112 | void moreClicked(); | 113 | void moreClicked(); |
113 | void lessClicked(); | 114 | void lessClicked(); |
114 | 115 | ||
115 | protected: | 116 | protected: |
116 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 117 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
117 | const Skin &skin ); | 118 | const Skin &skin ); |
118 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); | 119 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); |
119 | 120 | ||
120 | void loadDefaultSkin( const GUIInfo &guiInfo ); | 121 | void loadDefaultSkin( const GUIInfo &guiInfo ); |
121 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); | 122 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); |
122 | 123 | ||
123 | virtual void closeEvent( QCloseEvent * ); | 124 | virtual void closeEvent( QCloseEvent * ); |
124 | 125 | ||
125 | virtual void paintEvent( QPaintEvent *pe ); | 126 | virtual void paintEvent( QPaintEvent *pe ); |
126 | 127 | ||
127 | virtual void resizeEvent( QResizeEvent *e ); | 128 | virtual void resizeEvent( QResizeEvent *e ); |
128 | 129 | ||
129 | Button *buttonAt( const QPoint &position ); | 130 | Button *buttonAt( const QPoint &position ); |
130 | 131 | ||
131 | virtual void mousePressEvent( QMouseEvent *event ); | 132 | virtual void mousePressEvent( QMouseEvent *event ); |
132 | virtual void mouseReleaseEvent( QMouseEvent *event ); | 133 | virtual void mouseReleaseEvent( QMouseEvent *event ); |
133 | 134 | ||
134 | virtual void makeVisible(); | 135 | virtual void makeVisible(); |
135 | 136 | ||
136 | void handleCommand( Command command, bool buttonDown ); | 137 | void handleCommand( Command command, bool buttonDown ); |
137 | 138 | ||
138 | bool isOverButton( const QPoint &position, int buttonId ) const; | 139 | bool isOverButton( const QPoint &position, int buttonId ) const; |
139 | 140 | ||
140 | void paintAllButtons( QPainter &p ); | 141 | void paintAllButtons( QPainter &p ); |
141 | void paintButton( const Button &button ); | 142 | void paintButton( const Button &button ); |
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 0f49862..e9fb5a6 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,75 +1,76 @@ | |||
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 | 25 | ||
26 | #include <qcache.h> | 26 | #include <qcache.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | #include <qtimer.h> | ||
28 | 29 | ||
29 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
30 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
31 | 32 | ||
32 | #include <assert.h> | 33 | #include <assert.h> |
33 | 34 | ||
34 | struct SkinData | 35 | struct SkinData |
35 | { | 36 | { |
36 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 37 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
37 | 38 | ||
38 | QImage backgroundImage; | 39 | QImage backgroundImage; |
39 | QImage buttonUpImage; | 40 | QImage buttonUpImage; |
40 | QImage buttonDownImage; | 41 | QImage buttonDownImage; |
41 | QImage buttonMask; | 42 | QImage buttonMask; |
42 | ButtonMaskImageMap buttonMasks; | 43 | ButtonMaskImageMap buttonMasks; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | class SkinCache : public Singleton<SkinCache> | 46 | class SkinCache : public Singleton<SkinCache> |
46 | { | 47 | { |
47 | public: | 48 | public: |
48 | SkinCache(); | 49 | SkinCache(); |
49 | 50 | ||
50 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); | 51 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); |
51 | 52 | ||
52 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); | 53 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); |
53 | 54 | ||
54 | private: | 55 | private: |
55 | typedef QCache<SkinData> DataCache; | 56 | typedef QCache<SkinData> DataCache; |
56 | typedef QCache<QImage> BackgroundImageCache; | 57 | typedef QCache<QImage> BackgroundImageCache; |
57 | 58 | ||
58 | template <class CacheType> | 59 | template <class CacheType> |
59 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); | 60 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); |
60 | 61 | ||
61 | DataCache m_cache; | 62 | DataCache m_cache; |
62 | BackgroundImageCache m_backgroundImageCache; | 63 | BackgroundImageCache m_backgroundImageCache; |
63 | }; | 64 | }; |
64 | 65 | ||
65 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 66 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
66 | : m_fileNameInfix( fileNameInfix ) | 67 | : m_fileNameInfix( fileNameInfix ) |
67 | { | 68 | { |
68 | init( name ); | 69 | init( name ); |
69 | } | 70 | } |
70 | 71 | ||
71 | Skin::Skin( const QString &fileNameInfix ) | 72 | Skin::Skin( const QString &fileNameInfix ) |
72 | : m_fileNameInfix( fileNameInfix ) | 73 | : m_fileNameInfix( fileNameInfix ) |
73 | { | 74 | { |
74 | init( defaultSkinName() ); | 75 | init( defaultSkinName() ); |
75 | } | 76 | } |
@@ -137,105 +138,191 @@ void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | |||
137 | 138 | ||
138 | uchar **dest = d->buttonMask.jumpTable(); | 139 | uchar **dest = d->buttonMask.jumpTable(); |
139 | for ( int y = 0; y < d->buttonMask.height(); y++ ) { | 140 | for ( int y = 0; y < d->buttonMask.height(); y++ ) { |
140 | uchar *line = dest[y]; | 141 | uchar *line = dest[y]; |
141 | for ( int x = 0; x < d->buttonMask.width(); x++ ) | 142 | for ( int x = 0; x < d->buttonMask.width(); x++ ) |
142 | if ( !qRed( maskImage.pixel( x, y ) ) ) | 143 | if ( !qRed( maskImage.pixel( x, y ) ) ) |
143 | line[x] = tag; | 144 | line[x] = tag; |
144 | } | 145 | } |
145 | } | 146 | } |
146 | 147 | ||
147 | QImage Skin::buttonMaskImage( const QString &fileName ) const | 148 | QImage Skin::buttonMaskImage( const QString &fileName ) const |
148 | { | 149 | { |
149 | SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); | 150 | SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); |
150 | if ( it == d->buttonMasks.end() ) { | 151 | if ( it == d->buttonMasks.end() ) { |
151 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 152 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
152 | QString path = prefix + fileName + ".png"; | 153 | QString path = prefix + fileName + ".png"; |
153 | it = d->buttonMasks.insert( fileName, loadImage( path ) ); | 154 | it = d->buttonMasks.insert( fileName, loadImage( path ) ); |
154 | } | 155 | } |
155 | return *it; | 156 | return *it; |
156 | } | 157 | } |
157 | 158 | ||
158 | QString Skin::defaultSkinName() | 159 | QString Skin::defaultSkinName() |
159 | { | 160 | { |
160 | Config cfg( "OpiePlayer" ); | 161 | Config cfg( "OpiePlayer" ); |
161 | cfg.setGroup( "Options" ); | 162 | cfg.setGroup( "Options" ); |
162 | return cfg.readEntry( "Skin", "default" ); | 163 | return cfg.readEntry( "Skin", "default" ); |
163 | } | 164 | } |
164 | 165 | ||
165 | QImage Skin::loadImage( const QString &fileName ) | 166 | QImage Skin::loadImage( const QString &fileName ) |
166 | { | 167 | { |
167 | return QImage( Resource::findPixmap( fileName ) ); | 168 | return QImage( Resource::findPixmap( fileName ) ); |
168 | } | 169 | } |
169 | 170 | ||
170 | SkinCache::SkinCache() | 171 | SkinCache::SkinCache() |
171 | { | 172 | { |
172 | // let's say we cache two skins (audio+video) at maximum | 173 | // let's say we cache two skins (audio+video) at maximum |
173 | m_cache.setMaxCost( 2 ); | 174 | m_cache.setMaxCost( 2 ); |
174 | // ... and one background pixmap | 175 | // ... and one background pixmap |
175 | m_backgroundImageCache.setMaxCost( 1 ); | 176 | m_backgroundImageCache.setMaxCost( 1 ); |
176 | } | 177 | } |
177 | 178 | ||
178 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) | 179 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) |
179 | { | 180 | { |
180 | QString key = skinPath + fileNameInfix; | 181 | QString key = skinPath + fileNameInfix; |
181 | 182 | ||
182 | SkinData *data = m_cache.take( key ); | 183 | SkinData *data = m_cache.take( key ); |
183 | if ( !data ) | 184 | if ( !data ) |
184 | data = new SkinData; | 185 | data = new SkinData; |
186 | else | ||
187 | qDebug( "SkinCache: hit" ); | ||
185 | 188 | ||
186 | QImage *bgImage = m_backgroundImageCache.find( skinPath ); | 189 | QImage *bgImage = m_backgroundImageCache.find( skinPath ); |
187 | if ( bgImage ) | 190 | if ( bgImage ) { |
191 | qDebug( "SkinCache: hit on bgimage" ); | ||
188 | data->backgroundImage = *bgImage; | 192 | data->backgroundImage = *bgImage; |
193 | } | ||
189 | else | 194 | else |
190 | data->backgroundImage = QImage(); | 195 | data->backgroundImage = QImage(); |
191 | 196 | ||
192 | return data; | 197 | return data; |
193 | } | 198 | } |
194 | 199 | ||
195 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) | 200 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) |
196 | { | 201 | { |
197 | QImage *backgroundImage = new QImage( data->backgroundImage ); | 202 | QImage *backgroundImage = new QImage( data->backgroundImage ); |
198 | 203 | ||
199 | data->backgroundImage = QImage(); | 204 | data->backgroundImage = QImage(); |
200 | 205 | ||
201 | QString key = skinPath + fileNameInfix; | 206 | QString key = skinPath + fileNameInfix; |
202 | 207 | ||
203 | if ( m_cache.find( key, false /*ref*/ ) != 0 || | 208 | if ( m_cache.find( key, false /*ref*/ ) != 0 || |
204 | !m_cache.insert( key, data ) ) | 209 | !m_cache.insert( key, data ) ) |
205 | delete data; | 210 | delete data; |
206 | 211 | ||
207 | if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 || | 212 | if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 || |
208 | !m_backgroundImageCache.insert( skinPath, backgroundImage ) ) | 213 | !m_backgroundImageCache.insert( skinPath, backgroundImage ) ) |
209 | delete backgroundImage; | 214 | delete backgroundImage; |
210 | } | 215 | } |
211 | 216 | ||
217 | SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) | ||
218 | : m_skin( info.skinName, info.fileNameInfix ), m_info( info ) | ||
219 | { | ||
220 | m_currentState = LoadBackgroundImage; | ||
221 | } | ||
222 | |||
223 | SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() | ||
224 | { | ||
225 | switch ( m_currentState ) { | ||
226 | case LoadBackgroundImage: | ||
227 | qDebug( "load bgimage" ); | ||
228 | m_skin.backgroundImage(); | ||
229 | m_currentState = LoadButtonUpImage; | ||
230 | break; | ||
231 | case LoadButtonUpImage: | ||
232 | qDebug( "load upimage" ); | ||
233 | m_skin.buttonUpImage(); | ||
234 | m_currentState = LoadButtonDownImage; | ||
235 | break; | ||
236 | case LoadButtonDownImage: | ||
237 | qDebug( "load downimage" ); | ||
238 | m_skin.buttonDownImage(); | ||
239 | m_currentState = LoadButtonMasks; | ||
240 | m_currentButton = 0; | ||
241 | break; | ||
242 | case LoadButtonMasks: | ||
243 | qDebug( "load button masks %i", m_currentButton ); | ||
244 | m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName ); | ||
245 | |||
246 | m_currentButton++; | ||
247 | if ( m_currentButton >= m_info.buttonCount ) | ||
248 | m_currentState = LoadButtonMask; | ||
249 | |||
250 | break; | ||
251 | case LoadButtonMask: | ||
252 | qDebug( "load whole mask" ); | ||
253 | m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount ); | ||
254 | return LoadingCompleted; | ||
255 | } | ||
256 | |||
257 | return MoreToCome; | ||
258 | } | ||
259 | |||
212 | SkinLoader::SkinLoader() | 260 | SkinLoader::SkinLoader() |
261 | : m_currentLoader( 0 ), m_timerId( -1 ) | ||
213 | { | 262 | { |
214 | } | 263 | } |
215 | 264 | ||
216 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, | 265 | SkinLoader::~SkinLoader() |
217 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) | ||
218 | { | 266 | { |
219 | assert( isRunning() == false ); | 267 | qDebug( "SkinLoader::~SkinLoader()" ); |
268 | killTimers(); | ||
269 | delete m_currentLoader; | ||
270 | } | ||
220 | 271 | ||
221 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); | 272 | void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo ) |
273 | { | ||
274 | schedule( Skin::defaultSkinName(), guiInfo ); | ||
222 | } | 275 | } |
223 | 276 | ||
224 | void SkinLoader::run() | 277 | void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ) |
225 | { | 278 | { |
226 | qDebug( "SkinLoader::run()" ); | 279 | pendingSkins << Info( skinName, guiInfo ); |
227 | for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) | ||
228 | load( *it ); | ||
229 | qDebug( "SkinLoader is done." ); | ||
230 | } | 280 | } |
231 | 281 | ||
232 | void SkinLoader::load( const Info &nfo ) | 282 | void SkinLoader::start() |
233 | { | 283 | { |
234 | qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); | 284 | assert( m_timerId == -1 ); |
285 | m_timerId = startTimer( 100 /* ms */ ); | ||
286 | qDebug( "SkinLoader::start() %d jobs", pendingSkins.count() ); | ||
287 | } | ||
235 | 288 | ||
236 | Skin skin( nfo.skinName, nfo.fileNameInfix ); | 289 | void SkinLoader::timerEvent( QTimerEvent *ev ) |
237 | skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); | 290 | { |
291 | if ( ev->timerId() != m_timerId ) { | ||
292 | QObject::timerEvent( ev ); | ||
293 | return; | ||
294 | } | ||
295 | |||
296 | if ( !m_currentLoader ) { | ||
297 | |||
298 | if ( pendingSkins.isEmpty() ) { | ||
299 | qDebug( "all jobs done" ); | ||
300 | killTimer( m_timerId ); | ||
301 | m_timerId = -1; | ||
302 | // ### qt3: use deleteLater(); | ||
303 | QTimer::singleShot( 0, this, SLOT( deleteMe() ) ); | ||
304 | return; | ||
305 | } | ||
306 | |||
307 | Info nfo = *pendingSkins.begin(); | ||
308 | pendingSkins.remove( pendingSkins.begin() ); | ||
309 | |||
310 | m_currentLoader = new IncrementalLoader( nfo ); | ||
311 | qDebug( "new loader %i jobs left", pendingSkins.count() ); | ||
312 | } | ||
313 | |||
314 | if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) { | ||
315 | delete m_currentLoader; | ||
316 | m_currentLoader = 0; | ||
317 | } | ||
318 | |||
319 | qDebug( "finished step" ); | ||
320 | } | ||
321 | |||
322 | void SkinLoader::deleteMe() | ||
323 | { | ||
324 | delete this; | ||
238 | } | 325 | } |
239 | 326 | ||
240 | /* vim: et sw=4 ts=4 | 327 | /* vim: et sw=4 ts=4 |
241 | */ | 328 | */ |
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index 9180067..a43a1d0 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -1,105 +1,124 @@ | |||
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 <qobject.h> | ||
28 | 29 | ||
29 | #include "mediawidget.h" | 30 | #include "mediawidget.h" |
30 | #include "threadutil.h" | ||
31 | 31 | ||
32 | struct SkinData; | 32 | struct SkinData; |
33 | 33 | ||
34 | class Skin | 34 | class Skin |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | Skin( const QString &name, const QString &fileNameInfix ); | 37 | Skin( const QString &name, const QString &fileNameInfix ); |
38 | Skin( const QString &fileNameInfix ); | 38 | Skin( const QString &fileNameInfix ); |
39 | ~Skin(); | 39 | ~Skin(); |
40 | 40 | ||
41 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); | 41 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); |
42 | 42 | ||
43 | QImage backgroundImage() const; | 43 | QImage backgroundImage() const; |
44 | QImage buttonUpImage() const; | 44 | QImage buttonUpImage() const; |
45 | QImage buttonDownImage() const; | 45 | QImage buttonDownImage() const; |
46 | 46 | ||
47 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; | 47 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; |
48 | 48 | ||
49 | QImage buttonMaskImage( const QString &fileName ) const; | 49 | QImage buttonMaskImage( const QString &fileName ) const; |
50 | 50 | ||
51 | static QString defaultSkinName(); | 51 | static QString defaultSkinName(); |
52 | 52 | ||
53 | private: | 53 | private: |
54 | void init( const QString &name ); | 54 | void init( const QString &name ); |
55 | 55 | ||
56 | void addButtonToMask( int tag, const QImage &maskImage ) const; | 56 | void addButtonToMask( int tag, const QImage &maskImage ) const; |
57 | 57 | ||
58 | static QImage loadImage( const QString &fileName ); | 58 | static QImage loadImage( const QString &fileName ); |
59 | 59 | ||
60 | QString m_fileNameInfix; | 60 | QString m_fileNameInfix; |
61 | QString m_skinPath; | 61 | QString m_skinPath; |
62 | 62 | ||
63 | SkinData *d; | 63 | SkinData *d; |
64 | 64 | ||
65 | Skin( const Skin & ); | 65 | Skin( const Skin & ); |
66 | Skin &operator=( const Skin & ); | 66 | Skin &operator=( const Skin & ); |
67 | }; | 67 | }; |
68 | 68 | ||
69 | class SkinLoader : public ThreadUtil::Thread | 69 | class SkinLoader : public QObject |
70 | { | 70 | { |
71 | Q_OBJECT | ||
71 | public: | 72 | public: |
72 | SkinLoader(); | 73 | SkinLoader(); |
74 | virtual ~SkinLoader(); | ||
73 | 75 | ||
74 | void schedule( const QString &skinName, const QString &fileNameInfix, | 76 | void schedule( const MediaWidget::GUIInfo &guiInfo ); |
75 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); | 77 | void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ); |
78 | |||
79 | void start(); | ||
76 | 80 | ||
77 | protected: | 81 | protected: |
78 | virtual void run(); | 82 | virtual void timerEvent( QTimerEvent *ev ); |
83 | |||
84 | private slots: | ||
85 | void deleteMe(); | ||
79 | 86 | ||
80 | private: | 87 | private: |
81 | struct Info | 88 | struct Info : public MediaWidget::GUIInfo |
82 | { | 89 | { |
83 | Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} | 90 | Info() {} |
84 | Info( const QString &_skinName, const QString &_fileNameInfix, | 91 | Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo ) |
85 | const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) | 92 | : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName ) |
86 | : skinName( _skinName ), fileNameInfix( _fileNameInfix ), | ||
87 | skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) | ||
88 | {} | 93 | {} |
89 | 94 | ||
90 | const QString skinName; | 95 | QString skinName; |
91 | const QString fileNameInfix; | ||
92 | const MediaWidget::SkinButtonInfo *skinButtonInfo; | ||
93 | const uint buttonCount; | ||
94 | }; | 96 | }; |
95 | typedef QValueList<Info> InfoList; | 97 | typedef QValueList<Info> InfoList; |
96 | 98 | ||
97 | void load( const Info &nfo ); | 99 | class IncrementalLoader |
100 | { | ||
101 | public: | ||
102 | enum LoaderResult { LoadingCompleted, MoreToCome }; | ||
103 | |||
104 | IncrementalLoader( const Info &info ); | ||
105 | |||
106 | LoaderResult loadStep(); | ||
107 | |||
108 | private: | ||
109 | enum State { LoadBackgroundImage, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask }; | ||
110 | |||
111 | Skin m_skin; | ||
112 | Info m_info; | ||
113 | State m_currentState; | ||
114 | uint m_currentButton; | ||
115 | }; | ||
98 | 116 | ||
99 | InfoList pendingSkins; | 117 | InfoList pendingSkins; |
100 | ThreadUtil::Mutex guard; | 118 | IncrementalLoader *m_currentLoader; |
119 | int m_timerId; | ||
101 | }; | 120 | }; |
102 | 121 | ||
103 | #endif // SKIN_H | 122 | #endif // SKIN_H |
104 | /* vim: et sw=4 ts=4 | 123 | /* vim: et sw=4 ts=4 |
105 | */ | 124 | */ |