summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/playlistwidget.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp250
1 files changed, 138 insertions, 112 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 3b8f6d7..63df715 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -25,6 +25,7 @@
25#include <qpe/fileselector.h> 25#include <qpe/fileselector.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/lnkproperties.h> 27#include <qpe/lnkproperties.h>
28#include <qpe/storage.h>
28 29
29#include <qpe/applnk.h> 30#include <qpe/applnk.h>
30#include <qpe/config.h> 31#include <qpe/config.h>
@@ -216,6 +217,9 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
216 audioView->setColumnAlignment(1, Qt::AlignRight); 217 audioView->setColumnAlignment(1, Qt::AlignRight);
217 audioView->setColumnAlignment(2, Qt::AlignRight); 218 audioView->setColumnAlignment(2, Qt::AlignRight);
218 audioView->setAllColumnsShowFocus(TRUE); 219 audioView->setAllColumnsShowFocus(TRUE);
220// audioView->setMultiSelection( TRUE );
221// audioView->setSelectionMode( QListView::Extended);
222
219 tabWidget->insertTab(aTab,tr("Audio")); 223 tabWidget->insertTab(aTab,tr("Audio"));
220 224
221 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); 225 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
@@ -238,6 +242,9 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
238 videoView->setColumnAlignment(1, Qt::AlignRight); 242 videoView->setColumnAlignment(1, Qt::AlignRight);
239 videoView->setColumnAlignment(2, Qt::AlignRight); 243 videoView->setColumnAlignment(2, Qt::AlignRight);
240 videoView->setAllColumnsShowFocus(TRUE); 244 videoView->setAllColumnsShowFocus(TRUE);
245// videoView->setMultiSelection( TRUE );
246// videoView->setSelectionMode( QListView::Extended);
247
241 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); 248 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
242 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 249 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
243 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); 250 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
@@ -318,54 +325,54 @@ void PlayListWidget::initializeStates() {
318 325
319void PlayListWidget::readConfig( Config& cfg ) { 326void PlayListWidget::readConfig( Config& cfg ) {
320 cfg.setGroup("PlayList"); 327 cfg.setGroup("PlayList");
321 328 QString currentString = cfg.readEntry("current", "" );
322 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 329 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
323
324 for ( int i = 0; i < noOfFiles; i++ ) { 330 for ( int i = 0; i < noOfFiles; i++ ) {
325 QString entryName; 331 QString entryName;
326 entryName.sprintf( "File%i", i + 1 ); 332 entryName.sprintf( "File%i", i + 1 );
327 QString linkFile = cfg.readEntry( entryName ); 333 QString linkFile = cfg.readEntry( entryName );
328 DocLnk lnk( linkFile ); 334 DocLnk lnk( linkFile );
329 if ( lnk.isValid() ) 335 if ( lnk.isValid() ) {
330 d->selectedFiles->addToSelection( lnk ); 336 d->selectedFiles->addToSelection( lnk );
337 }
331 } 338 }
339// d->selectedFiles->setSelectedItem( (const QString &)currentString);
332} 340}
333 341
334 342
335void PlayListWidget::writeConfig( Config& cfg ) const { 343void PlayListWidget::writeConfig( Config& cfg ) const {
336 cfg.setGroup("PlayList");
337 344
345 d->selectedFiles->writeCurrent( cfg);
346 cfg.setGroup("PlayList");
338 int noOfFiles = 0; 347 int noOfFiles = 0;
339
340 d->selectedFiles->first(); 348 d->selectedFiles->first();
341 do { 349 do {
342 const DocLnk *lnk = d->selectedFiles->current(); 350 const DocLnk *lnk = d->selectedFiles->current();
343 if ( lnk ) { 351 if ( lnk ) {
344 QString entryName; 352 QString entryName;
345 entryName.sprintf( "File%i", noOfFiles + 1 ); 353 entryName.sprintf( "File%i", noOfFiles + 1 );
346 cfg.writeEntry( entryName, lnk->linkFile() ); 354 qDebug(entryName);
347 // if this link does exist, add it so we have the file 355 cfg.writeEntry( entryName, lnk->linkFile() );
348 // next time... 356 // if this link does exist, add it so we have the file
349 if ( !QFile::exists( lnk->linkFile() ) ) { 357 // next time...
350 // the way writing lnks doesn't really check for out 358 if ( !QFile::exists( lnk->linkFile() ) ) {
351 // of disk space, but check it anyway. 359 // the way writing lnks doesn't really check for out
352 if ( !lnk->writeLink() ) { 360 // of disk space, but check it anyway.
353 QMessageBox::critical( 0, tr("Out of space"), 361 if ( !lnk->writeLink() ) {
354 tr( "There was a problem saving " 362 QMessageBox::critical( 0, tr("Out of space"),
355 "the playlist.\n" 363 tr( "There was a problem saving "
356 "Your playlist " 364 "the playlist.\n"
357 "may be missing some entries\n" 365 "Your playlist "
358 "the next time you start it." ) 366 "may be missing some entries\n"
359 ); 367 "the next time you start it." )
368 );
369 }
370 }
371 noOfFiles++;
372 }
360 } 373 }
361 } 374 while ( d->selectedFiles->next() );
362 noOfFiles++;
363 }
364 } while ( d->selectedFiles->next() );
365
366 cfg.writeEntry("NumberOfFiles", noOfFiles ); 375 cfg.writeEntry("NumberOfFiles", noOfFiles );
367
368
369} 376}
370 377
371 378
@@ -386,17 +393,17 @@ void PlayListWidget::clearList() {
386 393
387 394
388void PlayListWidget::addAllToList() { 395void PlayListWidget::addAllToList() {
389 DocLnkSet files; 396 DocLnkSet filesAll;
390 Global::findDocuments(&files, "video/*;audio/*"); 397 Global::findDocuments(&filesAll, "video/*;audio/*");
391 QListIterator<DocLnk> dit( files.children() ); 398 QListIterator<DocLnk> Adit( filesAll.children() );
392 for ( ; dit.current(); ++dit ) 399 for ( ; Adit.current(); ++Adit )
393 d->selectedFiles->addToSelection( **dit ); 400 d->selectedFiles->addToSelection( **Adit );
394} 401}
395 402
396 403
397void PlayListWidget::addAllMusicToList() { 404void PlayListWidget::addAllMusicToList() {
398 DocLnkSet files; 405// DocLnkSet files;
399 Global::findDocuments(&files, "audio/*"); 406// Global::findDocuments(&files, "audio/*");
400 QListIterator<DocLnk> dit( files.children() ); 407 QListIterator<DocLnk> dit( files.children() );
401 for ( ; dit.current(); ++dit ) 408 for ( ; dit.current(); ++dit )
402 d->selectedFiles->addToSelection( **dit ); 409 d->selectedFiles->addToSelection( **dit );
@@ -404,9 +411,7 @@ void PlayListWidget::addAllMusicToList() {
404 411
405 412
406void PlayListWidget::addAllVideoToList() { 413void PlayListWidget::addAllVideoToList() {
407 DocLnkSet files; 414 QListIterator<DocLnk> dit( vFiles.children() );
408 Global::findDocuments(&files, "video/*");
409 QListIterator<DocLnk> dit( files.children() );
410 for ( ; dit.current(); ++dit ) 415 for ( ; dit.current(); ++dit )
411 d->selectedFiles->addToSelection( **dit ); 416 d->selectedFiles->addToSelection( **dit );
412} 417}
@@ -468,15 +473,15 @@ const DocLnk *PlayListWidget::current() { // this is fugly
468// switch (tabWidget->currentPageIndex()) { 473// switch (tabWidget->currentPageIndex()) {
469// case 0: //playlist 474// case 0: //playlist
470// { 475// {
471 qDebug("playlist"); 476 qDebug("playlist");
472 if ( mediaPlayerState->playlist() ) { 477 if ( mediaPlayerState->playlist() ) {
473 return d->selectedFiles->current(); 478 return d->selectedFiles->current();
474 } 479 }
475 else if ( d->setDocumentUsed && d->current ) { 480 else if ( d->setDocumentUsed && d->current ) {
476 return d->current; 481 return d->current;
477 } else { 482 } else {
478 return d->files->selected(); 483 return d->files->selected();
479 } 484 }
480// } 485// }
481// break; 486// break;
482// case 1://audio 487// case 1://audio
@@ -512,66 +517,66 @@ const DocLnk *PlayListWidget::current() { // this is fugly
512 517
513bool PlayListWidget::prev() { 518bool PlayListWidget::prev() {
514 if ( mediaPlayerState->playlist() ) { 519 if ( mediaPlayerState->playlist() ) {
515 if ( mediaPlayerState->shuffled() ) { 520 if ( mediaPlayerState->shuffled() ) {
516 const DocLnk *cur = current(); 521 const DocLnk *cur = current();
517 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 522 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
518 for ( int i = 0; i < j; i++ ) { 523 for ( int i = 0; i < j; i++ ) {
519 if ( !d->selectedFiles->next() ) 524 if ( !d->selectedFiles->next() )
520 d->selectedFiles->first(); 525 d->selectedFiles->first();
521 } 526 }
522 if ( cur == current() ) 527 if ( cur == current() )
523 if ( !d->selectedFiles->next() ) 528 if ( !d->selectedFiles->next() )
524 d->selectedFiles->first(); 529 d->selectedFiles->first();
525 return TRUE; 530 return TRUE;
526 } else { 531 } else {
527 if ( !d->selectedFiles->prev() ) { 532 if ( !d->selectedFiles->prev() ) {
528 if ( mediaPlayerState->looping() ) { 533 if ( mediaPlayerState->looping() ) {
529 return d->selectedFiles->last(); 534 return d->selectedFiles->last();
530 } else { 535 } else {
531 return FALSE; 536 return FALSE;
532 } 537 }
533 } 538 }
534 return TRUE; 539 return TRUE;
535 } 540 }
536 } else { 541 } else {
537 return mediaPlayerState->looping(); 542 return mediaPlayerState->looping();
538 } 543 }
539} 544}
540 545
541 546
542bool PlayListWidget::next() { 547bool PlayListWidget::next() {
543 if ( mediaPlayerState->playlist() ) { 548 if ( mediaPlayerState->playlist() ) {
544 if ( mediaPlayerState->shuffled() ) { 549 if ( mediaPlayerState->shuffled() ) {
545 return prev(); 550 return prev();
546 } else { 551 } else {
547 if ( !d->selectedFiles->next() ) { 552 if ( !d->selectedFiles->next() ) {
548 if ( mediaPlayerState->looping() ) { 553 if ( mediaPlayerState->looping() ) {
549 return d->selectedFiles->first(); 554 return d->selectedFiles->first();
550 } else { 555 } else {
551 return FALSE; 556 return FALSE;
552 } 557 }
553 } 558 }
554 return TRUE; 559 return TRUE;
555 } 560 }
556 } else { 561 } else {
557 return mediaPlayerState->looping(); 562 return mediaPlayerState->looping();
558 } 563 }
559} 564}
560 565
561 566
562bool PlayListWidget::first() { 567bool PlayListWidget::first() {
563 if ( mediaPlayerState->playlist() ) 568 if ( mediaPlayerState->playlist() )
564 return d->selectedFiles->first(); 569 return d->selectedFiles->first();
565 else 570 else
566 return mediaPlayerState->looping(); 571 return mediaPlayerState->looping();
567} 572}
568 573
569 574
570bool PlayListWidget::last() { 575bool PlayListWidget::last() {
571 if ( mediaPlayerState->playlist() ) 576 if ( mediaPlayerState->playlist() )
572 return d->selectedFiles->last(); 577 return d->selectedFiles->last();
573 else 578 else
574 return mediaPlayerState->looping(); 579 return mediaPlayerState->looping();
575} 580}
576 581
577 582
@@ -582,25 +587,29 @@ void PlayListWidget::saveList() {
582 fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); 587 fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
583 fileDlg->exec(); 588 fileDlg->exec();
584 if( fileDlg->result() == 1 ) { 589 if( fileDlg->result() == 1 ) {
585 if ( d->current ) 590 if ( d->current )
586 delete d->current; 591 delete d->current;
587 filename = fileDlg->LineEdit1->text();//+".playlist"; 592 filename = fileDlg->LineEdit1->text();//+".playlist";
588// qDebug("saving playlist "+filename+".playlist"); 593// qDebug("saving playlist "+filename+".playlist");
589 Config cfg( filename +".playlist"); 594 Config cfg( filename +".playlist");
590 writeConfig( cfg ); 595 writeConfig( cfg );
591 if( playLists->selected()->name() == filename) { 596
592// qDebug("same name so delete lnk"); 597// qDebug("same name so delete lnk??");
593 QFile().remove(playLists->selected()->file()); 598// if( playLists->selected()->name() == filename) {
594 QFile().remove(playLists->selected()->linkFile()); 599
595 playLists->reread(); 600// qDebug("same name so delete lnk");
596 } 601// QFile().remove(playLists->selected()->file());
597 602// QFile().remove(playLists->selected()->linkFile());
603// playLists->reread();
604// }
605// qDebug("new doclnk");
598 DocLnk lnk; 606 DocLnk lnk;
599// lnk.setComment( ""); 607// lnk.setComment( "");
600 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property 608 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
601 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D 609 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
602 lnk.setIcon("mpegplayer/playlist2"); 610 lnk.setIcon("mpegplayer/playlist2");
603 lnk.setName( filename); //sets file name 611 lnk.setName( filename); //sets file name
612 qDebug(filename);
604 if(!lnk.writeLink()) 613 if(!lnk.writeLink())
605 qDebug("Writing doclink did not work"); 614 qDebug("Writing doclink did not work");
606 } 615 }
@@ -608,8 +617,8 @@ void PlayListWidget::saveList() {
608 config.writeEntry("CurrentPlaylist",filename); 617 config.writeEntry("CurrentPlaylist",filename);
609 setCaption(tr("OpiePlayer: ")+filename); 618 setCaption(tr("OpiePlayer: ")+filename);
610 d->selectedFiles->first(); 619 d->selectedFiles->first();
611 if(fileDlg) 620 if(fileDlg)
612 delete fileDlg; 621 delete fileDlg;
613} 622}
614 623
615void PlayListWidget::loadList( const DocLnk & lnk) { 624void PlayListWidget::loadList( const DocLnk & lnk) {
@@ -621,11 +630,14 @@ void PlayListWidget::loadList( const DocLnk & lnk) {
621 clearList(); 630 clearList();
622 Config cfg( name+".playlist"); 631 Config cfg( name+".playlist");
623 readConfig(cfg); 632 readConfig(cfg);
633
624 tabWidget->setCurrentPage(0); 634 tabWidget->setCurrentPage(0);
635
625 Config config( "MediaPlayer" ); 636 Config config( "MediaPlayer" );
626 config.writeEntry("CurrentPlaylist", name); 637 config.writeEntry("CurrentPlaylist", name);
627 d->selectedFiles->first(); 638// d->selectedFiles->first();
628 } 639 }
640
629} 641}
630 642
631void PlayListWidget::setPlaylist( bool shown ) { 643void PlayListWidget::setPlaylist( bool shown ) {
@@ -783,7 +795,8 @@ void PlayListWidget::btnPlay(bool b) {
783// qApp->processEvents(); 795// qApp->processEvents();
784 d->selectedFiles->removeSelected( ); 796 d->selectedFiles->removeSelected( );
785 tabWidget->setCurrentPage(1); 797 tabWidget->setCurrentPage(1);
786 d->selectedFiles->unSelect(); 798 audioView->clearSelection();
799// d->selectedFiles->unSelect();
787// mediaPlayerState->setPlaying(FALSE); 800// mediaPlayerState->setPlaying(FALSE);
788 } 801 }
789 break; 802 break;
@@ -794,7 +807,8 @@ void PlayListWidget::btnPlay(bool b) {
794 qApp->processEvents(); 807 qApp->processEvents();
795 d->selectedFiles->removeSelected( ); 808 d->selectedFiles->removeSelected( );
796 tabWidget->setCurrentPage(2); 809 tabWidget->setCurrentPage(2);
797 d->selectedFiles->unSelect(); 810 videoView->clearSelection();
811// d->selectedFiles->unSelect();
798// mediaPlayerState->setPlaying(FALSE); 812// mediaPlayerState->setPlaying(FALSE);
799 } 813 }
800 break; 814 break;
@@ -905,16 +919,22 @@ void PlayListWidget::listDelete() {
905void PlayListWidget::populateAudioView() { 919void PlayListWidget::populateAudioView() {
906// if(files) 920// if(files)
907// files.~DocLnkSet(); 921// files.~DocLnkSet();
922 StorageInfo storageInfo;
923 const QList<FileSystem> &fs = storageInfo.fileSystems();
924
908 Global::findDocuments(&files, "audio/*"); 925 Global::findDocuments(&files, "audio/*");
909 QListIterator<DocLnk> dit( files.children() ); 926 QListIterator<DocLnk> dit( files.children() );
927 QListIterator<FileSystem> it ( fs );
910 audioView->clear(); 928 audioView->clear();
911 QString storage; 929 QString storage;
912 for ( ; dit.current(); ++dit ) { 930 for ( ; dit.current(); ++dit ) {
931 for( ; it.current(); ++it ){
932 const QString name = (*it)->name();
933 const QString path = (*it)->path();
934 if(dit.current()->file().find(path) != -1 ) storage=name;
935 }
936
913 QListViewItem * newItem; 937 QListViewItem * newItem;
914 if(dit.current()->file().find("/mnt/cf") != -1 ) storage=tr("CF");
915 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage=tr("CF");
916 else if(dit.current()->file().find("/mnt/card") != -1 ) storage=tr("SD");
917 else storage=tr("RAM");
918 if ( QFile( dit.current()->file()).exists() ) { 938 if ( QFile( dit.current()->file()).exists() ) {
919 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); 939 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
920 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); 940 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
@@ -923,15 +943,21 @@ void PlayListWidget::populateAudioView() {
923} 943}
924 944
925void PlayListWidget::populateVideoView() { 945void PlayListWidget::populateVideoView() {
946 StorageInfo storageInfo;
947 const QList<FileSystem> &fs = storageInfo.fileSystems();
948
926 Global::findDocuments(&vFiles, "video/*"); 949 Global::findDocuments(&vFiles, "video/*");
927 QListIterator<DocLnk> Vdit( vFiles.children() ); 950 QListIterator<DocLnk> Vdit( vFiles.children() );
951 QListIterator<FileSystem> it ( fs );
928 videoView->clear(); 952 videoView->clear();
929 QString storage; 953 QString storage;
930 for ( ; Vdit.current(); ++Vdit ) { 954 for ( ; Vdit.current(); ++Vdit ) {
931 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage=tr("CF"); 955 for( ; it.current(); ++it ){
932 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage=tr("CF"); 956 const QString name = (*it)->name();
933 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage=tr("SD"); 957 const QString path = (*it)->path();
934 else storage=tr("RAM"); 958 if( Vdit.current()->file().find(path) != -1 ) storage=name;
959 }
960
935 QListViewItem * newItem; 961 QListViewItem * newItem;
936 if ( QFile( Vdit.current()->file()).exists() ) { 962 if ( QFile( Vdit.current()->file()).exists() ) {
937 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); 963 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);