summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-10-15 01:38:28 (UTC)
committer llornkcor <llornkcor>2002-10-15 01:38:28 (UTC)
commit42ed74a1af7f96c06d2310b9804dacc703e31ad9 (patch) (unidiff)
treee1becb85cbf0501740f011913ad87132d235c729
parente0efd37513192d9a17fa9a9f46bbaed0ca38029c (diff)
downloadopie-42ed74a1af7f96c06d2310b9804dacc703e31ad9.zip
opie-42ed74a1af7f96c06d2310b9804dacc703e31ad9.tar.gz
opie-42ed74a1af7f96c06d2310b9804dacc703e31ad9.tar.bz2
fix for m3u files with spaces.. damn things.. who knows whats in that damn empty space.. really
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index f9192e8..7ada5ee 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -418,117 +418,117 @@ bool PlayListWidget::last() {
418 writem3u(); 418 writem3u();
419 } 419 }
420 420
421 421
422void PlayListWidget::loadList( const DocLnk & lnk) { 422void PlayListWidget::loadList( const DocLnk & lnk) {
423 QString name = lnk.name(); 423 QString name = lnk.name();
424 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); 424 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
425 425
426 if( name.length()>0) { 426 if( name.length()>0) {
427 setCaption("OpiePlayer: "+name); 427 setCaption("OpiePlayer: "+name);
428 qDebug("<<<<<<<<<<<<load list "+ lnk.file()); 428 qDebug("<<<<<<<<<<<<load list "+ lnk.file());
429 clearList(); 429 clearList();
430 readm3u(lnk.file()); 430 readm3u(lnk.file());
431 tabWidget->setCurrentPage(0); 431 tabWidget->setCurrentPage(0);
432 } 432 }
433} 433}
434 434
435 435
436void PlayListWidget::setPlaylist( bool shown ) { 436void PlayListWidget::setPlaylist( bool shown ) {
437 if ( shown ) { 437 if ( shown ) {
438 d->playListFrame->show(); 438 d->playListFrame->show();
439 } else { 439 } else {
440 d->playListFrame->hide(); 440 d->playListFrame->hide();
441 } 441 }
442} 442}
443 443
444 444
445void PlayListWidget::addSelected() { 445void PlayListWidget::addSelected() {
446 qDebug("addSelected"); 446 qDebug("addSelected");
447 switch (whichList()) { 447 switch (whichList()) {
448 case 0: //playlist 448 case 0: //playlist
449 break; 449 break;
450 case 1: { //audio 450 case 1: { //audio
451 QListViewItemIterator it( audioView ); 451 QListViewItemIterator it( audioView );
452 // iterate through all items of the listview 452 // iterate through all items of the listview
453 for ( ; it.current(); ++it ) { 453 for ( ; it.current(); ++it ) {
454 if ( it.current()->isSelected() ) { 454 if ( it.current()->isSelected() ) {
455 QListIterator<DocLnk> dit( files.children() ); 455 QListIterator<DocLnk> dit( files.children() );
456 for ( ; dit.current(); ++dit ) { 456 for ( ; dit.current(); ++dit ) {
457 if( dit.current()->name() == it.current()->text(0) ) { 457 if( dit.current()->name() == it.current()->text(0) ) {
458 if( QFileInfo( dit.current()->file()).exists()) { 458 if( QFileInfo( dit.current()->file()).exists()) {
459 d->selectedFiles->addToSelection( **dit ); 459 d->selectedFiles->addToSelection( **dit );
460 audioView->setSelected( it.current(),FALSE); 460 audioView->setSelected( it.current(),FALSE);
461 } 461 }
462 } 462 }
463 } 463 }
464 } 464 }
465 } 465 }
466 tabWidget->setCurrentPage(0); 466// tabWidget->setCurrentPage(0);
467 writeCurrentM3u(); 467 writeCurrentM3u();
468 } 468 }
469 break; 469 break;
470 case 2: { // video 470 case 2: { // video
471 QListViewItemIterator it( videoView ); 471 QListViewItemIterator it( videoView );
472 // iterate through all items of the listview 472 // iterate through all items of the listview
473 for ( ; it.current(); ++it ) { 473 for ( ; it.current(); ++it ) {
474 if ( it.current()->isSelected() ) { 474 if ( it.current()->isSelected() ) {
475 QListIterator<DocLnk> dit( vFiles.children() ); 475 QListIterator<DocLnk> dit( vFiles.children() );
476 for ( ; dit.current(); ++dit ) { 476 for ( ; dit.current(); ++dit ) {
477 if( dit.current()->name() == it.current()->text(0) ) { 477 if( dit.current()->name() == it.current()->text(0) ) {
478 if(QFileInfo( dit.current()->file()).exists()) { 478 if(QFileInfo( dit.current()->file()).exists()) {
479 d->selectedFiles->addToSelection( **dit ); 479 d->selectedFiles->addToSelection( **dit );
480 videoView->setSelected( it.current(),FALSE); 480 videoView->setSelected( it.current(),FALSE);
481 } 481 }
482 } 482 }
483 } 483 }
484 } 484 }
485 } 485 }
486 tabWidget->setCurrentPage(0); 486// tabWidget->setCurrentPage(0);
487 writeCurrentM3u(); 487 writeCurrentM3u();
488 } 488 }
489 break; 489 break;
490 }; 490 };
491} 491}
492 492
493 493
494void PlayListWidget::removeSelected() { 494void PlayListWidget::removeSelected() {
495 d->selectedFiles->removeSelected( ); 495 d->selectedFiles->removeSelected( );
496 writeCurrentM3u(); 496 writeCurrentM3u();
497} 497}
498 498
499 499
500void PlayListWidget::playIt( QListViewItem *it) { 500void PlayListWidget::playIt( QListViewItem *it) {
501 if(!it) return; 501 if(!it) return;
502 mediaPlayerState->setPlaying(FALSE); 502 mediaPlayerState->setPlaying(FALSE);
503 mediaPlayerState->setPlaying(TRUE); 503 mediaPlayerState->setPlaying(TRUE);
504 d->selectedFiles->unSelect(); 504 d->selectedFiles->unSelect();
505} 505}
506 506
507 507
508void PlayListWidget::addToSelection( QListViewItem *it) { 508void PlayListWidget::addToSelection( QListViewItem *it) {
509 d->setDocumentUsed = FALSE; 509 d->setDocumentUsed = FALSE;
510 510
511 if(it) { 511 if(it) {
512 switch ( whichList()) { 512 switch ( whichList()) {
513 case 1: { 513 case 1: {
514 QListIterator<DocLnk> dit( files.children() ); 514 QListIterator<DocLnk> dit( files.children() );
515 for ( ; dit.current(); ++dit ) { 515 for ( ; dit.current(); ++dit ) {
516 if( dit.current()->name() == it->text(0)) { 516 if( dit.current()->name() == it->text(0)) {
517 if(QFileInfo( dit.current()->file()).exists()) 517 if(QFileInfo( dit.current()->file()).exists())
518 d->selectedFiles->addToSelection( **dit ); 518 d->selectedFiles->addToSelection( **dit );
519 } 519 }
520 } 520 }
521 writeCurrentM3u(); 521 writeCurrentM3u();
522 } 522 }
523 break; 523 break;
524 case 2: { 524 case 2: {
525 QListIterator<DocLnk> dit( vFiles.children() ); 525 QListIterator<DocLnk> dit( vFiles.children() );
526 for ( ; dit.current(); ++dit ) { 526 for ( ; dit.current(); ++dit ) {
527 if( dit.current()->name() == it->text(0)) { 527 if( dit.current()->name() == it->text(0)) {
528 if( QFileInfo( dit.current()->file()).exists() ) 528 if( QFileInfo( dit.current()->file()).exists() )
529 d->selectedFiles->addToSelection( **dit ); 529 d->selectedFiles->addToSelection( **dit );
530 } 530 }
531 } 531 }
532 writeCurrentM3u(); 532 writeCurrentM3u();
533 533
534 } 534 }
@@ -723,191 +723,195 @@ void PlayListWidget::openFile() {
723 723
724 if(filename.left(4) == "http") { 724 if(filename.left(4) == "http") {
725 QString m3uFile, m3uFilePath; 725 QString m3uFile, m3uFilePath;
726 if(filename.find(":",8,TRUE) != -1) { //found a port 726 if(filename.find(":",8,TRUE) != -1) { //found a port
727 m3uFile = filename.left( filename.find( ":",8,TRUE)); 727 m3uFile = filename.left( filename.find( ":",8,TRUE));
728 m3uFile = m3uFile.right( 7); 728 m3uFile = m3uFile.right( 7);
729 } else if(filename.left(4) == "http"){ 729 } else if(filename.left(4) == "http"){
730 m3uFile=filename; 730 m3uFile=filename;
731 m3uFile = m3uFile.right( m3uFile.length() - 7); 731 m3uFile = m3uFile.right( m3uFile.length() - 7);
732 } else{ 732 } else{
733 m3uFile=filename; 733 m3uFile=filename;
734 } 734 }
735 735
736// qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); 736// qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile);
737 lnk.setName( filename ); //sets name 737 lnk.setName( filename ); //sets name
738 lnk.setFile( filename ); //sets file name 738 lnk.setFile( filename ); //sets file name
739 lnk.setIcon("opieplayer2/musicfile"); 739 lnk.setIcon("opieplayer2/musicfile");
740 d->selectedFiles->addToSelection( lnk ); 740 d->selectedFiles->addToSelection( lnk );
741 writeCurrentM3u(); 741 writeCurrentM3u();
742 } 742 }
743 else if( filename.right( 3) == "m3u" ) { 743 else if( filename.right( 3) == "m3u" ) {
744 readm3u( filename ); 744 readm3u( filename );
745 745
746 } else if( filename.right(3) == "pls" ) { 746 } else if( filename.right(3) == "pls" ) {
747 readPls( filename ); 747 readPls( filename );
748 } else { 748 } else {
749 d->selectedFiles->addToSelection( DocLnk(filename) ); 749 d->selectedFiles->addToSelection( DocLnk(filename) );
750 writeCurrentM3u(); 750 writeCurrentM3u();
751 } 751 }
752 } 752 }
753 753
754 if( fileDlg ) { 754 if( fileDlg ) {
755 delete fileDlg; 755 delete fileDlg;
756 } 756 }
757} 757}
758 758
759/* 759/*
760reads m3u and shows files/urls to playlist widget */ 760reads m3u and shows files/urls to playlist widget */
761void PlayListWidget::readm3u( const QString &filename ) { 761void PlayListWidget::readm3u( const QString &filename ) {
762 qDebug( "read m3u filename " + filename ); 762 qDebug( "read m3u filename " + filename );
763 763
764 Om3u *m3uList; 764 Om3u *m3uList;
765 QString s, name; 765 QString s, name;
766 m3uList = new Om3u( filename, IO_ReadOnly ); 766 m3uList = new Om3u( filename, IO_ReadOnly );
767 m3uList->readM3u(); 767 m3uList->readM3u();
768 DocLnk lnk; 768 DocLnk lnk;
769 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 769 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
770 s = *it; 770 s = *it;
771// s.replace( QRegExp( "%20" )," " );
772// qDebug("reading "+ s); 771// qDebug("reading "+ s);
773 if(s.left(4)=="http") { 772 if(s.left(4)=="http") {
774 lnk.setName( s ); //sets file name 773 lnk.setName( s ); //sets file name
774 lnk.setIcon("opieplayer2/musicfile");
775 if(s.right(4) != '.' || s.right(5) != '.')
776 lnk.setFile( s+"/"); //if url with no extension
777 else
775 lnk.setFile( s ); //sets file name 778 lnk.setFile( s ); //sets file name
776 lnk.setIcon("opieplayer2/musicfile"); 779
780 } else {
781 // if( QFileInfo( s ).exists() ) {
782 lnk.setName( QFileInfo(s).baseName());
783 // if(s.right(4) == '.') {//if regular file
784 if(s.left(1) != "/") {
785 // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s);
786 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
787 lnk.setIcon("SoundPlayer");
788 } else {
789 // qDebug("set link2 "+s);
790 lnk.setFile( s);
791 lnk.setIcon("SoundPlayer");
792 }
777 } 793 }
778 else { 794 d->selectedFiles->addToSelection( lnk );
779 if( QFileInfo( s ).exists() ) {
780 lnk.setName( QFileInfo(s).baseName());
781// qDebug("set link "+s);
782 if(s.at(s.length()-4) == '.') //if regular file
783 lnk.setFile( s);
784 else
785 lnk.setFile( s+"/"); //if url with no extension
786 }
787 }
788 d->selectedFiles->addToSelection( lnk );
789 } 795 }
790 Config config( "OpiePlayer" ); 796 Config config( "OpiePlayer" );
791 config.setGroup( "PlayList" ); 797 config.setGroup( "PlayList" );
792 798
793 config.writeEntry("CurrentPlaylist",filename); 799 config.writeEntry("CurrentPlaylist",filename);
794 config.write(); 800 config.write();
795 currentPlayList=filename; 801 currentPlayList=filename;
796 802
797// m3uList->write(); 803// m3uList->write();
798 m3uList->close(); 804 m3uList->close();
799 if(m3uList) delete m3uList; 805 if(m3uList) delete m3uList;
800 806
801 d->selectedFiles->setSelectedItem( s); 807 d->selectedFiles->setSelectedItem( s);
802 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); 808 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName());
803 809
804} 810}
805 811
806/* 812/*
807reads pls and adds files/urls to playlist */ 813reads pls and adds files/urls to playlist */
808void PlayListWidget::readPls( const QString &filename ) { 814void PlayListWidget::readPls( const QString &filename ) {
809 815
810 qDebug( "pls filename is " + filename ); 816 qDebug( "pls filename is " + filename );
811 Om3u *m3uList; 817 Om3u *m3uList;
812 QString s, name; 818 QString s, name;
813 m3uList = new Om3u( filename, IO_ReadOnly ); 819 m3uList = new Om3u( filename, IO_ReadOnly );
814 m3uList->readPls(); 820 m3uList->readPls();
815 821
816 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 822 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
817 s = *it; 823 s = *it;
818 // s.replace( QRegExp( "%20" )," " ); 824 // s.replace( QRegExp( "%20" )," " );
819 DocLnk lnk( s ); 825 DocLnk lnk( s );
820 QFileInfo f( s ); 826 QFileInfo f( s );
821 QString name = f.baseName(); 827 QString name = f.baseName();
822 828
823 if( name.left( 4 ) == "http" ) { 829 if( name.left( 4 ) == "http" ) {
824 name = s.right( s.length() - 7); 830 name = s.right( s.length() - 7);
825 } else { 831 } else {
826 name = s; 832 name = s;
827 } 833 }
828 834
829 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 835 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
830 836
831 lnk.setName( name ); 837 lnk.setName( name );
832 if( s.at( s.length() - 4) == '.') {// if this is probably a file 838 if( s.at( s.length() - 4) == '.') {// if this is probably a file
833 lnk.setFile( s ); 839 lnk.setFile( s );
834 } else { //if its a url 840 } else { //if its a url
835 if( name.right( 1 ).find( '/' ) == -1) { 841 if( name.right( 1 ).find( '/' ) == -1) {
836 s += "/"; 842 s += "/";
837 } 843 }
838 lnk.setFile( s ); 844 lnk.setFile( s );
839 } 845 }
840 lnk.setType( "audio/x-mpegurl" ); 846 lnk.setType( "audio/x-mpegurl" );
841 847
842 lnk.writeLink(); 848 lnk.writeLink();
843 d->selectedFiles->addToSelection( lnk ); 849 d->selectedFiles->addToSelection( lnk );
844 } 850 }
845 851
846 m3uList->close(); 852 m3uList->close();
847 if(m3uList) delete m3uList; 853 if(m3uList) delete m3uList;
848} 854}
849 855
850/* 856/*
851 writes current playlist to current m3u file */ 857 writes current playlist to current m3u file */
852void PlayListWidget::writeCurrentM3u() { 858void PlayListWidget::writeCurrentM3u() {
853 qDebug("writing to current m3u"); 859 qDebug("writing to current m3u");
854 Config cfg( "OpiePlayer" ); 860 Config cfg( "OpiePlayer" );
855 cfg.setGroup("PlayList"); 861 cfg.setGroup("PlayList");
856 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 862 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
857 863
858 if( d->selectedFiles->first()) { 864 if( d->selectedFiles->first()) {
859 Om3u *m3uList; 865 Om3u *m3uList;
860 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); 866 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
861 867
862
863 qDebug( d->selectedFiles->current()->file());
864 do { 868 do {
865 qDebug( d->selectedFiles->current()->file()); 869 qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file());
866 m3uList->add( d->selectedFiles->current()->file() ); 870 m3uList->add( d->selectedFiles->current()->file() );
867 } 871 }
868 while ( d->selectedFiles->next() ); 872 while ( d->selectedFiles->next() );
869 qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); 873 qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" );
870 m3uList->write(); 874 m3uList->write();
871 m3uList->close(); 875 m3uList->close();
872 876
873 if(m3uList) delete m3uList; 877 if(m3uList) delete m3uList;
874 } 878 }
875} 879}
876 880
877 /* 881 /*
878 writes current playlist to m3u file */ 882 writes current playlist to m3u file */
879void PlayListWidget::writem3u() { 883void PlayListWidget::writem3u() {
880 InputDialog *fileDlg; 884 InputDialog *fileDlg;
881 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); 885 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
882 fileDlg->exec(); 886 fileDlg->exec();
883 QString name, filename, list; 887 QString name, filename, list;
884 Om3u *m3uList; 888 Om3u *m3uList;
885 889
886 if( fileDlg->result() == 1 ) { 890 if( fileDlg->result() == 1 ) {
887 name = fileDlg->text(); 891 name = fileDlg->text();
888// qDebug( filename ); 892// qDebug( filename );
889 893
890 if( name.left( 1) != "/" ) { 894 if( name.left( 1) != "/" ) {
891 filename = QPEApplication::documentDir() + "/" + name; 895 filename = QPEApplication::documentDir() + "/" + name;
892 } 896 }
893 897
894 if( name.right( 3 ) != "m3u" ) { 898 if( name.right( 3 ) != "m3u" ) {
895 filename = QPEApplication::documentDir() + "/" +name+".m3u"; 899 filename = QPEApplication::documentDir() + "/" +name+".m3u";
896 } 900 }
897 901
898 if( d->selectedFiles->first()) { 902 if( d->selectedFiles->first()) {
899 m3uList = new Om3u(filename, IO_ReadWrite); 903 m3uList = new Om3u(filename, IO_ReadWrite);
900 904
901 do { 905 do {
902 m3uList->add( d->selectedFiles->current()->file()); 906 m3uList->add( d->selectedFiles->current()->file());
903 } 907 }
904 while ( d->selectedFiles->next() ); 908 while ( d->selectedFiles->next() );
905 // qDebug( list ); 909 // qDebug( list );
906 m3uList->write(); 910 m3uList->write();
907 m3uList->close(); 911 m3uList->close();
908 if(m3uList) delete m3uList; 912 if(m3uList) delete m3uList;
909 913
910 if(fileDlg) delete fileDlg; 914 if(fileDlg) delete fileDlg;
911 915
912 DocLnk lnk; 916 DocLnk lnk;
913 lnk.setFile( filename); 917 lnk.setFile( filename);