Diffstat (limited to 'noncore/multimedia/opieplayer2/playlistwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 108 |
1 files changed, 62 insertions, 46 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 37b998f..dc2c496 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -76,24 +76,26 @@ PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl ) | |||
76 | (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 76 | (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
77 | (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), | 77 | (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), |
78 | this, SLOT( addAllMusicToList() ) ); | 78 | this, SLOT( addAllMusicToList() ) ); |
79 | (void)new MenuItem( pmPlayList, tr( "Add all video files" ), | 79 | (void)new MenuItem( pmPlayList, tr( "Add all video files" ), |
80 | this, SLOT( addAllVideoToList() ) ); | 80 | this, SLOT( addAllVideoToList() ) ); |
81 | (void)new MenuItem( pmPlayList, tr( "Add all files" ), | 81 | (void)new MenuItem( pmPlayList, tr( "Add all files" ), |
82 | this, SLOT( addAllToList() ) ); | 82 | this, SLOT( addAllToList() ) ); |
83 | pmPlayList->insertSeparator(-1); | 83 | pmPlayList->insertSeparator(-1); |
84 | (void)new MenuItem( pmPlayList, tr( "Add File" ), | 84 | (void)new MenuItem( pmPlayList, tr( "Add File" ), |
85 | this,SLOT( openFile() ) ); | 85 | this,SLOT( openFile() ) ); |
86 | (void)new MenuItem( pmPlayList, tr("Add URL"), | 86 | (void)new MenuItem( pmPlayList, tr("Add URL"), |
87 | this,SLOT( openURL() ) ); | 87 | this,SLOT( openURL() ) ); |
88 | (void)new MenuItem( pmPlayList, tr( "Add Directory"), | ||
89 | this, SLOT(openDirectory())); | ||
88 | pmPlayList->insertSeparator(-1); | 90 | pmPlayList->insertSeparator(-1); |
89 | (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), | 91 | (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), |
90 | this, SLOT(writem3u() ) ); | 92 | this, SLOT(writem3u() ) ); |
91 | pmPlayList->insertSeparator(-1); | 93 | pmPlayList->insertSeparator(-1); |
92 | (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), | 94 | (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), |
93 | audioView, SLOT( scanFiles() ) ); | 95 | audioView, SLOT( scanFiles() ) ); |
94 | (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), | 96 | (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), |
95 | videoView, SLOT( scanFiles() ) ); | 97 | videoView, SLOT( scanFiles() ) ); |
96 | 98 | ||
97 | pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), | 99 | pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), |
98 | mediaPlayerState, SLOT( toggleFullscreen() ) ); | 100 | mediaPlayerState, SLOT( toggleFullscreen() ) ); |
99 | 101 | ||
@@ -653,73 +655,94 @@ void PlayListWidget::openURL() { | |||
653 | lnk.setFile( filename ); //sets file name | 655 | lnk.setFile( filename ); //sets file name |
654 | d->selectedFiles->addToSelection( lnk); | 656 | d->selectedFiles->addToSelection( lnk); |
655 | writeCurrentM3u(); | 657 | writeCurrentM3u(); |
656 | d->selectedFiles->setSelectedItem( lnk.name()); | 658 | d->selectedFiles->setSelectedItem( lnk.name()); |
657 | } | 659 | } |
658 | } | 660 | } |
659 | 661 | ||
660 | 662 | ||
661 | delete fileDlg; | 663 | delete fileDlg; |
662 | } | 664 | } |
663 | 665 | ||
664 | 666 | ||
665 | void PlayListWidget::openFile() { | 667 | static MimeTypes fileSelectorMimeTypes() { |
666 | |||
667 | QString filename, name; | ||
668 | |||
669 | Config cfg( "OpiePlayer" ); | ||
670 | cfg.setGroup("Dialog"); | ||
671 | MimeTypes types; | 668 | MimeTypes types; |
672 | QStringList audio, video, all; | 669 | QStringList audio, video, all; |
673 | audio << "audio/*"; | 670 | audio << "audio/*"; |
674 | audio << "playlist/plain"; | 671 | audio << "playlist/plain"; |
675 | audio << "audio/x-ogg"; | 672 | audio << "audio/x-ogg"; |
676 | audio << "audio/x-mpegurl"; | 673 | audio << "audio/x-mpegurl"; |
677 | 674 | ||
678 | video << "video/*"; | 675 | video << "video/*"; |
679 | video << "playlist/plain"; | 676 | video << "playlist/plain"; |
680 | 677 | ||
681 | all += audio; | 678 | all += audio; |
682 | all += video; | 679 | all += video; |
683 | types.insert("All Media Files", all ); | 680 | types.insert("All Media Files", all ); |
684 | types.insert("Audio", audio ); | 681 | types.insert("Audio", audio ); |
685 | types.insert("Video", video ); | 682 | types.insert("Video", video ); |
686 | 683 | ||
687 | QString str = OFileDialog::getOpenFileName( 1, | 684 | return types; |
688 | cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"", | ||
689 | types, 0 ); | ||
690 | |||
691 | if(str.left(2) == "//") { | ||
692 | str=str.right(str.length()-1); | ||
693 | } | 685 | } |
694 | cfg.writeEntry( "LastDirectory" ,QFileInfo( str ).dirPath() ); | ||
695 | 686 | ||
696 | if( !str.isEmpty() ) { | 687 | void PlayListWidget::openFile() { |
697 | 688 | ||
698 | odebug << "Selected filename is " + str << oendl; | 689 | QString filename, name; |
699 | filename = str; | ||
700 | DocLnk lnk; | ||
701 | 690 | ||
702 | if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { | 691 | Config cfg( "OpiePlayer" ); |
703 | readListFromFile( filename ); | 692 | cfg.setGroup("Dialog"); |
693 | MimeTypes types = fileSelectorMimeTypes(); | ||
694 | |||
695 | |||
696 | QString str = OFileDialog::getOpenFileName( 1, QString::null, | ||
697 | QString::null, types, 0, | ||
698 | tr("Add File to Playlist") ); | ||
699 | |||
700 | if( str.isEmpty() ) | ||
701 | return; | ||
702 | |||
703 | if(str.left(2) == "//") str=str.right(str.length()-1); | ||
704 | |||
705 | |||
706 | if( str.right( 3) == "m3u" || str.right(3) == "pls" ) { | ||
707 | readListFromFile( str ); | ||
704 | } else { | 708 | } else { |
705 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 709 | QFileInfo info( str ); |
706 | lnk.setFile( filename ); //sets file name | 710 | DocLnk lnk = addFileToPlaylist( str, info.baseName() ); |
707 | d->selectedFiles->addToSelection( lnk ); | ||
708 | writeCurrentM3u(); | ||
709 | d->selectedFiles->setSelectedItem( lnk.name() ); | 711 | d->selectedFiles->setSelectedItem( lnk.name() ); |
710 | } | 712 | } |
711 | } | 713 | } |
712 | } | ||
713 | 714 | ||
715 | void PlayListWidget::openDirectory() { | ||
716 | QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector, | ||
717 | QString::null, 0, | ||
718 | tr( "Add Files from Directory")); | ||
719 | |||
720 | if(str.isEmpty() ) | ||
721 | return; | ||
722 | |||
723 | if(str.left(2) == "//") str=str.right(str.length()-1); | ||
724 | QDir dir( str ); | ||
725 | QStringList lst = dir.entryList(QDir::Files|QDir::Readable); | ||
726 | |||
727 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
728 | QString filename = str + "/" + *it; | ||
729 | |||
730 | if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) | ||
731 | readListFromFile( filename ); | ||
732 | else { | ||
733 | addFileToPlaylist( filename, QFileInfo(*it).baseName() ); | ||
734 | } | ||
735 | } | ||
736 | } | ||
714 | 737 | ||
715 | void PlayListWidget::readListFromFile( const QString &filename ) { | 738 | void PlayListWidget::readListFromFile( const QString &filename ) { |
716 | odebug << "read list filename " + filename << oendl; | 739 | odebug << "read list filename " + filename << oendl; |
717 | QFileInfo fi(filename); | 740 | QFileInfo fi(filename); |
718 | Om3u *m3uList; | 741 | Om3u *m3uList; |
719 | QString s, name; | 742 | QString s, name; |
720 | m3uList = new Om3u( filename, IO_ReadOnly ); | 743 | m3uList = new Om3u( filename, IO_ReadOnly ); |
721 | if(fi.extension(false).find("m3u",0,false) != -1 ) | 744 | if(fi.extension(false).find("m3u",0,false) != -1 ) |
722 | m3uList->readM3u(); | 745 | m3uList->readM3u(); |
723 | else if(fi.extension(false).find("pls",0,false) != -1 ) | 746 | else if(fi.extension(false).find("pls",0,false) != -1 ) |
724 | m3uList->readPls(); | 747 | m3uList->readPls(); |
725 | 748 | ||
@@ -776,51 +799,34 @@ void PlayListWidget::readListFromFile( const QString &filename ) { | |||
776 | while ( d->selectedFiles->next() ); | 799 | while ( d->selectedFiles->next() ); |
777 | // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; | 800 | // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; |
778 | m3uList->write(); | 801 | m3uList->write(); |
779 | m3uList->close(); | 802 | m3uList->close(); |
780 | } | 803 | } |
781 | delete m3uList; | 804 | delete m3uList; |
782 | 805 | ||
783 | } | 806 | } |
784 | 807 | ||
785 | /* | 808 | /* |
786 | writes current playlist to m3u file */ | 809 | writes current playlist to m3u file */ |
787 | void PlayListWidget::writem3u() { | 810 | void PlayListWidget::writem3u() { |
788 | //InputDilog *fileDlg; | ||
789 | //fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | ||
790 | //fileDlg->exec(); | ||
791 | 811 | ||
792 | Config cfg( "OpiePlayer" ); | 812 | Config cfg( "OpiePlayer" ); |
793 | cfg.setGroup("Dialog"); | 813 | cfg.setGroup("Dialog"); |
794 | MimeTypes types; | 814 | MimeTypes types = fileSelectorMimeTypes(); |
795 | QStringList audio, video, all; | ||
796 | audio << "audio/*"; | ||
797 | audio << "playlist/plain"; | ||
798 | audio << "audio/x-mpegurl"; | ||
799 | 815 | ||
800 | video << "video/*"; | 816 | QString str = OFileDialog::getOpenFileName( 1, QString::null, |
801 | video << "playlist/plain"; | 817 | QString::null, types, 0, |
818 | tr( "Save Playlist" )); | ||
802 | 819 | ||
803 | all += audio; | ||
804 | all += video; | ||
805 | types.insert("All Media Files", all ); | ||
806 | types.insert("Audio", audio ); | ||
807 | types.insert("Video", video ); | ||
808 | |||
809 | QString str = OFileDialog::getOpenFileName( 1, | ||
810 | cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"", | ||
811 | types, 0 ); | ||
812 | if(str.left(2) == "//") str=str.right(str.length()-1); | 820 | if(str.left(2) == "//") str=str.right(str.length()-1); |
813 | cfg.writeEntry("LastDirectory" ,QFileInfo(str).dirPath()); | ||
814 | |||
815 | 821 | ||
816 | QString name, filename, list; | 822 | QString name, filename, list; |
817 | Om3u *m3uList; | 823 | Om3u *m3uList; |
818 | 824 | ||
819 | if( !str.isEmpty() ) { | 825 | if( !str.isEmpty() ) { |
820 | name = str; | 826 | name = str; |
821 | // name = fileDlg->text(); | 827 | // name = fileDlg->text(); |
822 | // odebug << filename << oendl; | 828 | // odebug << filename << oendl; |
823 | if( name.find("/",0,true) != -1) {// assume they specify a file path | 829 | if( name.find("/",0,true) != -1) {// assume they specify a file path |
824 | filename = name; | 830 | filename = name; |
825 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); | 831 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); |
826 | } | 832 | } |
@@ -998,25 +1004,24 @@ PlayListWidget::Entry PlayListWidget::currentEntry() const | |||
998 | return Entry( lnk->name(), lnk->file() ); | 1004 | return Entry( lnk->name(), lnk->file() ); |
999 | } | 1005 | } |
1000 | 1006 | ||
1001 | return Entry( currentFileListPathName() ); | 1007 | return Entry( currentFileListPathName() ); |
1002 | } | 1008 | } |
1003 | 1009 | ||
1004 | QString PlayListWidget::currentFileListPathName() const { | 1010 | QString PlayListWidget::currentFileListPathName() const { |
1005 | return currentFileListView->currentItem()->text( 3 ); | 1011 | return currentFileListView->currentItem()->text( 3 ); |
1006 | } | 1012 | } |
1007 | 1013 | ||
1008 | 1014 | ||
1009 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { | 1015 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { |
1010 | odebug << "qcop message "+msg << oendl; | ||
1011 | QDataStream stream ( data, IO_ReadOnly ); | 1016 | QDataStream stream ( data, IO_ReadOnly ); |
1012 | if ( msg == "play()" ) { //plays current selection | 1017 | if ( msg == "play()" ) { //plays current selection |
1013 | btnPlay( true); | 1018 | btnPlay( true); |
1014 | } else if ( msg == "stop()" ) { | 1019 | } else if ( msg == "stop()" ) { |
1015 | mediaPlayerState->setPlaying( false); | 1020 | mediaPlayerState->setPlaying( false); |
1016 | } else if ( msg == "togglePause()" ) { | 1021 | } else if ( msg == "togglePause()" ) { |
1017 | mediaPlayerState->togglePaused(); | 1022 | mediaPlayerState->togglePaused(); |
1018 | } else if ( msg == "next()" ) { //select next in list | 1023 | } else if ( msg == "next()" ) { //select next in list |
1019 | mediaPlayerState->setNext(); | 1024 | mediaPlayerState->setNext(); |
1020 | } else if ( msg == "prev()" ) { //select previous in list | 1025 | } else if ( msg == "prev()" ) { //select previous in list |
1021 | mediaPlayerState->setPrev(); | 1026 | mediaPlayerState->setPrev(); |
1022 | } else if ( msg == "toggleLooping()" ) { //loop or not loop | 1027 | } else if ( msg == "toggleLooping()" ) { //loop or not loop |
@@ -1039,12 +1044,23 @@ void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { | |||
1039 | QFileInfo fileInfo(file); | 1044 | QFileInfo fileInfo(file); |
1040 | DocLnk lnk; | 1045 | DocLnk lnk; |
1041 | lnk.setName( fileInfo.baseName() ); //sets name | 1046 | lnk.setName( fileInfo.baseName() ); //sets name |
1042 | lnk.setFile( file ); //sets file name | 1047 | lnk.setFile( file ); //sets file name |
1043 | addToSelection( lnk ); | 1048 | addToSelection( lnk ); |
1044 | } else if ( msg == "rem(QString)" ) { //remove from playlist | 1049 | } else if ( msg == "rem(QString)" ) { //remove from playlist |
1045 | QString file; | 1050 | QString file; |
1046 | stream >> file; | 1051 | stream >> file; |
1047 | 1052 | ||
1048 | } | 1053 | } |
1049 | 1054 | ||
1050 | } | 1055 | } |
1056 | |||
1057 | DocLnk PlayListWidget::addFileToPlaylist( const QString& file, | ||
1058 | const QString& name ) { | ||
1059 | DocLnk lnk; | ||
1060 | lnk.setName( name ); //sets name | ||
1061 | lnk.setFile( file ); //sets file name | ||
1062 | d->selectedFiles->addToSelection( lnk ); | ||
1063 | writeCurrentM3u(); | ||
1064 | |||
1065 | return lnk; | ||
1066 | } | ||