summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index b6525e1..897c458 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -1,679 +1,680 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; 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#include <qpe/qpetoolbar.h> 34#include <qpe/qpetoolbar.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#include <qpe/storage.h> 36#include <qpe/storage.h>
37#include <qpe/mimetype.h> 37#include <qpe/mimetype.h>
38#include <qpe/global.h> 38#include <qpe/global.h>
39#include <qpe/resource.h> 39#include <qpe/resource.h>
40 40
41#include <qdir.h> 41#include <qdir.h>
42#include <qmessagebox.h> 42#include <qmessagebox.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qtextstream.h> 44#include <qtextstream.h>
45 45
46#include "playlistselection.h" 46#include "playlistselection.h"
47#include "playlistwidget.h" 47#include "playlistwidget.h"
48#include "mediaplayerstate.h" 48#include "mediaplayerstate.h"
49#include "inputDialog.h" 49#include "inputDialog.h"
50#include "om3u.h" 50#include "om3u.h"
51 51
52//only needed for the random play 52//only needed for the random play
53#include <stdlib.h> 53#include <stdlib.h>
54 54
55#include "audiowidget.h" 55#include "audiowidget.h"
56#include "videowidget.h" 56#include "videowidget.h"
57 57
58extern MediaPlayerState *mediaPlayerState; 58extern MediaPlayerState *mediaPlayerState;
59 59
60 60
61PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 61PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
62 : PlayListWidgetGui( parent, name, fl ) { 62 : PlayListWidgetGui( parent, name, fl ) {
63 63
64 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 64 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
65 "opieplayer2/add_to_playlist", 65 "opieplayer2/add_to_playlist",
66 this , SLOT(addSelected() ) ); 66 this , SLOT(addSelected() ) );
67 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 67 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
68 "opieplayer2/remove_from_playlist", 68 "opieplayer2/remove_from_playlist",
69 this , SLOT(removeSelected() ) ); 69 this , SLOT(removeSelected() ) );
70 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 70 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
71 this , SLOT( btnPlay( bool) ), TRUE ); 71 this , SLOT( btnPlay( bool) ), TRUE );
72 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 72 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
73 mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); 73 mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE );
74 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 74 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
75 mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); 75 mediaPlayerState, SLOT( setLooping( bool ) ), TRUE );
76 76
77 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 77 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
78 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 78 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
79 this, SLOT( addAllMusicToList() ) ); 79 this, SLOT( addAllMusicToList() ) );
80 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 80 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
81 this, SLOT( addAllVideoToList() ) ); 81 this, SLOT( addAllVideoToList() ) );
82 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 82 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
83 this, SLOT( addAllToList() ) ); 83 this, SLOT( addAllToList() ) );
84 pmPlayList->insertSeparator(-1); 84 pmPlayList->insertSeparator(-1);
85// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), 85// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ),
86// this, SLOT( saveList() ) ); 86// this, SLOT( saveList() ) );
87 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), 87 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
88 this, SLOT(writem3u() ) ); 88 this, SLOT(writem3u() ) );
89 pmPlayList->insertSeparator(-1); 89 pmPlayList->insertSeparator(-1);
90 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), 90 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ),
91 this,SLOT( openFile() ) ); 91 this,SLOT( openFile() ) );
92 pmPlayList->insertSeparator(-1); 92 pmPlayList->insertSeparator(-1);
93 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 93 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
94 this,SLOT( scanForAudio() ) ); 94 this,SLOT( scanForAudio() ) );
95 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 95 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
96 this,SLOT( scanForVideo() ) ); 96 this,SLOT( scanForVideo() ) );
97 97
98 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 98 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
99 mediaPlayerState, SLOT( toggleFullscreen() ) ); 99 mediaPlayerState, SLOT( toggleFullscreen() ) );
100 100
101 Config cfg( "OpiePlayer" ); 101 Config cfg( "OpiePlayer" );
102 bool b= cfg.readBoolEntry("FullScreen", 0); 102 bool b= cfg.readBoolEntry("FullScreen", 0);
103 mediaPlayerState->setFullscreen( b ); 103 mediaPlayerState->setFullscreen( b );
104 pmView->setItemChecked( -16, b ); 104 pmView->setItemChecked( -16, b );
105 105
106 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 106 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
107 d->selectedFiles, SLOT(moveSelectedUp() ) ); 107 d->selectedFiles, SLOT(moveSelectedUp() ) );
108 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 108 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
109 d->selectedFiles, SLOT(removeSelected() ) ); 109 d->selectedFiles, SLOT(removeSelected() ) );
110 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 110 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
111 d->selectedFiles, SLOT(moveSelectedDown() ) ); 111 d->selectedFiles, SLOT(moveSelectedDown() ) );
112 QVBox *stretch2 = new QVBox( vbox1 ); 112 QVBox *stretch2 = new QVBox( vbox1 );
113 113
114 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 114 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
115 SLOT( deletePlaylist() ) ); 115 SLOT( deletePlaylist() ) );
116 connect( pmView, SIGNAL( activated( int ) ), 116 connect( pmView, SIGNAL( activated( int ) ),
117 this, SLOT( pmViewActivated( int ) ) ); 117 this, SLOT( pmViewActivated( int ) ) );
118 connect( skinsMenu, SIGNAL( activated( int ) ) , 118 connect( skinsMenu, SIGNAL( activated( int ) ) ,
119 this, SLOT( skinsMenuActivated( int ) ) ); 119 this, SLOT( skinsMenuActivated( int ) ) );
120 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 120 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
121 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 121 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
122 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 122 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
123 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 123 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
124 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 124 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
125 this,SLOT( playIt( QListViewItem *) ) ); 125 this,SLOT( playIt( QListViewItem *) ) );
126 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 126 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
127 this, SLOT( addToSelection( QListViewItem *) ) ); 127 this, SLOT( addToSelection( QListViewItem *) ) );
128 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 128 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
129 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 129 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
130 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 130 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
131 this,SLOT( playIt( QListViewItem *) ) ); 131 this,SLOT( playIt( QListViewItem *) ) );
132 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 132 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
133 this, SLOT( addToSelection( QListViewItem *) ) ); 133 this, SLOT( addToSelection( QListViewItem *) ) );
134 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 134 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
135 this, SLOT( loadList( const DocLnk & ) ) ); 135 this, SLOT( loadList( const DocLnk & ) ) );
136 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 136 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
137 this, SLOT( tabChanged( QWidget* ) ) ); 137 this, SLOT( tabChanged( QWidget* ) ) );
138 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), 138 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ),
139 d->tbPlay, SLOT( setOn( bool ) ) ); 139 d->tbPlay, SLOT( setOn( bool ) ) );
140 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 140 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
141 d->tbLoop, SLOT( setOn( bool ) ) ); 141 d->tbLoop, SLOT( setOn( bool ) ) );
142 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 142 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
143 d->tbShuffle, SLOT( setOn( bool ) ) ); 143 d->tbShuffle, SLOT( setOn( bool ) ) );
144 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), 144 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ),
145 this, SLOT( setPlaylist( bool ) ) ); 145 this, SLOT( setPlaylist( bool ) ) );
146 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 146 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
147 this, SLOT( playIt( QListViewItem *) ) ); 147 this, SLOT( playIt( QListViewItem *) ) );
148 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 148 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
149 mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 149 mediaPlayerState, SLOT( setVideoGamma( int ) ) );
150 150
151 // see which skins are installed 151 // see which skins are installed
152 videoScan=FALSE; 152 videoScan=FALSE;
153 audioScan=FALSE; 153 audioScan=FALSE;
154 populateSkinsMenu(); 154 populateSkinsMenu();
155 initializeStates(); 155 initializeStates();
156 156
157 cfg.setGroup("PlayList");
157 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); 158 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
158 loadList(DocLnk( currentPlaylist ) ); 159 loadList(DocLnk( currentPlaylist ) );
159 setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); 160 setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
160} 161}
161 162
162 163
163PlayListWidget::~PlayListWidget() { 164PlayListWidget::~PlayListWidget() {
164 if ( d->current ) { 165 if ( d->current ) {
165 delete d->current; 166 delete d->current;
166 } 167 }
167 delete d; 168 delete d;
168} 169}
169 170
170 171
171void PlayListWidget::initializeStates() { 172void PlayListWidget::initializeStates() {
172 d->tbPlay->setOn( mediaPlayerState->playing() ); 173 d->tbPlay->setOn( mediaPlayerState->playing() );
173 d->tbLoop->setOn( mediaPlayerState->looping() ); 174 d->tbLoop->setOn( mediaPlayerState->looping() );
174 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 175 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
175 setPlaylist( true ); 176 setPlaylist( true );
176} 177}
177 178
178 179
179void PlayListWidget::readConfig( Config& cfg ) { 180void PlayListWidget::readConfig( Config& cfg ) {
180 181
181 cfg.setGroup( "PlayList" ); 182 cfg.setGroup( "PlayList" );
182 QString currentString = cfg.readEntry( "current", "" ); 183 QString currentString = cfg.readEntry( "current", "" );
183 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 ); 184 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 );
184 185
185 for ( int i = 0; i < noOfFiles; i++ ) { 186 for ( int i = 0; i < noOfFiles; i++ ) {
186 QString entryName; 187 QString entryName;
187 entryName.sprintf( "File%i", i + 1 ); 188 entryName.sprintf( "File%i", i + 1 );
188 189
189 QString linkFile = cfg.readEntry( entryName ); 190 QString linkFile = cfg.readEntry( entryName );
190 191
191 qDebug("reading "+linkFile); 192 qDebug("reading "+linkFile);
192 193
193 if( QFileInfo( linkFile ).exists() ) { 194 if( QFileInfo( linkFile ).exists() ) {
194 195
195 DocLnk lnk( linkFile ); 196 DocLnk lnk( linkFile );
196 197
197 if ( QFileInfo( lnk.file() ).exists() || 198 if ( QFileInfo( lnk.file() ).exists() ||
198 199
199 linkFile.find( "http" , 0, TRUE) != -1) { 200 linkFile.find( "http" , 0, TRUE) != -1) {
200 201
201 d->selectedFiles->addToSelection( lnk ); 202 d->selectedFiles->addToSelection( lnk );
202 } 203 }
203 } 204 }
204 } 205 }
205 d->selectedFiles->setSelectedItem( currentString ); 206 d->selectedFiles->setSelectedItem( currentString );
206} 207}
207 208
208 209
209void PlayListWidget::writeConfig( Config& cfg ) const { 210void PlayListWidget::writeConfig( Config& cfg ) const {
210 211
211 Config config( "OpiePlayer" ); 212 Config config( "OpiePlayer" );
212 config.setGroup( "PlayList" ); 213 config.setGroup( "PlayList" );
213 214
214// if(config.readBoolEntry("newPlaylist")) { 215// if(config.readBoolEntry("newPlaylist")) {
215// new for testing 216// new for testing
216 QString name, filename, list; 217 QString name, filename, list;
217 Om3u *m3uList; 218 Om3u *m3uList;
218 name = "default"; 219 name = "default";
219 220
220 filename=QPEApplication::documentDir() + "/" + name+".m3u"; 221 filename=QPEApplication::documentDir() + "/" + name+".m3u";
221 m3uList = new Om3u(filename, IO_ReadWrite); 222 m3uList = new Om3u(filename, IO_ReadWrite);
222 d->selectedFiles->first(); 223 d->selectedFiles->first();
223 do { 224 do {
224 qDebug(d->selectedFiles->current()->file()); 225 qDebug(d->selectedFiles->current()->file());
225 m3uList->add( d->selectedFiles->current()->file() ); 226 m3uList->add( d->selectedFiles->current()->file() );
226 } 227 }
227 while ( d->selectedFiles->next() ); 228 while ( d->selectedFiles->next() );
228 // qDebug( list ); 229 // qDebug( list );
229 230
230 // m3uList->write(); 231 // m3uList->write();
231 m3uList->close(); 232 m3uList->close();
232 if(m3uList) delete m3uList; 233 if(m3uList) delete m3uList;
233 234
234 DocLnk lnk; 235 DocLnk lnk;
235 lnk.setFile( filename); 236 lnk.setFile( filename);
236 lnk.setIcon("opieplayer2/playlist2"); 237 lnk.setIcon("opieplayer2/playlist2");
237 lnk.setName( name); //sets file name 238 lnk.setName( name); //sets file name
238 239
239 qDebug("writing default playlist "+filename); 240 qDebug("writing default playlist "+filename);
240 241
241 config.writeEntry("CurrentPlaylist", filename); 242 config.writeEntry("CurrentPlaylist", filename);
242// currentPlayList=filename; 243// currentPlayList=filename;
243 if(!lnk.writeLink()) { 244 if(!lnk.writeLink()) {
244 qDebug("Writing doclink did not work"); 245 qDebug("Writing doclink did not work");
245 } 246 }
246// } else { 247// } else {
247 248
248// d->selectedFiles->writeCurrent( cfg ); 249// d->selectedFiles->writeCurrent( cfg );
249// int noOfFiles = 0; 250// int noOfFiles = 0;
250// d->selectedFiles->first(); 251// d->selectedFiles->first();
251 252
252// do { 253// do {
253// const DocLnk *lnk = d->selectedFiles->current(); 254// const DocLnk *lnk = d->selectedFiles->current();
254 255
255// if ( lnk ) { 256// if ( lnk ) {
256 257
257// QString entryName; 258// QString entryName;
258// entryName.sprintf( "File%i", noOfFiles + 1 ); 259// entryName.sprintf( "File%i", noOfFiles + 1 );
259 260
260// cfg.writeEntry( entryName, lnk->linkFile() ); 261// cfg.writeEntry( entryName, lnk->linkFile() );
261// // if this link does exist, add it so we have the file 262// // if this link does exist, add it so we have the file
262// // next time... 263// // next time...
263 264
264// if ( !QFile::exists( lnk->linkFile() ) ) { 265// if ( !QFile::exists( lnk->linkFile() ) ) {
265// lnk->writeLink(); 266// lnk->writeLink();
266// } 267// }
267// } 268// }
268// noOfFiles++; 269// noOfFiles++;
269// } 270// }
270// while ( d->selectedFiles->next() ); 271// while ( d->selectedFiles->next() );
271// cfg.writeEntry("NumberOfFiles", noOfFiles ); 272// cfg.writeEntry("NumberOfFiles", noOfFiles );
272// } 273// }
273} 274}
274 275
275void PlayListWidget::addToSelection( const DocLnk& lnk ) { 276void PlayListWidget::addToSelection( const DocLnk& lnk ) {
276 d->setDocumentUsed = FALSE; 277 d->setDocumentUsed = FALSE;
277 if ( mediaPlayerState->playlist() ) { 278 if ( mediaPlayerState->playlist() ) {
278 if( QFileInfo( lnk.file() ).exists() || 279 if( QFileInfo( lnk.file() ).exists() ||
279 lnk.file().left(4) == "http" ) 280 lnk.file().left(4) == "http" )
280 d->selectedFiles->addToSelection( lnk ); 281 d->selectedFiles->addToSelection( lnk );
281 writeCurrentM3u(); 282 writeCurrentM3u();
282 } 283 }
283 else 284 else
284 mediaPlayerState->setPlaying( TRUE ); 285 mediaPlayerState->setPlaying( TRUE );
285} 286}
286 287
287 288
288void PlayListWidget::clearList() { 289void PlayListWidget::clearList() {
289 while ( first() ) { 290 while ( first() ) {
290 d->selectedFiles->removeSelected(); 291 d->selectedFiles->removeSelected();
291 } 292 }
292} 293}
293 294
294void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 295void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
295 switch (mouse) { 296 switch (mouse) {
296 case 1: 297 case 1:
297 break; 298 break;
298 case 2: 299 case 2:
299 { 300 {
300 QPopupMenu m; 301 QPopupMenu m;
301 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 302 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
302 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 303 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
303 m.exec( QCursor::pos() ); 304 m.exec( QCursor::pos() );
304 } 305 }
305 break; 306 break;
306 } 307 }
307} 308}
308 309
309 310
310void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 311void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
311 switch (mouse) { 312 switch (mouse) {
312 case 1: 313 case 1:
313 break; 314 break;
314 case 2: 315 case 2:
315 { 316 {
316 QPopupMenu m; 317 QPopupMenu m;
317 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 318 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
318 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 319 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
319 m.exec( QCursor::pos() ); 320 m.exec( QCursor::pos() );
320 } 321 }
321 break; 322 break;
322 } 323 }
323} 324}
324 325
325 326
326void PlayListWidget::addAllToList() { 327void PlayListWidget::addAllToList() {
327 DocLnkSet filesAll; 328 DocLnkSet filesAll;
328 Global::findDocuments(&filesAll, "video/*;audio/*"); 329 Global::findDocuments(&filesAll, "video/*;audio/*");
329 QListIterator<DocLnk> Adit( filesAll.children() ); 330 QListIterator<DocLnk> Adit( filesAll.children() );
330 for ( ; Adit.current(); ++Adit ) { 331 for ( ; Adit.current(); ++Adit ) {
331 if( QFileInfo( Adit.current()->file() ).exists() ) { 332 if( QFileInfo( Adit.current()->file() ).exists() ) {
332 d->selectedFiles->addToSelection( **Adit ); 333 d->selectedFiles->addToSelection( **Adit );
333 } 334 }
334 } 335 }
335 writeCurrentM3u(); 336 writeCurrentM3u();
336} 337}
337 338
338 339
339void PlayListWidget::addAllMusicToList() { 340void PlayListWidget::addAllMusicToList() {
340 QListIterator<DocLnk> dit( files.children() ); 341 QListIterator<DocLnk> dit( files.children() );
341 for ( ; dit.current(); ++dit ) { 342 for ( ; dit.current(); ++dit ) {
342 if( QFileInfo(dit.current()->file() ).exists() ) { 343 if( QFileInfo(dit.current()->file() ).exists() ) {
343 d->selectedFiles->addToSelection( **dit ); 344 d->selectedFiles->addToSelection( **dit );
344 } 345 }
345 } 346 }
346 writeCurrentM3u(); 347 writeCurrentM3u();
347} 348}
348 349
349 350
350void PlayListWidget::addAllVideoToList() { 351void PlayListWidget::addAllVideoToList() {
351 QListIterator<DocLnk> dit( vFiles.children() ); 352 QListIterator<DocLnk> dit( vFiles.children() );
352 for ( ; dit.current(); ++dit ) { 353 for ( ; dit.current(); ++dit ) {
353 if( QFileInfo( dit.current()->file() ).exists() ) { 354 if( QFileInfo( dit.current()->file() ).exists() ) {
354 d->selectedFiles->addToSelection( **dit ); 355 d->selectedFiles->addToSelection( **dit );
355 } 356 }
356 } 357 }
357 writeCurrentM3u(); 358 writeCurrentM3u();
358} 359}
359 360
360 361
361void PlayListWidget::setDocument( const QString& fileref ) { 362void PlayListWidget::setDocument( const QString& fileref ) {
362 //qDebug( fileref ); 363 //qDebug( fileref );
363 fromSetDocument = TRUE; 364 fromSetDocument = TRUE;
364 if ( fileref.isNull() ) { 365 if ( fileref.isNull() ) {
365 QMessageBox::critical( 0, tr( "Invalid File" ), 366 QMessageBox::critical( 0, tr( "Invalid File" ),
366 tr( "There was a problem in getting the file." ) ); 367 tr( "There was a problem in getting the file." ) );
367 return; 368 return;
368 } 369 }
369 370
370 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u 371 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u
371 readm3u( fileref ); 372 readm3u( fileref );
372 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls 373 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls
373 readPls( fileref ); 374 readPls( fileref );
374 }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist 375 }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist
375// clearList(); 376// clearList();
376// loadList( DocLnk( fileref ) ); 377// loadList( DocLnk( fileref ) );
377// d->selectedFiles->first(); 378// d->selectedFiles->first();
378// } 379// }
379 else { 380 else {
380 clearList(); 381 clearList();
381 addToSelection( DocLnk( fileref ) ); 382 addToSelection( DocLnk( fileref ) );
382 d->setDocumentUsed = TRUE; 383 d->setDocumentUsed = TRUE;
383 mediaPlayerState->setPlaying( FALSE ); 384 mediaPlayerState->setPlaying( FALSE );
384 mediaPlayerState->setPlaying( TRUE ); 385 mediaPlayerState->setPlaying( TRUE );
385 } 386 }
386} 387}
387 388
388 389
389void PlayListWidget::useSelectedDocument() { 390void PlayListWidget::useSelectedDocument() {
390 d->setDocumentUsed = FALSE; 391 d->setDocumentUsed = FALSE;
391} 392}
392 393
393 394
394const DocLnk *PlayListWidget::current() { // this is fugly 395const DocLnk *PlayListWidget::current() { // this is fugly
395 switch ( whichList() ) { 396 switch ( whichList() ) {
396 case 0: //playlist 397 case 0: //playlist
397 { 398 {
398// qDebug("playlist"); 399// qDebug("playlist");
399 if ( mediaPlayerState->playlist() ) { 400 if ( mediaPlayerState->playlist() ) {
400 return d->selectedFiles->current(); 401 return d->selectedFiles->current();
401 } else if ( d->setDocumentUsed && d->current ) { 402 } else if ( d->setDocumentUsed && d->current ) {
402 return d->current; 403 return d->current;
403 } else { 404 } else {
404 return &(d->files->selectedDocument()); 405 return &(d->files->selectedDocument());
405 } 406 }
406 } 407 }
407 break; 408 break;
408 }; 409 };
409 return 0; 410 return 0;
410} 411}
411 412
412 413
413bool PlayListWidget::prev() { 414bool PlayListWidget::prev() {
414 if ( mediaPlayerState->playlist() ) { 415 if ( mediaPlayerState->playlist() ) {
415 if ( mediaPlayerState->shuffled() ) { 416 if ( mediaPlayerState->shuffled() ) {
416 const DocLnk *cur = current(); 417 const DocLnk *cur = current();
417 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 418 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
418 for ( int i = 0; i < j; i++ ) { 419 for ( int i = 0; i < j; i++ ) {
419 if ( !d->selectedFiles->next() ) 420 if ( !d->selectedFiles->next() )
420 d->selectedFiles->first(); 421 d->selectedFiles->first();
421 } 422 }
422 if ( cur == current() ) 423 if ( cur == current() )
423 if ( !d->selectedFiles->next() ) { 424 if ( !d->selectedFiles->next() ) {
424 d->selectedFiles->first(); 425 d->selectedFiles->first();
425 } 426 }
426 return TRUE; 427 return TRUE;
427 } else { 428 } else {
428 if ( !d->selectedFiles->prev() ) { 429 if ( !d->selectedFiles->prev() ) {
429 if ( mediaPlayerState->looping() ) { 430 if ( mediaPlayerState->looping() ) {
430 return d->selectedFiles->last(); 431 return d->selectedFiles->last();
431 } else { 432 } else {
432 return FALSE; 433 return FALSE;
433 } 434 }
434 } 435 }
435 return TRUE; 436 return TRUE;
436 } 437 }
437 } else { 438 } else {
438 return mediaPlayerState->looping(); 439 return mediaPlayerState->looping();
439 } 440 }
440} 441}
441 442
442 443
443bool PlayListWidget::next() { 444bool PlayListWidget::next() {
444//qDebug("<<<<<<<<<<<<next()"); 445//qDebug("<<<<<<<<<<<<next()");
445 if ( mediaPlayerState->playlist() ) { 446 if ( mediaPlayerState->playlist() ) {
446 if ( mediaPlayerState->shuffled() ) { 447 if ( mediaPlayerState->shuffled() ) {
447 return prev(); 448 return prev();
448 } else { 449 } else {
449 if ( !d->selectedFiles->next() ) { 450 if ( !d->selectedFiles->next() ) {
450 if ( mediaPlayerState->looping() ) { 451 if ( mediaPlayerState->looping() ) {
451 return d->selectedFiles->first(); 452 return d->selectedFiles->first();
452 } else { 453 } else {
453 return FALSE; 454 return FALSE;
454 } 455 }
455 } 456 }
456 return TRUE; 457 return TRUE;
457 } 458 }
458 } else { 459 } else {
459 return mediaPlayerState->looping(); 460 return mediaPlayerState->looping();
460 } 461 }
461} 462}
462 463
463 464
464bool PlayListWidget::first() { 465bool PlayListWidget::first() {
465 if ( mediaPlayerState->playlist() ) 466 if ( mediaPlayerState->playlist() )
466 return d->selectedFiles->first(); 467 return d->selectedFiles->first();
467 else 468 else
468 return mediaPlayerState->looping(); 469 return mediaPlayerState->looping();
469} 470}
470 471
471 472
472bool PlayListWidget::last() { 473bool PlayListWidget::last() {
473 if ( mediaPlayerState->playlist() ) 474 if ( mediaPlayerState->playlist() )
474 return d->selectedFiles->last(); 475 return d->selectedFiles->last();
475 else 476 else
476 return mediaPlayerState->looping(); 477 return mediaPlayerState->looping();
477} 478}
478 479
479 480
480 void PlayListWidget::saveList() { 481 void PlayListWidget::saveList() {
481 writem3u(); 482 writem3u();
482 } 483 }
483 484
484 485
485void PlayListWidget::loadList( const DocLnk & lnk) { 486void PlayListWidget::loadList( const DocLnk & lnk) {
486 QString name = lnk.name(); 487 QString name = lnk.name();
487 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); 488 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
488 489
489 if( name.length()>0) { 490 if( name.length()>0) {
490 setCaption("OpiePlayer: "+name); 491 setCaption("OpiePlayer: "+name);
491 qDebug("<<<<<<<<<<<<load list "+ lnk.file()); 492 qDebug("<<<<<<<<<<<<load list "+ lnk.file());
492 clearList(); 493 clearList();
493 readm3u(lnk.file()); 494 readm3u(lnk.file());
494 tabWidget->setCurrentPage(0); 495 tabWidget->setCurrentPage(0);
495 } 496 }
496} 497}
497 498
498 499
499void PlayListWidget::setPlaylist( bool shown ) { 500void PlayListWidget::setPlaylist( bool shown ) {
500 if ( shown ) { 501 if ( shown ) {
501 d->playListFrame->show(); 502 d->playListFrame->show();
502 } else { 503 } else {
503 d->playListFrame->hide(); 504 d->playListFrame->hide();
504 } 505 }
505} 506}
506 507
507 508
508void PlayListWidget::addSelected() { 509void PlayListWidget::addSelected() {
509 510
510 switch (whichList()) { 511 switch (whichList()) {
511 case 0: //playlist 512 case 0: //playlist
512 break; 513 break;
513 case 1: { //audio 514 case 1: { //audio
514 QListViewItemIterator it( audioView ); 515 QListViewItemIterator it( audioView );
515 // iterate through all items of the listview 516 // iterate through all items of the listview
516 for ( ; it.current(); ++it ) { 517 for ( ; it.current(); ++it ) {
517 if ( it.current()->isSelected() ) { 518 if ( it.current()->isSelected() ) {
518 QListIterator<DocLnk> dit( files.children() ); 519 QListIterator<DocLnk> dit( files.children() );
519 for ( ; dit.current(); ++dit ) { 520 for ( ; dit.current(); ++dit ) {
520 if( dit.current()->name() == it.current()->text(0) ) { 521 if( dit.current()->name() == it.current()->text(0) ) {
521 if( QFileInfo( dit.current()->file()).exists()) { 522 if( QFileInfo( dit.current()->file()).exists()) {
522 d->selectedFiles->addToSelection( **dit ); 523 d->selectedFiles->addToSelection( **dit );
523 audioView->setSelected( it.current(),FALSE); 524 audioView->setSelected( it.current(),FALSE);
524 } 525 }
525 } 526 }
526 } 527 }
527 } 528 }
528 } 529 }
529 tabWidget->setCurrentPage(0); 530 tabWidget->setCurrentPage(0);
530 writeCurrentM3u(); 531 writeCurrentM3u();
531 } 532 }
532 break; 533 break;
533 case 2: { // video 534 case 2: { // video
534 QListViewItemIterator it( videoView ); 535 QListViewItemIterator it( videoView );
535 // iterate through all items of the listview 536 // iterate through all items of the listview
536 for ( ; it.current(); ++it ) { 537 for ( ; it.current(); ++it ) {
537 if ( it.current()->isSelected() ) { 538 if ( it.current()->isSelected() ) {
538 QListIterator<DocLnk> dit( vFiles.children() ); 539 QListIterator<DocLnk> dit( vFiles.children() );
539 for ( ; dit.current(); ++dit ) { 540 for ( ; dit.current(); ++dit ) {
540 if( dit.current()->name() == it.current()->text(0) ) { 541 if( dit.current()->name() == it.current()->text(0) ) {
541 if(QFileInfo( dit.current()->file()).exists()) { 542 if(QFileInfo( dit.current()->file()).exists()) {
542 d->selectedFiles->addToSelection( **dit ); 543 d->selectedFiles->addToSelection( **dit );
543 videoView->setSelected( it.current(),FALSE); 544 videoView->setSelected( it.current(),FALSE);
544 } 545 }
545 } 546 }
546 } 547 }
547 } 548 }
548 } 549 }
549 tabWidget->setCurrentPage(0); 550 tabWidget->setCurrentPage(0);
550 writeCurrentM3u(); 551 writeCurrentM3u();
551 } 552 }
552 break; 553 break;
553 }; 554 };
554} 555}
555 556
556 557
557void PlayListWidget::removeSelected() { 558void PlayListWidget::removeSelected() {
558 d->selectedFiles->removeSelected( ); 559 d->selectedFiles->removeSelected( );
559} 560}
560 561
561 562
562void PlayListWidget::playIt( QListViewItem *it) { 563void PlayListWidget::playIt( QListViewItem *it) {
563 if(!it) return; 564 if(!it) return;
564 mediaPlayerState->setPlaying(FALSE); 565 mediaPlayerState->setPlaying(FALSE);
565 mediaPlayerState->setPlaying(TRUE); 566 mediaPlayerState->setPlaying(TRUE);
566 d->selectedFiles->unSelect(); 567 d->selectedFiles->unSelect();
567} 568}
568 569
569 570
570void PlayListWidget::addToSelection( QListViewItem *it) { 571void PlayListWidget::addToSelection( QListViewItem *it) {
571 d->setDocumentUsed = FALSE; 572 d->setDocumentUsed = FALSE;
572 573
573 if(it) { 574 if(it) {
574 switch ( whichList()) { 575 switch ( whichList()) {
575 case 1: { 576 case 1: {
576 QListIterator<DocLnk> dit( files.children() ); 577 QListIterator<DocLnk> dit( files.children() );
577 for ( ; dit.current(); ++dit ) { 578 for ( ; dit.current(); ++dit ) {
578 if( dit.current()->name() == it->text(0)) { 579 if( dit.current()->name() == it->text(0)) {
579 if(QFileInfo( dit.current()->file()).exists()) 580 if(QFileInfo( dit.current()->file()).exists())
580 d->selectedFiles->addToSelection( **dit ); 581 d->selectedFiles->addToSelection( **dit );
581 } 582 }
582 } 583 }
583 writeCurrentM3u(); 584 writeCurrentM3u();
584 585
585 } 586 }
586 587
587 break; 588 break;
588 case 2: { 589 case 2: {
589 QListIterator<DocLnk> dit( vFiles.children() ); 590 QListIterator<DocLnk> dit( vFiles.children() );
590 for ( ; dit.current(); ++dit ) { 591 for ( ; dit.current(); ++dit ) {
591 if( dit.current()->name() == it->text(0)) { 592 if( dit.current()->name() == it->text(0)) {
592 if( QFileInfo( dit.current()->file()).exists() ) 593 if( QFileInfo( dit.current()->file()).exists() )
593 d->selectedFiles->addToSelection( **dit ); 594 d->selectedFiles->addToSelection( **dit );
594 } 595 }
595 } 596 }
596 writeCurrentM3u(); 597 writeCurrentM3u();
597 598
598 } 599 }
599 break; 600 break;
600 case 0: 601 case 0:
601 break; 602 break;
602 }; 603 };
603 tabWidget->setCurrentPage(0); 604 tabWidget->setCurrentPage(0);
604 } 605 }
605} 606}
606 607
607 608
608void PlayListWidget::tabChanged(QWidget *) { 609void PlayListWidget::tabChanged(QWidget *) {
609 610
610 switch ( whichList()) { 611 switch ( whichList()) {
611 case 0: 612 case 0:
612 { 613 {
613 if( !tbDeletePlaylist->isHidden() ) { 614 if( !tbDeletePlaylist->isHidden() ) {
614 tbDeletePlaylist->hide(); 615 tbDeletePlaylist->hide();
615 } 616 }
616 d->tbRemoveFromList->setEnabled(TRUE); 617 d->tbRemoveFromList->setEnabled(TRUE);
617 d->tbAddToList->setEnabled(FALSE); 618 d->tbAddToList->setEnabled(FALSE);
618 } 619 }
619 break; 620 break;
620 case 1: 621 case 1:
621 { 622 {
622 audioView->clear(); 623 audioView->clear();
623 populateAudioView(); 624 populateAudioView();
624 625
625 if( !tbDeletePlaylist->isHidden() ) { 626 if( !tbDeletePlaylist->isHidden() ) {
626 tbDeletePlaylist->hide(); 627 tbDeletePlaylist->hide();
627 } 628 }
628 d->tbRemoveFromList->setEnabled(FALSE); 629 d->tbRemoveFromList->setEnabled(FALSE);
629 d->tbAddToList->setEnabled(TRUE); 630 d->tbAddToList->setEnabled(TRUE);
630 } 631 }
631 break; 632 break;
632 case 2: 633 case 2:
633 { 634 {
634 videoView->clear(); 635 videoView->clear();
635 populateVideoView(); 636 populateVideoView();
636 if( !tbDeletePlaylist->isHidden() ) { 637 if( !tbDeletePlaylist->isHidden() ) {
637 tbDeletePlaylist->hide(); 638 tbDeletePlaylist->hide();
638 } 639 }
639 d->tbRemoveFromList->setEnabled(FALSE); 640 d->tbRemoveFromList->setEnabled(FALSE);
640 d->tbAddToList->setEnabled(TRUE); 641 d->tbAddToList->setEnabled(TRUE);
641 } 642 }
642 break; 643 break;
643 case 3: 644 case 3:
644 { 645 {
645 if( tbDeletePlaylist->isHidden() ) { 646 if( tbDeletePlaylist->isHidden() ) {
646 tbDeletePlaylist->show(); 647 tbDeletePlaylist->show();
647 } 648 }
648 playLists->reread(); 649 playLists->reread();
649 } 650 }
650 break; 651 break;
651 }; 652 };
652} 653}
653 654
654 655
655void PlayListWidget::btnPlay(bool b) { 656void PlayListWidget::btnPlay(bool b) {
656// mediaPlayerState->setPlaying(false); 657// mediaPlayerState->setPlaying(false);
657 mediaPlayerState->setPlaying(b); 658 mediaPlayerState->setPlaying(b);
658 insanityBool=FALSE; 659 insanityBool=FALSE;
659} 660}
660 661
661void PlayListWidget::deletePlaylist() { 662void PlayListWidget::deletePlaylist() {
662 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 663 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
663 (tr("You really want to delete\nthis playlist?")), 664 (tr("You really want to delete\nthis playlist?")),
664 (tr("Yes")), (tr("No")), 0 )){ 665 (tr("Yes")), (tr("No")), 0 )){
665 case 0: // Yes clicked, 666 case 0: // Yes clicked,
666 QFile().remove(playLists->selectedDocument().file()); 667 QFile().remove(playLists->selectedDocument().file());
667 QFile().remove(playLists->selectedDocument().linkFile()); 668 QFile().remove(playLists->selectedDocument().linkFile());
668 playLists->reread(); 669 playLists->reread();
669 break; 670 break;
670 case 1: // Cancel 671 case 1: // Cancel
671 break; 672 break;
672 }; 673 };
673} 674}
674 675
675 676
676void PlayListWidget::playSelected() { 677void PlayListWidget::playSelected() {
677 btnPlay( TRUE); 678 btnPlay( TRUE);
678} 679}
679 680