author | llornkcor <llornkcor> | 2002-08-16 02:46:12 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-08-16 02:46:12 (UTC) |
commit | 40527ffb82b83ad521ed766f11b47636db055ffe (patch) (unidiff) | |
tree | d94fb1f21fa57b9dfbe2aa45beab05de024c97a3 | |
parent | f25db7780ff234b2770ac13d8c02887b79a57a26 (diff) | |
download | opie-40527ffb82b83ad521ed766f11b47636db055ffe.zip opie-40527ffb82b83ad521ed766f11b47636db055ffe.tar.gz opie-40527ffb82b83ad521ed766f11b47636db055ffe.tar.bz2 |
check for local file existing before adding to playlist
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index e33998f..612fd45 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -301,54 +301,56 @@ PlayListWidget::~PlayListWidget() { | |||
301 | if ( d->current ) { | 301 | if ( d->current ) { |
302 | delete d->current; | 302 | delete d->current; |
303 | } | 303 | } |
304 | delete d; | 304 | delete d; |
305 | } | 305 | } |
306 | 306 | ||
307 | 307 | ||
308 | void PlayListWidget::initializeStates() { | 308 | void PlayListWidget::initializeStates() { |
309 | 309 | ||
310 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 310 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
311 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 311 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
312 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 312 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
313 | setPlaylist( true); | 313 | setPlaylist( true); |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | void PlayListWidget::readConfig( Config& cfg ) { | 317 | void PlayListWidget::readConfig( Config& cfg ) { |
318 | cfg.setGroup("PlayList"); | 318 | cfg.setGroup("PlayList"); |
319 | QString currentString = cfg.readEntry("current", "" ); | 319 | QString currentString = cfg.readEntry("current", "" ); |
320 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 320 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
321 | for ( int i = 0; i < noOfFiles; i++ ) { | 321 | for ( int i = 0; i < noOfFiles; i++ ) { |
322 | QString entryName; | 322 | QString entryName; |
323 | entryName.sprintf( "File%i", i + 1 ); | 323 | entryName.sprintf( "File%i", i + 1 ); |
324 | QString linkFile = cfg.readEntry( entryName ); | 324 | QString linkFile = cfg.readEntry( entryName ); |
325 | DocLnk lnk( linkFile ); | 325 | if(QFileInfo( linkFile).exists() ) { |
326 | if ( lnk.isValid() ) { | 326 | DocLnk lnk( linkFile ); |
327 | d->selectedFiles->addToSelection( lnk ); | 327 | if ( QFileInfo( lnk.file()).exists() || linkFile.find("http",0,TRUE) != -1) { |
328 | d->selectedFiles->addToSelection( lnk ); | ||
329 | } | ||
328 | } | 330 | } |
329 | } | 331 | } |
330 | d->selectedFiles->setSelectedItem( currentString); | 332 | d->selectedFiles->setSelectedItem( currentString); |
331 | } | 333 | } |
332 | 334 | ||
333 | 335 | ||
334 | void PlayListWidget::writeConfig( Config& cfg ) const { | 336 | void PlayListWidget::writeConfig( Config& cfg ) const { |
335 | 337 | ||
336 | d->selectedFiles->writeCurrent( cfg); | 338 | d->selectedFiles->writeCurrent( cfg); |
337 | cfg.setGroup("PlayList"); | 339 | cfg.setGroup("PlayList"); |
338 | int noOfFiles = 0; | 340 | int noOfFiles = 0; |
339 | d->selectedFiles->first(); | 341 | d->selectedFiles->first(); |
340 | do { | 342 | do { |
341 | const DocLnk *lnk = d->selectedFiles->current(); | 343 | const DocLnk *lnk = d->selectedFiles->current(); |
342 | if ( lnk ) { | 344 | if ( lnk ) { |
343 | QString entryName; | 345 | QString entryName; |
344 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 346 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
345 | cfg.writeEntry( entryName, lnk->linkFile() ); | 347 | cfg.writeEntry( entryName, lnk->linkFile() ); |
346 | // if this link does exist, add it so we have the file | 348 | // if this link does exist, add it so we have the file |
347 | // next time... | 349 | // next time... |
348 | if ( !QFile::exists( lnk->linkFile() ) ) { | 350 | if ( !QFile::exists( lnk->linkFile() ) ) { |
349 | // the way writing lnks doesn't really check for out | 351 | // the way writing lnks doesn't really check for out |
350 | // of disk space, but check it anyway. | 352 | // of disk space, but check it anyway. |
351 | if ( !lnk->writeLink() ) { | 353 | if ( !lnk->writeLink() ) { |
352 | QMessageBox::critical( 0, tr("Out of space"), | 354 | QMessageBox::critical( 0, tr("Out of space"), |
353 | tr( "There was a problem saving " | 355 | tr( "There was a problem saving " |
354 | "the playlist.\n" | 356 | "the playlist.\n" |
@@ -630,108 +632,112 @@ void PlayListWidget::setView( char view ) { | |||
630 | if ( view == 'l' ) | 632 | if ( view == 'l' ) |
631 | showMaximized(); | 633 | showMaximized(); |
632 | else | 634 | else |
633 | hide(); | 635 | hide(); |
634 | } | 636 | } |
635 | 637 | ||
636 | void PlayListWidget::addSelected() { | 638 | void PlayListWidget::addSelected() { |
637 | 639 | ||
638 | Config cfg( "OpiePlayer" ); | 640 | Config cfg( "OpiePlayer" ); |
639 | cfg.setGroup("PlayList"); | 641 | cfg.setGroup("PlayList"); |
640 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 642 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
641 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 643 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
642 | 644 | ||
643 | switch (tabWidget->currentPageIndex()) { | 645 | switch (tabWidget->currentPageIndex()) { |
644 | case 0: //playlist | 646 | case 0: //playlist |
645 | break; | 647 | break; |
646 | case 1: { //audio | 648 | case 1: { //audio |
647 | QListViewItemIterator it( audioView ); | 649 | QListViewItemIterator it( audioView ); |
648 | // iterate through all items of the listview | 650 | // iterate through all items of the listview |
649 | for ( ; it.current(); ++it ) { | 651 | for ( ; it.current(); ++it ) { |
650 | if ( it.current()->isSelected() ) { | 652 | if ( it.current()->isSelected() ) { |
651 | QListIterator<DocLnk> dit( files.children() ); | 653 | QListIterator<DocLnk> dit( files.children() ); |
652 | for ( ; dit.current(); ++dit ) { | 654 | for ( ; dit.current(); ++dit ) { |
653 | if( dit.current()->name() == it.current()->text(0) ) { | 655 | if( dit.current()->name() == it.current()->text(0) ) { |
654 | d->selectedFiles->addToSelection( **dit ); | 656 | if(QFileInfo( dit.current()->file()).exists()) |
657 | d->selectedFiles->addToSelection( **dit ); | ||
655 | } | 658 | } |
656 | } | 659 | } |
657 | audioView->setSelected( it.current(),FALSE); | 660 | audioView->setSelected( it.current(),FALSE); |
658 | } | 661 | } |
659 | } | 662 | } |
660 | tabWidget->setCurrentPage(0); | 663 | tabWidget->setCurrentPage(0); |
661 | } | 664 | } |
662 | break; | 665 | break; |
663 | case 2: { // video | 666 | case 2: { // video |
664 | QListViewItemIterator it( videoView ); | 667 | QListViewItemIterator it( videoView ); |
665 | // iterate through all items of the listview | 668 | // iterate through all items of the listview |
666 | for ( ; it.current(); ++it ) { | 669 | for ( ; it.current(); ++it ) { |
667 | if ( it.current()->isSelected() ) { | 670 | if ( it.current()->isSelected() ) { |
668 | QListIterator<DocLnk> dit( vFiles.children() ); | 671 | QListIterator<DocLnk> dit( vFiles.children() ); |
669 | for ( ; dit.current(); ++dit ) { | 672 | for ( ; dit.current(); ++dit ) { |
670 | if( dit.current()->name() == it.current()->text(0) ) { | 673 | if( dit.current()->name() == it.current()->text(0) ) { |
671 | d->selectedFiles->addToSelection( **dit ); | 674 | if(QFileInfo( dit.current()->file()).exists()) |
675 | d->selectedFiles->addToSelection( **dit ); | ||
672 | } | 676 | } |
673 | } | 677 | } |
674 | videoView->setSelected( it.current(),FALSE); | 678 | videoView->setSelected( it.current(),FALSE); |
675 | } | 679 | } |
676 | } | 680 | } |
677 | tabWidget->setCurrentPage(0); | 681 | tabWidget->setCurrentPage(0); |
678 | } | 682 | } |
679 | break; | 683 | break; |
680 | }; | 684 | }; |
681 | } | 685 | } |
682 | 686 | ||
683 | void PlayListWidget::removeSelected() { | 687 | void PlayListWidget::removeSelected() { |
684 | d->selectedFiles->removeSelected( ); | 688 | d->selectedFiles->removeSelected( ); |
685 | } | 689 | } |
686 | 690 | ||
687 | void PlayListWidget::playIt( QListViewItem *it) { | 691 | void PlayListWidget::playIt( QListViewItem *it) { |
688 | // if(it==NULL) return; | 692 | // if(it==NULL) return; |
689 | qDebug("playIt"); | 693 | qDebug("playIt"); |
690 | mediaPlayerState->setPlaying(FALSE); | 694 | mediaPlayerState->setPlaying(FALSE); |
691 | mediaPlayerState->setPlaying(TRUE); | 695 | mediaPlayerState->setPlaying(TRUE); |
692 | d->selectedFiles->unSelect(); | 696 | d->selectedFiles->unSelect(); |
693 | } | 697 | } |
694 | 698 | ||
695 | void PlayListWidget::addToSelection( QListViewItem *it) { | 699 | void PlayListWidget::addToSelection( QListViewItem *it) { |
696 | d->setDocumentUsed = FALSE; | 700 | d->setDocumentUsed = FALSE; |
697 | 701 | ||
698 | if(it) { | 702 | if(it) { |
699 | switch (tabWidget->currentPageIndex()) { | 703 | switch (tabWidget->currentPageIndex()) { |
700 | case 1: { | 704 | case 1: { |
701 | QListIterator<DocLnk> dit( files.children() ); | 705 | QListIterator<DocLnk> dit( files.children() ); |
702 | for ( ; dit.current(); ++dit ) { | 706 | for ( ; dit.current(); ++dit ) { |
703 | if( dit.current()->name() == it->text(0)) { | 707 | if( dit.current()->name() == it->text(0)) { |
704 | d->selectedFiles->addToSelection( **dit ); | 708 | if(QFileInfo( dit.current()->file()).exists()) |
709 | d->selectedFiles->addToSelection( **dit ); | ||
705 | } | 710 | } |
706 | } | 711 | } |
707 | } | 712 | } |
708 | break; | 713 | break; |
709 | case 2: { | 714 | case 2: { |
710 | QListIterator<DocLnk> dit( vFiles.children() ); | 715 | QListIterator<DocLnk> dit( vFiles.children() ); |
711 | for ( ; dit.current(); ++dit ) { | 716 | for ( ; dit.current(); ++dit ) { |
712 | if( dit.current()->name() == it->text(0)) { | 717 | if( dit.current()->name() == it->text(0)) { |
713 | d->selectedFiles->addToSelection( **dit ); | 718 | if(QFileInfo( dit.current()->file()).exists()) |
719 | d->selectedFiles->addToSelection( **dit ); | ||
714 | } | 720 | } |
715 | } | 721 | } |
716 | } | 722 | } |
717 | break; | 723 | break; |
718 | case 0: | 724 | case 0: |
719 | break; | 725 | break; |
720 | }; | 726 | }; |
721 | tabWidget->setCurrentPage(0); | 727 | tabWidget->setCurrentPage(0); |
722 | } | 728 | } |
723 | } | 729 | } |
724 | 730 | ||
725 | void PlayListWidget::tabChanged(QWidget *) { | 731 | void PlayListWidget::tabChanged(QWidget *) { |
726 | 732 | ||
727 | switch ( tabWidget->currentPageIndex()) { | 733 | switch ( tabWidget->currentPageIndex()) { |
728 | case 0: | 734 | case 0: |
729 | { | 735 | { |
730 | if( !tbDeletePlaylist->isHidden()) | 736 | if( !tbDeletePlaylist->isHidden()) |
731 | tbDeletePlaylist->hide(); | 737 | tbDeletePlaylist->hide(); |
732 | d->tbRemoveFromList->setEnabled(TRUE); | 738 | d->tbRemoveFromList->setEnabled(TRUE); |
733 | d->tbAddToList->setEnabled(FALSE); | 739 | d->tbAddToList->setEnabled(FALSE); |
734 | } | 740 | } |
735 | break; | 741 | break; |
736 | case 1: | 742 | case 1: |
737 | { | 743 | { |
@@ -1090,58 +1096,60 @@ void PlayListWidget::doUnblank() { | |||
1090 | if (fd != -1) { | 1096 | if (fd != -1) { |
1091 | ioctl(fd,FBIOBLANK,0); | 1097 | ioctl(fd,FBIOBLANK,0); |
1092 | close(fd); | 1098 | close(fd); |
1093 | } | 1099 | } |
1094 | QCopEnvelope h("QPE/System", "setBacklight(int)"); | 1100 | QCopEnvelope h("QPE/System", "setBacklight(int)"); |
1095 | h <<-3;// v[1]; // -3 Force on | 1101 | h <<-3;// v[1]; // -3 Force on |
1096 | } | 1102 | } |
1097 | 1103 | ||
1098 | void PlayListWidget::readm3u(const QString &filename) { | 1104 | void PlayListWidget::readm3u(const QString &filename) { |
1099 | 1105 | ||
1100 | qDebug("m3u filename is "+filename); | 1106 | qDebug("m3u filename is "+filename); |
1101 | QFile f(filename); | 1107 | QFile f(filename); |
1102 | 1108 | ||
1103 | if(f.open(IO_ReadOnly)) { | 1109 | if(f.open(IO_ReadOnly)) { |
1104 | QTextStream t(&f); | 1110 | QTextStream t(&f); |
1105 | QString s;//, first, second; | 1111 | QString s;//, first, second; |
1106 | int i=0; | 1112 | int i=0; |
1107 | while ( !t.atEnd()) { | 1113 | while ( !t.atEnd()) { |
1108 | s=t.readLine(); | 1114 | s=t.readLine(); |
1109 | 1115 | ||
1110 | if(s.find("#",0,TRUE) == -1) { | 1116 | if(s.find("#",0,TRUE) == -1) { |
1111 | if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat | 1117 | if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat |
1112 | if(s.left(2) == "E:" || s.left(2) == "P:") { | 1118 | if(s.left(2) == "E:" || s.left(2) == "P:") { |
1113 | s=s.right(s.length()-2); | 1119 | s=s.right(s.length()-2); |
1114 | DocLnk lnk( s ); | 1120 | if(QFile(s).exists()) { |
1115 | QFileInfo f(s); | 1121 | DocLnk lnk( s ); |
1116 | QString name = f.baseName(); | 1122 | QFileInfo f(s); |
1117 | name = name.right( name.length()-name.findRev( "\\",-1,TRUE ) -1 ); | 1123 | QString name = f.baseName(); |
1118 | lnk.setName( name ); | 1124 | name = name.right( name.length()-name.findRev( "\\",-1,TRUE ) -1 ); |
1119 | s=s.replace( QRegExp("\\"),"/"); | 1125 | lnk.setName( name ); |
1120 | lnk.setFile( s ); | 1126 | s=s.replace( QRegExp("\\"),"/"); |
1121 | lnk.writeLink(); | 1127 | lnk.setFile( s ); |
1122 | qDebug("add "+name); | 1128 | lnk.writeLink(); |
1123 | d->selectedFiles->addToSelection( lnk); | 1129 | qDebug("add "+name); |
1130 | d->selectedFiles->addToSelection( lnk); | ||
1131 | } | ||
1124 | } else { // is url | 1132 | } else { // is url |
1125 | s.replace(QRegExp("%20")," "); | 1133 | s.replace(QRegExp("%20")," "); |
1126 | DocLnk lnk( s ); | 1134 | DocLnk lnk( s ); |
1127 | QString name; | 1135 | QString name; |
1128 | if(name.left(4)=="http") { | 1136 | if(name.left(4)=="http") { |
1129 | name = s.right( s.length() - 7); | 1137 | name = s.right( s.length() - 7); |
1130 | } else { | 1138 | } else { |
1131 | name = s; | 1139 | name = s; |
1132 | } | 1140 | } |
1133 | lnk.setName(name); | 1141 | lnk.setName(name); |
1134 | if(s.at(s.length()-4) == '.') { | 1142 | if(s.at(s.length()-4) == '.') { |
1135 | lnk.setFile( s); | 1143 | lnk.setFile( s); |
1136 | } else { | 1144 | } else { |
1137 | lnk.setFile( s+"/"); | 1145 | lnk.setFile( s+"/"); |
1138 | } | 1146 | } |
1139 | lnk.setType("audio/x-mpegurl"); | 1147 | lnk.setType("audio/x-mpegurl"); |
1140 | lnk.writeLink(); | 1148 | lnk.writeLink(); |
1141 | d->selectedFiles->addToSelection( lnk); | 1149 | d->selectedFiles->addToSelection( lnk); |
1142 | } | 1150 | } |
1143 | i++; | 1151 | i++; |
1144 | } | 1152 | } |
1145 | } | 1153 | } |
1146 | } | 1154 | } |
1147 | } | 1155 | } |