summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-02 17:27:32 (UTC)
committer simon <simon>2002-12-02 17:27:32 (UTC)
commit2f2f6cfbc31e0144060588b26814301ce99ebd39 (patch) (unidiff)
tree9ca13234ce515afc57b2a11b5b4f9c2144a6b038
parent28f9d0587b2ee6a6a9467f658567a45ab7e95b94 (diff)
downloadopie-2f2f6cfbc31e0144060588b26814301ce99ebd39.zip
opie-2f2f6cfbc31e0144060588b26814301ce99ebd39.tar.gz
opie-2f2f6cfbc31e0144060588b26814301ce99ebd39.tar.bz2
- as MediaPlayerState::isUsingPlaylist() always returns true we can remove
it and simplify some code in the playlistwidget due to that
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayerstate.cpp3
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayerstate.h1
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp92
3 files changed, 35 insertions, 61 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp
index 43040c2..586870c 100644
--- a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp
+++ b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp
@@ -21,115 +21,112 @@
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; General Public License for more 22..}^=.=       =       ; General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = General Public License along with 26  -_. . .   )=.  = General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34// this file is based on work by trolltech 34// this file is based on work by trolltech
35 35
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/qlibrary.h> 37#include <qpe/qlibrary.h>
38#include <qpe/config.h> 38#include <qpe/config.h>
39#include <qvaluelist.h> 39#include <qvaluelist.h>
40#include <qobject.h> 40#include <qobject.h>
41#include <qdir.h> 41#include <qdir.h>
42#include "mediaplayerstate.h" 42#include "mediaplayerstate.h"
43 43
44 44
45 45
46//#define MediaPlayerDebug(x) qDebug x 46//#define MediaPlayerDebug(x) qDebug x
47#define MediaPlayerDebug(x) 47#define MediaPlayerDebug(x)
48 48
49 49
50MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) 50MediaPlayerState::MediaPlayerState( QObject *parent, const char *name )
51 : QObject( parent, name ) { 51 : QObject( parent, name ) {
52 Config cfg( "OpiePlayer" ); 52 Config cfg( "OpiePlayer" );
53 readConfig( cfg ); 53 readConfig( cfg );
54 streaming = false; 54 streaming = false;
55 seekable = true; 55 seekable = true;
56} 56}
57 57
58 58
59MediaPlayerState::~MediaPlayerState() { 59MediaPlayerState::~MediaPlayerState() {
60} 60}
61 61
62 62
63void MediaPlayerState::readConfig( Config& cfg ) { 63void MediaPlayerState::readConfig( Config& cfg ) {
64 cfg.setGroup("Options"); 64 cfg.setGroup("Options");
65 fullscreen = cfg.readBoolEntry( "FullScreen" ); 65 fullscreen = cfg.readBoolEntry( "FullScreen" );
66 scaled = cfg.readBoolEntry( "Scaling" ); 66 scaled = cfg.readBoolEntry( "Scaling" );
67 looping = cfg.readBoolEntry( "Looping" ); 67 looping = cfg.readBoolEntry( "Looping" );
68 shuffled = cfg.readBoolEntry( "Shuffle" ); 68 shuffled = cfg.readBoolEntry( "Shuffle" );
69 usePlaylist = cfg.readBoolEntry( "UsePlayList" );
70 videoGamma = cfg.readNumEntry( "VideoGamma" ); 69 videoGamma = cfg.readNumEntry( "VideoGamma" );
71 usePlaylist = TRUE;
72 playing = FALSE; 70 playing = FALSE;
73 streaming = FALSE; 71 streaming = FALSE;
74 paused = FALSE; 72 paused = FALSE;
75 curPosition = 0; 73 curPosition = 0;
76 curLength = 0; 74 curLength = 0;
77 curView = 'l'; 75 curView = 'l';
78} 76}
79 77
80 78
81void MediaPlayerState::writeConfig( Config& cfg ) const { 79void MediaPlayerState::writeConfig( Config& cfg ) const {
82 cfg.setGroup( "Options" ); 80 cfg.setGroup( "Options" );
83 cfg.writeEntry( "FullScreen", fullscreen ); 81 cfg.writeEntry( "FullScreen", fullscreen );
84 cfg.writeEntry( "Scaling", scaled ); 82 cfg.writeEntry( "Scaling", scaled );
85 cfg.writeEntry( "Looping", looping ); 83 cfg.writeEntry( "Looping", looping );
86 cfg.writeEntry( "Shuffle", shuffled ); 84 cfg.writeEntry( "Shuffle", shuffled );
87 cfg.writeEntry( "UsePlayList", usePlaylist );
88 cfg.writeEntry( "VideoGamma", videoGamma ); 85 cfg.writeEntry( "VideoGamma", videoGamma );
89} 86}
90 87
91// slots 88// slots
92void MediaPlayerState::setIsStreaming( bool b ) { 89void MediaPlayerState::setIsStreaming( bool b ) {
93 streaming = b; 90 streaming = b;
94} 91}
95 92
96void MediaPlayerState::setIsSeekable( bool b ) { 93void MediaPlayerState::setIsSeekable( bool b ) {
97 seekable = b; 94 seekable = b;
98 emit isSeekableToggled(b); 95 emit isSeekableToggled(b);
99} 96}
100 97
101 98
102void MediaPlayerState::setFullscreen( bool b ) { 99void MediaPlayerState::setFullscreen( bool b ) {
103 if ( fullscreen == b ) { 100 if ( fullscreen == b ) {
104 return; 101 return;
105 } 102 }
106 fullscreen = b; 103 fullscreen = b;
107 emit fullscreenToggled(b); 104 emit fullscreenToggled(b);
108} 105}
109 106
110 107
111void MediaPlayerState::setBlanked( bool b ) { 108void MediaPlayerState::setBlanked( bool b ) {
112 if ( blanked == b ) { 109 if ( blanked == b ) {
113 return; 110 return;
114 } 111 }
115 blanked = b; 112 blanked = b;
116 emit blankToggled(b); 113 emit blankToggled(b);
117} 114}
118 115
119 116
120void MediaPlayerState::setScaled( bool b ) { 117void MediaPlayerState::setScaled( bool b ) {
121 if ( scaled == b ) { 118 if ( scaled == b ) {
122 return; 119 return;
123 } 120 }
124 scaled = b; 121 scaled = b;
125 emit scaledToggled(b); 122 emit scaledToggled(b);
126} 123}
127 124
128void MediaPlayerState::setLooping( bool b ) { 125void MediaPlayerState::setLooping( bool b ) {
129 if ( looping == b ) { 126 if ( looping == b ) {
130 return; 127 return;
131 } 128 }
132 looping = b; 129 looping = b;
133 emit loopingToggled(b); 130 emit loopingToggled(b);
134} 131}
135 132
diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.h b/noncore/multimedia/opieplayer2/mediaplayerstate.h
index 7a80ad8..fc4e6cb 100644
--- a/noncore/multimedia/opieplayer2/mediaplayerstate.h
+++ b/noncore/multimedia/opieplayer2/mediaplayerstate.h
@@ -11,97 +11,96 @@
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; General Public License for more 22..}^=.=       =       ; General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = General Public License along with 26  -_. . .   )=.  = General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34// this file is based on work by trolltech 34// this file is based on work by trolltech
35 35
36#ifndef MEDIA_PLAYER_STATE_H 36#ifndef MEDIA_PLAYER_STATE_H
37#define MEDIA_PLAYER_STATE_H 37#define MEDIA_PLAYER_STATE_H
38 38
39 39
40#include <qobject.h> 40#include <qobject.h>
41 41
42 42
43class MediaPlayerDecoder; 43class MediaPlayerDecoder;
44class Config; 44class Config;
45 45
46 46
47class MediaPlayerState : public QObject { 47class MediaPlayerState : public QObject {
48Q_OBJECT 48Q_OBJECT
49public: 49public:
50 MediaPlayerState( QObject *parent, const char *name ); 50 MediaPlayerState( QObject *parent, const char *name );
51 ~MediaPlayerState(); 51 ~MediaPlayerState();
52 52
53 bool isStreaming() const { return streaming; } 53 bool isStreaming() const { return streaming; }
54 bool isSeekable() const { return seekable; } 54 bool isSeekable() const { return seekable; }
55 bool isFullscreen() const { return fullscreen; } 55 bool isFullscreen() const { return fullscreen; }
56 bool isScaled() const { return scaled; } 56 bool isScaled() const { return scaled; }
57 bool isLooping() const { return looping; } 57 bool isLooping() const { return looping; }
58 bool isShuffled() const { return shuffled; } 58 bool isShuffled() const { return shuffled; }
59 bool isUsingPlaylist() const { return usePlaylist; }
60 bool isPaused() const { return paused; } 59 bool isPaused() const { return paused; }
61 bool isPlaying() const { return playing; } 60 bool isPlaying() const { return playing; }
62 bool isStopped() const { return stopped; } 61 bool isStopped() const { return stopped; }
63 long position() const { return curPosition; } 62 long position() const { return curPosition; }
64 long length() const { return curLength; } 63 long length() const { return curLength; }
65 char view() const { return curView; } 64 char view() const { return curView; }
66 65
67public slots: 66public slots:
68 void setIsStreaming( bool b ); 67 void setIsStreaming( bool b );
69 void setIsSeekable( bool b ); 68 void setIsSeekable( bool b );
70 void setFullscreen( bool b ); 69 void setFullscreen( bool b );
71 void setScaled( bool b ); 70 void setScaled( bool b );
72 void setLooping( bool b ); 71 void setLooping( bool b );
73 void setShuffled( bool b ); 72 void setShuffled( bool b );
74 void setPaused( bool b ); 73 void setPaused( bool b );
75 void setPlaying( bool b ); 74 void setPlaying( bool b );
76 void setStopped( bool b ); 75 void setStopped( bool b );
77 void setPosition( long p ); 76 void setPosition( long p );
78 void updatePosition( long p ); 77 void updatePosition( long p );
79 void setLength( long l ); 78 void setLength( long l );
80 void setView( char v ); 79 void setView( char v );
81 void setBlanked( bool b ); 80 void setBlanked( bool b );
82 void setVideoGamma( int v ); 81 void setVideoGamma( int v );
83 82
84 void setPrev(); 83 void setPrev();
85 void setNext(); 84 void setNext();
86 void setList(); 85 void setList();
87 void setVideo(); 86 void setVideo();
88 void setAudio(); 87 void setAudio();
89 88
90 void toggleFullscreen(); 89 void toggleFullscreen();
91 void toggleScaled(); 90 void toggleScaled();
92 void toggleLooping(); 91 void toggleLooping();
93 void toggleShuffled(); 92 void toggleShuffled();
94 void togglePaused(); 93 void togglePaused();
95 void togglePlaying(); 94 void togglePlaying();
96 void toggleBlank(); 95 void toggleBlank();
97 void writeConfig( Config& cfg ) const; 96 void writeConfig( Config& cfg ) const;
98 97
99 98
100signals: 99signals:
101 void fullscreenToggled( bool ); 100 void fullscreenToggled( bool );
102 void scaledToggled( bool ); 101 void scaledToggled( bool );
103 void loopingToggled( bool ); 102 void loopingToggled( bool );
104 void shuffledToggled( bool ); 103 void shuffledToggled( bool );
105 void pausedToggled( bool ); 104 void pausedToggled( bool );
106 void playingToggled( bool ); 105 void playingToggled( bool );
107 void stopToggled( bool ); 106 void stopToggled( bool );
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 5b277cc..f53def6 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -160,105 +160,101 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
160 populateSkinsMenu(); 160 populateSkinsMenu();
161 initializeStates(); 161 initializeStates();
162 162
163 cfg.setGroup("PlayList"); 163 cfg.setGroup("PlayList");
164 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 164 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
165 loadList(DocLnk( currentPlaylist ) ); 165 loadList(DocLnk( currentPlaylist ) );
166} 166}
167 167
168 168
169PlayListWidget::~PlayListWidget() { 169PlayListWidget::~PlayListWidget() {
170 delete d; 170 delete d;
171} 171}
172 172
173 173
174void PlayListWidget::initializeStates() { 174void PlayListWidget::initializeStates() {
175 d->tbPlay->setOn( mediaPlayerState->isPlaying() ); 175 d->tbPlay->setOn( mediaPlayerState->isPlaying() );
176 d->tbLoop->setOn( mediaPlayerState->isLooping() ); 176 d->tbLoop->setOn( mediaPlayerState->isLooping() );
177 d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); 177 d->tbShuffle->setOn( mediaPlayerState->isShuffled() );
178 d->playListFrame->show(); 178 d->playListFrame->show();
179} 179}
180 180
181void PlayListWidget::writeDefaultPlaylist() { 181void PlayListWidget::writeDefaultPlaylist() {
182 182
183 Config config( "OpiePlayer" ); 183 Config config( "OpiePlayer" );
184 config.setGroup( "PlayList" ); 184 config.setGroup( "PlayList" );
185 QString filename=QPEApplication::documentDir() + "/default.m3u"; 185 QString filename=QPEApplication::documentDir() + "/default.m3u";
186 QString currentString = config.readEntry( "CurrentPlaylist", filename); 186 QString currentString = config.readEntry( "CurrentPlaylist", filename);
187 if( currentString == filename) { 187 if( currentString == filename) {
188 Om3u *m3uList; 188 Om3u *m3uList;
189 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); 189 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
190 if( d->selectedFiles->first() ) { 190 if( d->selectedFiles->first() ) {
191 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 191 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
192 do { 192 do {
193 // qDebug(d->selectedFiles->current()->file()); 193 // qDebug(d->selectedFiles->current()->file());
194 m3uList->add( d->selectedFiles->current()->file() ); 194 m3uList->add( d->selectedFiles->current()->file() );
195 } 195 }
196 while ( d->selectedFiles->next() ); 196 while ( d->selectedFiles->next() );
197 197
198 m3uList->write(); 198 m3uList->write();
199 m3uList->close(); 199 m3uList->close();
200 if(m3uList) delete m3uList; 200 if(m3uList) delete m3uList;
201 201
202 } 202 }
203 } 203 }
204} 204}
205 205
206void PlayListWidget::addToSelection( const DocLnk& lnk ) { 206void PlayListWidget::addToSelection( const DocLnk& lnk ) {
207 d->setDocumentUsed = FALSE; 207 d->setDocumentUsed = FALSE;
208 if ( mediaPlayerState->isUsingPlaylist() ) { 208 if( QFileInfo( lnk.file() ).exists() ||
209 if( QFileInfo( lnk.file() ).exists() || 209 lnk.file().left(4) == "http" ) {
210 lnk.file().left(4) == "http" ) { 210 d->selectedFiles->addToSelection( lnk );
211 d->selectedFiles->addToSelection( lnk );
212 }
213// writeCurrentM3u();
214 } 211 }
215 else 212// writeCurrentM3u();
216 mediaPlayerState->setPlaying( TRUE );
217} 213}
218 214
219 215
220void PlayListWidget::clearList() { 216void PlayListWidget::clearList() {
221 while ( first() ) { 217 while ( first() ) {
222 d->selectedFiles->removeSelected(); 218 d->selectedFiles->removeSelected();
223 } 219 }
224} 220}
225 221
226void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 222void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
227 switch (mouse) { 223 switch (mouse) {
228 case 1: 224 case 1:
229 break; 225 break;
230 case 2: 226 case 2:
231 { 227 {
232 QPopupMenu m; 228 QPopupMenu m;
233 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 229 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
234 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 230 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
235 m.exec( QCursor::pos() ); 231 m.exec( QCursor::pos() );
236 } 232 }
237 break; 233 break;
238 } 234 }
239} 235}
240 236
241 237
242void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 238void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
243 switch (mouse) { 239 switch (mouse) {
244 case 1: 240 case 1:
245 break; 241 break;
246 case 2: 242 case 2:
247 { 243 {
248 QPopupMenu m; 244 QPopupMenu m;
249 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 245 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
250 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 246 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
251 m.exec( QCursor::pos() ); 247 m.exec( QCursor::pos() );
252 } 248 }
253 break; 249 break;
254 } 250 }
255} 251}
256 252
257 253
258void PlayListWidget::addAllToList() { 254void PlayListWidget::addAllToList() {
259 255
260// QTime t; 256// QTime t;
261// t.start(); 257// t.start();
262 258
263 if(!audioScan) { 259 if(!audioScan) {
264 if(audioView->childCount() < 1) 260 if(audioView->childCount() < 1)
@@ -377,168 +373,150 @@ void PlayListWidget::addAllVideoToList() {
377 d->selectedFiles->addToSelection( **dit ); 373 d->selectedFiles->addToSelection( **dit );
378 } 374 }
379 } 375 }
380*/ 376*/
381 tabWidget->setCurrentPage(0); 377 tabWidget->setCurrentPage(0);
382 writeCurrentM3u(); 378 writeCurrentM3u();
383 d->selectedFiles->first(); 379 d->selectedFiles->first();
384} 380}
385 381
386 382
387void PlayListWidget::setDocument( const QString& fileref ) { 383void PlayListWidget::setDocument( const QString& fileref ) {
388 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); 384 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref );
389 fromSetDocument = TRUE; 385 fromSetDocument = TRUE;
390 if ( fileref.isNull() ) { 386 if ( fileref.isNull() ) {
391 QMessageBox::warning( this, tr( "Invalid File" ), 387 QMessageBox::warning( this, tr( "Invalid File" ),
392 tr( "There was a problem in getting the file." ) ); 388 tr( "There was a problem in getting the file." ) );
393 return; 389 return;
394 } 390 }
395 391
396 clearList(); 392 clearList();
397 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u 393 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u
398 readm3u( fileref ); 394 readm3u( fileref );
399 } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { 395 } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) {
400 readm3u( DocLnk( fileref).file() ); 396 readm3u( DocLnk( fileref).file() );
401 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls 397 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls
402 readPls( fileref ); 398 readPls( fileref );
403 } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { 399 } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) {
404 readPls( DocLnk( fileref).file() ); 400 readPls( DocLnk( fileref).file() );
405 } else { 401 } else {
406 clearList(); 402 clearList();
407 addToSelection( DocLnk( fileref ) ); 403 addToSelection( DocLnk( fileref ) );
408 writeCurrentM3u(); 404 writeCurrentM3u();
409 405
410 d->setDocumentUsed = TRUE; 406 d->setDocumentUsed = TRUE;
411 mediaPlayerState->setPlaying( FALSE ); 407 mediaPlayerState->setPlaying( FALSE );
412 mediaPlayerState->setPlaying( TRUE ); 408 mediaPlayerState->setPlaying( TRUE );
413 } 409 }
414} 410}
415 411
416 412
417void PlayListWidget::useSelectedDocument() { 413void PlayListWidget::useSelectedDocument() {
418 d->setDocumentUsed = FALSE; 414 d->setDocumentUsed = FALSE;
419} 415}
420 416
421 417
422const DocLnk *PlayListWidget::current() const { // this is fugly 418const DocLnk *PlayListWidget::current() const { // this is fugly
423 assert( currentTab() == CurrentPlayList ); 419 assert( currentTab() == CurrentPlayList );
424 420
425// qDebug("playlist"); 421 return d->selectedFiles->current();
426 if ( mediaPlayerState->isUsingPlaylist() )
427 return d->selectedFiles->current();
428
429 assert( false );
430} 422}
431 423
432 424
433bool PlayListWidget::prev() { 425bool PlayListWidget::prev() {
434 if ( mediaPlayerState->isUsingPlaylist() ) { 426 if ( mediaPlayerState->isShuffled() ) {
435 if ( mediaPlayerState->isShuffled() ) { 427 const DocLnk *cur = current();
436 const DocLnk *cur = current(); 428 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
437 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 429 for ( int i = 0; i < j; i++ ) {
438 for ( int i = 0; i < j; i++ ) { 430 if ( !d->selectedFiles->next() )
439 if ( !d->selectedFiles->next() ) 431 d->selectedFiles->first();
440 d->selectedFiles->first(); 432 }
433 if ( cur == current() )
434 if ( !d->selectedFiles->next() ) {
435 d->selectedFiles->first();
441 } 436 }
442 if ( cur == current() ) 437 return TRUE;
443 if ( !d->selectedFiles->next() ) { 438 } else {
444 d->selectedFiles->first(); 439 if ( !d->selectedFiles->prev() ) {
445 } 440 if ( mediaPlayerState->isLooping() ) {
446 return TRUE; 441 return d->selectedFiles->last();
447 } else { 442 } else {
448 if ( !d->selectedFiles->prev() ) { 443 return FALSE;
449 if ( mediaPlayerState->isLooping() ) {
450 return d->selectedFiles->last();
451 } else {
452 return FALSE;
453 }
454 } 444 }
455 return TRUE;
456 } 445 }
457 } else { 446 return TRUE;
458 return mediaPlayerState->isLooping(); 447 }
459 }
460} 448}
461 449
462 450
463bool PlayListWidget::next() { 451bool PlayListWidget::next() {
464//qDebug("<<<<<<<<<<<<next()"); 452//qDebug("<<<<<<<<<<<<next()");
465 if ( mediaPlayerState->isUsingPlaylist() ) { 453 if ( mediaPlayerState->isShuffled() ) {
466 if ( mediaPlayerState->isShuffled() ) { 454 return prev();
467 return prev(); 455 } else {
468 } else { 456 if ( !d->selectedFiles->next() ) {
469 if ( !d->selectedFiles->next() ) { 457 if ( mediaPlayerState->isLooping() ) {
470 if ( mediaPlayerState->isLooping() ) { 458 return d->selectedFiles->first();
471 return d->selectedFiles->first(); 459 } else {
472 } else { 460 return FALSE;
473 return FALSE;
474 }
475 } 461 }
476 return TRUE;
477 } 462 }
478 } else { 463 return TRUE;
479 return mediaPlayerState->isLooping();
480 } 464 }
481} 465}
482 466
483 467
484bool PlayListWidget::first() { 468bool PlayListWidget::first() {
485 if ( mediaPlayerState->isUsingPlaylist() ) 469 return d->selectedFiles->first();
486 return d->selectedFiles->first();
487 else
488 return mediaPlayerState->isLooping();
489} 470}
490 471
491 472
492bool PlayListWidget::last() { 473bool PlayListWidget::last() {
493 if ( mediaPlayerState->isUsingPlaylist() ) 474 return d->selectedFiles->last();
494 return d->selectedFiles->last();
495 else
496 return mediaPlayerState->isLooping();
497} 475}
498 476
499 477
500 void PlayListWidget::saveList() { 478 void PlayListWidget::saveList() {
501 writem3u(); 479 writem3u();
502 } 480 }
503 481
504 482
505void PlayListWidget::loadList( const DocLnk & lnk) { 483void PlayListWidget::loadList( const DocLnk & lnk) {
506 QString name = lnk.name(); 484 QString name = lnk.name();
507 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); 485 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
508 486
509 if( name.length()>0) { 487 if( name.length()>0) {
510 setCaption("OpiePlayer: "+name); 488 setCaption("OpiePlayer: "+name);
511// qDebug("<<<<<<<<<<<<load list "+ lnk.file()); 489// qDebug("<<<<<<<<<<<<load list "+ lnk.file());
512 clearList(); 490 clearList();
513 readm3u(lnk.file()); 491 readm3u(lnk.file());
514 tabWidget->setCurrentPage(0); 492 tabWidget->setCurrentPage(0);
515 } 493 }
516} 494}
517 495
518void PlayListWidget::addSelected() { 496void PlayListWidget::addSelected() {
519 assert( inFileListMode() ); 497 assert( inFileListMode() );
520 498
521 QListView *fileListView = currentFileListView(); 499 QListView *fileListView = currentFileListView();
522 QListViewItemIterator it( fileListView ); 500 QListViewItemIterator it( fileListView );
523 for ( ; it.current(); ++it ) 501 for ( ; it.current(); ++it )
524 if ( it.current()->isSelected() ) { 502 if ( it.current()->isSelected() ) {
525 QString filename = it.current()->text(3); 503 QString filename = it.current()->text(3);
526 504
527 DocLnk lnk; 505 DocLnk lnk;
528 lnk.setName( QFileInfo( filename ).baseName() ); //sets name 506 lnk.setName( QFileInfo( filename ).baseName() ); //sets name
529 lnk.setFile( filename ); //sets file name 507 lnk.setFile( filename ); //sets file name
530 508
531 d->selectedFiles->addToSelection( lnk ); 509 d->selectedFiles->addToSelection( lnk );
532 } 510 }
533 511
534 fileListView->clearSelection(); 512 fileListView->clearSelection();
535 513
536 tabWidget->setCurrentPage( 0 ); 514 tabWidget->setCurrentPage( 0 );
537 writeCurrentM3u(); 515 writeCurrentM3u();
538} 516}
539 517
540 518
541void PlayListWidget::removeSelected() { 519void PlayListWidget::removeSelected() {
542 d->selectedFiles->removeSelected( ); 520 d->selectedFiles->removeSelected( );
543 writeCurrentM3u(); 521 writeCurrentM3u();
544} 522}