summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-14 02:21:41 (UTC)
committer llornkcor <llornkcor>2002-11-14 02:21:41 (UTC)
commit8cdfc8e0209bbd9190176fdfcbeea2684cb5e8b8 (patch) (unidiff)
tree89d993febecd3a4396e3c22fe5defaa3431e9375
parent9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9 (diff)
downloadopie-8cdfc8e0209bbd9190176fdfcbeea2684cb5e8b8.zip
opie-8cdfc8e0209bbd9190176fdfcbeea2684cb5e8b8.tar.gz
opie-8cdfc8e0209bbd9190176fdfcbeea2684cb5e8b8.tar.bz2
much faster way of adding files to playlist, when tabs have already been initialized with files
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp109
1 files changed, 96 insertions, 13 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index a6a9eca..c2b5c77 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -9,64 +9,65 @@
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 <qdatetime.h>
41#include <qdir.h> 42#include <qdir.h>
42#include <qmessagebox.h> 43#include <qmessagebox.h>
43#include <qregexp.h> 44#include <qregexp.h>
44#include <qtextstream.h> 45#include <qtextstream.h>
45 46
46#include "playlistselection.h" 47#include "playlistselection.h"
47#include "playlistwidget.h" 48#include "playlistwidget.h"
48#include "mediaplayerstate.h" 49#include "mediaplayerstate.h"
49#include "inputDialog.h" 50#include "inputDialog.h"
50#include "om3u.h" 51#include "om3u.h"
51 52
52//only needed for the random play 53//only needed for the random play
53#include <stdlib.h> 54#include <stdlib.h>
54 55
55#include "audiowidget.h" 56#include "audiowidget.h"
56#include "videowidget.h" 57#include "videowidget.h"
57 58
58extern MediaPlayerState *mediaPlayerState; 59extern MediaPlayerState *mediaPlayerState;
59// extern AudioWidget *audioUI; 60// extern AudioWidget *audioUI;
60// extern VideoWidget *videoUI; 61// extern VideoWidget *videoUI;
61 62
62QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg"; 63QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg";
63// no m3u's here please 64// no m3u's here please
64 65
65PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 66PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
66 : PlayListWidgetGui( parent, name, fl ) { 67 : PlayListWidgetGui( parent, name, fl ) {
67 68
68 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 69 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
69 "opieplayer2/add_to_playlist", 70 "opieplayer2/add_to_playlist",
70 this , SLOT(addSelected() ) ); 71 this , SLOT(addSelected() ) );
71 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 72 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
72 "opieplayer2/remove_from_playlist", 73 "opieplayer2/remove_from_playlist",
@@ -124,73 +125,72 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
124 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 125 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
125 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 126 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
126 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 127 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
127 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 128 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
128 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 129 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
129 this,SLOT( playIt( QListViewItem *) ) ); 130 this,SLOT( playIt( QListViewItem *) ) );
130 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 131 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
131 this, SLOT( addToSelection( QListViewItem *) ) ); 132 this, SLOT( addToSelection( QListViewItem *) ) );
132 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 133 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
133 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 134 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
134 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 135 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
135 this,SLOT( playIt( QListViewItem *) ) ); 136 this,SLOT( playIt( QListViewItem *) ) );
136 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 137 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
137 this, SLOT( addToSelection( QListViewItem *) ) ); 138 this, SLOT( addToSelection( QListViewItem *) ) );
138 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 139 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
139 this, SLOT( loadList( const DocLnk & ) ) ); 140 this, SLOT( loadList( const DocLnk & ) ) );
140 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 141 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
141 this, SLOT( tabChanged( QWidget* ) ) ); 142 this, SLOT( tabChanged( QWidget* ) ) );
142 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), 143 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ),
143 d->tbPlay, SLOT( setOn( bool ) ) ); 144 d->tbPlay, SLOT( setOn( bool ) ) );
144 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 145 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
145 d->tbLoop, SLOT( setOn( bool ) ) ); 146 d->tbLoop, SLOT( setOn( bool ) ) );
146 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 147 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
147 d->tbShuffle, SLOT( setOn( bool ) ) ); 148 d->tbShuffle, SLOT( setOn( bool ) ) );
148 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), 149 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ),
149 this, SLOT( setPlaylist( bool ) ) ); 150 this, SLOT( setPlaylist( bool ) ) );
150 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 151 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
151 this, SLOT( playIt( QListViewItem *) ) ); 152 this, SLOT( playIt( QListViewItem *) ) );
152 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 153 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
153 mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 154 mediaPlayerState, SLOT( setVideoGamma( int ) ) );
154 155
155 // see which skins are installed 156 // see which skins are installed
156 videoScan=FALSE; 157 videoScan=false;
157 audioScan=FALSE; 158 audioScan=false;
158 populateSkinsMenu(); 159 populateSkinsMenu();
159 initializeStates(); 160 initializeStates();
160 161
161 cfg.setGroup("PlayList"); 162 cfg.setGroup("PlayList");
162 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 163 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
163 loadList(DocLnk( currentPlaylist ) ); 164 loadList(DocLnk( currentPlaylist ) );
164
165} 165}
166 166
167 167
168PlayListWidget::~PlayListWidget() { 168PlayListWidget::~PlayListWidget() {
169 if ( d->current ) { 169 if ( d->current ) {
170 delete d->current; 170 delete d->current;
171 } 171 }
172 delete d; 172 delete d;
173} 173}
174 174
175 175
176void PlayListWidget::initializeStates() { 176void PlayListWidget::initializeStates() {
177 d->tbPlay->setOn( mediaPlayerState->playing() ); 177 d->tbPlay->setOn( mediaPlayerState->playing() );
178 d->tbLoop->setOn( mediaPlayerState->looping() ); 178 d->tbLoop->setOn( mediaPlayerState->looping() );
179 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 179 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
180 setPlaylist( true ); 180 setPlaylist( true );
181} 181}
182 182
183void PlayListWidget::writeDefaultPlaylist() { 183void PlayListWidget::writeDefaultPlaylist() {
184 184
185 Config config( "OpiePlayer" ); 185 Config config( "OpiePlayer" );
186 config.setGroup( "PlayList" ); 186 config.setGroup( "PlayList" );
187 QString filename=QPEApplication::documentDir() + "/default.m3u"; 187 QString filename=QPEApplication::documentDir() + "/default.m3u";
188 QString currentString = config.readEntry( "CurrentPlaylist", filename); 188 QString currentString = config.readEntry( "CurrentPlaylist", filename);
189 if( currentString == filename) { 189 if( currentString == filename) {
190 Om3u *m3uList; 190 Om3u *m3uList;
191 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); 191 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
192 if( d->selectedFiles->first() ) { 192 if( d->selectedFiles->first() ) {
193 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 193 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
194 do { 194 do {
195 // qDebug(d->selectedFiles->current()->file()); 195 // qDebug(d->selectedFiles->current()->file());
196 m3uList->add( d->selectedFiles->current()->file() ); 196 m3uList->add( d->selectedFiles->current()->file() );
@@ -229,103 +229,186 @@ void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , in
229 switch (mouse) { 229 switch (mouse) {
230 case 1: 230 case 1:
231 break; 231 break;
232 case 2: 232 case 2:
233 { 233 {
234 QPopupMenu m; 234 QPopupMenu m;
235 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 235 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
236 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 236 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
237 m.exec( QCursor::pos() ); 237 m.exec( QCursor::pos() );
238 } 238 }
239 break; 239 break;
240 } 240 }
241} 241}
242 242
243 243
244void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 244void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
245 switch (mouse) { 245 switch (mouse) {
246 case 1: 246 case 1:
247 break; 247 break;
248 case 2: 248 case 2:
249 { 249 {
250 QPopupMenu m; 250 QPopupMenu m;
251 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 251 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
252 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 252 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
253 m.exec( QCursor::pos() ); 253 m.exec( QCursor::pos() );
254 } 254 }
255 break; 255 break;
256 } 256 }
257} 257}
258 258
259 259
260void PlayListWidget::addAllToList() { 260void PlayListWidget::addAllToList() {
261 DocLnkSet filesAll; 261
262 Global::findDocuments(&filesAll, "video/*;"+audioMimes); 262// QTime t;
263 QListIterator<DocLnk> Adit( filesAll.children() ); 263// t.start();
264 for ( ; Adit.current(); ++Adit ) { 264
265 if( QFileInfo( Adit.current()->file() ).exists() ) { 265 if(!audioScan) {
266 d->selectedFiles->addToSelection( **Adit ); 266 if(audioView->childCount() < 1)
267 } 267 populateAudioView();
268 } 268 }
269
270 QListViewItemIterator audioIt( audioView );
271 DocLnk lnk;
272 QString filename;
273 // iterate through all items of the listview
274 for ( ; audioIt.current(); ++audioIt ) {
275 filename = audioIt.current()->text(3);
276 lnk.setName( QFileInfo(filename).baseName() ); //sets name
277 lnk.setFile( filename ); //sets file name
278 d->selectedFiles->addToSelection( lnk);
279 }
280
281 if(!videoScan) {
282 if(videoView->childCount() < 1)
283 populateVideoView();
284 }
285
286 QListViewItemIterator videoIt( videoView );
287 for ( ; videoIt.current(); ++videoIt ) {
288 filename = videoIt.current()->text(3);
289 lnk.setName( QFileInfo(filename).baseName() ); //sets name
290 lnk.setFile( filename ); //sets file name
291 d->selectedFiles->addToSelection( lnk);
292 }
293
294 // d->selectedFiles->addToSelection( );
295 // if ( it.current()->isSelected() )
296 // lst->append( audioIt.current() );
297 // }
298
299 /*
300 if(!audioScan)
301 scanForAudio();
302 if(!videoScan)
303 scanForVideo();
304
305 DocLnkSet filesAll;
306 Global::findDocuments(&filesAll, "video/*;"+audioMimes);
307 QListIterator<DocLnk> Adit( filesAll.children() );
308 for ( ; Adit.current(); ++Adit ) {
309 if( QFileInfo( Adit.current()->file() ).exists() ) {
310 d->selectedFiles->addToSelection( **Adit );
311 }
312 }
313*/
314 // qDebug("elapsed time %d", t.elapsed() );
315
269 tabWidget->setCurrentPage(0); 316 tabWidget->setCurrentPage(0);
270 317
271 writeCurrentM3u(); 318 writeCurrentM3u();
272 d->selectedFiles->first(); 319 d->selectedFiles->first();
273} 320}
274 321
275 322
276void PlayListWidget::addAllMusicToList() { 323void PlayListWidget::addAllMusicToList() {
277 if(!audioScan) 324
325 if(!audioScan) {
326 if(audioView->childCount() < 1)
327 populateAudioView();
328 }
329
330 QListViewItemIterator audioIt( audioView );
331 DocLnk lnk;
332 QString filename;
333 // iterate through all items of the listview
334 for ( ; audioIt.current(); ++audioIt ) {
335 filename = audioIt.current()->text(3);
336 lnk.setName( QFileInfo(filename).baseName() ); //sets name
337 lnk.setFile( filename ); //sets file name
338 d->selectedFiles->addToSelection( lnk);
339 }
340
341 /* if(!audioScan)
278 scanForAudio(); 342 scanForAudio();
279 QListIterator<DocLnk> dit( files.children() ); 343 QListIterator<DocLnk> dit( files.children() );
280 for ( ; dit.current(); ++dit ) { 344 for ( ; dit.current(); ++dit ) {
281 if( QFileInfo(dit.current()->file() ).exists() ) { 345 if( QFileInfo(dit.current()->file() ).exists() ) {
282 d->selectedFiles->addToSelection( **dit ); 346 d->selectedFiles->addToSelection( **dit );
283 } 347 }
284 } 348 }
349 */
285 tabWidget->setCurrentPage(0); 350 tabWidget->setCurrentPage(0);
286 writeCurrentM3u(); 351 writeCurrentM3u();
287 d->selectedFiles->first(); 352 d->selectedFiles->first();
288} 353}
289 354
290 355
291void PlayListWidget::addAllVideoToList() { 356void PlayListWidget::addAllVideoToList() {
292 if(!videoScan) 357
358 if(!videoScan) {
359 if(videoView->childCount() < 1)
360 populateVideoView();
361 }
362
363 QListViewItemIterator videoIt( videoView );
364 DocLnk lnk;
365 QString filename;
366 for ( ; videoIt.current(); ++videoIt ) {
367 filename = videoIt.current()->text(3);
368 lnk.setName( QFileInfo(filename).baseName() ); //sets name
369 lnk.setFile( filename ); //sets file name
370 d->selectedFiles->addToSelection( lnk);
371 }
372
373
374 /* if(!videoScan)
293 scanForVideo(); 375 scanForVideo();
294 QListIterator<DocLnk> dit( vFiles.children() ); 376 QListIterator<DocLnk> dit( vFiles.children() );
295 for ( ; dit.current(); ++dit ) { 377 for ( ; dit.current(); ++dit ) {
296 if( QFileInfo( dit.current()->file() ).exists() ) { 378 if( QFileInfo( dit.current()->file() ).exists() ) {
297 d->selectedFiles->addToSelection( **dit ); 379 d->selectedFiles->addToSelection( **dit );
298 } 380 }
299 } 381 }
382*/
300 tabWidget->setCurrentPage(0); 383 tabWidget->setCurrentPage(0);
301 writeCurrentM3u(); 384 writeCurrentM3u();
302 d->selectedFiles->first(); 385 d->selectedFiles->first();
303} 386}
304 387
305 388
306void PlayListWidget::setDocument( const QString& fileref ) { 389void PlayListWidget::setDocument( const QString& fileref ) {
307 qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); 390 qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref );
308 fromSetDocument = TRUE; 391 fromSetDocument = TRUE;
309 if ( fileref.isNull() ) { 392 if ( fileref.isNull() ) {
310 QMessageBox::warning( this, tr( "Invalid File" ), 393 QMessageBox::warning( this, tr( "Invalid File" ),
311 tr( "There was a problem in getting the file." ) ); 394 tr( "There was a problem in getting the file." ) );
312 return; 395 return;
313 } 396 }
314 397
315 clearList(); 398 clearList();
316 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u 399 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u
317 readm3u( fileref ); 400 readm3u( fileref );
318 } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { 401 } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) {
319 readm3u( DocLnk( fileref).file() ); 402 readm3u( DocLnk( fileref).file() );
320 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls 403 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls
321 readPls( fileref ); 404 readPls( fileref );
322 } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { 405 } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) {
323 readPls( DocLnk( fileref).file() ); 406 readPls( DocLnk( fileref).file() );
324 } else { 407 } else {
325 clearList(); 408 clearList();
326 addToSelection( DocLnk( fileref ) ); 409 addToSelection( DocLnk( fileref ) );
327 writeCurrentM3u(); 410 writeCurrentM3u();
328 411
329 d->setDocumentUsed = TRUE; 412 d->setDocumentUsed = TRUE;
330 mediaPlayerState->setPlaying( FALSE ); 413 mediaPlayerState->setPlaying( FALSE );
331 mediaPlayerState->setPlaying( TRUE ); 414 mediaPlayerState->setPlaying( TRUE );