Diffstat (limited to 'noncore/multimedia/opieplayer2/mediaplayer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 120 |
1 files changed, 69 insertions, 51 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index c230d6f..bbc60dd 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp | |||
@@ -22,28 +22,27 @@ | |||
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 | audioUI = 0; | 34 | m_audioUI = 0; |
35 | videoUI = 0; | 35 | m_videoUI = 0; |
36 | xineControl = 0; | 36 | m_xineControl = 0; |
37 | recreateAudioAndVideoWidgets(); | ||
38 | 37 | ||
39 | fd=-1;fl=-1; | 38 | fd=-1;fl=-1; |
40 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); | 39 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); |
41 | 40 | ||
42 | qApp->processEvents(); | 41 | qApp->processEvents(); |
43 | // QPEApplication::grabKeyboard(); // EVIL | 42 | // QPEApplication::grabKeyboard(); // EVIL |
44 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 43 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
45 | 44 | ||
46 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); | 45 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); |
47 | 46 | ||
48 | // What is pauseCheck good for? (Simon) | 47 | // What is pauseCheck good for? (Simon) |
49 | // connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); | 48 | // connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); |
@@ -51,27 +50,27 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla | |||
51 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 50 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
52 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 51 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
53 | connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); | 52 | connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); |
54 | 53 | ||
55 | volControl = new VolumeControl; | 54 | volControl = new VolumeControl; |
56 | Config cfg( "OpiePlayer" ); | 55 | Config cfg( "OpiePlayer" ); |
57 | cfg.setGroup("PlayList"); | 56 | cfg.setGroup("PlayList"); |
58 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); | 57 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); |
59 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); | 58 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); |
60 | } | 59 | } |
61 | 60 | ||
62 | MediaPlayer::~MediaPlayer() { | 61 | MediaPlayer::~MediaPlayer() { |
63 | delete xineControl; | 62 | delete m_xineControl; |
64 | delete audioUI; | 63 | delete m_audioUI; |
65 | delete videoUI; | 64 | delete m_videoUI; |
66 | delete volControl; | 65 | delete volControl; |
67 | } | 66 | } |
68 | 67 | ||
69 | void MediaPlayer::pauseCheck( bool b ) { | 68 | void MediaPlayer::pauseCheck( bool b ) { |
70 | if ( b && !mediaPlayerState.isPlaying() ) { | 69 | if ( b && !mediaPlayerState.isPlaying() ) { |
71 | mediaPlayerState.setPaused( FALSE ); | 70 | mediaPlayerState.setPaused( FALSE ); |
72 | } | 71 | } |
73 | } | 72 | } |
74 | 73 | ||
75 | void MediaPlayer::play() { | 74 | void MediaPlayer::play() { |
76 | mediaPlayerState.setPlaying( FALSE ); | 75 | mediaPlayerState.setPlaying( FALSE ); |
77 | mediaPlayerState.setPlaying( TRUE ); | 76 | mediaPlayerState.setPlaying( TRUE ); |
@@ -94,44 +93,44 @@ void MediaPlayer::setPlaying( bool play ) { | |||
94 | // since there is no selected file in the playlist, but a selected file in the file list, | 93 | // since there is no selected file in the playlist, but a selected file in the file list, |
95 | // so we remember and shutoff | 94 | // so we remember and shutoff |
96 | l = mediaPlayerState.isLooping(); | 95 | l = mediaPlayerState.isLooping(); |
97 | if(l) { | 96 | if(l) { |
98 | mediaPlayerState.setLooping( false ); | 97 | mediaPlayerState.setLooping( false ); |
99 | } | 98 | } |
100 | r = mediaPlayerState.isShuffled(); | 99 | r = mediaPlayerState.isShuffled(); |
101 | mediaPlayerState.setShuffled( false ); | 100 | mediaPlayerState.setShuffled( false ); |
102 | } | 101 | } |
103 | 102 | ||
104 | PlayListWidget::Entry playListEntry = playList.currentEntry(); | 103 | PlayListWidget::Entry playListEntry = playList.currentEntry(); |
105 | fileName = playListEntry.name; | 104 | fileName = playListEntry.name; |
106 | xineControl->play( playListEntry.file ); | 105 | xineControl()->play( playListEntry.file ); |
107 | 106 | ||
108 | long seconds = mediaPlayerState.length(); | 107 | long seconds = mediaPlayerState.length(); |
109 | time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); | 108 | time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); |
110 | 109 | ||
111 | if( fileName.left(4) == "http" ) { | 110 | if( fileName.left(4) == "http" ) { |
112 | fileName = QFileInfo( fileName ).baseName(); | 111 | fileName = QFileInfo( fileName ).baseName(); |
113 | if ( xineControl->getMetaInfo().isEmpty() ) { | 112 | if ( xineControl()->getMetaInfo().isEmpty() ) { |
114 | tickerText = tr( " File: " ) + fileName; | 113 | tickerText = tr( " File: " ) + fileName; |
115 | } else { | 114 | } else { |
116 | tickerText = xineControl->getMetaInfo(); | 115 | tickerText = xineControl()->getMetaInfo(); |
117 | } | 116 | } |
118 | } else { | 117 | } else { |
119 | if ( xineControl->getMetaInfo().isEmpty() ) { | 118 | if ( xineControl()->getMetaInfo().isEmpty() ) { |
120 | tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; | 119 | tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; |
121 | } else { | 120 | } else { |
122 | tickerText = xineControl->getMetaInfo() + " Length: " + time + " "; | 121 | tickerText = xineControl()->getMetaInfo() + " Length: " + time + " "; |
123 | } | 122 | } |
124 | } | 123 | } |
125 | audioUI->setTickerText( tickerText ); | 124 | audioUI()->setTickerText( tickerText ); |
126 | } | 125 | } |
127 | 126 | ||
128 | 127 | ||
129 | void MediaPlayer::prev() { | 128 | void MediaPlayer::prev() { |
130 | if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist | 129 | if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist |
131 | if ( playList.prev() ) { | 130 | if ( playList.prev() ) { |
132 | play(); | 131 | play(); |
133 | } else if ( mediaPlayerState.isLooping() ) { | 132 | } else if ( mediaPlayerState.isLooping() ) { |
134 | if ( playList.last() ) { | 133 | if ( playList.last() ) { |
135 | play(); | 134 | play(); |
136 | } | 135 | } |
137 | } else { | 136 | } else { |
@@ -180,95 +179,95 @@ void MediaPlayer::startIncreasingVolume() { | |||
180 | 179 | ||
181 | bool drawnOnScreenDisplay = FALSE; | 180 | bool drawnOnScreenDisplay = FALSE; |
182 | unsigned int onScreenDisplayVolume = 0; | 181 | unsigned int onScreenDisplayVolume = 0; |
183 | const int yoff = 110; | 182 | const int yoff = 110; |
184 | 183 | ||
185 | void MediaPlayer::stopChangingVolume() { | 184 | void MediaPlayer::stopChangingVolume() { |
186 | killTimers(); | 185 | killTimers(); |
187 | // Get rid of the on-screen display stuff | 186 | // Get rid of the on-screen display stuff |
188 | drawnOnScreenDisplay = FALSE; | 187 | drawnOnScreenDisplay = FALSE; |
189 | onScreenDisplayVolume = 0; | 188 | onScreenDisplayVolume = 0; |
190 | int w=0; | 189 | int w=0; |
191 | int h=0; | 190 | int h=0; |
192 | if( !xineControl->hasVideo() ) { | 191 | if( !xineControl()->hasVideo() ) { |
193 | w = audioUI->width(); | 192 | w = audioUI()->width(); |
194 | h = audioUI->height(); | 193 | h = audioUI()->height(); |
195 | audioUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); | 194 | audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); |
196 | } else { | 195 | } else { |
197 | w = videoUI->width(); | 196 | w = videoUI()->width(); |
198 | h = videoUI->height(); | 197 | h = videoUI()->height(); |
199 | videoUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); | 198 | videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); |
200 | } | 199 | } |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 203 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
205 | if ( volumeDirection == +1 ) { | 204 | if ( volumeDirection == +1 ) { |
206 | volControl->incVol( 2 ); | 205 | volControl->incVol( 2 ); |
207 | } else if ( volumeDirection == -1 ) { | 206 | } else if ( volumeDirection == -1 ) { |
208 | volControl->decVol( 2 ); | 207 | volControl->decVol( 2 ); |
209 | } | 208 | } |
210 | 209 | ||
211 | 210 | ||
212 | // TODO FIXME | 211 | // TODO FIXME |
213 | // huh?? | 212 | // huh?? |
214 | unsigned int v= 0; | 213 | unsigned int v= 0; |
215 | v = volControl->volume(); | 214 | v = volControl->volume(); |
216 | v = v / 10; | 215 | v = v / 10; |
217 | 216 | ||
218 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { | 217 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { |
219 | return; | 218 | return; |
220 | } | 219 | } |
221 | 220 | ||
222 | int w=0; int h=0; | 221 | int w=0; int h=0; |
223 | if( !xineControl->hasVideo() ) { | 222 | if( !xineControl()->hasVideo() ) { |
224 | w = audioUI->width(); | 223 | w = audioUI()->width(); |
225 | h = audioUI->height(); | 224 | h = audioUI()->height(); |
226 | 225 | ||
227 | if ( drawnOnScreenDisplay ) { | 226 | if ( drawnOnScreenDisplay ) { |
228 | if ( onScreenDisplayVolume > v ) { | 227 | if ( onScreenDisplayVolume > v ) { |
229 | audioUI->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); | 228 | audioUI()->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); |
230 | } | 229 | } |
231 | } | 230 | } |
232 | drawnOnScreenDisplay = TRUE; | 231 | drawnOnScreenDisplay = TRUE; |
233 | onScreenDisplayVolume = v; | 232 | onScreenDisplayVolume = v; |
234 | QPainter p( audioUI ); | 233 | QPainter p( audioUI() ); |
235 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 234 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
236 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 235 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
237 | 236 | ||
238 | QFont f; | 237 | QFont f; |
239 | f.setPixelSize( 20 ); | 238 | f.setPixelSize( 20 ); |
240 | f.setBold( TRUE ); | 239 | f.setBold( TRUE ); |
241 | p.setFont( f ); | 240 | p.setFont( f ); |
242 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); | 241 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); |
243 | 242 | ||
244 | for ( unsigned int i = 0; i < 10; i++ ) { | 243 | for ( unsigned int i = 0; i < 10; i++ ) { |
245 | if ( v > i ) { | 244 | if ( v > i ) { |
246 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 245 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
247 | } else { | 246 | } else { |
248 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | 247 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); |
249 | } | 248 | } |
250 | } | 249 | } |
251 | } else { | 250 | } else { |
252 | w = videoUI->width(); | 251 | w = videoUI()->width(); |
253 | h = videoUI->height(); | 252 | h = videoUI()->height(); |
254 | 253 | ||
255 | if ( drawnOnScreenDisplay ) { | 254 | if ( drawnOnScreenDisplay ) { |
256 | if ( onScreenDisplayVolume > v ) { | 255 | if ( onScreenDisplayVolume > v ) { |
257 | videoUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); | 256 | videoUI()->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); |
258 | } | 257 | } |
259 | } | 258 | } |
260 | drawnOnScreenDisplay = TRUE; | 259 | drawnOnScreenDisplay = TRUE; |
261 | onScreenDisplayVolume = v; | 260 | onScreenDisplayVolume = v; |
262 | QPainter p( videoUI ); | 261 | QPainter p( videoUI() ); |
263 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 262 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
264 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 263 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
265 | 264 | ||
266 | QFont f; | 265 | QFont f; |
267 | f.setPixelSize( 20 ); | 266 | f.setPixelSize( 20 ); |
268 | f.setBold( TRUE ); | 267 | f.setBold( TRUE ); |
269 | p.setFont( f ); | 268 | p.setFont( f ); |
270 | p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) ); | 269 | p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) ); |
271 | 270 | ||
272 | for ( unsigned int i = 0; i < 10; i++ ) { | 271 | for ( unsigned int i = 0; i < 10; i++ ) { |
273 | if ( v > i ) { | 272 | if ( v > i ) { |
274 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 273 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
@@ -337,41 +336,60 @@ void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | |||
337 | } | 336 | } |
338 | } | 337 | } |
339 | 338 | ||
340 | void MediaPlayer::cleanUp() {// this happens on closing | 339 | void MediaPlayer::cleanUp() {// this happens on closing |
341 | Config cfg( "OpiePlayer" ); | 340 | Config cfg( "OpiePlayer" ); |
342 | mediaPlayerState.writeConfig( cfg ); | 341 | mediaPlayerState.writeConfig( cfg ); |
343 | playList.writeDefaultPlaylist( ); | 342 | playList.writeDefaultPlaylist( ); |
344 | 343 | ||
345 | // QPEApplication::grabKeyboard(); | 344 | // QPEApplication::grabKeyboard(); |
346 | // QPEApplication::ungrabKeyboard(); | 345 | // QPEApplication::ungrabKeyboard(); |
347 | } | 346 | } |
348 | 347 | ||
349 | void MediaPlayer::recreateAudioAndVideoWidgets() | 348 | void MediaPlayer::recreateAudioAndVideoWidgets() const |
350 | { | 349 | { |
351 | delete xineControl; | 350 | delete m_xineControl; |
352 | delete audioUI; | 351 | delete m_audioUI; |
353 | delete videoUI; | 352 | delete m_videoUI; |
354 | audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); | 353 | m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); |
355 | videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); | 354 | m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); |
356 | 355 | ||
357 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 356 | connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
358 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 357 | connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
359 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 358 | connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
360 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 359 | connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
361 | 360 | ||
362 | connect( videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 361 | connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
363 | connect( videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 362 | connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
364 | connect( videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 363 | connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
365 | connect( videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 364 | connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
366 | 365 | ||
367 | xineControl = new XineControl( videoUI->vidWidget(), mediaPlayerState ); | 366 | m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState ); |
368 | connect( xineControl, SIGNAL( initialized() ), | 367 | } |
369 | &mediaPlayerState, SLOT( setBackendInitialized() ) ); | 368 | |
369 | AudioWidget *MediaPlayer::audioUI() const | ||
370 | { | ||
371 | if ( !m_audioUI ) | ||
372 | recreateAudioAndVideoWidgets(); | ||
373 | return m_audioUI; | ||
374 | } | ||
375 | |||
376 | VideoWidget *MediaPlayer::videoUI() const | ||
377 | { | ||
378 | if ( !m_videoUI ) | ||
379 | recreateAudioAndVideoWidgets(); | ||
380 | return m_videoUI; | ||
381 | } | ||
382 | |||
383 | XineControl *MediaPlayer::xineControl() const | ||
384 | { | ||
385 | if ( !m_xineControl ) | ||
386 | recreateAudioAndVideoWidgets(); | ||
387 | return m_xineControl; | ||
370 | } | 388 | } |
371 | 389 | ||
372 | void MediaPlayer::reloadSkins() | 390 | void MediaPlayer::reloadSkins() |
373 | { | 391 | { |
374 | audioUI->loadSkin(); | 392 | audioUI()->loadSkin(); |
375 | videoUI->loadSkin(); | 393 | videoUI()->loadSkin(); |
376 | } | 394 | } |
377 | 395 | ||