summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-19 12:15:24 (UTC)
committer llornkcor <llornkcor>2002-03-19 12:15:24 (UTC)
commit58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5 (patch) (unidiff)
tree6f58918f36e66d026d4bbb67574f2d195f15b6ad
parent7a4ff15ff356a484a498249f01354dce549eaec2 (diff)
downloadopie-58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5.zip
opie-58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5.tar.gz
opie-58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5.tar.bz2
reverted back till I figure out
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp4
-rw-r--r--core/multimedia/opieplayer/audiowidget.h1
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp30
-rw-r--r--core/multimedia/opieplayer/mpegplayer.pro2
-rw-r--r--core/multimedia/opieplayer/playlistselection.cpp8
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp173
-rw-r--r--core/multimedia/opieplayer/playlistwidget.h1
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp19
8 files changed, 158 insertions, 80 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index 3901446..cda3f77 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -1,336 +1,338 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qpixmap.h> 24#include <qpixmap.h>
25#include <qbutton.h> 25#include <qbutton.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qframe.h> 27#include <qframe.h>
28 28
29#include "audiowidget.h" 29#include "audiowidget.h"
30#include "mediaplayerstate.h" 30#include "mediaplayerstate.h"
31 31
32extern MediaPlayerState *mediaPlayerState; 32extern MediaPlayerState *mediaPlayerState;
33 33
34 34
35static const int xo = -2; // movable x offset 35static const int xo = -2; // movable x offset
36static const int yo = 22; // movable y offset 36static const int yo = 22; // movable y offset
37 37
38 38
39struct MediaButton { 39struct MediaButton {
40 int xPos, yPos; 40 int xPos, yPos;
41 int color; 41 int color;
42 bool isToggle, isBig, isHeld, isDown; 42 bool isToggle, isBig, isHeld, isDown;
43}; 43};
44 44
45 45
46// Layout information for the audioButtons (and if it is a toggle button or not) 46// Layout information for the audioButtons (and if it is a toggle button or not)
47MediaButton audioButtons[] = { 47MediaButton audioButtons[] = {
48 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play 48 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play
49 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop 49 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop
50 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause 50 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause
51 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next 51 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next
52 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous 52 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous
53 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up 53 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up
54 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down 54 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down
55 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop 55 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop
56 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist 56 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist
57}; 57};
58 58
59 59
60static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 60static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
61 61
62 62
63AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 63AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
64 QWidget( parent, name, f ) 64 QWidget( parent, name, f )
65{ 65{
66// QPEApplication::grabKeyboard(); 66// QPEApplication::grabKeyboard();
67 setCaption( tr("OpiePlayer") ); 67 setCaption( tr("OpiePlayer") );
68 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 68 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
69 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); 69 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) );
70 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); 70 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) );
71 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); 71 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) );
72 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); 72 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) );
73 73
74 songInfo = new Ticker( this ); 74 songInfo = new Ticker( this );
75 songInfo->setFocusPolicy( QWidget::NoFocus ); 75 songInfo->setFocusPolicy( QWidget::NoFocus );
76 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); 76 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) );
77 77
78 slider = new QSlider( Qt::Horizontal, this ); 78 slider = new QSlider( Qt::Horizontal, this );
79 slider->setFixedWidth( 220 ); 79 slider->setFixedWidth( 220 );
80 slider->setFixedHeight( 20 ); 80 slider->setFixedHeight( 20 );
81 slider->setMinValue( 0 ); 81 slider->setMinValue( 0 );
82 slider->setMaxValue( 1 ); 82 slider->setMaxValue( 1 );
83 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 83 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
84 slider->setFocusPolicy( QWidget::NoFocus ); 84 slider->setFocusPolicy( QWidget::NoFocus );
85 slider->setGeometry( QRect( 7, 262, 220, 20 ) ); 85 slider->setGeometry( QRect( 7, 262, 220, 20 ) );
86 86
87 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 87 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
88 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 88 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
89 89
90 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 90 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
91 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 91 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
92 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 92 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
93 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 93 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
94 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 94 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
95 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 95 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
96 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 96 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
97 97
98 // Intialise state 98 // Intialise state
99 setLength( mediaPlayerState->length() ); 99 setLength( mediaPlayerState->length() );
100 setPosition( mediaPlayerState->position() ); 100 setPosition( mediaPlayerState->position() );
101 setLooping( mediaPlayerState->fullscreen() ); 101 setLooping( mediaPlayerState->fullscreen() );
102 setPaused( mediaPlayerState->paused() ); 102 setPaused( mediaPlayerState->paused() );
103 setPlaying( mediaPlayerState->playing() ); 103 setPlaying( mediaPlayerState->playing() );
104 104
105} 105}
106 106
107 107
108AudioWidget::~AudioWidget() { 108AudioWidget::~AudioWidget() {
109 for ( int i = 0; i < 4; i++ ) 109 for ( int i = 0; i < 4; i++ )
110 delete pixmaps[i]; 110 delete pixmaps[i];
111} 111}
112 112
113 113
114static bool audioSliderBeingMoved = FALSE; 114static bool audioSliderBeingMoved = FALSE;
115 115
116 116
117void AudioWidget::sliderPressed() { 117void AudioWidget::sliderPressed() {
118 audioSliderBeingMoved = TRUE; 118 audioSliderBeingMoved = TRUE;
119} 119}
120 120
121 121
122void AudioWidget::sliderReleased() { 122void AudioWidget::sliderReleased() {
123 audioSliderBeingMoved = FALSE; 123 audioSliderBeingMoved = FALSE;
124 if ( slider->width() == 0 ) 124 if ( slider->width() == 0 )
125 return; 125 return;
126 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 126 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
127 mediaPlayerState->setPosition( val ); 127 mediaPlayerState->setPosition( val );
128} 128}
129 129
130 130
131void AudioWidget::setPosition( long i ) { 131void AudioWidget::setPosition( long i ) {
132 updateSlider( i, mediaPlayerState->length() ); 132 updateSlider( i, mediaPlayerState->length() );
133} 133}
134 134
135 135
136void AudioWidget::setLength( long max ) { 136void AudioWidget::setLength( long max ) {
137 updateSlider( mediaPlayerState->position(), max ); 137 updateSlider( mediaPlayerState->position(), max );
138} 138}
139 139
140 140
141void AudioWidget::setView( char view ) { 141void AudioWidget::setView( char view ) {
142 if ( view == 'a' ) { 142 if ( view == 'a' ) {
143 startTimer( 150 ); 143 startTimer( 150 );
144 showMaximized(); 144 showMaximized();
145 } else { 145 } else {
146 killTimers(); 146 killTimers();
147 hide(); 147 hide();
148 } 148 }
149} 149}
150 150
151 151
152void AudioWidget::updateSlider( long i, long max ) { 152void AudioWidget::updateSlider( long i, long max ) {
153 if ( max == 0 ) 153 if ( max == 0 )
154 return; 154 return;
155 // Will flicker too much if we don't do this 155 // Will flicker too much if we don't do this
156 // Scale to something reasonable 156 // Scale to something reasonable
157 int width = slider->width(); 157 int width = slider->width();
158 int val = int((double)i * width / max); 158 int val = int((double)i * width / max);
159 if ( !audioSliderBeingMoved ) { 159 if ( !audioSliderBeingMoved ) {
160 if ( slider->value() != val ) 160 if ( slider->value() != val )
161 slider->setValue( val ); 161 slider->setValue( val );
162 if ( slider->maxValue() != width ) 162 if ( slider->maxValue() != width )
163 slider->setMaxValue( width ); 163 slider->setMaxValue( width );
164 } 164 }
165} 165}
166 166
167 167
168void AudioWidget::setToggleButton( int i, bool down ) { 168void AudioWidget::setToggleButton( int i, bool down ) {
169 if ( down != audioButtons[i].isDown ) 169 if ( down != audioButtons[i].isDown )
170 toggleButton( i ); 170 toggleButton( i );
171} 171}
172 172
173 173
174void AudioWidget::toggleButton( int i ) { 174void AudioWidget::toggleButton( int i ) {
175 audioButtons[i].isDown = !audioButtons[i].isDown; 175 audioButtons[i].isDown = !audioButtons[i].isDown;
176 QPainter p(this); 176 QPainter p(this);
177 paintButton ( &p, i ); 177 paintButton ( &p, i );
178} 178}
179 179
180 180
181void AudioWidget::paintButton( QPainter *p, int i ) { 181void AudioWidget::paintButton( QPainter *p, int i ) {
182 int x = audioButtons[i].xPos; 182 int x = audioButtons[i].xPos;
183 int y = audioButtons[i].yPos; 183 int y = audioButtons[i].yPos;
184 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; 184 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown;
185 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); 185 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64);
186 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); 186 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize );
187 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); 187 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 );
188} 188}
189 189
190 190
191void AudioWidget::timerEvent( QTimerEvent * ) { 191void AudioWidget::timerEvent( QTimerEvent * ) {
192 static int frame = 0; 192 static int frame = 0;
193 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 193 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
194 frame = frame >= 7 ? 0 : frame + 1; 194 frame = frame >= 7 ? 0 : frame + 1;
195 int x = audioButtons[AudioPlay].xPos; 195 int x = audioButtons[AudioPlay].xPos;
196 int y = audioButtons[AudioPlay].yPos; 196 int y = audioButtons[AudioPlay].yPos;
197 QPainter p( this ); 197 QPainter p( this );
198 // Optimize to only draw the little bit of the changing images which is different 198 // Optimize to only draw the little bit of the changing images which is different
199 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); 199 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 );
200 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); 200 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 );
201 } 201 }
202} 202}
203 203
204 204
205void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 205void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
206 for ( int i = 0; i < numButtons; i++ ) { 206 for ( int i = 0; i < numButtons; i++ ) {
207 int size = audioButtons[i].isBig; 207 int size = audioButtons[i].isBig;
208 int x = audioButtons[i].xPos; 208 int x = audioButtons[i].xPos;
209 int y = audioButtons[i].yPos; 209 int y = audioButtons[i].yPos;
210 if ( event->state() == QMouseEvent::LeftButton ) { 210 if ( event->state() == QMouseEvent::LeftButton ) {
211 // The test to see if the mouse click is inside the circular button or not 211 // The test to see if the mouse click is inside the circular button or not
212 // (compared with the radius squared to avoid a square-root of our distance) 212 // (compared with the radius squared to avoid a square-root of our distance)
213 int radius = 32 + 13 * size; 213 int radius = 32 + 13 * size;
214 QPoint center = QPoint( x + radius, y + radius ); 214 QPoint center = QPoint( x + radius, y + radius );
215 QPoint dXY = center - event->pos(); 215 QPoint dXY = center - event->pos();
216 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 216 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
217 bool isOnButton = dist <= (radius * radius); 217 bool isOnButton = dist <= (radius * radius);
218// QRect r( x, y, 64 + 22*size, 64 + 22*size ); 218// QRect r( x, y, 64 + 22*size, 64 + 22*size );
219// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code 219// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code
220 if ( isOnButton && !audioButtons[i].isHeld ) { 220 if ( isOnButton && !audioButtons[i].isHeld ) {
221 audioButtons[i].isHeld = TRUE; 221 audioButtons[i].isHeld = TRUE;
222 toggleButton(i); 222 toggleButton(i);
223 qDebug("button toggled %d",i); 223 qDebug("button toggled1 %d",i);
224 switch (i) { 224 switch (i) {
225 case AudioVolumeUp: emit moreClicked(); return; 225 case AudioVolumeUp: emit moreClicked(); return;
226 case AudioVolumeDown: emit lessClicked(); return; 226 case AudioVolumeDown: emit lessClicked(); return;
227 } 227 }
228 } else if ( !isOnButton && audioButtons[i].isHeld ) { 228 } else if ( !isOnButton && audioButtons[i].isHeld ) {
229 audioButtons[i].isHeld = FALSE; 229 audioButtons[i].isHeld = FALSE;
230 toggleButton(i); 230 toggleButton(i);
231 qDebug("button toggled2 %d",i);
231 } 232 }
232 } else { 233 } else {
233 if ( audioButtons[i].isHeld ) { 234 if ( audioButtons[i].isHeld ) {
234 audioButtons[i].isHeld = FALSE; 235 audioButtons[i].isHeld = FALSE;
235 if ( !audioButtons[i].isToggle ) 236 if ( !audioButtons[i].isToggle )
236 setToggleButton( i, FALSE ); 237 setToggleButton( i, FALSE );
238 qDebug("button toggled3 %d",i);
237 switch (i) { 239 switch (i) {
238 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 240 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
239 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 241 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
240 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 242 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
241 case AudioNext: mediaPlayerState->setNext(); return; 243 case AudioNext: mediaPlayerState->setNext(); return;
242 case AudioPrevious: mediaPlayerState->setPrev(); return; 244 case AudioPrevious: mediaPlayerState->setPrev(); return;
243 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 245 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
244 case AudioVolumeUp: emit moreReleased(); return; 246 case AudioVolumeUp: emit moreReleased(); return;
245 case AudioVolumeDown: emit lessReleased(); return; 247 case AudioVolumeDown: emit lessReleased(); return;
246 case AudioPlayList: mediaPlayerState->setList(); return; 248 case AudioPlayList: mediaPlayerState->setList(); return;
247 } 249 }
248 } 250 }
249 } 251 }
250 } 252 }
251} 253}
252 254
253 255
254void AudioWidget::mousePressEvent( QMouseEvent *event ) { 256void AudioWidget::mousePressEvent( QMouseEvent *event ) {
255 mouseMoveEvent( event ); 257 mouseMoveEvent( event );
256} 258}
257 259
258 260
259void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 261void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
260 mouseMoveEvent( event ); 262 mouseMoveEvent( event );
261} 263}
262 264
263 265
264void AudioWidget::showEvent( QShowEvent* ) { 266void AudioWidget::showEvent( QShowEvent* ) {
265 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 267 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
266 mouseMoveEvent( &event ); 268 mouseMoveEvent( &event );
267} 269}
268 270
269 271
270void AudioWidget::closeEvent( QCloseEvent* ) { 272void AudioWidget::closeEvent( QCloseEvent* ) {
271 mediaPlayerState->setList(); 273 mediaPlayerState->setList();
272} 274}
273 275
274 276
275void AudioWidget::paintEvent( QPaintEvent * ) { 277void AudioWidget::paintEvent( QPaintEvent * ) {
276 QPainter p( this ); 278 QPainter p( this );
277 for ( int i = 0; i < numButtons; i++ ) 279 for ( int i = 0; i < numButtons; i++ )
278 paintButton( &p, i ); 280 paintButton( &p, i );
279} 281}
280 282
281 283
282void AudioWidget::keyReleaseEvent( QKeyEvent *e) 284void AudioWidget::keyReleaseEvent( QKeyEvent *e)
283{ 285{
284 switch ( e->key() ) { 286 switch ( e->key() ) {
285////////////////////////////// Zaurus keys 287////////////////////////////// Zaurus keys
286 case Key_Home: 288 case Key_Home:
287 break; 289 break;
288 case Key_F9: //activity 290 case Key_F9: //activity
289 break; 291 break;
290 case Key_F10: //contacts 292 case Key_F10: //contacts
291 break; 293 break;
292 case Key_F11: //menu 294 case Key_F11: //menu
293 break; 295 break;
294 case Key_F12: //home 296 case Key_F12: //home
295 break; 297 break;
296 case Key_F13: //mail 298 case Key_F13: //mail
297 break; 299 break;
298 case Key_Space: { 300 case Key_Space: {
299 if(mediaPlayerState->playing()) { 301 if(mediaPlayerState->playing()) {
300// toggleButton(1); 302// toggleButton(1);
301 mediaPlayerState->setPlaying(FALSE); 303 mediaPlayerState->setPlaying(FALSE);
302// toggleButton(1); 304// toggleButton(1);
303 } else { 305 } else {
304// toggleButton(0); 306// toggleButton(0);
305 mediaPlayerState->setPlaying(TRUE); 307 mediaPlayerState->setPlaying(TRUE);
306// toggleButton(0); 308// toggleButton(0);
307 } 309 }
308 } 310 }
309 break; 311 break;
310 case Key_Down: 312 case Key_Down:
311 toggleButton(6); 313 toggleButton(6);
312 emit lessClicked(); 314 emit lessClicked();
313 emit lessReleased(); 315 emit lessReleased();
314 toggleButton(6); 316 toggleButton(6);
315 break; 317 break;
316 case Key_Up: 318 case Key_Up:
317 toggleButton(5); 319 toggleButton(5);
318 emit moreClicked(); 320 emit moreClicked();
319 emit moreReleased(); 321 emit moreReleased();
320 toggleButton(5); 322 toggleButton(5);
321 break; 323 break;
322 case Key_Right: 324 case Key_Right:
323// toggleButton(3); 325// toggleButton(3);
324 mediaPlayerState->setNext(); 326 mediaPlayerState->setNext();
325// toggleButton(3); 327// toggleButton(3);
326 break; 328 break;
327 case Key_Left: 329 case Key_Left:
328// toggleButton(4); 330// toggleButton(4);
329 mediaPlayerState->setPrev(); 331 mediaPlayerState->setPrev();
330// toggleButton(4); 332// toggleButton(4);
331 break; 333 break;
332 case Key_Escape: 334 case Key_Escape:
333 break; 335 break;
334 336
335 }; 337 };
336} 338}
diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h
index a2850aa..d1d72b6 100644
--- a/core/multimedia/opieplayer/audiowidget.h
+++ b/core/multimedia/opieplayer/audiowidget.h
@@ -1,144 +1,145 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#ifndef AUDIO_WIDGET_H 21#ifndef AUDIO_WIDGET_H
21#define AUDIO_WIDGET_H 22#define AUDIO_WIDGET_H
22 23
23#include <qwidget.h> 24#include <qwidget.h>
24#include <qpainter.h> 25#include <qpainter.h>
25#include <qdrawutil.h> 26#include <qdrawutil.h>
26#include <qpixmap.h> 27#include <qpixmap.h>
27#include <qstring.h> 28#include <qstring.h>
28#include <qslider.h> 29#include <qslider.h>
29#include <qframe.h> 30#include <qframe.h>
30 31
31 32
32class QPixmap; 33class QPixmap;
33 34
34 35
35enum AudioButtons { 36enum AudioButtons {
36 AudioPlay, 37 AudioPlay,
37 AudioStop, 38 AudioStop,
38 AudioPause, 39 AudioPause,
39 AudioNext, 40 AudioNext,
40 AudioPrevious, 41 AudioPrevious,
41 AudioVolumeUp, 42 AudioVolumeUp,
42 AudioVolumeDown, 43 AudioVolumeDown,
43 AudioLoop, 44 AudioLoop,
44 AudioPlayList 45 AudioPlayList
45}; 46};
46 47
47 48
48#define USE_DBLBUF 49#define USE_DBLBUF
49 50
50 51
51class Ticker : public QFrame { 52class Ticker : public QFrame {
52 Q_OBJECT 53 Q_OBJECT
53public: 54public:
54 Ticker( QWidget* parent=0 ) : QFrame( parent ) { 55 Ticker( QWidget* parent=0 ) : QFrame( parent ) {
55 setFrameStyle( WinPanel | Sunken ); 56 setFrameStyle( WinPanel | Sunken );
56 setText( "No Song" ); 57 setText( "No Song" );
57 } 58 }
58 ~Ticker() { } 59 ~Ticker() { }
59 void setText( const QString& text ) { 60 void setText( const QString& text ) {
60 pos = 0; // reset it everytime the text is changed 61 pos = 0; // reset it everytime the text is changed
61 scrollText = text; 62 scrollText = text;
62 pixelLen = fontMetrics().width( scrollText ); 63 pixelLen = fontMetrics().width( scrollText );
63 killTimers(); 64 killTimers();
64 if ( pixelLen > width() ) 65 if ( pixelLen > width() )
65 startTimer( 50 ); 66 startTimer( 50 );
66 update(); 67 update();
67 } 68 }
68protected: 69protected:
69 void timerEvent( QTimerEvent * ) { 70 void timerEvent( QTimerEvent * ) {
70 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; 71 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
71#ifndef USE_DBLBUF 72#ifndef USE_DBLBUF
72 scroll( -1, 0, contentsRect() ); 73 scroll( -1, 0, contentsRect() );
73#else 74#else
74 repaint( FALSE ); 75 repaint( FALSE );
75#endif 76#endif
76 } 77 }
77 void drawContents( QPainter *p ) { 78 void drawContents( QPainter *p ) {
78#ifndef USE_DBLBUF 79#ifndef USE_DBLBUF
79 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) 80 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
80 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 81 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
81#else 82#else
82 // Double buffering code. 83 // Double buffering code.
83 // Looks like qvfb makes it look like it flickers but I don't think it really is 84 // Looks like qvfb makes it look like it flickers but I don't think it really is
84 QPixmap pm( width(), height() ); 85 QPixmap pm( width(), height() );
85 pm.fill( colorGroup().base() ); 86 pm.fill( colorGroup().base() );
86 QPainter pmp( &pm ); 87 QPainter pmp( &pm );
87 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) 88 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
88 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 89 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
89 p->drawPixmap( 0, 0, pm ); 90 p->drawPixmap( 0, 0, pm );
90#endif 91#endif
91 } 92 }
92private: 93private:
93 QString scrollText; 94 QString scrollText;
94 int pos, pixelLen; 95 int pos, pixelLen;
95}; 96};
96 97
97 98
98class AudioWidget : public QWidget { 99class AudioWidget : public QWidget {
99 Q_OBJECT 100 Q_OBJECT
100public: 101public:
101 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); 102 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
102 ~AudioWidget(); 103 ~AudioWidget();
103 void setTickerText( const QString &text ) { songInfo->setText( text ); } 104 void setTickerText( const QString &text ) { songInfo->setText( text ); }
104 105
105public slots: 106public slots:
106 void updateSlider( long, long ); 107 void updateSlider( long, long );
107 void sliderPressed( ); 108 void sliderPressed( );
108 void sliderReleased( ); 109 void sliderReleased( );
109 void setPaused( bool b) { setToggleButton( AudioPause, b ); } 110 void setPaused( bool b) { setToggleButton( AudioPause, b ); }
110 void setLooping( bool b) { setToggleButton( AudioLoop, b ); } 111 void setLooping( bool b) { setToggleButton( AudioLoop, b ); }
111 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } 112 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); }
112 void setPosition( long ); 113 void setPosition( long );
113 void setLength( long ); 114 void setLength( long );
114 void setView( char ); 115 void setView( char );
115 116
116signals: 117signals:
117 void moreClicked(); 118 void moreClicked();
118 void lessClicked(); 119 void lessClicked();
119 void moreReleased(); 120 void moreReleased();
120 void lessReleased(); 121 void lessReleased();
121 void sliderMoved(long); 122 void sliderMoved(long);
122 123
123protected: 124protected:
124 void paintEvent( QPaintEvent *pe ); 125 void paintEvent( QPaintEvent *pe );
125 void showEvent( QShowEvent *se ); 126 void showEvent( QShowEvent *se );
126 void mouseMoveEvent( QMouseEvent *event ); 127 void mouseMoveEvent( QMouseEvent *event );
127 void mousePressEvent( QMouseEvent *event ); 128 void mousePressEvent( QMouseEvent *event );
128 void mouseReleaseEvent( QMouseEvent *event ); 129 void mouseReleaseEvent( QMouseEvent *event );
129 void timerEvent( QTimerEvent *event ); 130 void timerEvent( QTimerEvent *event );
130 void closeEvent( QCloseEvent *event ); 131 void closeEvent( QCloseEvent *event );
131 void keyReleaseEvent( QKeyEvent *e); 132 void keyReleaseEvent( QKeyEvent *e);
132 133
133private: 134private:
134 void toggleButton( int ); 135 void toggleButton( int );
135 void setToggleButton( int, bool ); 136 void setToggleButton( int, bool );
136 void paintButton( QPainter *p, int i ); 137 void paintButton( QPainter *p, int i );
137 QPixmap *pixmaps[4]; 138 QPixmap *pixmaps[4];
138 Ticker *songInfo; 139 Ticker *songInfo;
139 QSlider *slider; 140 QSlider *slider;
140}; 141};
141 142
142 143
143#endif // AUDIO_WIDGET_H 144#endif // AUDIO_WIDGET_H
144 145
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 4b2827e..b9f96de 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -1,476 +1,474 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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// L.J.Potter added changes Fri 02-15-2002 20// L.J.Potter added changes Fri 02-15-2002
21 21
22
23#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
24 23
25#ifdef Q_WS_QWS 24#ifdef Q_WS_QWS
26#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
27#endif 26#endif
28#include <stdio.h> 27#include <stdio.h>
29#include <stdlib.h> 28#include <stdlib.h>
30#include <string.h> 29#include <string.h>
31#include <pthread.h> 30#include <pthread.h>
32#include <errno.h> 31#include <errno.h>
33#include <unistd.h> 32#include <unistd.h>
34#include "loopcontrol.h" 33#include "loopcontrol.h"
35#include "videowidget.h" 34#include "videowidget.h"
36#include "audiodevice.h" 35#include "audiodevice.h"
37#include <qpe/mediaplayerplugininterface.h> 36#include <qpe/mediaplayerplugininterface.h>
38#include "mediaplayerstate.h" 37#include "mediaplayerstate.h"
39 38
40 39
41extern VideoWidget *videoUI; // now only needed to tell it to play a frame 40extern VideoWidget *videoUI; // now only needed to tell it to play a frame
42extern MediaPlayerState *mediaPlayerState; 41extern MediaPlayerState *mediaPlayerState;
43 42
44 43
45//#define DecodeLoopDebug(x) qDebug x 44//#define DecodeLoopDebug(x) qDebug x
46#define DecodeLoopDebug(x) 45#define DecodeLoopDebug(x)
47 46
48 47
49static char *audioBuffer = NULL; 48static char *audioBuffer = NULL;
50static AudioDevice *audioDevice = NULL; 49static AudioDevice *audioDevice = NULL;
51static bool disabledSuspendScreenSaver = FALSE; 50static bool disabledSuspendScreenSaver = FALSE;
52static bool previousSuspendMode = FALSE; 51static bool previousSuspendMode = FALSE;
53 52
54 53
55pthread_t audio_tid; 54pthread_t audio_tid;
56pthread_attr_t audio_attr; 55pthread_attr_t audio_attr;
57bool threadOkToGo = FALSE; 56bool threadOkToGo = FALSE;
58 57
59 58
60class Mutex { 59class Mutex {
61public: 60public:
62 Mutex() { 61 Mutex() {
63 pthread_mutexattr_t attr; 62 pthread_mutexattr_t attr;
64 pthread_mutexattr_init( &attr ); 63 pthread_mutexattr_init( &attr );
65 pthread_mutex_init( &mutex, &attr ); 64 pthread_mutex_init( &mutex, &attr );
66 pthread_mutexattr_destroy( &attr ); 65 pthread_mutexattr_destroy( &attr );
67 } 66 }
68 67
69 ~Mutex() { 68 ~Mutex() {
70 pthread_mutex_destroy( &mutex ); 69 pthread_mutex_destroy( &mutex );
71 } 70 }
72 71
73 void lock() { 72 void lock() {
74 pthread_mutex_lock( &mutex ); 73 pthread_mutex_lock( &mutex );
75 } 74 }
76 75
77 void unlock() { 76 void unlock() {
78 pthread_mutex_unlock( &mutex ); 77 pthread_mutex_unlock( &mutex );
79 } 78 }
80private: 79private:
81 pthread_mutex_t mutex; 80 pthread_mutex_t mutex;
82}; 81};
83 82
84 83
85void *startAudioThread( void *ptr ) { 84void *startAudioThread( void *ptr ) {
86 LoopControl *mpegView = (LoopControl *)ptr; 85 LoopControl *mpegView = (LoopControl *)ptr;
87 while ( TRUE ) { 86 while ( TRUE ) {
88 if ( threadOkToGo && mpegView->moreAudio ) 87 if ( threadOkToGo && mpegView->moreAudio )
89 mpegView->startAudio(); 88 mpegView->startAudio();
90 else 89 else
91 usleep( 10000 ); // Semi-buzy-wait till we are playing again 90 usleep( 10000 ); // Semi-buzy-wait till we are playing again
92 } 91 }
93 return 0; 92 return 0;
94} 93}
95 94
96 95
97Mutex *audioMutex; 96Mutex *audioMutex;
98 97
99 98
100LoopControl::LoopControl( QObject *parent, const char *name ) 99LoopControl::LoopControl( QObject *parent, const char *name )
101 : QObject( parent, name ) { 100 : QObject( parent, name ) {
102 isMuted = FALSE; 101 isMuted = FALSE;
103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 102 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
104//qDebug("starting loopcontrol"); 103//qDebug("starting loopcontrol");
105 audioMutex = new Mutex; 104 audioMutex = new Mutex;
106 105
107 pthread_attr_init(&audio_attr); 106 pthread_attr_init(&audio_attr);
108#define USE_REALTIME_AUDIO_THREAD 107#define USE_REALTIME_AUDIO_THREAD
109#ifdef USE_REALTIME_AUDIO_THREAD 108#ifdef USE_REALTIME_AUDIO_THREAD
110 // Attempt to set it to real-time round robin 109 // Attempt to set it to real-time round robin
111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { 110 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) {
112 sched_param params; 111 sched_param params;
113 params.sched_priority = 50; 112 params.sched_priority = 50;
114 pthread_attr_setschedparam(&audio_attr,&params); 113 pthread_attr_setschedparam(&audio_attr,&params);
115 } else { 114 } else {
116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 115 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." );
117 pthread_attr_destroy(&audio_attr); 116 pthread_attr_destroy(&audio_attr);
118 pthread_attr_init(&audio_attr); 117 pthread_attr_init(&audio_attr);
119 } 118 }
120#endif 119#endif
121//qDebug("create audio thread"); 120//qDebug("create audio thread");
122 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
123} 122}
124 123
125 124
126LoopControl::~LoopControl() { 125LoopControl::~LoopControl() {
127 stop(); 126 stop();
128} 127}
129 128
130 129
131static long prev_frame = 0; 130static long prev_frame = 0;
132static int currentSample = 0; 131static int currentSample = 0;
133 132
134 133
135void LoopControl::timerEvent( QTimerEvent *te ) { 134void LoopControl::timerEvent( QTimerEvent *te ) {
136 135
137 if ( te->timerId() == videoId ) 136 if ( te->timerId() == videoId )
138 startVideo(); 137 startVideo();
139 138
140 if ( te->timerId() == sliderId ) { 139 if ( te->timerId() == sliderId ) {
141 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { 140 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) {
142 mediaPlayerState->updatePosition( audioSampleCounter ); 141 mediaPlayerState->updatePosition( audioSampleCounter );
143 } else if ( hasVideoChannel && moreVideo ) { 142 } else if ( hasVideoChannel && moreVideo ) {
144 mediaPlayerState->updatePosition( current_frame ); 143 mediaPlayerState->updatePosition( current_frame );
145 } 144 }
146 } 145 }
147 146
148 if ( !moreVideo && !moreAudio ) { 147 if ( !moreVideo && !moreAudio ) {
149 mediaPlayerState->setPlaying( FALSE ); 148 mediaPlayerState->setPlaying( FALSE );
150 mediaPlayerState->setNext(); 149 mediaPlayerState->setNext();
151 } 150 }
152} 151}
153 152
154 153
155void LoopControl::setPosition( long pos ) { 154void LoopControl::setPosition( long pos ) {
156 audioMutex->lock(); 155 audioMutex->lock();
157 156
158 if ( hasVideoChannel && hasAudioChannel ) { 157 if ( hasVideoChannel && hasAudioChannel ) {
159 playtime.restart(); 158 playtime.restart();
160 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 159 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
161 current_frame = pos + 1; 160 current_frame = pos + 1;
162 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 161 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
163 prev_frame = current_frame - 1; 162 prev_frame = current_frame - 1;
164 currentSample = (int)( (double)current_frame * freq / framerate ); 163 currentSample = (int)( (double)current_frame * freq / framerate );
165 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 164 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
166 audioSampleCounter = currentSample - 1; 165 audioSampleCounter = currentSample - 1;
167 } else if ( hasVideoChannel ) { 166 } else if ( hasVideoChannel ) {
168 playtime.restart(); 167 playtime.restart();
169 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 168 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
170 current_frame = pos + 1; 169 current_frame = pos + 1;
171 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 170 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
172 prev_frame = current_frame - 1; 171 prev_frame = current_frame - 1;
173 } else if ( hasAudioChannel ) { 172 } else if ( hasAudioChannel ) {
174 playtime.restart(); 173 playtime.restart();
175 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); 174 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) );
176 currentSample = pos + 1; 175 currentSample = pos + 1;
177 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 176 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
178 audioSampleCounter = currentSample - 1; 177 audioSampleCounter = currentSample - 1;
179 } 178 }
180 179
181 audioMutex->unlock(); 180 audioMutex->unlock();
182} 181}
183 182
184 183
185void LoopControl::startVideo() { 184void LoopControl::startVideo() {
186 185
187 if ( moreVideo ) { 186 if ( moreVideo ) {
188 187
189 if ( mediaPlayerState->curDecoder() ) { 188 if ( mediaPlayerState->curDecoder() ) {
190 189
191 if ( hasAudioChannel && !isMuted ) { 190 if ( hasAudioChannel && !isMuted ) {
192 191
193 current_frame = long( playtime.elapsed() * framerate / 1000 ); 192 current_frame = long( playtime.elapsed() * framerate / 1000 );
194 193
195 if ( prev_frame != -1 && current_frame <= prev_frame ) 194 if ( prev_frame != -1 && current_frame <= prev_frame )
196 return; 195 return;
197 196
198 } else { 197 } else {
199 // Don't skip 198 // Don't skip
200 current_frame++; 199 current_frame++;
201 } 200 }
202 201
203 if ( prev_frame == -1 || current_frame > prev_frame ) { 202 if ( prev_frame == -1 || current_frame > prev_frame ) {
204 if ( current_frame > prev_frame + 1 ) { 203 if ( current_frame > prev_frame + 1 ) {
205 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 204 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
206 } 205 }
207 moreVideo = videoUI->playVideo(); 206 moreVideo = videoUI->playVideo();
208 prev_frame = current_frame; 207 prev_frame = current_frame;
209 } 208 }
210 209
211 } else { 210 } else {
212 211
213 moreVideo = FALSE; 212 moreVideo = FALSE;
214 killTimer( videoId ); 213 killTimer( videoId );
215 214
216 } 215 }
217 216
218 } 217 }
219} 218}
220 219
221 220
222void LoopControl::startAudio() { 221void LoopControl::startAudio() {
223 222
223//qDebug("start audio");
224 audioMutex->lock(); 224 audioMutex->lock();
225 if ( moreAudio ) { 225 if ( moreAudio ) {
226 226
227 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
228 228
229 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
230 230
231 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
233 233
234 long samplesRead = 0; 234 long samplesRead = 0;
235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
237 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
238 238
239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
241// } 241// }
242// else if ( sampleWaitTime <= -5000 ) { 242// else if ( sampleWaitTime <= -5000 ) {
243// // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 243// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
245// currentSample = sampleWeShouldBeAt; 245// currentSample = sampleWeShouldBeAt;
246// } 246// }
247 247
248 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 248 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
249 audioSampleCounter = currentSample + samplesRead - 1; 249 audioSampleCounter = currentSample + samplesRead - 1;
250 250
251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
252 252
253 } else { 253 } else {
254 254
255 moreAudio = FALSE; 255 moreAudio = FALSE;
256 256
257 } 257 }
258 258
259 } 259 }
260 260
261 audioMutex->unlock(); 261 audioMutex->unlock();
262} 262}
263 263
264 264
265void LoopControl::killTimers() { 265void LoopControl::killTimers() {
266 266
267 audioMutex->lock(); 267 audioMutex->lock();
268 268
269 if ( hasVideoChannel ) 269 if ( hasVideoChannel )
270 killTimer( videoId ); 270 killTimer( videoId );
271 killTimer( sliderId ); 271 killTimer( sliderId );
272 threadOkToGo = FALSE; 272 threadOkToGo = FALSE;
273 273
274 audioMutex->unlock(); 274 audioMutex->unlock();
275} 275}
276 276
277 277
278void LoopControl::startTimers() { 278void LoopControl::startTimers() {
279 279
280 audioMutex->lock(); 280 audioMutex->lock();
281 281
282 moreVideo = FALSE; 282 moreVideo = FALSE;
283 moreAudio = FALSE; 283 moreAudio = FALSE;
284 284
285 if ( hasVideoChannel ) { 285 if ( hasVideoChannel ) {
286 moreVideo = TRUE; 286 moreVideo = TRUE;
287 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value 287 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value
288 videoId = startTimer( mSecsBetweenFrames ); 288 videoId = startTimer( mSecsBetweenFrames );
289 } 289 }
290 290
291 if ( hasAudioChannel ) { 291 if ( hasAudioChannel ) {
292 moreAudio = TRUE; 292 moreAudio = TRUE;
293 threadOkToGo = TRUE; 293 threadOkToGo = TRUE;
294 } 294 }
295 295
296 sliderId = startTimer( 300 ); // update slider every 1/3 second 296 sliderId = startTimer( 300 ); // update slider every 1/3 second
297 297
298 audioMutex->unlock(); 298 audioMutex->unlock();
299} 299}
300 300
301 301
302void LoopControl::setPaused( bool pause ) { 302void LoopControl::setPaused( bool pause ) {
303 303
304 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) 304 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() )
305 return; 305 return;
306 306
307 if ( pause ) { 307 if ( pause ) {
308 killTimers(); 308 killTimers();
309 } else { 309 } else {
310 // Force an update of the position 310 // Force an update of the position
311 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 311 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
312 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 312 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
313 // Just like we never stopped 313 // Just like we never stopped
314 startTimers(); 314 startTimers();
315 } 315 }
316} 316}
317 317
318 318
319void LoopControl::stop( bool willPlayAgainShortly ) { 319void LoopControl::stop( bool willPlayAgainShortly ) {
320 320
321#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 321#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
322 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 322 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
323 disabledSuspendScreenSaver = FALSE; 323 disabledSuspendScreenSaver = FALSE;
324 // Re-enable the suspend mode 324 // Re-enable the suspend mode
325 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 325 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
326 } 326 }
327#endif 327#endif
328 328
329 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { 329 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
330 330
331 killTimers(); 331 killTimers();
332 332
333 audioMutex->lock(); 333 audioMutex->lock();
334 334
335 mediaPlayerState->curDecoder()->close(); 335 mediaPlayerState->curDecoder()->close();
336 336
337 if ( audioDevice ) { 337 if ( audioDevice ) {
338 delete audioDevice; 338 delete audioDevice;
339 delete audioBuffer; 339 delete audioBuffer;
340 audioDevice = 0; 340 audioDevice = 0;
341 audioBuffer = 0; 341 audioBuffer = 0;
342 } 342 }
343 343
344 audioMutex->unlock(); 344 audioMutex->unlock();
345 345
346 } 346 }
347} 347}
348 348
349 349
350bool LoopControl::init( const QString& filename ) { 350bool LoopControl::init( const QString& filename ) {
351 stop(); 351 stop();
352 352
353 audioMutex->lock(); 353 audioMutex->lock();
354 354
355 fileName = filename; 355 fileName = filename;
356 stream = 0; // only play stream 0 for now 356 stream = 0; // only play stream 0 for now
357 current_frame = total_video_frames = total_audio_samples = 0; 357 current_frame = total_video_frames = total_audio_samples = 0;
358 358
359 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 359 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
360 360
361 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 361 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
362 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 362 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
363 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 363 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
364 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 364 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
365 mediaPlayerState->libMpeg3Decoder()->close(); 365 mediaPlayerState->libMpeg3Decoder()->close();
366 } 366 }
367 } 367 }
368 368
369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
370 audioMutex->unlock(); 370 audioMutex->unlock();
371 return FALSE; 371 return FALSE;
372 } 372 }
373 373
374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
376 376
377 if ( hasAudioChannel ) { 377 if ( hasAudioChannel ) {
378 int astream = 0; 378 int astream = 0;
379 379
380 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 380 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
381// qDebug( "LC- channels = %d", channels ); 381 qDebug( "LC- channels = %d", channels );
382 382
383 if ( !total_audio_samples ) 383 if ( !total_audio_samples )
384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
385 385
386// total_audio_samples += 1000; 386// total_audio_samples += 1000;
387 387
388 mediaPlayerState->setLength( total_audio_samples ); 388 mediaPlayerState->setLength( total_audio_samples );
389 389
390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
391// qDebug( "LC- frequency = %d", freq ); 391 qDebug( "LC- frequency = %d", freq );
392 392
393 audioSampleCounter = 0; 393 audioSampleCounter = 0;
394 int bits_per_sample; 394 int bits_per_sample;
395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) { 395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) {
396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
397// qDebug("using stupid hack"); 397 qDebug("using stupid hack");
398 } else { 398 } else {
399 bits_per_sample=0; 399 bits_per_sample=0;
400// freq=44100;
401 channels=2;
402 } 400 }
403 401
404 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 402 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
405 audioBuffer = new char[ audioDevice->bufferSize() ]; 403 audioBuffer = new char[ audioDevice->bufferSize() ];
406 channels = audioDevice->channels(); 404 channels = audioDevice->channels();
407 405
408 //### must check which frequency is actually used. 406 //### must check which frequency is actually used.
409 static const int size = 1; 407 static const int size = 1;
410 short int buf[size]; 408 short int buf[size];
411 long samplesRead = 0; 409 long samplesRead = 0;
412 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 410 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
413 } 411 }
414 412
415 if ( hasVideoChannel ) { 413 if ( hasVideoChannel ) {
416 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); 414 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
417 415
418 mediaPlayerState->setLength( total_video_frames ); 416 mediaPlayerState->setLength( total_video_frames );
419 417
420 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); 418 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
421 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); 419 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
422 420
423 if ( framerate <= 1.0 ) { 421 if ( framerate <= 1.0 ) {
424 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); 422 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
425 framerate = 25; 423 framerate = 25;
426 } 424 }
427 425
428 if ( total_video_frames == 1 ) { 426 if ( total_video_frames == 1 ) {
429 DecodeLoopDebug(( "Cannot seek to frame" )); 427 DecodeLoopDebug(( "Cannot seek to frame" ));
430 } 428 }
431 429
432 } 430 }
433 431
434 current_frame = 0; 432 current_frame = 0;
435 prev_frame = -1; 433 prev_frame = -1;
436 434
437 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 435 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
438 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 436 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
439 437
440 audioMutex->unlock(); 438 audioMutex->unlock();
441 439
442 return TRUE; 440 return TRUE;
443} 441}
444 442
445 443
446void LoopControl::play() { 444void LoopControl::play() {
447 qDebug("LC- play"); 445 qDebug("LC- play");
448#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 446#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
449 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 447 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
450 disabledSuspendScreenSaver = TRUE; 448 disabledSuspendScreenSaver = TRUE;
451 previousSuspendMode = hasVideoChannel; 449 previousSuspendMode = hasVideoChannel;
452 // Stop the screen from blanking and power saving state 450 // Stop the screen from blanking and power saving state
453 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 451 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
454 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 452 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
455 } 453 }
456#endif 454#endif
457 455
458 playtime.start(); 456 playtime.start();
459 startTimers(); 457 startTimers();
460} 458}
461 459
462 460
463void LoopControl::setMute( bool on ) { 461void LoopControl::setMute( bool on ) {
464 if ( on != isMuted ) { 462 if ( on != isMuted ) {
465 isMuted = on; 463 isMuted = on;
466 if ( !on ) { 464 if ( !on ) {
467 // Force an update of the position 465 // Force an update of the position
468 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 466 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
469 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 467 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
470 // Resume playing audio 468 // Resume playing audio
471 moreAudio = TRUE; 469 moreAudio = TRUE;
472 } 470 }
473 } 471 }
474} 472}
475 473
476 474
diff --git a/core/multimedia/opieplayer/mpegplayer.pro b/core/multimedia/opieplayer/mpegplayer.pro
index b9e9ffe..241e29e 100644
--- a/core/multimedia/opieplayer/mpegplayer.pro
+++ b/core/multimedia/opieplayer/mpegplayer.pro
@@ -1,26 +1,26 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3#release 3#release
4DESTDIR = $(OPIEDIR)/bin 4DESTDIR = $(OPIEDIR)/bin
5HEADERS = loopcontrol.h mediaplayerplugininterface.h playlistselection.h mediaplayerstate.h \ 5HEADERS = loopcontrol.h mediaplayerplugininterface.h playlistselection.h mediaplayerstate.h \
6 videowidget.h audiowidget.h playlistwidget.h mediaplayer.h audiodevice.h inputDialog.h 6 videowidget.h audiowidget.h playlistwidget.h mediaplayer.h audiodevice.h inputDialog.h
7SOURCES = main.cpp \ 7SOURCES = main.cpp \
8 loopcontrol.cpp playlistselection.cpp mediaplayerstate.cpp \ 8 loopcontrol.cpp playlistselection.cpp mediaplayerstate.cpp \
9 videowidget.cpp audiowidget.cpp playlistwidget.cpp mediaplayer.cpp audiodevice.cpp inputDialog.cpp 9 videowidget.cpp audiowidget.cpp playlistwidget.cpp mediaplayer.cpp audiodevice.cpp inputDialog.cpp
10TARGET = mpegplayer 10TARGET = mpegplayer
11INCLUDEPATH += $(OPIEDIR)/include 11INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include 12DEPENDPATH += $(OPIEDIR)/include
13LIBS += -lqpe -lpthread 13LIBS += -lqpe -lpthread
14 14
15# INTERFACES = 15# INTERFACES =
16# INCLUDEPATH += $(OPIEDIR)/include 16# INCLUDEPATH += $(OPIEDIR)/include
17# CONFIG+=static 17# CONFIG+=static
18# TMAKE_CXXFLAGS += -DQPIM_STANDALONE 18# TMAKE_CXXFLAGS += -DQPIM_STANDALONE
19# LIBS += libmpeg3/libmpeg3.a -lpthread 19# LIBS += libmpeg3/libmpeg3.a -lpthread
20# LIBS += $(OPIEDIR)/plugins/codecs/liblibmadplugin.so 20# LIBS += $(OPIEDIR)/plugins/codecs/liblibmadplugin.so
21 21
22INCLUDEPATH += $(OPIEDIR)/include 22INCLUDEPATH += $(OPIEDIR)/include
23DEPENDPATH += $(OPIEDIR)/include 23DEPENDPATH += $(OPIEDIR)/include
24 24
25TRANSLATIONS = ../i18n/de/mpegplayer.ts 25TRANSLATIONS += ../i18n/de/mpegplayer.ts
26TRANSLATIONS += ../i18n/pt_BR/mpegplayer.ts 26TRANSLATIONS += ../i18n/pt_BR/mpegplayer.ts
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp
index 991301a..756e3b4 100644
--- a/core/multimedia/opieplayer/playlistselection.cpp
+++ b/core/multimedia/opieplayer/playlistselection.cpp
@@ -1,183 +1,183 @@
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#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpainter.h> 22#include <qpainter.h>
23#include <qimage.h> 23#include <qimage.h>
24#include <qheader.h> 24#include <qheader.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28 28
29#include "playlistselection.h" 29#include "playlistselection.h"
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33class PlayListSelectionItem : public QListViewItem { 33class PlayListSelectionItem : public QListViewItem {
34public: 34public:
35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { 35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
36 setText( 0, f->name() ); 36 setText( 0, f->name() );
37 setPixmap( 0, f->pixmap() ); 37 setPixmap( 0, f->pixmap() );
38 } 38 }
39 39
40 ~PlayListSelectionItem() { 40 ~PlayListSelectionItem() {
41 }; 41 };
42 42
43 const DocLnk *file() const { return fl; } 43 const DocLnk *file() const { return fl; }
44 44
45private: 45private:
46 const DocLnk *fl; 46 const DocLnk *fl;
47}; 47};
48 48
49 49
50PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) 50PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
51 : QListView( parent, name ) 51 : QListView( parent, name )
52{ 52{
53 qDebug("starting playlistselector"); 53 qDebug("starting playlistselector");
54// #ifdef USE_PLAYLIST_BACKGROUND 54// #ifdef USE_PLAYLIST_BACKGROUND
55// setStaticBackground( TRUE ); 55// setStaticBackground( TRUE );
56// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) ); 56// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) );
57 57
58 setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); 58// setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) );
59// #endif 59// #endif
60// addColumn("Title",236); 60// addColumn("Title",236);
61// setAllColumnsShowFocus( TRUE ); 61// setAllColumnsShowFocus( TRUE );
62 addColumn( tr( "Playlist Selection" ) ); 62 addColumn( tr( "Playlist Selection" ) );
63 header()->hide(); 63 header()->hide();
64 setSorting( -1, FALSE ); 64 setSorting( -1, FALSE );
65} 65}
66 66
67 67
68PlayListSelection::~PlayListSelection() { 68PlayListSelection::~PlayListSelection() {
69} 69}
70 70
71 71
72// #ifdef USE_PLAYLIST_BACKGROUND 72// #ifdef USE_PLAYLIST_BACKGROUND
73void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { 73void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
74// qDebug("drawBackground"); 74// qDebug("drawBackground");
75 p->fillRect( r, QBrush( white ) ); 75 p->fillRect( r, QBrush( white ) );
76 QImage logo = Resource::loadImage( "launcher/opielogo" ); 76// QImage logo = Resource::loadImage( "launcher/opielogo" );
77 if ( !logo.isNull() ) 77// if ( !logo.isNull() )
78 p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); 78// p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
79} 79}
80// #endif 80// #endif
81 81
82 82
83void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { 83void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
84 if ( event->state() == QMouseEvent::LeftButton ) { 84 if ( event->state() == QMouseEvent::LeftButton ) {
85 QListViewItem *currentItem = selectedItem(); 85 QListViewItem *currentItem = selectedItem();
86 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); 86 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
87 if ( currentItem && currentItem->itemAbove() == itemUnder ) 87 if ( currentItem && currentItem->itemAbove() == itemUnder )
88 moveSelectedUp(); 88 moveSelectedUp();
89 else if ( currentItem && currentItem->itemBelow() == itemUnder ) 89 else if ( currentItem && currentItem->itemBelow() == itemUnder )
90 moveSelectedDown(); 90 moveSelectedDown();
91 } 91 }
92} 92}
93 93
94 94
95const DocLnk *PlayListSelection::current() { 95const DocLnk *PlayListSelection::current() {
96 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); 96 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
97 if ( item ) 97 if ( item )
98 return item->file(); 98 return item->file();
99 return NULL; 99 return NULL;
100} 100}
101 101
102 102
103void PlayListSelection::addToSelection( const DocLnk &lnk ) { 103void PlayListSelection::addToSelection( const DocLnk &lnk ) {
104 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); 104 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
105 QListViewItem *current = selectedItem(); 105 QListViewItem *current = selectedItem();
106 if ( current ) 106 if ( current )
107 item->moveItem( current ); 107 item->moveItem( current );
108 setSelected( item, TRUE ); 108 setSelected( item, TRUE );
109 ensureItemVisible( selectedItem() ); 109 ensureItemVisible( selectedItem() );
110} 110}
111 111
112 112
113void PlayListSelection::removeSelected() { 113void PlayListSelection::removeSelected() {
114 QListViewItem *item = selectedItem(); 114 QListViewItem *item = selectedItem();
115 if ( item ) 115 if ( item )
116 delete item; 116 delete item;
117 setSelected( currentItem(), TRUE ); 117 setSelected( currentItem(), TRUE );
118 ensureItemVisible( selectedItem() ); 118 ensureItemVisible( selectedItem() );
119} 119}
120 120
121 121
122void PlayListSelection::moveSelectedUp() { 122void PlayListSelection::moveSelectedUp() {
123 QListViewItem *item = selectedItem(); 123 QListViewItem *item = selectedItem();
124 if ( item && item->itemAbove() ) 124 if ( item && item->itemAbove() )
125 item->itemAbove()->moveItem( item ); 125 item->itemAbove()->moveItem( item );
126 ensureItemVisible( selectedItem() ); 126 ensureItemVisible( selectedItem() );
127} 127}
128 128
129 129
130void PlayListSelection::moveSelectedDown() { 130void PlayListSelection::moveSelectedDown() {
131 QListViewItem *item = selectedItem(); 131 QListViewItem *item = selectedItem();
132 if ( item && item->itemBelow() ) 132 if ( item && item->itemBelow() )
133 item->moveItem( item->itemBelow() ); 133 item->moveItem( item->itemBelow() );
134 ensureItemVisible( selectedItem() ); 134 ensureItemVisible( selectedItem() );
135} 135}
136 136
137 137
138bool PlayListSelection::prev() { 138bool PlayListSelection::prev() {
139 QListViewItem *item = selectedItem(); 139 QListViewItem *item = selectedItem();
140 if ( item && item->itemAbove() ) 140 if ( item && item->itemAbove() )
141 setSelected( item->itemAbove(), TRUE ); 141 setSelected( item->itemAbove(), TRUE );
142 else 142 else
143 return FALSE; 143 return FALSE;
144 ensureItemVisible( selectedItem() ); 144 ensureItemVisible( selectedItem() );
145 return TRUE; 145 return TRUE;
146} 146}
147 147
148 148
149bool PlayListSelection::next() { 149bool PlayListSelection::next() {
150 QListViewItem *item = selectedItem(); 150 QListViewItem *item = selectedItem();
151 if ( item && item->itemBelow() ) 151 if ( item && item->itemBelow() )
152 setSelected( item->itemBelow(), TRUE ); 152 setSelected( item->itemBelow(), TRUE );
153 else 153 else
154 return FALSE; 154 return FALSE;
155 ensureItemVisible( selectedItem() ); 155 ensureItemVisible( selectedItem() );
156 return TRUE; 156 return TRUE;
157} 157}
158 158
159 159
160bool PlayListSelection::first() { 160bool PlayListSelection::first() {
161 QListViewItem *item = firstChild(); 161 QListViewItem *item = firstChild();
162 if ( item ) 162 if ( item )
163 setSelected( item, TRUE ); 163 setSelected( item, TRUE );
164 else 164 else
165 return FALSE; 165 return FALSE;
166 ensureItemVisible( selectedItem() ); 166 ensureItemVisible( selectedItem() );
167 return TRUE; 167 return TRUE;
168} 168}
169 169
170 170
171bool PlayListSelection::last() { 171bool PlayListSelection::last() {
172 QListViewItem *prevItem = NULL; 172 QListViewItem *prevItem = NULL;
173 QListViewItem *item = firstChild(); 173 QListViewItem *item = firstChild();
174 while ( ( item = item->nextSibling() ) ) 174 while ( ( item = item->nextSibling() ) )
175 prevItem = item; 175 prevItem = item;
176 if ( prevItem ) 176 if ( prevItem )
177 setSelected( prevItem, TRUE ); 177 setSelected( prevItem, TRUE );
178 else 178 else
179 return FALSE; 179 return FALSE;
180 ensureItemVisible( selectedItem() ); 180 ensureItemVisible( selectedItem() );
181 return TRUE; 181 return TRUE;
182} 182}
183 183
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 524747e..cf665c8 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,814 +1,889 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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// code added by L. J. Potter Sat 03-02-2002 06:17:54 20// code added by L. J. Potter Sat 03-02-2002 06:17:54
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/fileselector.h> 23#include <qpe/fileselector.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/global.h> 28#include <qpe/global.h>
29#include <qpe/resource.h> 29#include <qpe/resource.h>
30#include <qaction.h> 30#include <qaction.h>
31#include <qimage.h> 31#include <qimage.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qdir.h> 33#include <qdir.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qlabel.h> 35#include <qlabel.h>
36#include <qlist.h> 36#include <qlist.h>
37#include <qlistbox.h> 37#include <qlistbox.h>
38#include <qmainwindow.h> 38#include <qmainwindow.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41#include <qtabwidget.h> 41#include <qtabwidget.h>
42#include <qlistview.h> 42#include <qlistview.h>
43#include <qpoint.h> 43#include <qpoint.h>
44#include <qlineedit.h> 44#include <qlineedit.h>
45#include <qpushbutton.h> 45#include <qpushbutton.h>
46 46
47//#include <qtimer.h> 47//#include <qtimer.h>
48 48
49#include "playlistselection.h" 49#include "playlistselection.h"
50#include "playlistwidget.h" 50#include "playlistwidget.h"
51#include "mediaplayerstate.h" 51#include "mediaplayerstate.h"
52 52
53#include "inputDialog.h" 53#include "inputDialog.h"
54 54
55#include <stdlib.h> 55#include <stdlib.h>
56 56
57#define BUTTONS_ON_TOOLBAR 57#define BUTTONS_ON_TOOLBAR
58#define SIDE_BUTTONS 58#define SIDE_BUTTONS
59#define CAN_SAVE_LOAD_PLAYLISTS 59#define CAN_SAVE_LOAD_PLAYLISTS
60 60
61extern MediaPlayerState *mediaPlayerState; 61extern MediaPlayerState *mediaPlayerState;
62 62
63// class myFileSelector { 63// class myFileSelector {
64 64
65// }; 65// };
66class PlayListWidgetPrivate { 66class PlayListWidgetPrivate {
67public: 67public:
68 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; 68 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
69 QFrame *playListFrame; 69 QFrame *playListFrame;
70 FileSelector *files; 70 FileSelector *files;
71 PlayListSelection *selectedFiles; 71 PlayListSelection *selectedFiles;
72 bool setDocumentUsed; 72 bool setDocumentUsed;
73 DocLnk *current; 73 DocLnk *current;
74}; 74};
75 75
76 76
77class ToolButton : public QToolButton { 77class ToolButton : public QToolButton {
78public: 78public:
79 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 79 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
80 : QToolButton( parent, name ) { 80 : QToolButton( parent, name ) {
81 setTextLabel( name ); 81 setTextLabel( name );
82 setPixmap( Resource::loadPixmap( icon ) ); 82 setPixmap( Resource::loadPixmap( icon ) );
83 setAutoRaise( TRUE ); 83 setAutoRaise( TRUE );
84 setFocusPolicy( QWidget::NoFocus ); 84 setFocusPolicy( QWidget::NoFocus );
85 setToggleButton( t ); 85 setToggleButton( t );
86 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 86 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
87 QPEMenuToolFocusManager::manager()->addWidget( this ); 87 QPEMenuToolFocusManager::manager()->addWidget( this );
88 } 88 }
89}; 89};
90 90
91 91
92class MenuItem : public QAction { 92class MenuItem : public QAction {
93public: 93public:
94 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) 94 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
95 : QAction( text, QString::null, 0, 0 ) { 95 : QAction( text, QString::null, 0, 0 ) {
96 connect( this, SIGNAL( activated() ), handler, slot ); 96 connect( this, SIGNAL( activated() ), handler, slot );
97 addTo( parent ); 97 addTo( parent );
98 } 98 }
99}; 99};
100 100
101 101
102PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 102PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
103 : QMainWindow( parent, name, fl ) { 103 : QMainWindow( parent, name, fl ) {
104 104
105 d = new PlayListWidgetPrivate; 105 d = new PlayListWidgetPrivate;
106 d->setDocumentUsed = FALSE; 106 d->setDocumentUsed = FALSE;
107 d->current = NULL; 107 d->current = NULL;
108 fromSetDocument = FALSE; 108 fromSetDocument = FALSE;
109 insanityBool=FALSE;
109// menuTimer = new QTimer( this ,"menu timer"), 110// menuTimer = new QTimer( this ,"menu timer"),
110// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); 111// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
111 112
112 setBackgroundMode( PaletteButton ); 113 setBackgroundMode( PaletteButton );
113 114
114 setCaption( tr("OpiePlayer") ); 115 setCaption( tr("OpiePlayer") );
115 setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); 116 setIcon( Resource::loadPixmap( "MPEGPlayer" ) );
116 117
117 setToolBarsMovable( FALSE ); 118 setToolBarsMovable( FALSE );
118 119
119 // Create Toolbar 120 // Create Toolbar
120 QPEToolBar *toolbar = new QPEToolBar( this ); 121 QPEToolBar *toolbar = new QPEToolBar( this );
121 toolbar->setHorizontalStretchable( TRUE ); 122 toolbar->setHorizontalStretchable( TRUE );
122 123
123 // Create Menubar 124 // Create Menubar
124 QPEMenuBar *menu = new QPEMenuBar( toolbar ); 125 QPEMenuBar *menu = new QPEMenuBar( toolbar );
125 menu->setMargin( 0 ); 126 menu->setMargin( 0 );
126 127
127 QPEToolBar *bar = new QPEToolBar( this ); 128 QPEToolBar *bar = new QPEToolBar( this );
128 bar->setLabel( tr( "Play Operations" ) ); 129 bar->setLabel( tr( "Play Operations" ) );
129// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list", 130// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list",
130// this , SLOT( addSelected()) ); 131// this , SLOT( addSelected()) );
131 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); 132 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close");
132 tbDeletePlaylist->setFlat(TRUE); 133 tbDeletePlaylist->setFlat(TRUE);
133 tbDeletePlaylist->setFixedSize(20,20); 134 tbDeletePlaylist->setFixedSize(20,20);
134 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); 135 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist()));
135 136
136 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", 137 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist",
137 this , SLOT(addSelected()) ); 138 this , SLOT(addSelected()) );
138 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", 139 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist",
139 this , SLOT(removeSelected()) ); 140 this , SLOT(removeSelected()) );
140// d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); 141// d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE );
141 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", 142 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play",
142 this , SLOT( btnPlay(bool) ), TRUE ); 143 this , SLOT( btnPlay(bool) ), TRUE );
143 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle", 144 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle",
144 mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 145 mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
145 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", 146 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop",
146 mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 147 mediaPlayerState, SLOT(setLooping(bool)), TRUE );
147 tbDeletePlaylist->hide(); 148 tbDeletePlaylist->hide();
148 149
149 QPopupMenu *pmPlayList = new QPopupMenu( this ); 150 QPopupMenu *pmPlayList = new QPopupMenu( this );
150 menu->insertItem( tr( "File" ), pmPlayList ); 151 menu->insertItem( tr( "File" ), pmPlayList );
151 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 152 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
152 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); 153 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
153 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 154 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
154 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 155 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
155 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 156 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
156 // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); 157 // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) );
157 158
158 QPopupMenu *pmView = new QPopupMenu( this ); 159 QPopupMenu *pmView = new QPopupMenu( this );
159 menu->insertItem( tr( "View" ), pmView ); 160 menu->insertItem( tr( "View" ), pmView );
160 161
161 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); 162 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
162 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); 163 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
163 fullScreenButton->addTo(pmView); 164 fullScreenButton->addTo(pmView);
164 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0); 165 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0);
165 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); 166 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
166 scaleButton->addTo(pmView); 167 scaleButton->addTo(pmView);
167 168
168 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 169 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
169 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 170 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
170 171
171 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 172 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
172 173
173 tabWidget = new QTabWidget( hbox6, "tabWidget" ); 174 tabWidget = new QTabWidget( hbox6, "tabWidget" );
174 tabWidget->setTabShape(QTabWidget::Triangular); 175 tabWidget->setTabShape(QTabWidget::Triangular);
175 176
176 QWidget *pTab; 177 QWidget *pTab;
177 pTab = new QWidget( tabWidget, "pTab" ); 178 pTab = new QWidget( tabWidget, "pTab" );
178// playlistView = new QListView( pTab, "playlistview" ); 179// playlistView = new QListView( pTab, "playlistview" );
179// playlistView->setMinimumSize(236,260); 180// playlistView->setMinimumSize(236,260);
180 tabWidget->insertTab( pTab,"Playlist"); 181 tabWidget->insertTab( pTab,"Playlist");
181 182
182 183
183 // Add the playlist area 184 // Add the playlist area
184 185
185 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); 186 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
186 d->playListFrame = vbox3; 187 d->playListFrame = vbox3;
187 d->playListFrame ->setMinimumSize(235,260); 188 d->playListFrame ->setMinimumSize(235,260);
188 189
189 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 190 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
190 191
191 d->selectedFiles = new PlayListSelection( hbox2); 192 d->selectedFiles = new PlayListSelection( hbox2);
192 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); 193 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
193 194
194 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); 195 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold);
195 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 196 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
196 this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); 197 this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) );
197 198
198 199
199 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch 200 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
200 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); 201 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
201 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); 202 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
202 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); 203 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
203 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch 204 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
204 205
205 QWidget *aTab; 206 QWidget *aTab;
206 aTab = new QWidget( tabWidget, "aTab" ); 207 aTab = new QWidget( tabWidget, "aTab" );
207 audioView = new QListView( aTab, "Audioview" ); 208 audioView = new QListView( aTab, "Audioview" );
208 audioView->setMinimumSize(233,260); 209 audioView->setMinimumSize(233,260);
209 audioView->addColumn( "Title",150); 210 audioView->addColumn( "Title",140);
210 audioView->addColumn("Size", 45); 211 audioView->addColumn("Size", -1);
211 audioView->addColumn("Media",35); 212 audioView->addColumn("Media",-1);
212 audioView->setColumnAlignment(1, Qt::AlignRight); 213 audioView->setColumnAlignment(1, Qt::AlignRight);
213 audioView->setColumnAlignment(2, Qt::AlignRight); 214 audioView->setColumnAlignment(2, Qt::AlignRight);
214 audioView->setAllColumnsShowFocus(TRUE); 215 audioView->setAllColumnsShowFocus(TRUE);
215 tabWidget->insertTab(aTab,"Audio"); 216 tabWidget->insertTab(aTab,"Audio");
216 217
217 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); 218 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
218 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 219 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
219 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); 220 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
220 221
221 222
222// audioView 223// audioView
223 Global::findDocuments(&files, "audio/*"); 224 Global::findDocuments(&files, "audio/*");
224 QListIterator<DocLnk> dit( files.children() ); 225 QListIterator<DocLnk> dit( files.children() );
225 QString storage; 226 QString storage;
226 for ( ; dit.current(); ++dit ) { 227 for ( ; dit.current(); ++dit ) {
227 QListViewItem * newItem; 228 QListViewItem * newItem;
228 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; 229 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
229 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; 230 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
230 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD"; 231 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD";
231 else storage="RAM"; 232 else storage="RAM";
232 if ( QFile( dit.current()->file()).exists() ) { 233 if ( QFile( dit.current()->file()).exists() ) {
233 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); 234 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
234 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); 235 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
235 } 236 }
236 } 237 }
237// videowidget 238// videowidget
238 239
239 QWidget *vTab; 240 QWidget *vTab;
240 vTab = new QWidget( tabWidget, "vTab" ); 241 vTab = new QWidget( tabWidget, "vTab" );
241 videoView = new QListView( vTab, "Videoview" ); 242 videoView = new QListView( vTab, "Videoview" );
242 videoView->setMinimumSize(233,260); 243 videoView->setMinimumSize(233,260);
243 244
244 videoView->addColumn("Title",150); 245 videoView->addColumn("Title",140);
245 videoView->addColumn("Size",45); 246 videoView->addColumn("Size",-1);
246 videoView->addColumn("Media",35); 247 videoView->addColumn("Media",-1);
247 videoView->setColumnAlignment(1, Qt::AlignRight); 248 videoView->setColumnAlignment(1, Qt::AlignRight);
248 videoView->setColumnAlignment(2, Qt::AlignRight); 249 videoView->setColumnAlignment(2, Qt::AlignRight);
249 videoView->setAllColumnsShowFocus(TRUE); 250 videoView->setAllColumnsShowFocus(TRUE);
250 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); 251 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
251 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 252 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
252 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); 253 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
253 254
254 tabWidget->insertTab( vTab,"Video"); 255 tabWidget->insertTab( vTab,"Video");
255 256
256 Global::findDocuments(&vFiles, "video/*"); 257 Global::findDocuments(&vFiles, "video/*");
257 QListIterator<DocLnk> Vdit( vFiles.children() ); 258 QListIterator<DocLnk> Vdit( vFiles.children() );
258 for ( ; Vdit.current(); ++Vdit ) { 259 for ( ; Vdit.current(); ++Vdit ) {
259 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; 260 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
260 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; 261 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
261 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD"; 262 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD";
262 else storage="RAM"; 263 else storage="RAM";
263 QListViewItem * newItem; 264 QListViewItem * newItem;
264 if ( QFile( Vdit.current()->file()).exists() ) { 265 if ( QFile( Vdit.current()->file()).exists() ) {
265 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); 266 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
266 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" )); 267 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
267 } 268 }
268 } 269 }
269 270
270//playlists list 271//playlists list
271 QWidget *LTab; 272 QWidget *LTab;
272 LTab = new QWidget( tabWidget, "LTab" ); 273 LTab = new QWidget( tabWidget, "LTab" );
273 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy 274 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy
274 playLists->setMinimumSize(233,260);; 275 playLists->setMinimumSize(233,260);;
275 tabWidget->insertTab(LTab,"Lists"); 276 tabWidget->insertTab(LTab,"Lists");
276 277
277 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); 278 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) );
278// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 279// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
279 280
280 281
281// add the library area 282// add the library area
282 283
283// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 284// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
284// this, SLOT( fauxPlay( QListViewItem *) ) ); 285// this, SLOT( fauxPlay( QListViewItem *) ) );
285// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 286// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
286// this, SLOT( fauxPlay( QListViewItem *)) ); 287// this, SLOT( fauxPlay( QListViewItem *)) );
287 288
288// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 289// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
289// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 290// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
290 291
291 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 292 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
292 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 293 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
293 294
294 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); 295 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
295 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); 296 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
296 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); 297 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
297 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); 298 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
298 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); 299 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
299 300
300 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); 301 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
301// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); 302// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
302 303
303 setCentralWidget( vbox5 ); 304 setCentralWidget( vbox5 );
304 305
305 Config cfg( "MediaPlayer" ); 306 Config cfg( "MediaPlayer" );
306 readConfig( cfg ); 307 readConfig( cfg );
307 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 308 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
308// qDebug("currentList is "+currentPlaylist); 309// qDebug("currentList is "+currentPlaylist);
309 loadList(DocLnk( currentPlaylist)); 310 loadList(DocLnk( currentPlaylist));
310 setCaption("OpiePlayer: "+ currentPlaylist ); 311 setCaption("OpiePlayer: "+ currentPlaylist );
311 312
312 initializeStates(); 313 initializeStates();
313} 314}
314 315
315 316
316PlayListWidget::~PlayListWidget() { 317PlayListWidget::~PlayListWidget() {
317 Config cfg( "MediaPlayer" ); 318 Config cfg( "MediaPlayer" );
318 writeConfig( cfg ); 319 writeConfig( cfg );
319 320
320 321
321 if ( d->current ) 322 if ( d->current )
322 delete d->current; 323 delete d->current;
323 delete d; 324 delete d;
324} 325}
325 326
326 327
327void PlayListWidget::initializeStates() { 328void PlayListWidget::initializeStates() {
328 329
329 d->tbPlay->setOn( mediaPlayerState->playing() ); 330 d->tbPlay->setOn( mediaPlayerState->playing() );
330 d->tbLoop->setOn( mediaPlayerState->looping() ); 331 d->tbLoop->setOn( mediaPlayerState->looping() );
331 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 332 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
332// d->tbFull->setOn( mediaPlayerState->fullscreen() ); 333// d->tbFull->setOn( mediaPlayerState->fullscreen() );
333// d->tbScale->setOn( mediaPlayerState->scaled() ); 334// d->tbScale->setOn( mediaPlayerState->scaled() );
334// d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); 335// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
335// setPlaylist( mediaPlayerState->playlist() ); 336// setPlaylist( mediaPlayerState->playlist() );
336 setPlaylist( true); 337 setPlaylist( true);
337 d->selectedFiles->first(); 338 d->selectedFiles->first();
338} 339}
339 340
340 341
341void PlayListWidget::readConfig( Config& cfg ) { 342void PlayListWidget::readConfig( Config& cfg ) {
342 cfg.setGroup("PlayList"); 343 cfg.setGroup("PlayList");
343 344
344 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 345 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
345 346
346 for ( int i = 0; i < noOfFiles; i++ ) { 347 for ( int i = 0; i < noOfFiles; i++ ) {
347 QString entryName; 348 QString entryName;
348 entryName.sprintf( "File%i", i + 1 ); 349 entryName.sprintf( "File%i", i + 1 );
349 QString linkFile = cfg.readEntry( entryName ); 350 QString linkFile = cfg.readEntry( entryName );
350 DocLnk lnk( linkFile ); 351 DocLnk lnk( linkFile );
351 if ( lnk.isValid() ) 352 if ( lnk.isValid() )
352 d->selectedFiles->addToSelection( lnk ); 353 d->selectedFiles->addToSelection( lnk );
353 } 354 }
354} 355}
355 356
356 357
357void PlayListWidget::writeConfig( Config& cfg ) const { 358void PlayListWidget::writeConfig( Config& cfg ) const {
358 cfg.setGroup("PlayList"); 359 cfg.setGroup("PlayList");
359 360
360 int noOfFiles = 0; 361 int noOfFiles = 0;
361 362
362 d->selectedFiles->first(); 363 d->selectedFiles->first();
363 do { 364 do {
364 const DocLnk *lnk = d->selectedFiles->current(); 365 const DocLnk *lnk = d->selectedFiles->current();
365 if ( lnk ) { 366 if ( lnk ) {
366 QString entryName; 367 QString entryName;
367 entryName.sprintf( "File%i", noOfFiles + 1 ); 368 entryName.sprintf( "File%i", noOfFiles + 1 );
368 cfg.writeEntry( entryName, lnk->linkFile() ); 369 cfg.writeEntry( entryName, lnk->linkFile() );
369 // if this link does exist, add it so we have the file 370 // if this link does exist, add it so we have the file
370 // next time... 371 // next time...
371 if ( !QFile::exists( lnk->linkFile() ) ) { 372 if ( !QFile::exists( lnk->linkFile() ) ) {
372 // the way writing lnks doesn't really check for out 373 // the way writing lnks doesn't really check for out
373 // of disk space, but check it anyway. 374 // of disk space, but check it anyway.
374 if ( !lnk->writeLink() ) { 375 if ( !lnk->writeLink() ) {
375 QMessageBox::critical( 0, tr("Out of space"), 376 QMessageBox::critical( 0, tr("Out of space"),
376 tr( "There was a problem saving " 377 tr( "There was a problem saving "
377 "the playlist.\n" 378 "the playlist.\n"
378 "Your playlist " 379 "Your playlist "
379 "may be missing some entries\n" 380 "may be missing some entries\n"
380 "the next time you start it." ) 381 "the next time you start it." )
381 ); 382 );
382 } 383 }
383 } 384 }
384 noOfFiles++; 385 noOfFiles++;
385 } 386 }
386 } while ( d->selectedFiles->next() ); 387 } while ( d->selectedFiles->next() );
387 388
388 cfg.writeEntry("NumberOfFiles", noOfFiles ); 389 cfg.writeEntry("NumberOfFiles", noOfFiles );
389 390
390 391
391} 392}
392 393
393 394
394void PlayListWidget::addToSelection( const DocLnk& lnk ) { 395void PlayListWidget::addToSelection( const DocLnk& lnk ) {
395// qDebug("add"); 396// qDebug("add");
396 d->setDocumentUsed = FALSE; 397 d->setDocumentUsed = FALSE;
397 if ( mediaPlayerState->playlist() ) 398 if ( mediaPlayerState->playlist() )
398 d->selectedFiles->addToSelection( lnk ); 399 d->selectedFiles->addToSelection( lnk );
399 else 400 else
400 mediaPlayerState->setPlaying( TRUE ); 401 mediaPlayerState->setPlaying( TRUE );
401} 402}
402 403
403 404
404void PlayListWidget::clearList() { 405void PlayListWidget::clearList() {
405 while ( first() ) 406 while ( first() )
406 d->selectedFiles->removeSelected(); 407 d->selectedFiles->removeSelected();
407} 408}
408 409
409 410
410void PlayListWidget::addAllToList() { 411void PlayListWidget::addAllToList() {
411 DocLnkSet files; 412 DocLnkSet files;
412 Global::findDocuments(&files, "video/*;audio/*"); 413 Global::findDocuments(&files, "video/*;audio/*");
413 QListIterator<DocLnk> dit( files.children() ); 414 QListIterator<DocLnk> dit( files.children() );
414 for ( ; dit.current(); ++dit ) 415 for ( ; dit.current(); ++dit )
415 d->selectedFiles->addToSelection( **dit ); 416 d->selectedFiles->addToSelection( **dit );
416} 417}
417 418
418 419
419void PlayListWidget::addAllMusicToList() { 420void PlayListWidget::addAllMusicToList() {
420 DocLnkSet files; 421 DocLnkSet files;
421 Global::findDocuments(&files, "audio/*"); 422 Global::findDocuments(&files, "audio/*");
422 QListIterator<DocLnk> dit( files.children() ); 423 QListIterator<DocLnk> dit( files.children() );
423 for ( ; dit.current(); ++dit ) 424 for ( ; dit.current(); ++dit )
424 d->selectedFiles->addToSelection( **dit ); 425 d->selectedFiles->addToSelection( **dit );
425} 426}
426 427
427 428
428void PlayListWidget::addAllVideoToList() { 429void PlayListWidget::addAllVideoToList() {
429 DocLnkSet files; 430 DocLnkSet files;
430 Global::findDocuments(&files, "video/*"); 431 Global::findDocuments(&files, "video/*");
431 QListIterator<DocLnk> dit( files.children() ); 432 QListIterator<DocLnk> dit( files.children() );
432 for ( ; dit.current(); ++dit ) 433 for ( ; dit.current(); ++dit )
433 d->selectedFiles->addToSelection( **dit ); 434 d->selectedFiles->addToSelection( **dit );
434} 435}
435 436
436 437
437void PlayListWidget::setDocument(const QString& fileref) { 438void PlayListWidget::setDocument(const QString& fileref) {
438 fromSetDocument = TRUE; 439 fromSetDocument = TRUE;
439 if ( fileref.isNull() ) { 440 if ( fileref.isNull() ) {
440 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); 441 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
441 return; 442 return;
442 } 443 }
443// qDebug("setDocument "+fileref); 444// qDebug("setDocument "+fileref);
444 if(fileref.find("playlist",0,TRUE) == -1) { 445 if(fileref.find("playlist",0,TRUE) == -1) {
445 clearList(); 446 clearList();
446 addToSelection( DocLnk( fileref ) ); 447 addToSelection( DocLnk( fileref ) );
447 d->setDocumentUsed = TRUE; 448 d->setDocumentUsed = TRUE;
448 mediaPlayerState->setPlaying( FALSE ); 449 mediaPlayerState->setPlaying( FALSE );
449 qApp->processEvents(); 450 qApp->processEvents();
450 mediaPlayerState->setPlaying( TRUE ); 451 mediaPlayerState->setPlaying( TRUE );
451 qApp->processEvents(); 452 qApp->processEvents();
452 setCaption("OpiePlayer"); 453 setCaption("OpiePlayer");
453 454
454 } else { //is playlist 455 } else { //is playlist
455 clearList(); 456 clearList();
456 loadList(DocLnk(fileref)); 457 loadList(DocLnk(fileref));
457 d->selectedFiles->first(); 458 d->selectedFiles->first();
458 } 459 }
459} 460}
460 461
461 462
462void PlayListWidget::setActiveWindow() { 463void PlayListWidget::setActiveWindow() {
463 // When we get raised we need to ensure that it switches views 464 // When we get raised we need to ensure that it switches views
464 char origView = mediaPlayerState->view(); 465 char origView = mediaPlayerState->view();
465 mediaPlayerState->setView( 'l' ); // invalidate 466 mediaPlayerState->setView( 'l' ); // invalidate
466 mediaPlayerState->setView( origView ); // now switch back 467 mediaPlayerState->setView( origView ); // now switch back
467} 468}
468 469
469 470
470void PlayListWidget::useSelectedDocument() { 471void PlayListWidget::useSelectedDocument() {
471 d->setDocumentUsed = FALSE; 472 d->setDocumentUsed = FALSE;
472} 473}
473 474
474 475
475const DocLnk *PlayListWidget::current() { // this is fugly 476const DocLnk *PlayListWidget::current() { // this is fugly
476 477
477// if( fromSetDocument) { 478// if( fromSetDocument) {
478// qDebug("from setDoc"); 479// qDebug("from setDoc");
479// DocLnkSet files; 480// DocLnkSet files;
480// Global::findDocuments(&files, "video/*;audio/*"); 481// Global::findDocuments(&files, "video/*;audio/*");
481// QListIterator<DocLnk> dit( files.children() ); 482// QListIterator<DocLnk> dit( files.children() );
482// for ( ; dit.current(); ++dit ) { 483// for ( ; dit.current(); ++dit ) {
483// if(dit.current()->linkFile() == setDocFileRef) { 484// if(dit.current()->linkFile() == setDocFileRef) {
484// qDebug(setDocFileRef); 485// qDebug(setDocFileRef);
485// return dit; 486// return dit;
486// } 487// }
487// } 488// }
488// } else 489// } else
489 switch (tabWidget->currentPageIndex()) { 490// qDebug("current");
490 case 0: //playlist 491// switch (tabWidget->currentPageIndex()) {
491 { 492// case 0: //playlist
492 if ( mediaPlayerState->playlist() ) { 493// {
493 return d->selectedFiles->current(); 494 qDebug("playlist");
494 } 495 if ( mediaPlayerState->playlist() ) {
495 else if ( d->setDocumentUsed && d->current ) { 496 return d->selectedFiles->current();
496 return d->current;
497 } else {
498 return d->files->selected();
499 }
500 } 497 }
501 break; 498 else if ( d->setDocumentUsed && d->current ) {
502 case 1: { //audio 499 return d->current;
503 Global::findDocuments(&files, "audio/*"); 500 } else {
504 QListIterator<DocLnk> dit( files.children() ); 501 return d->files->selected();
505 for ( ; dit.current(); ++dit ) {
506 if( dit.current()->name() == audioView->currentItem()->text(0))
507 return dit;
508 }
509 }
510 break;
511 case 2: { // video
512 Global::findDocuments(&vFiles, "video/*");
513 QListIterator<DocLnk> Vdit( vFiles.children() );
514 for ( ; Vdit.current(); ++Vdit ) {
515 if( Vdit.current()->name() == videoView->currentItem()->text(0))
516 return Vdit;
517 }
518 } 502 }
519 break; 503// }
520 }; 504// break;
505// case 1://audio
506// {
507// qDebug("audioView");
508// Global::findDocuments(&files, "audio/*");
509// QListIterator<DocLnk> dit( files.children() );
510// for ( ; dit.current(); ++dit ) {
511// if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) {
512// qDebug("here");
513// insanityBool=TRUE;
514// return dit;
515// }
516// }
517// }
518// break;
519// case 2: // video
520// {
521// qDebug("videoView");
522// Global::findDocuments(&vFiles, "video/*");
523// QListIterator<DocLnk> Vdit( vFiles.children() );
524// for ( ; Vdit.current(); ++Vdit ) {
525// if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) {
526// insanityBool=TRUE;
527// return Vdit;
528// }
529// }
530// }
531// break;
532// };
533// return 0;
521} 534}
522 535
523bool PlayListWidget::prev() { 536bool PlayListWidget::prev() {
524 if ( mediaPlayerState->playlist() ) { 537 if ( mediaPlayerState->playlist() ) {
525 if ( mediaPlayerState->shuffled() ) { 538 if ( mediaPlayerState->shuffled() ) {
526 const DocLnk *cur = current(); 539 const DocLnk *cur = current();
527 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 540 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
528 for ( int i = 0; i < j; i++ ) { 541 for ( int i = 0; i < j; i++ ) {
529 if ( !d->selectedFiles->next() ) 542 if ( !d->selectedFiles->next() )
530 d->selectedFiles->first(); 543 d->selectedFiles->first();
531 } 544 }
532 if ( cur == current() ) 545 if ( cur == current() )
533 if ( !d->selectedFiles->next() ) 546 if ( !d->selectedFiles->next() )
534 d->selectedFiles->first(); 547 d->selectedFiles->first();
535 return TRUE; 548 return TRUE;
536 } else { 549 } else {
537 if ( !d->selectedFiles->prev() ) { 550 if ( !d->selectedFiles->prev() ) {
538 if ( mediaPlayerState->looping() ) { 551 if ( mediaPlayerState->looping() ) {
539 return d->selectedFiles->last(); 552 return d->selectedFiles->last();
540 } else { 553 } else {
541 return FALSE; 554 return FALSE;
542 } 555 }
543 } 556 }
544 return TRUE; 557 return TRUE;
545 } 558 }
546 } else { 559 } else {
547 return mediaPlayerState->looping(); 560 return mediaPlayerState->looping();
548 } 561 }
549} 562}
550 563
551 564
552bool PlayListWidget::next() { 565bool PlayListWidget::next() {
553 if ( mediaPlayerState->playlist() ) { 566 if ( mediaPlayerState->playlist() ) {
554 if ( mediaPlayerState->shuffled() ) { 567 if ( mediaPlayerState->shuffled() ) {
555 return prev(); 568 return prev();
556 } else { 569 } else {
557 if ( !d->selectedFiles->next() ) { 570 if ( !d->selectedFiles->next() ) {
558 if ( mediaPlayerState->looping() ) { 571 if ( mediaPlayerState->looping() ) {
559 return d->selectedFiles->first(); 572 return d->selectedFiles->first();
560 } else { 573 } else {
561 return FALSE; 574 return FALSE;
562 } 575 }
563 } 576 }
564 return TRUE; 577 return TRUE;
565 } 578 }
566 } else { 579 } else {
567 return mediaPlayerState->looping(); 580 return mediaPlayerState->looping();
568 } 581 }
569} 582}
570 583
571 584
572bool PlayListWidget::first() { 585bool PlayListWidget::first() {
573 if ( mediaPlayerState->playlist() ) 586 if ( mediaPlayerState->playlist() )
574 return d->selectedFiles->first(); 587 return d->selectedFiles->first();
575 else 588 else
576 return mediaPlayerState->looping(); 589 return mediaPlayerState->looping();
577} 590}
578 591
579 592
580bool PlayListWidget::last() { 593bool PlayListWidget::last() {
581 if ( mediaPlayerState->playlist() ) 594 if ( mediaPlayerState->playlist() )
582 return d->selectedFiles->last(); 595 return d->selectedFiles->last();
583 else 596 else
584 return mediaPlayerState->looping(); 597 return mediaPlayerState->looping();
585} 598}
586 599
587 600
588void PlayListWidget::saveList() { 601void PlayListWidget::saveList() {
589 602
590 QString filename; 603 QString filename;
591 InputDialog *fileDlg; 604 InputDialog *fileDlg;
592 fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0); 605 fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0);
593 fileDlg->exec(); 606 fileDlg->exec();
594 if( fileDlg->result() == 1 ) { 607 if( fileDlg->result() == 1 ) {
595 if ( d->current ) 608 if ( d->current )
596 delete d->current; 609 delete d->current;
597 filename = fileDlg->LineEdit1->text();//+".playlist"; 610 filename = fileDlg->LineEdit1->text();//+".playlist";
598// qDebug("saving playlist "+filename+".playlist"); 611// qDebug("saving playlist "+filename+".playlist");
599 Config cfg( filename +".playlist"); 612 Config cfg( filename +".playlist");
600 writeConfig( cfg ); 613 writeConfig( cfg );
601 if( playLists->selected()->name() == filename) { 614 if( playLists->selected()->name() == filename) {
602// qDebug("same name so delete lnk"); 615// qDebug("same name so delete lnk");
603 QFile().remove(playLists->selected()->file()); 616 QFile().remove(playLists->selected()->file());
604 QFile().remove(playLists->selected()->linkFile()); 617 QFile().remove(playLists->selected()->linkFile());
605 playLists->reread(); 618 playLists->reread();
606 } 619 }
607 620
608 DocLnk lnk; 621 DocLnk lnk;
609// lnk.setComment( ""); 622// lnk.setComment( "");
610 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property 623 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
611 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D 624 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
612 lnk.setIcon("mpegplayer/playlist2"); 625 lnk.setIcon("mpegplayer/playlist2");
613 lnk.setName( filename); //sets file name 626 lnk.setName( filename); //sets file name
614 if(!lnk.writeLink()) 627 if(!lnk.writeLink())
615 qDebug("Writing doclink did not work"); 628 qDebug("Writing doclink did not work");
616 } 629 }
617 Config config( "MediaPlayer" ); 630 Config config( "MediaPlayer" );
618 config.writeEntry("CurrentPlaylist",filename); 631 config.writeEntry("CurrentPlaylist",filename);
619 setCaption("OpiePlayer: "+filename); 632 setCaption("OpiePlayer: "+filename);
620 d->selectedFiles->first(); 633 d->selectedFiles->first();
621 if(fileDlg) 634 if(fileDlg)
622 delete fileDlg; 635 delete fileDlg;
623} 636}
624 637
625void PlayListWidget::loadList( const DocLnk & lnk) { 638void PlayListWidget::loadList( const DocLnk & lnk) {
626 QString name= lnk.name(); 639 QString name= lnk.name();
627// qDebug("currentList is "+name); 640// qDebug("currentList is "+name);
628 if( name.length()>1) { 641 if( name.length()>1) {
629 setCaption("OpiePlayer: "+name); 642 setCaption("OpiePlayer: "+name);
630// qDebug("load list "+ name+".playlist"); 643// qDebug("load list "+ name+".playlist");
631 clearList(); 644 clearList();
632 Config cfg( name+".playlist"); 645 Config cfg( name+".playlist");
633 readConfig(cfg); 646 readConfig(cfg);
634 tabWidget->setCurrentPage(0); 647 tabWidget->setCurrentPage(0);
635 Config config( "MediaPlayer" ); 648 Config config( "MediaPlayer" );
636 config.writeEntry("CurrentPlaylist", name); 649 config.writeEntry("CurrentPlaylist", name);
637 d->selectedFiles->first(); 650 d->selectedFiles->first();
638 } 651 }
639} 652}
640 653
641void PlayListWidget::setPlaylist( bool shown ) { 654void PlayListWidget::setPlaylist( bool shown ) {
642 if ( shown ) 655 if ( shown )
643 d->playListFrame->show(); 656 d->playListFrame->show();
644 else 657 else
645 d->playListFrame->hide(); 658 d->playListFrame->hide();
646} 659}
647 660
648void PlayListWidget::setView( char view ) { 661void PlayListWidget::setView( char view ) {
649 if ( view == 'l' ) 662 if ( view == 'l' )
650 showMaximized(); 663 showMaximized();
651 else 664 else
652 hide(); 665 hide();
653} 666}
654 667
655void PlayListWidget::addSelected() { 668void PlayListWidget::addSelected() {
656 669
657 switch (tabWidget->currentPageIndex()) { 670 Config cfg( "MediaPlayer" );
658 case 0: //playlist 671 cfg.setGroup("PlayList");
659 break; 672 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
660 case 1: { //audio 673 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
661 addToSelection( audioView->selectedItem() ); 674
662 } 675 switch (tabWidget->currentPageIndex()) {
663 break; 676 case 0: //playlist
664 case 2: { // video 677 break;
665 addToSelection( videoView->selectedItem() ); 678 case 1: { //audio
666 } 679 for ( int i = 0; i < noOfFiles; i++ ) {
667 break; 680 QString entryName;
668 }; 681 entryName.sprintf( "File%i", i + 1 );
682 QString linkFile = cfg.readEntry( entryName );
683 if( DocLnk( linkFile).name() == audioView->selectedItem()->text(0) ) {
684 int result= QMessageBox::warning(this,"OpiePlayer",
685 tr("This is all ready in your playlist.\nContinue?"),
686 tr("Yes"),tr("No"),0,0,1);
687 if (result !=0)
688 return;
689 }
690 }
691 addToSelection( audioView->selectedItem() );
692 tabWidget->setCurrentPage(1);
693 }
694 break;
695 case 2: { // video
696 for ( int i = 0; i < noOfFiles; i++ ) {
697 QString entryName;
698 entryName.sprintf( "File%i", i + 1 );
699 QString linkFile = cfg.readEntry( entryName );
700 if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) {
701 int result= QMessageBox::warning(this,"OpiePlayer",
702 tr("This is all ready in your playlist.\nContinue?"),
703 tr("Yes"),tr("No"),0,0,1);
704 if (result !=0)
705 return;
706 }
707 }
708 addToSelection( videoView->selectedItem() );
709 tabWidget->setCurrentPage(2);
710 }
711 break;
712 };
669} 713}
670 714
671void PlayListWidget::removeSelected() { 715void PlayListWidget::removeSelected() {
672 d->selectedFiles->removeSelected( ); 716 d->selectedFiles->removeSelected( );
673} 717}
674 718
675 719
676void PlayListWidget::playIt( QListViewItem *it) { 720void PlayListWidget::playIt( QListViewItem *it) {
677// d->setDocumentUsed = FALSE; 721// d->setDocumentUsed = FALSE;
678 mediaPlayerState->setPlaying(TRUE); 722 mediaPlayerState->setPlaying(TRUE);
679} 723}
680 724
681void PlayListWidget::addToSelection( QListViewItem *it) { 725void PlayListWidget::addToSelection( QListViewItem *it) {
682 d->setDocumentUsed = FALSE; 726 d->setDocumentUsed = FALSE;
683 727
684 if(it) { 728 if(it) {
685// qDebug("add to selection"); 729// qDebug("add to selection");
686 switch (tabWidget->currentPageIndex()) { 730 switch (tabWidget->currentPageIndex()) {
687 case 1: { 731 case 1: {
688// qDebug("case 1"); 732// qDebug("case 1");
689 QListIterator<DocLnk> dit( files.children() ); 733 QListIterator<DocLnk> dit( files.children() );
690 for ( ; dit.current(); ++dit ) { 734 for ( ; dit.current(); ++dit ) {
691// qDebug(dit.current()->name()); 735// qDebug(dit.current()->name());
692 if( dit.current()->name() == it->text(0)) { 736 if( dit.current()->name() == it->text(0)) {
693 d->selectedFiles->addToSelection( **dit ); 737 d->selectedFiles->addToSelection( **dit );
694 } 738 }
695 } 739 }
696 } 740 }
697 break; 741 break;
698 case 2: { 742 case 2: {
699// qDebug("case 2"); 743// qDebug("case 2");
700 QListIterator<DocLnk> dit( vFiles.children() ); 744 QListIterator<DocLnk> dit( vFiles.children() );
701 for ( ; dit.current(); ++dit ) { 745 for ( ; dit.current(); ++dit ) {
702// qDebug(dit.current()->name()); 746// qDebug(dit.current()->name());
703 if( dit.current()->name() == it->text(0)) { 747 if( dit.current()->name() == it->text(0)) {
704 d->selectedFiles->addToSelection( **dit ); 748 d->selectedFiles->addToSelection( **dit );
705 } 749 }
706 } 750 }
707 } 751 }
708 break; 752 break;
709 case 0: 753 case 0:
710 break; 754 break;
711 }; 755 };
712 tabWidget->setCurrentPage(0); 756 tabWidget->setCurrentPage(0);
713// mediaPlayerState->setPlaying( TRUE ); 757// mediaPlayerState->setPlaying( TRUE );
714 } 758 }
715} 759}
716 760
717void PlayListWidget::tabChanged(QWidget *widg) { 761void PlayListWidget::tabChanged(QWidget *widg) {
718 762
719 switch ( tabWidget->currentPageIndex()) { 763 switch ( tabWidget->currentPageIndex()) {
720 case 0: 764 case 0:
721 { 765 {
722 if( !tbDeletePlaylist->isHidden()) 766 if( !tbDeletePlaylist->isHidden())
723 tbDeletePlaylist->hide(); 767 tbDeletePlaylist->hide();
724 d->tbRemoveFromList->setEnabled(TRUE); 768 d->tbRemoveFromList->setEnabled(TRUE);
725 d->tbAddToList->setEnabled(FALSE); 769 d->tbAddToList->setEnabled(FALSE);
726 } 770 }
727 break; 771 break;
728 case 1: 772 case 1:
729 { 773 {
730 if( !tbDeletePlaylist->isHidden()) 774 if( !tbDeletePlaylist->isHidden())
731 tbDeletePlaylist->hide(); 775 tbDeletePlaylist->hide();
732 d->tbRemoveFromList->setEnabled(FALSE); 776 d->tbRemoveFromList->setEnabled(FALSE);
733 d->tbAddToList->setEnabled(TRUE); 777 d->tbAddToList->setEnabled(TRUE);
734 } 778 }
735 break; 779 break;
736 case 2: 780 case 2:
737 { 781 {
738 if( !tbDeletePlaylist->isHidden()) 782 if( !tbDeletePlaylist->isHidden())
739 tbDeletePlaylist->hide(); 783 tbDeletePlaylist->hide();
740 d->tbRemoveFromList->setEnabled(FALSE); 784 d->tbRemoveFromList->setEnabled(FALSE);
741 d->tbAddToList->setEnabled(TRUE); 785 d->tbAddToList->setEnabled(TRUE);
742 } 786 }
743 break; 787 break;
744 case 3: 788 case 3:
745 { 789 {
746 if( tbDeletePlaylist->isHidden()) 790 if( tbDeletePlaylist->isHidden())
747 tbDeletePlaylist->show(); 791 tbDeletePlaylist->show();
748 playLists->reread(); 792 playLists->reread();
749 } 793 }
750 break; 794 break;
751 }; 795 };
752} 796}
753 797
754 798
755/* 799/*
756 play button is pressed*/ 800 play button is pressed*/
757void PlayListWidget::btnPlay(bool b) { 801void PlayListWidget::btnPlay(bool b) {
758 mediaPlayerState->setPlaying(b); 802// mediaPlayerState->setPlaying(b);
803 switch ( tabWidget->currentPageIndex()) {
804 case 0:
805 {
806 mediaPlayerState->setPlaying(b);
807 }
808 break;
809 case 1:
810 {
811 addToSelection( audioView->selectedItem() );
812 mediaPlayerState->setPlaying(b);
813// qApp->processEvents();
814 d->selectedFiles->removeSelected( );
815 tabWidget->setCurrentPage(1);
816// mediaPlayerState->setPlaying(FALSE);
817 }
818 break;
819 case 2:
820 {
821 addToSelection( videoView->selectedItem() );
822 mediaPlayerState->setPlaying(b);
823 qApp->processEvents();
824 d->selectedFiles->removeSelected( );
825 tabWidget->setCurrentPage(2);
826// mediaPlayerState->setPlaying(FALSE);
827 }
828 break;
829 };
830
831
832
833
759} 834}
760 835
761void PlayListWidget::deletePlaylist() { 836void PlayListWidget::deletePlaylist() {
762 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 837 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
763 (tr("You really want to delete\nthis playlist?")), 838 (tr("You really want to delete\nthis playlist?")),
764 (tr("Yes")), (tr("No")), 0 )){ 839 (tr("Yes")), (tr("No")), 0 )){
765 case 0: // Yes clicked, 840 case 0: // Yes clicked,
766 QFile().remove(playLists->selected()->file()); 841 QFile().remove(playLists->selected()->file());
767 QFile().remove(playLists->selected()->linkFile()); 842 QFile().remove(playLists->selected()->linkFile());
768 playLists->reread(); 843 playLists->reread();
769 break; 844 break;
770 case 1: // Cancel 845 case 1: // Cancel
771 break; 846 break;
772 }; 847 };
773 848
774} 849}
775 850
776void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) 851void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
777{ 852{
778 switch (mouse) { 853 switch (mouse) {
779 case 1: 854 case 1:
780 break; 855 break;
781 case 2:{ 856 case 2:{
782 QPopupMenu m; 857 QPopupMenu m;
783 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 858 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
784 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 859 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
785// m.insertSeparator(); 860// m.insertSeparator();
786// m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); 861// m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
787 m.exec( QCursor::pos() ); 862 m.exec( QCursor::pos() );
788 } 863 }
789 break; 864 break;
790 }; 865 };
791 866
792} 867}
793 868
794void PlayListWidget::playSelected() 869void PlayListWidget::playSelected()
795{ 870{
796 btnPlay( TRUE); 871 btnPlay( TRUE);
797} 872}
798 873
799void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) 874void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
800{ 875{
801 switch (mouse) { 876 switch (mouse) {
802 case 1: 877 case 1:
803 break; 878 break;
804 case 2:{ 879 case 2:{
805 QPopupMenu m; 880 QPopupMenu m;
806 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 881 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
807 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 882 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
808// m.insertSeparator(); 883// m.insertSeparator();
809 m.exec( QCursor::pos() ); 884 m.exec( QCursor::pos() );
810 } 885 }
811 break; 886 break;
812 }; 887 };
813 888
814} 889}
diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h
index effc600..10a42df 100644
--- a/core/multimedia/opieplayer/playlistwidget.h
+++ b/core/multimedia/opieplayer/playlistwidget.h
@@ -1,107 +1,108 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#ifndef PLAY_LIST_WIDGET_H 20#ifndef PLAY_LIST_WIDGET_H
21#define PLAY_LIST_WIDGET_H 21#define PLAY_LIST_WIDGET_H
22 22
23#include <qmainwindow.h> 23#include <qmainwindow.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qtabwidget.h> 25#include <qtabwidget.h>
26#include <qpe/fileselector.h> 26#include <qpe/fileselector.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28 28
29/* #include <qtimer.h> */ 29/* #include <qtimer.h> */
30 30
31 31
32class PlayListWidgetPrivate; 32class PlayListWidgetPrivate;
33class Config; 33class Config;
34class QListViewItem; 34class QListViewItem;
35class QListView; 35class QListView;
36class QPoint; 36class QPoint;
37class QAction; 37class QAction;
38class QLabel; 38class QLabel;
39 39
40class PlayListWidget : public QMainWindow { 40class PlayListWidget : public QMainWindow {
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); 43 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 );
44 ~PlayListWidget(); 44 ~PlayListWidget();
45 QTabWidget * tabWidget; 45 QTabWidget * tabWidget;
46 QAction *fullScreenButton, *scaleButton; 46 QAction *fullScreenButton, *scaleButton;
47 DocLnkSet files; 47 DocLnkSet files;
48 DocLnkSet vFiles; 48 DocLnkSet vFiles;
49 QListView *audioView, *videoView, *playlistView; 49 QListView *audioView, *videoView, *playlistView;
50 QLabel *libString; 50 QLabel *libString;
51 bool fromSetDocument; 51 bool fromSetDocument;
52 bool insanityBool;
52 QString setDocFileRef; 53 QString setDocFileRef;
53 // retrieve the current playlist entry (media file link) 54 // retrieve the current playlist entry (media file link)
54 const DocLnk *current(); 55 const DocLnk *current();
55 void useSelectedDocument(); 56 void useSelectedDocument();
56/* QTimer * menuTimer; */ 57/* QTimer * menuTimer; */
57 FileSelector* playLists; 58 FileSelector* playLists;
58 QPushButton *tbDeletePlaylist; 59 QPushButton *tbDeletePlaylist;
59public slots: 60public slots:
60 void setDocument( const QString& fileref ); 61 void setDocument( const QString& fileref );
61 void addToSelection( const DocLnk& ); // Add a media file to the playlist 62 void addToSelection( const DocLnk& ); // Add a media file to the playlist
62 void addToSelection( QListViewItem* ); // Add a media file to the playlist 63 void addToSelection( QListViewItem* ); // Add a media file to the playlist
63 void setActiveWindow(); // need to handle this to show the right view 64 void setActiveWindow(); // need to handle this to show the right view
64 void setPlaylist( bool ); // Show/Hide the playlist 65 void setPlaylist( bool ); // Show/Hide the playlist
65 void setView( char ); 66 void setView( char );
66 void clearList(); 67 void clearList();
67 void addAllToList(); 68 void addAllToList();
68 void addAllMusicToList(); 69 void addAllMusicToList();
69 void addAllVideoToList(); 70 void addAllVideoToList();
70 void saveList(); // Save the playlist 71 void saveList(); // Save the playlist
71 void loadList( const DocLnk &); // Load a playlist 72 void loadList( const DocLnk &); // Load a playlist
72 void playIt( QListViewItem *); 73 void playIt( QListViewItem *);
73 74
74 void btnPlay(bool); 75 void btnPlay(bool);
75 void deletePlaylist(); 76 void deletePlaylist();
76 bool first(); 77 bool first();
77 bool last(); 78 bool last();
78 bool next(); 79 bool next();
79 bool prev(); 80 bool prev();
80 void addSelected(); 81 void addSelected();
81 void removeSelected(); 82 void removeSelected();
82 void tabChanged(QWidget*); 83 void tabChanged(QWidget*);
83 void viewPressed( int, QListViewItem *, const QPoint&, int); 84 void viewPressed( int, QListViewItem *, const QPoint&, int);
84 void playlistViewPressed( int, QListViewItem *, const QPoint&, int); 85 void playlistViewPressed( int, QListViewItem *, const QPoint&, int);
85 void playSelected(); 86 void playSelected();
86/* void setFullScreen(); */ 87/* void setFullScreen(); */
87/* void setScaled(); */ 88/* void setScaled(); */
88protected: 89protected:
89/* void contentsMousePressEvent( QMouseEvent * e ); */ 90/* void contentsMousePressEvent( QMouseEvent * e ); */
90/* void contentsMouseReleaseEvent( QMouseEvent * e ); */ 91/* void contentsMouseReleaseEvent( QMouseEvent * e ); */
91 92
92private: 93private:
93 void initializeStates(); 94 void initializeStates();
94 void readConfig( Config& cfg ); 95 void readConfig( Config& cfg );
95 void writeConfig( Config& cfg ) const; 96 void writeConfig( Config& cfg ) const;
96 PlayListWidgetPrivate *d; // Private implementation data 97 PlayListWidgetPrivate *d; // Private implementation data
97 98
98protected slots: 99protected slots:
99/* void cancelMenuTimer(); */ 100/* void cancelMenuTimer(); */
100/* void showFileMenu(); */ 101/* void showFileMenu(); */
101 102
102 103
103}; 104};
104 105
105 106
106#endif // PLAY_LIST_WIDGET_H 107#endif // PLAY_LIST_WIDGET_H
107 108
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp
index bb5f9e8..23b36e5 100644
--- a/core/multimedia/opieplayer/videowidget.cpp
+++ b/core/multimedia/opieplayer/videowidget.cpp
@@ -1,471 +1,472 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#include <qpe/resource.h> 20#include <qpe/resource.h>
21#include <qpe/mediaplayerplugininterface.h> 21#include <qpe/mediaplayerplugininterface.h>
22#include <qwidget.h> 22#include <qwidget.h>
23#include <qpainter.h> 23#include <qpainter.h>
24#include <qpixmap.h> 24#include <qpixmap.h>
25#include <qslider.h> 25#include <qslider.h>
26#include <qdrawutil.h> 26#include <qdrawutil.h>
27#include "videowidget.h" 27#include "videowidget.h"
28#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
29 29
30 30
31#ifdef Q_WS_QWS 31#ifdef Q_WS_QWS
32# define USE_DIRECT_PAINTER 32# define USE_DIRECT_PAINTER
33# include <qdirectpainter_qws.h> 33# include <qdirectpainter_qws.h>
34# include <qgfxraster_qws.h> 34# include <qgfxraster_qws.h>
35#endif 35#endif
36 36
37 37
38extern MediaPlayerState *mediaPlayerState; 38extern MediaPlayerState *mediaPlayerState;
39 39
40 40
41static const int xo = 2; // movable x offset 41static const int xo = 2; // movable x offset
42static const int yo = 0; // movable y offset 42static const int yo = 0; // movable y offset
43 43
44 44
45struct MediaButton { 45struct MediaButton {
46 int xPos, yPos; 46 int xPos, yPos;
47 bool isToggle, isHeld, isDown; 47 bool isToggle, isHeld, isDown;
48 int controlType; 48 int controlType;
49}; 49};
50 50
51 51
52// Layout information for the videoButtons (and if it is a toggle button or not) 52// Layout information for the videoButtons (and if it is a toggle button or not)
53MediaButton videoButtons[] = { 53MediaButton videoButtons[] = {
54 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous 54 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous
55 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop 55 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop
56 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play 56 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play
57 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause 57 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause
58 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next 58 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next
59 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist 59 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist
60 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen 60 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen
61}; 61};
62 62
63 63
64static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 64static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
65 65
66 66
67VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 67VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
68 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { 68 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) {
69 setCaption( tr("OpiePlayer") ); 69 setCaption( tr("OpiePlayer") );
70 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 70 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); 71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) );
72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); 72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) );
73 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); 73 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) );
74 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); 74 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 );
75 75
76 slider = new QSlider( Qt::Horizontal, this ); 76 slider = new QSlider( Qt::Horizontal, this );
77 slider->setMinValue( 0 ); 77 slider->setMinValue( 0 );
78 slider->setMaxValue( 1 ); 78 slider->setMaxValue( 1 );
79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
80 slider->setFocusPolicy( QWidget::NoFocus ); 80 slider->setFocusPolicy( QWidget::NoFocus );
81 slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 81 slider->setGeometry( QRect( 7, 250, 220, 20 ) );
82 82
83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
85 85
86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
90 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 90 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
91 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 91 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
92 92
93 // Intialise state 93 // Intialise state
94 setLength( mediaPlayerState->length() ); 94 setLength( mediaPlayerState->length() );
95 setPosition( mediaPlayerState->position() ); 95 setPosition( mediaPlayerState->position() );
96 setFullscreen( mediaPlayerState->fullscreen() ); 96 setFullscreen( mediaPlayerState->fullscreen() );
97 setPaused( mediaPlayerState->paused() ); 97 setPaused( mediaPlayerState->paused() );
98 setPlaying( mediaPlayerState->playing() ); 98 setPlaying( mediaPlayerState->playing() );
99} 99}
100 100
101 101
102VideoWidget::~VideoWidget() { 102VideoWidget::~VideoWidget() {
103 for ( int i = 0; i < 3; i++ ) 103 for ( int i = 0; i < 3; i++ )
104 delete pixmaps[i]; 104 delete pixmaps[i];
105 delete currentFrame; 105 delete currentFrame;
106} 106}
107 107
108 108
109static bool videoSliderBeingMoved = FALSE; 109static bool videoSliderBeingMoved = FALSE;
110 110
111 111
112void VideoWidget::sliderPressed() { 112void VideoWidget::sliderPressed() {
113 videoSliderBeingMoved = TRUE; 113 videoSliderBeingMoved = TRUE;
114} 114}
115 115
116 116
117void VideoWidget::sliderReleased() { 117void VideoWidget::sliderReleased() {
118 videoSliderBeingMoved = FALSE; 118 videoSliderBeingMoved = FALSE;
119 if ( slider->width() == 0 ) 119 if ( slider->width() == 0 )
120 return; 120 return;
121 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 121 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
122 mediaPlayerState->setPosition( val ); 122 mediaPlayerState->setPosition( val );
123} 123}
124 124
125 125
126void VideoWidget::setPosition( long i ) { 126void VideoWidget::setPosition( long i ) {
127 updateSlider( i, mediaPlayerState->length() ); 127 updateSlider( i, mediaPlayerState->length() );
128} 128}
129 129
130 130
131void VideoWidget::setLength( long max ) { 131void VideoWidget::setLength( long max ) {
132 updateSlider( mediaPlayerState->position(), max ); 132 updateSlider( mediaPlayerState->position(), max );
133} 133}
134 134
135 135
136void VideoWidget::setView( char view ) { 136void VideoWidget::setView( char view ) {
137 if ( view == 'v' ) { 137 if ( view == 'v' ) {
138 makeVisible(); 138 makeVisible();
139 } else { 139 } else {
140 // Effectively blank the view next time we show it so it looks nicer 140 // Effectively blank the view next time we show it so it looks nicer
141 scaledWidth = 0; 141 scaledWidth = 0;
142 scaledHeight = 0; 142 scaledHeight = 0;
143 hide(); 143 hide();
144 } 144 }
145} 145}
146 146
147 147
148void VideoWidget::updateSlider( long i, long max ) { 148void VideoWidget::updateSlider( long i, long max ) {
149 // Will flicker too much if we don't do this 149 // Will flicker too much if we don't do this
150 if ( max == 0 ) 150 if ( max == 0 )
151 return; 151 return;
152 int width = slider->width(); 152 int width = slider->width();
153 int val = int((double)i * width / max); 153 int val = int((double)i * width / max);
154 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { 154 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) {
155 if ( slider->value() != val ) 155 if ( slider->value() != val )
156 slider->setValue( val ); 156 slider->setValue( val );
157 if ( slider->maxValue() != width ) 157 if ( slider->maxValue() != width )
158 slider->setMaxValue( width ); 158 slider->setMaxValue( width );
159 } 159 }
160} 160}
161 161
162 162
163void VideoWidget::setToggleButton( int i, bool down ) { 163void VideoWidget::setToggleButton( int i, bool down ) {
164 if ( down != videoButtons[i].isDown ) 164 if ( down != videoButtons[i].isDown )
165 toggleButton( i ); 165 toggleButton( i );
166} 166}
167 167
168 168
169void VideoWidget::toggleButton( int i ) { 169void VideoWidget::toggleButton( int i ) {
170 videoButtons[i].isDown = !videoButtons[i].isDown; 170 videoButtons[i].isDown = !videoButtons[i].isDown;
171 QPainter p(this); 171 QPainter p(this);
172 paintButton ( &p, i ); 172 paintButton ( &p, i );
173} 173}
174 174
175 175
176void VideoWidget::paintButton( QPainter *p, int i ) { 176void VideoWidget::paintButton( QPainter *p, int i ) {
177 int x = videoButtons[i].xPos; 177 int x = videoButtons[i].xPos;
178 int y = videoButtons[i].yPos; 178 int y = videoButtons[i].yPos;
179 int offset = 10 + videoButtons[i].isDown; 179 int offset = 10 + videoButtons[i].isDown;
180 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); 180 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] );
181 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); 181 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 );
182} 182}
183 183
184 184
185void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 185void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
186 for ( int i = 0; i < numButtons; i++ ) { 186 for ( int i = 0; i < numButtons; i++ ) {
187 int x = videoButtons[i].xPos; 187 int x = videoButtons[i].xPos;
188 int y = videoButtons[i].yPos; 188 int y = videoButtons[i].yPos;
189 if ( event->state() == QMouseEvent::LeftButton ) { 189 if ( event->state() == QMouseEvent::LeftButton ) {
190 // The test to see if the mouse click is inside the circular button or not 190 // The test to see if the mouse click is inside the circular button or not
191 // (compared with the radius squared to avoid a square-root of our distance) 191 // (compared with the radius squared to avoid a square-root of our distance)
192 int radius = 16; 192 int radius = 16;
193 QPoint center = QPoint( x + radius, y + radius ); 193 QPoint center = QPoint( x + radius, y + radius );
194 QPoint dXY = center - event->pos(); 194 QPoint dXY = center - event->pos();
195 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 195 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
196 bool isOnButton = dist <= (radius * radius); 196 bool isOnButton = dist <= (radius * radius);
197 if ( isOnButton != videoButtons[i].isHeld ) { 197 if ( isOnButton != videoButtons[i].isHeld ) {
198 videoButtons[i].isHeld = isOnButton; 198 videoButtons[i].isHeld = isOnButton;
199 toggleButton(i); 199 toggleButton(i);
200 } 200 }
201 } else { 201 } else {
202 if ( videoButtons[i].isHeld ) { 202 if ( videoButtons[i].isHeld ) {
203 videoButtons[i].isHeld = FALSE; 203 videoButtons[i].isHeld = FALSE;
204 if ( !videoButtons[i].isToggle ) 204 if ( !videoButtons[i].isToggle )
205 setToggleButton( i, FALSE ); 205 setToggleButton( i, FALSE );
206 switch (i) {
207 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return;
208 case VideoStop: mediaPlayerState->setPlaying(FALSE); return;
209 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return;
210 case VideoNext: mediaPlayerState->setNext(); return;
211 case VideoPrevious: mediaPlayerState->setPrev(); return;
212 case VideoPlayList: mediaPlayerState->setList(); return;
213 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
214 }
215 } 206 }
216 } 207 }
208 switch (i) {
209 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return;
210 case VideoStop: mediaPlayerState->setPlaying(FALSE); return;
211 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return;
212 case VideoNext: mediaPlayerState->setNext(); return;
213 case VideoPrevious: mediaPlayerState->setPrev(); return;
214 case VideoPlayList: mediaPlayerState->setList(); return;
215 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
216 }
217
217 } 218 }
218} 219}
219 220
220 221
221void VideoWidget::mousePressEvent( QMouseEvent *event ) { 222void VideoWidget::mousePressEvent( QMouseEvent *event ) {
222 mouseMoveEvent( event ); 223 mouseMoveEvent( event );
223} 224}
224 225
225 226
226void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 227void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
227 if ( mediaPlayerState->fullscreen() ) { 228 if ( mediaPlayerState->fullscreen() ) {
228 mediaPlayerState->setFullscreen( FALSE ); 229 mediaPlayerState->setFullscreen( FALSE );
229 makeVisible(); 230 makeVisible();
230 231
231 mouseMoveEvent( event ); 232 mouseMoveEvent( event );
232 } 233 }
233} 234}
234 235
235 236
236void VideoWidget::makeVisible() { 237void VideoWidget::makeVisible() {
237 if ( mediaPlayerState->fullscreen() ) { 238 if ( mediaPlayerState->fullscreen() ) {
238 setBackgroundMode( QWidget::NoBackground ); 239 setBackgroundMode( QWidget::NoBackground );
239 showFullScreen(); 240 showFullScreen();
240 resize( qApp->desktop()->size() ); 241 resize( qApp->desktop()->size() );
241 slider->hide(); 242 slider->hide();
242 } else { 243 } else {
243 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 244 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
244 showNormal(); 245 showNormal();
245 showMaximized(); 246 showMaximized();
246 slider->show(); 247 slider->show();
247 } 248 }
248} 249}
249 250
250 251
251void VideoWidget::paintEvent( QPaintEvent * ) { 252void VideoWidget::paintEvent( QPaintEvent * ) {
252 QPainter p( this ); 253 QPainter p( this );
253 254
254 if ( mediaPlayerState->fullscreen() ) { 255 if ( mediaPlayerState->fullscreen() ) {
255 // Clear the background 256 // Clear the background
256 p.setBrush( QBrush( Qt::black ) ); 257 p.setBrush( QBrush( Qt::black ) );
257 p.drawRect( rect() ); 258 p.drawRect( rect() );
258 259
259 // Draw the current frame 260 // Draw the current frame
260 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen 261 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen
261 } else { 262 } else {
262 // draw border 263 // draw border
263 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); 264 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL );
264 265
265 // Clear the movie screen first 266 // Clear the movie screen first
266 p.setBrush( QBrush( Qt::black ) ); 267 p.setBrush( QBrush( Qt::black ) );
267 p.drawRect( 9, 20, 220, 160 ); 268 p.drawRect( 9, 20, 220, 160 );
268 269
269 // draw current frame (centrally positioned from scaling to maintain aspect ratio) 270 // draw current frame (centrally positioned from scaling to maintain aspect ratio)
270 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 271 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
271 272
272 // draw the buttons 273 // draw the buttons
273 for ( int i = 0; i < numButtons; i++ ) 274 for ( int i = 0; i < numButtons; i++ )
274 paintButton( &p, i ); 275 paintButton( &p, i );
275 276
276 // draw the slider 277 // draw the slider
277 slider->repaint( TRUE ); 278 slider->repaint( TRUE );
278 } 279 }
279} 280}
280 281
281 282
282void VideoWidget::closeEvent( QCloseEvent* ) { 283void VideoWidget::closeEvent( QCloseEvent* ) {
283 mediaPlayerState->setList(); 284 mediaPlayerState->setList();
284} 285}
285 286
286 287
287bool VideoWidget::playVideo() { 288bool VideoWidget::playVideo() {
288 bool result = FALSE; 289 bool result = FALSE;
289 290
290 int stream = 0; 291 int stream = 0;
291 292
292 int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); 293 int sw = mediaPlayerState->curDecoder()->videoWidth( stream );
293 int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); 294 int sh = mediaPlayerState->curDecoder()->videoHeight( stream );
294 int dd = QPixmap::defaultDepth(); 295 int dd = QPixmap::defaultDepth();
295 int w = height(); 296 int w = height();
296 int h = width(); 297 int h = width();
297 298
298 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; 299 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888;
299 300
300 if ( mediaPlayerState->fullscreen() ) { 301 if ( mediaPlayerState->fullscreen() ) {
301#ifdef USE_DIRECT_PAINTER 302#ifdef USE_DIRECT_PAINTER
302 QDirectPainter p(this); 303 QDirectPainter p(this);
303 304
304 if ( ( qt_screen->transformOrientation() == 3 ) && 305 if ( ( qt_screen->transformOrientation() == 3 ) &&
305 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { 306 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) {
306 307
307 w = 320; 308 w = 320;
308 h = 240; 309 h = 240;
309 310
310 if ( mediaPlayerState->scaled() ) { 311 if ( mediaPlayerState->scaled() ) {
311 // maintain aspect ratio 312 // maintain aspect ratio
312 if ( w * sh > sw * h ) 313 if ( w * sh > sw * h )
313 w = sw * h / sh; 314 w = sw * h / sh;
314 else 315 else
315 h = sh * w / sw; 316 h = sh * w / sw;
316 } else { 317 } else {
317 w = sw; 318 w = sw;
318 h = sh; 319 h = sh;
319 } 320 }
320 321
321 w--; // we can't allow libmpeg to overwrite. 322 w--; // we can't allow libmpeg to overwrite.
322 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); 323 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) );
323 324
324 int ox = roff.x() - height() + 2 + (height() - w) / 2; 325 int ox = roff.x() - height() + 2 + (height() - w) / 2;
325 int oy = roff.y() + (width() - h) / 2; 326 int oy = roff.y() + (width() - h) / 2;
326 int sx = 0, sy = 0; 327 int sx = 0, sy = 0;
327 328
328 uchar* fp = p.frameBuffer() + p.lineStep() * oy; 329 uchar* fp = p.frameBuffer() + p.lineStep() * oy;
329 fp += dd * ox / 8; 330 fp += dd * ox / 8;
330 uchar **jt = new uchar*[h]; 331 uchar **jt = new uchar*[h];
331 for ( int i = h; i; i-- ) { 332 for ( int i = h; i; i-- ) {
332 jt[h - i] = fp; 333 jt[h - i] = fp;
333 fp += p.lineStep(); 334 fp += p.lineStep();
334 } 335 }
335 336
336 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; 337 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0;
337 338
338 delete [] jt; 339 delete [] jt;
339 } else { 340 } else {
340#endif 341#endif
341 QPainter p(this); 342 QPainter p(this);
342 343
343 w = 320; 344 w = 320;
344 h = 240; 345 h = 240;
345 346
346 if ( mediaPlayerState->scaled() ) { 347 if ( mediaPlayerState->scaled() ) {
347 // maintain aspect ratio 348 // maintain aspect ratio
348 if ( w * sh > sw * h ) 349 if ( w * sh > sw * h )
349 w = sw * h / sh; 350 w = sw * h / sh;
350 else 351 else
351 h = sh * w / sw; 352 h = sh * w / sw;
352 } else { 353 } else {
353 w = sw; 354 w = sw;
354 h = sh; 355 h = sh;
355 } 356 }
356 357
357 int bytes = ( dd == 16 ) ? 2 : 4; 358 int bytes = ( dd == 16 ) ? 2 : 4;
358 QImage tempFrame( w, h, bytes << 3 ); 359 QImage tempFrame( w, h, bytes << 3 );
359 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 360 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(),
360 0, 0, sw, sh, w, h, format, 0) == 0; 361 0, 0, sw, sh, w, h, format, 0) == 0;
361 if ( result && mediaPlayerState->fullscreen() ) { 362 if ( result && mediaPlayerState->fullscreen() ) {
362 363
363 int rw = h, rh = w; 364 int rw = h, rh = w;
364 QImage rotatedFrame( rw, rh, bytes << 3 ); 365 QImage rotatedFrame( rw, rh, bytes << 3 );
365 366
366 ushort* in = (ushort*)tempFrame.bits(); 367 ushort* in = (ushort*)tempFrame.bits();
367 ushort* out = (ushort*)rotatedFrame.bits(); 368 ushort* out = (ushort*)rotatedFrame.bits();
368 int spl = rotatedFrame.bytesPerLine() / bytes; 369 int spl = rotatedFrame.bytesPerLine() / bytes;
369 for (int x=0; x<h; x++) { 370 for (int x=0; x<h; x++) {
370 if ( bytes == 2 ) { 371 if ( bytes == 2 ) {
371 ushort* lout = out++ + (w - 1)*spl; 372 ushort* lout = out++ + (w - 1)*spl;
372 for (int y=0; y<w; y++) { 373 for (int y=0; y<w; y++) {
373 *lout=*in++; 374 *lout=*in++;
374 lout-=spl; 375 lout-=spl;
375 } 376 }
376 } else { 377 } else {
377 ulong* lout = ((ulong *)out)++ + (w - 1)*spl; 378 ulong* lout = ((ulong *)out)++ + (w - 1)*spl;
378 for (int y=0; y<w; y++) { 379 for (int y=0; y<w; y++) {
379 *lout=*((ulong*)in)++; 380 *lout=*((ulong*)in)++;
380 lout-=spl; 381 lout-=spl;
381 } 382 }
382 } 383 }
383 } 384 }
384 385
385 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); 386 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh );
386 } 387 }
387#ifdef USE_DIRECT_PAINTER 388#ifdef USE_DIRECT_PAINTER
388 } 389 }
389#endif 390#endif
390 } else { 391 } else {
391 392
392 w = 220; 393 w = 220;
393 h = 160; 394 h = 160;
394 395
395 // maintain aspect ratio 396 // maintain aspect ratio
396 if ( w * sh > sw * h ) 397 if ( w * sh > sw * h )
397 w = sw * h / sh; 398 w = sw * h / sh;
398 else 399 else
399 h = sh * w / sw; 400 h = sh * w / sw;
400 401
401 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; 402 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0;
402 403
403 QPainter p( this ); 404 QPainter p( this );
404 405
405 // Image changed size, therefore need to blank the possibly unpainted regions first 406 // Image changed size, therefore need to blank the possibly unpainted regions first
406 if ( scaledWidth != w || scaledHeight != h ) { 407 if ( scaledWidth != w || scaledHeight != h ) {
407 p.setBrush( QBrush( Qt::black ) ); 408 p.setBrush( QBrush( Qt::black ) );
408 p.drawRect( 9, 20, 220, 160 ); 409 p.drawRect( 9, 20, 220, 160 );
409 } 410 }
410 411
411 scaledWidth = w; 412 scaledWidth = w;
412 scaledHeight = h; 413 scaledHeight = h;
413 414
414 if ( result ) { 415 if ( result ) {
415 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 416 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
416 } 417 }
417 418
418 } 419 }
419 420
420 return result; 421 return result;
421} 422}
422 423
423 424
424 425
425void VideoWidget::keyReleaseEvent( QKeyEvent *e) 426void VideoWidget::keyReleaseEvent( QKeyEvent *e)
426{ 427{
427 switch ( e->key() ) { 428 switch ( e->key() ) {
428////////////////////////////// Zaurus keys 429////////////////////////////// Zaurus keys
429 case Key_Home: 430 case Key_Home:
430 break; 431 break;
431 case Key_F9: //activity 432 case Key_F9: //activity
432 break; 433 break;
433 case Key_F10: //contacts 434 case Key_F10: //contacts
434 break; 435 break;
435 case Key_F11: //menu 436 case Key_F11: //menu
436 break; 437 break;
437 case Key_F12: //home 438 case Key_F12: //home
438 break; 439 break;
439 case Key_F13: //mail 440 case Key_F13: //mail
440 break; 441 break;
441 case Key_Space: { 442 case Key_Space: {
442 if(mediaPlayerState->playing()) { 443 if(mediaPlayerState->playing()) {
443 mediaPlayerState->setPlaying(FALSE); 444 mediaPlayerState->setPlaying(FALSE);
444 } else { 445 } else {
445 mediaPlayerState->setPlaying(TRUE); 446 mediaPlayerState->setPlaying(TRUE);
446 } 447 }
447 } 448 }
448 break; 449 break;
449 case Key_Down: 450 case Key_Down:
450// toggleButton(6); 451// toggleButton(6);
451// emit lessClicked(); 452// emit lessClicked();
452// emit lessReleased(); 453// emit lessReleased();
453// toggleButton(6); 454// toggleButton(6);
454 break; 455 break;
455 case Key_Up: 456 case Key_Up:
456// toggleButton(5); 457// toggleButton(5);
457// emit moreClicked(); 458// emit moreClicked();
458// emit moreReleased(); 459// emit moreReleased();
459// toggleButton(5); 460// toggleButton(5);
460 break; 461 break;
461 case Key_Right: 462 case Key_Right:
462 mediaPlayerState->setNext(); 463 mediaPlayerState->setNext();
463 break; 464 break;
464 case Key_Left: 465 case Key_Left:
465 mediaPlayerState->setPrev(); 466 mediaPlayerState->setPrev();
466 break; 467 break;
467 case Key_Escape: 468 case Key_Escape:
468 break; 469 break;
469 470
470 }; 471 };
471} 472}