-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 299181b..8b295b0 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -967,247 +967,257 @@ void PlayListWidget::scanForAudio() { | |||
967 | // qDebug("scan for audio"); | 967 | // qDebug("scan for audio"); |
968 | files.detachChildren(); | 968 | files.detachChildren(); |
969 | QListIterator<DocLnk> sdit( files.children() ); | 969 | QListIterator<DocLnk> sdit( files.children() ); |
970 | for ( ; sdit.current(); ++sdit ) { | 970 | for ( ; sdit.current(); ++sdit ) { |
971 | delete sdit.current(); | 971 | delete sdit.current(); |
972 | } | 972 | } |
973 | Global::findDocuments( &files, audioMimes); | 973 | Global::findDocuments( &files, audioMimes); |
974 | audioScan = true; | 974 | audioScan = true; |
975 | } | 975 | } |
976 | void PlayListWidget::scanForVideo() { | 976 | void PlayListWidget::scanForVideo() { |
977 | // qDebug("scan for video"); | 977 | // qDebug("scan for video"); |
978 | vFiles.detachChildren(); | 978 | vFiles.detachChildren(); |
979 | QListIterator<DocLnk> sdit( vFiles.children() ); | 979 | QListIterator<DocLnk> sdit( vFiles.children() ); |
980 | for ( ; sdit.current(); ++sdit ) { | 980 | for ( ; sdit.current(); ++sdit ) { |
981 | delete sdit.current(); | 981 | delete sdit.current(); |
982 | } | 982 | } |
983 | Global::findDocuments(&vFiles, "video/*"); | 983 | Global::findDocuments(&vFiles, "video/*"); |
984 | videoScan = true; | 984 | videoScan = true; |
985 | } | 985 | } |
986 | 986 | ||
987 | void PlayListWidget::populateAudioView() { | 987 | void PlayListWidget::populateAudioView() { |
988 | 988 | ||
989 | audioView->clear(); | 989 | audioView->clear(); |
990 | StorageInfo storageInfo; | 990 | StorageInfo storageInfo; |
991 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 991 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
992 | if(!audioScan) scanForAudio(); | 992 | if(!audioScan) scanForAudio(); |
993 | 993 | ||
994 | QListIterator<DocLnk> dit( files.children() ); | 994 | QListIterator<DocLnk> dit( files.children() ); |
995 | QListIterator<FileSystem> it ( fs ); | 995 | QListIterator<FileSystem> it ( fs ); |
996 | 996 | ||
997 | QString storage; | 997 | QString storage; |
998 | for ( ; dit.current(); ++dit ) { | 998 | for ( ; dit.current(); ++dit ) { |
999 | for( ; it.current(); ++it ){ | 999 | for( ; it.current(); ++it ){ |
1000 | const QString name = (*it)->name(); | 1000 | const QString name = (*it)->name(); |
1001 | const QString path = (*it)->path(); | 1001 | const QString path = (*it)->path(); |
1002 | if(dit.current()->file().find(path) != -1 ) storage=name; | 1002 | if(dit.current()->file().find(path) != -1 ) storage=name; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | QListViewItem * newItem; | 1005 | QListViewItem * newItem; |
1006 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { | 1006 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { |
1007 | long size; | 1007 | long size; |
1008 | if( dit.current()->file().left(4) == "http" ) | 1008 | if( dit.current()->file().left(4) == "http" ) |
1009 | size=0; | 1009 | size=0; |
1010 | else | 1010 | else |
1011 | size = QFile( dit.current()->file() ).size(); | 1011 | size = QFile( dit.current()->file() ).size(); |
1012 | // qDebug(dit.current()->name()); | 1012 | // qDebug(dit.current()->name()); |
1013 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1013 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1014 | QString::number(size ), storage, dit.current()->file()); | 1014 | QString::number(size ), storage, dit.current()->file()); |
1015 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 1015 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
1016 | } | 1016 | } |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | void PlayListWidget::populateVideoView() { | 1021 | void PlayListWidget::populateVideoView() { |
1022 | videoView->clear(); | 1022 | videoView->clear(); |
1023 | StorageInfo storageInfo; | 1023 | StorageInfo storageInfo; |
1024 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1024 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1025 | 1025 | ||
1026 | if(!videoScan ) scanForVideo(); | 1026 | if(!videoScan ) scanForVideo(); |
1027 | 1027 | ||
1028 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 1028 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
1029 | QListIterator<FileSystem> it ( fs ); | 1029 | QListIterator<FileSystem> it ( fs ); |
1030 | videoView->clear(); | 1030 | videoView->clear(); |
1031 | QString storage; | 1031 | QString storage; |
1032 | for ( ; Vdit.current(); ++Vdit ) { | 1032 | for ( ; Vdit.current(); ++Vdit ) { |
1033 | for( ; it.current(); ++it ){ | 1033 | for( ; it.current(); ++it ){ |
1034 | const QString name = (*it)->name(); | 1034 | const QString name = (*it)->name(); |
1035 | const QString path = (*it)->path(); | 1035 | const QString path = (*it)->path(); |
1036 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 1036 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | QListViewItem * newItem; | 1039 | QListViewItem * newItem; |
1040 | if ( QFile( Vdit.current()->file()).exists() ) { | 1040 | if ( QFile( Vdit.current()->file()).exists() ) { |
1041 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 1041 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
1042 | QString::number( QFile( Vdit.current()->file() ).size() ), | 1042 | QString::number( QFile( Vdit.current()->file() ).size() ), |
1043 | storage, Vdit.current()->file()); | 1043 | storage, Vdit.current()->file()); |
1044 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | 1044 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); |
1045 | } | 1045 | } |
1046 | } | 1046 | } |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | void PlayListWidget::openFile() { | 1049 | void PlayListWidget::openFile() { |
1050 | qDebug("<<<<<<<<<OPEN File"); | 1050 | qDebug("<<<<<<<<<OPEN File"); |
1051 | QString filename, name; | 1051 | QString filename, name; |
1052 | InputDialog *fileDlg; | 1052 | InputDialog *fileDlg; |
1053 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 1053 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
1054 | fileDlg->exec(); | 1054 | fileDlg->exec(); |
1055 | if( fileDlg->result() == 1 ) { | 1055 | if( fileDlg->result() == 1 ) { |
1056 | filename = fileDlg->text(); | 1056 | filename = fileDlg->text(); |
1057 | qDebug( "Selected filename is " + filename ); | 1057 | qDebug( "Selected filename is " + filename ); |
1058 | // Om3u *m3uList; | 1058 | // Om3u *m3uList; |
1059 | DocLnk lnk; | 1059 | DocLnk lnk; |
1060 | Config cfg( "OpiePlayer" ); | 1060 | Config cfg( "OpiePlayer" ); |
1061 | cfg.setGroup("PlayList"); | 1061 | cfg.setGroup("PlayList"); |
1062 | 1062 | ||
1063 | QString m3uFile; | ||
1064 | m3uFile = filename; | ||
1063 | if(filename.left(4) == "http") { | 1065 | if(filename.left(4) == "http") { |
1064 | QString m3uFile, m3uFilePath; | ||
1065 | if(filename.find(":",8,TRUE) != -1) { //found a port | 1066 | if(filename.find(":",8,TRUE) != -1) { //found a port |
1066 | m3uFile = filename.left( filename.find( ":",8,TRUE)); | ||
1067 | m3uFile = m3uFile.right( 7); | ||
1068 | } else if(filename.left(4) == "http"){ | ||
1069 | m3uFile=filename; | ||
1070 | m3uFile = m3uFile.right( m3uFile.length() - 7); | ||
1071 | } else{ | ||
1072 | m3uFile=filename; | ||
1073 | } | ||
1074 | 1067 | ||
1075 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); | 1068 | // m3uFile = filename.left( filename.find( ":",8,TRUE)); |
1076 | lnk.setName( filename ); //sets name | 1069 | m3uFile = filename; |
1070 | if( m3uFile.right( 1 ).find( '/' ) == -1) { | ||
1071 | m3uFile += "/"; | ||
1072 | } | ||
1073 | filename = m3uFile; | ||
1074 | // qDebug("1 "+m3uFile); | ||
1075 | // } else if(filename.left(4) == "http"){ | ||
1076 | // m3uFile=filename; | ||
1077 | // m3uFile = m3uFile.right( m3uFile.length() - 7); | ||
1078 | // qDebug("2 "+m3uFile); | ||
1079 | // } else{ | ||
1080 | // m3uFile=filename; | ||
1081 | // qDebug("3 "+m3uFile); | ||
1082 | } | ||
1083 | lnk.setName( m3uFile ); //sets name | ||
1077 | lnk.setFile( filename ); //sets file name | 1084 | lnk.setFile( filename ); //sets file name |
1078 | lnk.setIcon("opieplayer2/musicfile"); | 1085 | lnk.setIcon("opieplayer2/musicfile"); |
1079 | d->selectedFiles->addToSelection( lnk ); | 1086 | d->selectedFiles->addToSelection( lnk ); |
1080 | writeCurrentM3u(); | 1087 | writeCurrentM3u(); |
1081 | } | 1088 | } |
1082 | else if( filename.right( 3) == "m3u" ) { | 1089 | else if( filename.right( 3) == "m3u" ) { |
1083 | readm3u( filename ); | 1090 | readm3u( filename ); |
1084 | 1091 | ||
1085 | } else if( filename.right(3) == "pls" ) { | 1092 | } else if( filename.right(3) == "pls" ) { |
1086 | readPls( filename ); | 1093 | readPls( filename ); |
1087 | } else { | 1094 | } else { |
1088 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 1095 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
1089 | lnk.setFile( filename ); //sets file name | 1096 | lnk.setFile( filename ); //sets file name |
1090 | d->selectedFiles->addToSelection( lnk); | 1097 | d->selectedFiles->addToSelection( lnk); |
1091 | writeCurrentM3u(); | 1098 | writeCurrentM3u(); |
1092 | } | 1099 | } |
1093 | } | 1100 | } |
1094 | 1101 | ||
1095 | if( fileDlg ) { | 1102 | if( fileDlg ) { |
1096 | delete fileDlg; | 1103 | delete fileDlg; |
1097 | } | 1104 | } |
1098 | } | 1105 | } |
1099 | 1106 | ||
1100 | 1107 | ||
1101 | /* | 1108 | /* |
1102 | reads m3u and shows files/urls to playlist widget */ | 1109 | reads m3u and shows files/urls to playlist widget */ |
1103 | void PlayListWidget::readm3u( const QString &filename ) { | 1110 | void PlayListWidget::readm3u( const QString &filename ) { |
1104 | qDebug( "read m3u filename " + filename ); | 1111 | qDebug( "read m3u filename " + filename ); |
1105 | 1112 | ||
1106 | Om3u *m3uList; | 1113 | Om3u *m3uList; |
1107 | QString s, name; | 1114 | QString s, name; |
1108 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1115 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1109 | m3uList->readM3u(); | 1116 | m3uList->readM3u(); |
1110 | DocLnk lnk; | 1117 | DocLnk lnk; |
1111 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1118 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1112 | s = *it; | 1119 | s = *it; |
1113 | // qDebug("reading "+ s); | 1120 | // qDebug("reading "+ s); |
1114 | if(s.left(4)=="http") { | 1121 | if(s.left(4)=="http") { |
1115 | lnk.setName( s ); //sets file name | 1122 | lnk.setName( s ); //sets file name |
1116 | lnk.setIcon("opieplayer2/musicfile"); | 1123 | lnk.setIcon("opieplayer2/musicfile"); |
1117 | if(s.right(4) != '.' || s.right(5) != '.') | 1124 | |
1125 | // if(s.right(4) != '.' || s.right(5) != '.') | ||
1126 | if(s.right(4) != '.' || s.right(5) != '.' ) | ||
1127 | if( s.right(1) != "/") | ||
1118 | lnk.setFile( s+"/"); //if url with no extension | 1128 | lnk.setFile( s+"/"); //if url with no extension |
1119 | else | 1129 | else |
1120 | lnk.setFile( s ); //sets file name | 1130 | lnk.setFile( s ); //sets file name |
1121 | 1131 | ||
1122 | } else { | 1132 | } else { |
1123 | // if( QFileInfo( s ).exists() ) { | 1133 | // if( QFileInfo( s ).exists() ) { |
1124 | lnk.setName( fullBaseName ( QFileInfo(s))); | 1134 | lnk.setName( fullBaseName ( QFileInfo(s))); |
1125 | // if(s.right(4) == '.') {//if regular file | 1135 | // if(s.right(4) == '.') {//if regular file |
1126 | if(s.left(1) != "/") { | 1136 | if(s.left(1) != "/") { |
1127 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); | 1137 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); |
1128 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | 1138 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); |
1129 | lnk.setIcon("SoundPlayer"); | 1139 | lnk.setIcon("SoundPlayer"); |
1130 | } else { | 1140 | } else { |
1131 | // qDebug("set link2 "+s); | 1141 | // qDebug("set link2 "+s); |
1132 | lnk.setFile( s); | 1142 | lnk.setFile( s); |
1133 | lnk.setIcon("SoundPlayer"); | 1143 | lnk.setIcon("SoundPlayer"); |
1134 | } | 1144 | } |
1135 | } | 1145 | } |
1136 | d->selectedFiles->addToSelection( lnk ); | 1146 | d->selectedFiles->addToSelection( lnk ); |
1137 | } | 1147 | } |
1138 | Config config( "OpiePlayer" ); | 1148 | Config config( "OpiePlayer" ); |
1139 | config.setGroup( "PlayList" ); | 1149 | config.setGroup( "PlayList" ); |
1140 | 1150 | ||
1141 | config.writeEntry("CurrentPlaylist",filename); | 1151 | config.writeEntry("CurrentPlaylist",filename); |
1142 | config.write(); | 1152 | config.write(); |
1143 | currentPlayList=filename; | 1153 | currentPlayList=filename; |
1144 | 1154 | ||
1145 | // m3uList->write(); | 1155 | // m3uList->write(); |
1146 | m3uList->close(); | 1156 | m3uList->close(); |
1147 | if(m3uList) delete m3uList; | 1157 | if(m3uList) delete m3uList; |
1148 | 1158 | ||
1149 | d->selectedFiles->setSelectedItem( s); | 1159 | d->selectedFiles->setSelectedItem( s); |
1150 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | 1160 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); |
1151 | 1161 | ||
1152 | } | 1162 | } |
1153 | 1163 | ||
1154 | /* | 1164 | /* |
1155 | reads pls and adds files/urls to playlist */ | 1165 | reads pls and adds files/urls to playlist */ |
1156 | void PlayListWidget::readPls( const QString &filename ) { | 1166 | void PlayListWidget::readPls( const QString &filename ) { |
1157 | 1167 | ||
1158 | qDebug( "pls filename is " + filename ); | 1168 | qDebug( "pls filename is " + filename ); |
1159 | Om3u *m3uList; | 1169 | Om3u *m3uList; |
1160 | QString s, name; | 1170 | QString s, name; |
1161 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1171 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1162 | m3uList->readPls(); | 1172 | m3uList->readPls(); |
1163 | 1173 | ||
1164 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1174 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1165 | s = *it; | 1175 | s = *it; |
1166 | // s.replace( QRegExp( "%20" )," " ); | 1176 | // s.replace( QRegExp( "%20" )," " ); |
1167 | DocLnk lnk( s ); | 1177 | DocLnk lnk( s ); |
1168 | QFileInfo f( s ); | 1178 | QFileInfo f( s ); |
1169 | QString name = fullBaseName ( f); | 1179 | QString name = fullBaseName ( f); |
1170 | 1180 | ||
1171 | if( name.left( 4 ) == "http" ) { | 1181 | if( name.left( 4 ) == "http" ) { |
1172 | name = s.right( s.length() - 7); | 1182 | name = s.right( s.length() - 7); |
1173 | } else { | 1183 | } else { |
1174 | name = s; | 1184 | name = s; |
1175 | } | 1185 | } |
1176 | 1186 | ||
1177 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 1187 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
1178 | 1188 | ||
1179 | lnk.setName( name ); | 1189 | lnk.setName( name ); |
1180 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 1190 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
1181 | lnk.setFile( s ); | 1191 | lnk.setFile( s ); |
1182 | } else { //if its a url | 1192 | } else { //if its a url |
1183 | if( name.right( 1 ).find( '/' ) == -1) { | 1193 | if( name.right( 1 ).find( '/' ) == -1) { |
1184 | s += "/"; | 1194 | s += "/"; |
1185 | } | 1195 | } |
1186 | lnk.setFile( s ); | 1196 | lnk.setFile( s ); |
1187 | } | 1197 | } |
1188 | lnk.setType( "audio/x-mpegurl" ); | 1198 | lnk.setType( "audio/x-mpegurl" ); |
1189 | 1199 | ||
1190 | lnk.writeLink(); | 1200 | lnk.writeLink(); |
1191 | d->selectedFiles->addToSelection( lnk ); | 1201 | d->selectedFiles->addToSelection( lnk ); |
1192 | } | 1202 | } |
1193 | 1203 | ||
1194 | m3uList->close(); | 1204 | m3uList->close(); |
1195 | if(m3uList) delete m3uList; | 1205 | if(m3uList) delete m3uList; |
1196 | } | 1206 | } |
1197 | 1207 | ||
1198 | /* | 1208 | /* |
1199 | writes current playlist to current m3u file */ | 1209 | writes current playlist to current m3u file */ |
1200 | void PlayListWidget::writeCurrentM3u() { | 1210 | void PlayListWidget::writeCurrentM3u() { |
1201 | qDebug("writing to current m3u"); | 1211 | qDebug("writing to current m3u"); |
1202 | Config cfg( "OpiePlayer" ); | 1212 | Config cfg( "OpiePlayer" ); |
1203 | cfg.setGroup("PlayList"); | 1213 | cfg.setGroup("PlayList"); |
1204 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 1214 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
1205 | Om3u *m3uList; | 1215 | Om3u *m3uList; |
1206 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); | 1216 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); |
1207 | 1217 | ||
1208 | if( d->selectedFiles->first()) { | 1218 | if( d->selectedFiles->first()) { |
1209 | do { | 1219 | do { |
1210 | qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); | 1220 | qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); |
1211 | m3uList->add( d->selectedFiles->current()->file() ); | 1221 | m3uList->add( d->selectedFiles->current()->file() ); |
1212 | } | 1222 | } |
1213 | while ( d->selectedFiles->next() ); | 1223 | while ( d->selectedFiles->next() ); |