Diffstat (limited to 'core/multimedia/opieplayer/mediaplayer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index 6c743ec..15f6928 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp | |||
@@ -1,111 +1,113 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include <qmessagebox.h> | ||
23 | |||
24 | #include "mediaplayer.h" | 22 | #include "mediaplayer.h" |
25 | #include "playlistwidget.h" | 23 | #include "playlistwidget.h" |
26 | #include "audiowidget.h" | 24 | #include "audiowidget.h" |
27 | #include "loopcontrol.h" | 25 | #include "loopcontrol.h" |
28 | #include "audiodevice.h" | 26 | #include "audiodevice.h" |
29 | |||
30 | #include "mediaplayerstate.h" | 27 | #include "mediaplayerstate.h" |
31 | 28 | ||
29 | /* OPIE */ | ||
30 | #include <opie2/odebug.h> | ||
31 | |||
32 | /* QT */ | ||
33 | #include <qmessagebox.h> | ||
32 | 34 | ||
33 | extern AudioWidget *audioUI; | 35 | extern AudioWidget *audioUI; |
34 | extern PlayListWidget *playList; | 36 | extern PlayListWidget *playList; |
35 | extern LoopControl *loopControl; | 37 | extern LoopControl *loopControl; |
36 | extern MediaPlayerState *mediaPlayerState; | 38 | extern MediaPlayerState *mediaPlayerState; |
37 | 39 | ||
38 | 40 | ||
39 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) | 41 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) |
40 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { | 42 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { |
41 | 43 | ||
42 | // QPEApplication::grabKeyboard(); | 44 | // QPEApplication::grabKeyboard(); |
43 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 45 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
44 | 46 | ||
45 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 47 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
46 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( pauseCheck(bool) ) ); | 48 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( pauseCheck(bool) ) ); |
47 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 49 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
48 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 50 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
49 | 51 | ||
50 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 52 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
51 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 53 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
52 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 54 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
53 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 55 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
54 | } | 56 | } |
55 | 57 | ||
56 | 58 | ||
57 | MediaPlayer::~MediaPlayer() { | 59 | MediaPlayer::~MediaPlayer() { |
58 | 60 | ||
59 | } | 61 | } |
60 | 62 | ||
61 | 63 | ||
62 | void MediaPlayer::pauseCheck( bool b ) { | 64 | void MediaPlayer::pauseCheck( bool b ) { |
63 | // Only pause if playing | 65 | // Only pause if playing |
64 | if ( b && !mediaPlayerState->playing() ) | 66 | if ( b && !mediaPlayerState->playing() ) |
65 | mediaPlayerState->setPaused( FALSE ); | 67 | mediaPlayerState->setPaused( FALSE ); |
66 | } | 68 | } |
67 | 69 | ||
68 | 70 | ||
69 | void MediaPlayer::play() { | 71 | void MediaPlayer::play() { |
70 | mediaPlayerState->setPlaying( FALSE ); | 72 | mediaPlayerState->setPlaying( FALSE ); |
71 | mediaPlayerState->setPlaying( TRUE ); | 73 | mediaPlayerState->setPlaying( TRUE ); |
72 | } | 74 | } |
73 | 75 | ||
74 | 76 | ||
75 | void MediaPlayer::setPlaying( bool play ) { | 77 | void MediaPlayer::setPlaying( bool play ) { |
76 | // qDebug("MediaPlayer setPlaying %d", play); | 78 | // odebug << "MediaPlayer setPlaying " << play << "" << oendl; |
77 | if ( !play ) { | 79 | if ( !play ) { |
78 | mediaPlayerState->setPaused( FALSE ); | 80 | mediaPlayerState->setPaused( FALSE ); |
79 | loopControl->stop( FALSE ); | 81 | loopControl->stop( FALSE ); |
80 | return; | 82 | return; |
81 | } | 83 | } |
82 | 84 | ||
83 | if ( mediaPlayerState->paused() ) { | 85 | if ( mediaPlayerState->paused() ) { |
84 | mediaPlayerState->setPaused( FALSE ); | 86 | mediaPlayerState->setPaused( FALSE ); |
85 | return; | 87 | return; |
86 | } | 88 | } |
87 | // qDebug("about to ctrash"); | 89 | // odebug << "about to ctrash" << oendl; |
88 | const DocLnk *playListCurrent = playList->current(); | 90 | const DocLnk *playListCurrent = playList->current(); |
89 | 91 | ||
90 | if ( playListCurrent != NULL ) { | 92 | if ( playListCurrent != NULL ) { |
91 | loopControl->stop( TRUE ); | 93 | loopControl->stop( TRUE ); |
92 | currentFile = playListCurrent; | 94 | currentFile = playListCurrent; |
93 | } | 95 | } |
94 | if ( currentFile == NULL ) { | 96 | if ( currentFile == NULL ) { |
95 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); | 97 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); |
96 | mediaPlayerState->setPlaying( FALSE ); | 98 | mediaPlayerState->setPlaying( FALSE ); |
97 | return; | 99 | return; |
98 | } | 100 | } |
99 | 101 | ||
100 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { | 102 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { |
101 | QMessageBox::critical( 0, tr( "File not found"), | 103 | QMessageBox::critical( 0, tr( "File not found"), |
102 | tr( "The following file was not found: <i>" ) | 104 | tr( "The following file was not found: <i>" ) |
103 | + currentFile->file() + "</i>" ); | 105 | + currentFile->file() + "</i>" ); |
104 | mediaPlayerState->setPlaying( FALSE ); | 106 | mediaPlayerState->setPlaying( FALSE ); |
105 | return; | 107 | return; |
106 | } | 108 | } |
107 | 109 | ||
108 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { | 110 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { |
109 | QMessageBox::critical( 0, tr( "No decoder found"), | 111 | QMessageBox::critical( 0, tr( "No decoder found"), |
110 | tr( "Sorry, no appropriate decoders found for this file: <i>" ) | 112 | tr( "Sorry, no appropriate decoders found for this file: <i>" ) |
111 | + currentFile->file() + "</i>" ); | 113 | + currentFile->file() + "</i>" ); |
@@ -170,102 +172,102 @@ void MediaPlayer::startDecreasingVolume() { | |||
170 | void MediaPlayer::startIncreasingVolume() { | 172 | void MediaPlayer::startIncreasingVolume() { |
171 | volumeDirection = +1; | 173 | volumeDirection = +1; |
172 | startTimer( 100 ); | 174 | startTimer( 100 ); |
173 | AudioDevice::increaseVolume(); | 175 | AudioDevice::increaseVolume(); |
174 | 176 | ||
175 | } | 177 | } |
176 | 178 | ||
177 | bool drawnOnScreenDisplay = FALSE; | 179 | bool drawnOnScreenDisplay = FALSE; |
178 | unsigned int onScreenDisplayVolume = 0; | 180 | unsigned int onScreenDisplayVolume = 0; |
179 | const int yoff = 110; | 181 | const int yoff = 110; |
180 | 182 | ||
181 | void MediaPlayer::stopChangingVolume() { | 183 | void MediaPlayer::stopChangingVolume() { |
182 | killTimers(); | 184 | killTimers(); |
183 | 185 | ||
184 | // Get rid of the on-screen display stuff | 186 | // Get rid of the on-screen display stuff |
185 | drawnOnScreenDisplay = FALSE; | 187 | drawnOnScreenDisplay = FALSE; |
186 | onScreenDisplayVolume = 0; | 188 | onScreenDisplayVolume = 0; |
187 | int w = audioUI->width(); | 189 | int w = audioUI->width(); |
188 | int h = audioUI->height(); | 190 | int h = audioUI->height(); |
189 | audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); | 191 | audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); |
190 | } | 192 | } |
191 | 193 | ||
192 | 194 | ||
193 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 195 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
194 | // qDebug("timer"); | 196 | // odebug << "timer" << oendl; |
195 | if ( volumeDirection == +1 ) | 197 | if ( volumeDirection == +1 ) |
196 | AudioDevice::increaseVolume(); | 198 | AudioDevice::increaseVolume(); |
197 | else if ( volumeDirection == -1 ) | 199 | else if ( volumeDirection == -1 ) |
198 | AudioDevice::decreaseVolume(); | 200 | AudioDevice::decreaseVolume(); |
199 | 201 | ||
200 | // Display an on-screen display volume | 202 | // Display an on-screen display volume |
201 | unsigned int l, r, v; bool m; | 203 | unsigned int l, r, v; bool m; |
202 | AudioDevice::getVolume( l, r, m ); | 204 | AudioDevice::getVolume( l, r, m ); |
203 | v = ((l + r) * 11) / (2*0xFFFF); | 205 | v = ((l + r) * 11) / (2*0xFFFF); |
204 | 206 | ||
205 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { | 207 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { |
206 | // qDebug("returning %d, %d, %d, %d", v, l, r, m); | 208 | // odebug << "returning " << v << ", " << l << ", " << r << ", " << m << "" << oendl; |
207 | return; | 209 | return; |
208 | } | 210 | } |
209 | 211 | ||
210 | int w = audioUI->width(); | 212 | int w = audioUI->width(); |
211 | int h = audioUI->height(); | 213 | int h = audioUI->height(); |
212 | 214 | ||
213 | if ( drawnOnScreenDisplay ) { | 215 | if ( drawnOnScreenDisplay ) { |
214 | if ( onScreenDisplayVolume > v ) | 216 | if ( onScreenDisplayVolume > v ) |
215 | audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, | 217 | audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, |
216 | (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); | 218 | (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); |
217 | } | 219 | } |
218 | 220 | ||
219 | drawnOnScreenDisplay = TRUE; | 221 | drawnOnScreenDisplay = TRUE; |
220 | onScreenDisplayVolume = v; | 222 | onScreenDisplayVolume = v; |
221 | 223 | ||
222 | QPainter p( audioUI ); | 224 | QPainter p( audioUI ); |
223 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 225 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
224 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 226 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
225 | 227 | ||
226 | QFont f; | 228 | QFont f; |
227 | f.setPixelSize( 20 ); | 229 | f.setPixelSize( 20 ); |
228 | f.setBold( TRUE ); | 230 | f.setBold( TRUE ); |
229 | p.setFont( f ); | 231 | p.setFont( f ); |
230 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); | 232 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); |
231 | 233 | ||
232 | for ( unsigned int i = 0; i < 10; i++ ) { | 234 | for ( unsigned int i = 0; i < 10; i++ ) { |
233 | if ( v > i ) | 235 | if ( v > i ) |
234 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 236 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
235 | else | 237 | else |
236 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | 238 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); |
237 | } | 239 | } |
238 | } | 240 | } |
239 | 241 | ||
240 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 242 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
241 | switch ( e->key() ) { | 243 | switch ( e->key() ) { |
242 | ////////////////////////////// Zaurus keys | 244 | ////////////////////////////// Zaurus keys |
243 | case Key_Home: | 245 | case Key_Home: |
244 | break; | 246 | break; |
245 | case Key_F9: //activity | 247 | case Key_F9: //activity |
246 | break; | 248 | break; |
247 | case Key_F10: //contacts | 249 | case Key_F10: //contacts |
248 | break; | 250 | break; |
249 | case Key_F11: //menu | 251 | case Key_F11: //menu |
250 | break; | 252 | break; |
251 | case Key_F12: //home | 253 | case Key_F12: //home |
252 | // qDebug("Blank here"); | 254 | // odebug << "Blank here" << oendl; |
253 | break; | 255 | break; |
254 | case Key_F13: //mail | 256 | case Key_F13: //mail |
255 | break; | 257 | break; |
256 | } | 258 | } |
257 | } | 259 | } |
258 | 260 | ||
259 | void MediaPlayer::doBlank() { | 261 | void MediaPlayer::doBlank() { |
260 | 262 | ||
261 | } | 263 | } |
262 | 264 | ||
263 | void MediaPlayer::doUnblank() { | 265 | void MediaPlayer::doUnblank() { |
264 | 266 | ||
265 | } | 267 | } |
266 | 268 | ||
267 | void MediaPlayer::cleanUp() { | 269 | void MediaPlayer::cleanUp() { |
268 | // QPEApplication::grabKeyboard(); | 270 | // QPEApplication::grabKeyboard(); |
269 | // QPEApplication::ungrabKeyboard(); | 271 | // QPEApplication::ungrabKeyboard(); |
270 | 272 | ||
271 | } | 273 | } |