summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-19 12:34:09 (UTC)
committer llornkcor <llornkcor>2002-06-19 12:34:09 (UTC)
commitb55f69a46fd27ce26235029f702c0f3942fde68c (patch) (unidiff)
tree47aa9ca1e9c80367050a93715f384eef2285e7b9
parent1d60bfb5925c5009122ae04009f8e99658436b35 (diff)
downloadopie-b55f69a46fd27ce26235029f702c0f3942fde68c.zip
opie-b55f69a46fd27ce26235029f702c0f3942fde68c.tar.gz
opie-b55f69a46fd27ce26235029f702c0f3942fde68c.tar.bz2
dont crash on malformed urls
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp79
1 files changed, 49 insertions, 30 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 41fcb30..2323ac2 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -395,55 +395,61 @@ void PlayListWidget::writeConfig( Config& cfg ) const {
395 // next time... 395 // next time...
396 if ( !QFile::exists( lnk->linkFile() ) ) { 396 if ( !QFile::exists( lnk->linkFile() ) ) {
397 // the way writing lnks doesn't really check for out 397 // the way writing lnks doesn't really check for out
398 // of disk space, but check it anyway. 398 // of disk space, but check it anyway.
399 if ( !lnk->writeLink() ) { 399 if ( !lnk->writeLink() ) {
400 QMessageBox::critical( 0, tr("Out of space"), 400 QMessageBox::critical( 0, tr("Out of space"),
401 tr( "There was a problem saving " 401 tr( "There was a problem saving "
402 "the playlist.\n" 402 "the playlist.\n"
403 "Your playlist " 403 "Your playlist "
404 "may be missing some entries\n" 404 "may be missing some entries\n"
405 "the next time you start it." ) 405 "the next time you start it." )
406 ); 406 );
407 } 407 }
408 } 408 }
409 noOfFiles++; 409 noOfFiles++;
410 } 410 }
411 } 411 }
412 while ( d->selectedFiles->next() ); 412 while ( d->selectedFiles->next() );
413 cfg.writeEntry("NumberOfFiles", noOfFiles ); 413 cfg.writeEntry("NumberOfFiles", noOfFiles );
414} 414}
415 415
416 416
417void PlayListWidget::addToSelection( const DocLnk& lnk ) { 417void PlayListWidget::addToSelection( const DocLnk& lnk ) {
418// qDebug("add"); 418// qDebug("add");
419 d->setDocumentUsed = FALSE; 419 if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) {
420 if ( mediaPlayerState->playlist() ) { 420 QMessageBox::message("Note","You are trying to play\na malformed url.");
421 if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) 421
422 d->selectedFiles->addToSelection( lnk ); 422 } else {
423
424 d->setDocumentUsed = FALSE;
425 if ( mediaPlayerState->playlist() ) {
426 if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" )
427 d->selectedFiles->addToSelection( lnk );
428 }
429 else
430 mediaPlayerState->setPlaying( TRUE );
423 } 431 }
424 else
425 mediaPlayerState->setPlaying( TRUE );
426} 432}
427 433
428 434
429void PlayListWidget::clearList() { 435void PlayListWidget::clearList() {
430 while ( first() ) 436 while ( first() )
431 d->selectedFiles->removeSelected(); 437 d->selectedFiles->removeSelected();
432} 438}
433 439
434 440
435void PlayListWidget::addAllToList() { 441void PlayListWidget::addAllToList() {
436 DocLnkSet filesAll; 442 DocLnkSet filesAll;
437 Global::findDocuments(&filesAll, "video/*;audio/*"); 443 Global::findDocuments(&filesAll, "video/*;audio/*");
438 QListIterator<DocLnk> Adit( filesAll.children() ); 444 QListIterator<DocLnk> Adit( filesAll.children() );
439 for ( ; Adit.current(); ++Adit ) 445 for ( ; Adit.current(); ++Adit )
440 if(QFileInfo(Adit.current()->file()).exists()) 446 if(QFileInfo(Adit.current()->file()).exists())
441 d->selectedFiles->addToSelection( **Adit ); 447 d->selectedFiles->addToSelection( **Adit );
442} 448}
443 449
444 450
445void PlayListWidget::addAllMusicToList() { 451void PlayListWidget::addAllMusicToList() {
446 QListIterator<DocLnk> dit( files.children() ); 452 QListIterator<DocLnk> dit( files.children() );
447 for ( ; dit.current(); ++dit ) 453 for ( ; dit.current(); ++dit )
448 if(QFileInfo(dit.current()->file()).exists()) 454 if(QFileInfo(dit.current()->file()).exists())
449 d->selectedFiles->addToSelection( **dit ); 455 d->selectedFiles->addToSelection( **dit );
@@ -825,76 +831,80 @@ void PlayListWidget::tabChanged(QWidget *widg) {
825 videoView->clear(); 831 videoView->clear();
826 populateVideoView(); 832 populateVideoView();
827 if( !tbDeletePlaylist->isHidden()) 833 if( !tbDeletePlaylist->isHidden())
828 tbDeletePlaylist->hide(); 834 tbDeletePlaylist->hide();
829 d->tbRemoveFromList->setEnabled(FALSE); 835 d->tbRemoveFromList->setEnabled(FALSE);
830 d->tbAddToList->setEnabled(TRUE); 836 d->tbAddToList->setEnabled(TRUE);
831 } 837 }
832 break; 838 break;
833 case 3: 839 case 3:
834 { 840 {
835 if( tbDeletePlaylist->isHidden()) 841 if( tbDeletePlaylist->isHidden())
836 tbDeletePlaylist->show(); 842 tbDeletePlaylist->show();
837 playLists->reread(); 843 playLists->reread();
838 } 844 }
839 break; 845 break;
840 }; 846 };
841} 847}
842 848
843void PlayListWidget::btnPlay(bool b) { 849void PlayListWidget::btnPlay(bool b) {
844 850
845// mediaPlayerState->setPlaying(b); 851// mediaPlayerState->setPlaying(b);
846 switch ( tabWidget->currentPageIndex()) { 852 switch ( tabWidget->currentPageIndex()) {
847 case 0: 853 case 0:
848 { 854 {
849 855 qDebug("here we are");
850 mediaPlayerState->setPlaying(b); 856 if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 || d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) {
851 } 857 QMessageBox::message("Note","You are trying to play\na malformed url.");
858
859 } else {
860
861 mediaPlayerState->setPlaying(b);
862 } }
852 break; 863 break;
853 case 1: 864 case 1:
854 { 865 {
855 addToSelection( audioView->currentItem() ); 866 addToSelection( audioView->currentItem() );
856 mediaPlayerState->setPlaying(b); 867 mediaPlayerState->setPlaying(b);
857 d->selectedFiles->removeSelected( ); 868 d->selectedFiles->removeSelected( );
858 tabWidget->setCurrentPage(1); 869 tabWidget->setCurrentPage(1);
859 d->selectedFiles->unSelect(); 870 d->selectedFiles->unSelect();
860 insanityBool=FALSE; 871 insanityBool=FALSE;
861// audioView->clearSelection(); 872 }// audioView->clearSelection();
862 }
863 break; 873 break;
864 case 2: 874 case 2:
865 { 875 {
866 addToSelection( videoView->currentItem() ); 876 addToSelection( videoView->currentItem() );
867 mediaPlayerState->setPlaying(b); 877 mediaPlayerState->setPlaying(b);
868 qApp->processEvents(); 878 qApp->processEvents();
869 d->selectedFiles->removeSelected( ); 879 d->selectedFiles->removeSelected( );
870 tabWidget->setCurrentPage(2); 880 tabWidget->setCurrentPage(2);
871 d->selectedFiles->unSelect(); 881 d->selectedFiles->unSelect();
872 insanityBool=FALSE; 882 insanityBool=FALSE;
873// videoView->clearSelection(); 883 }// videoView->clearSelection();
874 }
875 break; 884 break;
876 }; 885 };
886
877} 887}
878 888
879void PlayListWidget::deletePlaylist() { 889void PlayListWidget::deletePlaylist() {
880 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 890 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
881 (tr("You really want to delete\nthis playlist?")), 891 (tr("You really want to delete\nthis playlist?")),
882 (tr("Yes")), (tr("No")), 0 )){ 892 (tr("Yes")), (tr("No")), 0 )){
883 case 0: // Yes clicked, 893 case 0: // Yes clicked,
884 QFile().remove(playLists->selected()->file()); 894 QFile().remove(playLists->selected()->file());
885 QFile().remove(playLists->selected()->linkFile()); 895 QFile().remove(playLists->selected()->linkFile());
886 playLists->reread(); 896 playLists->reread();
887 break; 897 break;
888 case 1: // Cancel 898 case 1: // Cancel
889 break; 899 break;
890 }; 900 };
891} 901}
892 902
893void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) 903void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
894{ 904{
895 switch (mouse) { 905 switch (mouse) {
896 case 1: 906 case 1:
897 break; 907 break;
898 case 2:{ 908 case 2:{
899 909
900 QPopupMenu m; 910 QPopupMenu m;
@@ -1047,74 +1057,78 @@ void PlayListWidget::populateVideoView() {
1047 for( ; it.current(); ++it ){ 1057 for( ; it.current(); ++it ){
1048 const QString name = (*it)->name(); 1058 const QString name = (*it)->name();
1049 const QString path = (*it)->path(); 1059 const QString path = (*it)->path();
1050 if( Vdit.current()->file().find(path) != -1 ) storage=name; 1060 if( Vdit.current()->file().find(path) != -1 ) storage=name;
1051 } 1061 }
1052 1062
1053 QListViewItem * newItem; 1063 QListViewItem * newItem;
1054 if ( QFile( Vdit.current()->file()).exists() ) { 1064 if ( QFile( Vdit.current()->file()).exists() ) {
1055 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), 1065 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(),
1056 QString::number( QFile( Vdit.current()->file()).size() ), storage); 1066 QString::number( QFile( Vdit.current()->file()).size() ), storage);
1057 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); 1067 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" ));
1058 } 1068 }
1059 } 1069 }
1060} 1070}
1061 1071
1062void PlayListWidget::openFile() { 1072void PlayListWidget::openFile() {
1063 QString filename, name; 1073 QString filename, name;
1064 InputDialog *fileDlg; 1074 InputDialog *fileDlg;
1065 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 1075 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
1066 fileDlg->exec(); 1076 fileDlg->exec();
1067 if( fileDlg->result() == 1 ) { 1077 if( fileDlg->result() == 1 ) {
1068 filename = fileDlg->LineEdit1->text(); 1078 filename = fileDlg->LineEdit1->text();
1069// http://205.188.234.129:8030 1079// http://205.188.234.129:8030
1070// http://66.28.68.70:8000 1080// http://66.28.68.70:8000
1071 filename.replace(QRegExp("%20")," "); 1081// filename.replace(QRegExp("%20")," ");
1072 1082 if(filename.find(" ",0,TRUE) != -1 || filename.find("%20",0,TRUE) != -1) {
1073 qDebug("Selected filename is "+filename); 1083 QMessageBox::message("Note","Spaces in urls are not allowed.");
1084 return;
1085 } else {
1086 qDebug("Selected filename is "+filename);
1074 if(filename.right(3) == "m3u") 1087 if(filename.right(3) == "m3u")
1075 readm3u( filename); 1088 readm3u( filename);
1076 else if(filename.right(3) == "pls") 1089 else if(filename.right(3) == "pls")
1077 readPls( filename); 1090 readPls( filename);
1078 else { 1091 else {
1079 DocLnk lnk; 1092 DocLnk lnk;
1080 1093
1081 lnk.setName(filename); //sets file name 1094 lnk.setName(filename); //sets file name
1082 if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") 1095 if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3")
1083 filename += "/"; 1096 filename += "/";
1084 lnk.setFile(filename); //sets File property 1097 lnk.setFile(filename); //sets File property
1085 1098
1086 lnk.setType("audio/x-mpegurl"); 1099 lnk.setType("audio/x-mpegurl");
1087 lnk.setExec("opieplayer"); 1100 lnk.setExec("opieplayer");
1088 lnk.setIcon("opieplayer/MPEGPlayer"); 1101 lnk.setIcon("opieplayer/MPEGPlayer");
1089 1102
1090 if(!lnk.writeLink()) 1103 if(!lnk.writeLink())
1091 qDebug("Writing doclink did not work"); 1104 qDebug("Writing doclink did not work");
1092 d->selectedFiles->addToSelection( lnk); 1105 d->selectedFiles->addToSelection( lnk);
1093// if(fileDlg2) 1106// if(fileDlg2)
1094// delete fileDlg2; 1107// delete fileDlg2;
1095 } 1108 }
1096 } 1109 }
1110 }
1097 if(fileDlg) 1111 if(fileDlg)
1098 delete fileDlg; 1112 delete fileDlg;
1099} 1113}
1100 1114
1101void PlayListWidget::keyReleaseEvent( QKeyEvent *e) 1115void PlayListWidget::keyReleaseEvent( QKeyEvent *e)
1102{ 1116{
1103 switch ( e->key() ) { 1117 switch ( e->key() ) {
1104////////////////////////////// Zaurus keys 1118////////////////////////////// Zaurus keys
1105 case Key_F9: //activity 1119 case Key_F9: //activity
1106// if(audioUI->isHidden()) 1120// if(audioUI->isHidden())
1107// audioUI->showMaximized(); 1121// audioUI->showMaximized();
1108 break; 1122 break;
1109 case Key_F10: //contacts 1123 case Key_F10: //contacts
1110// if( videoUI->isHidden()) 1124// if( videoUI->isHidden())
1111// videoUI->showMaximized(); 1125// videoUI->showMaximized();
1112 break; 1126 break;
1113 case Key_F11: //menu 1127 case Key_F11: //menu
1114 break; 1128 break;
1115 case Key_F12: //home 1129 case Key_F12: //home
1116// doBlank(); 1130// doBlank();
1117 break; 1131 break;
1118 case Key_F13: //mail 1132 case Key_F13: //mail
1119// doUnblank(); 1133// doUnblank();
1120 break; 1134 break;
@@ -1184,81 +1198,86 @@ void PlayListWidget::doUnblank() {
1184 // this crashes opieplayer with a segfault 1198 // this crashes opieplayer with a segfault
1185// int fd; 1199// int fd;
1186// fd=open("/dev/fb0",O_RDWR); 1200// fd=open("/dev/fb0",O_RDWR);
1187 qDebug("do unblanking"); 1201 qDebug("do unblanking");
1188 if (fd != -1) { 1202 if (fd != -1) {
1189 ioctl(fd,FBIOBLANK,0); 1203 ioctl(fd,FBIOBLANK,0);
1190 close(fd); 1204 close(fd);
1191 } 1205 }
1192 QCopEnvelope h("QPE/System", "setBacklight(int)"); 1206 QCopEnvelope h("QPE/System", "setBacklight(int)");
1193 h <<-3;// v[1]; // -3 Force on 1207 h <<-3;// v[1]; // -3 Force on
1194} 1208}
1195 1209
1196void PlayListWidget::readm3u(const QString &filename) { 1210void PlayListWidget::readm3u(const QString &filename) {
1197 1211
1198 qDebug("m3u filename is "+filename); 1212 qDebug("m3u filename is "+filename);
1199 QFile f(filename); 1213 QFile f(filename);
1200 1214
1201 if(f.open(IO_ReadOnly)) { 1215 if(f.open(IO_ReadOnly)) {
1202 QTextStream t(&f); 1216 QTextStream t(&f);
1203 QString s;//, first, second; 1217 QString s;//, first, second;
1204 int i=0; 1218 int i=0;
1205 while ( !t.atEnd()) { 1219 while ( !t.atEnd()) {
1206// Lview->insertLine(t.readLine(),-1); 1220// Lview->insertLine(t.readLine(),-1);
1207 s=t.readLine(); 1221 s=t.readLine();
1208 if(s.find("#",0,TRUE) == -1) { 1222 if(s.find(" ",0,TRUE) != -1 || s.find("%20",0,TRUE) != -1) {
1223 QMessageBox::message("Note","Spaces in urls are not allowed.");
1224 }
1225 else if(s.find("#",0,TRUE) == -1) {
1209 if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat 1226 if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat
1210 if(s.left(2) == "E:" || s.left(2) == "P:") { 1227 if(s.left(2) == "E:" || s.left(2) == "P:") {
1211 s=s.right(s.length()-2); 1228 s=s.right(s.length()-2);
1212 DocLnk lnk( s ); 1229 DocLnk lnk( s );
1213 QFileInfo f(s); 1230 QFileInfo f(s);
1214 QString name = f.baseName(); 1231 QString name = f.baseName();
1215 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); 1232 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
1216 lnk.setName( name); 1233 lnk.setName( name);
1217 s=s.replace( QRegExp("\\"),"/"); 1234 s=s.replace( QRegExp("\\"),"/");
1218 lnk.setFile( s); 1235 lnk.setFile( s);
1219// lnk.setIcon(opieplayer/MPEGPlayer); 1236// lnk.setIcon(opieplayer/MPEGPlayer);
1220 qDebug("add "+name); 1237 qDebug("add "+name);
1221 d->selectedFiles->addToSelection( lnk); 1238 d->selectedFiles->addToSelection( lnk);
1222 } else { // is url 1239 } else { // is url
1240
1223 s.replace(QRegExp("%20")," "); 1241 s.replace(QRegExp("%20")," ");
1224 DocLnk lnk( s); 1242 DocLnk lnk( s);
1225 QString name = s.right( s.length() - 7); 1243 QString name = s.right( s.length() - 7);
1226// name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); 1244// name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
1227 lnk.setName(name); 1245 lnk.setName(name);
1228 lnk.setFile( s+"/"); 1246 lnk.setFile( s+"/");
1229// lnk.setFile( filename); 1247// lnk.setFile( filename);
1230// lnk.setComment( s+"/"); 1248// lnk.setComment( s+"/");
1231 lnk.setType("audio/x-mpegurl"); 1249 lnk.setType("audio/x-mpegurl");
1232// lnk.setIcon( "opieplayer/MPEGPlayer"); 1250// lnk.setIcon( "opieplayer/MPEGPlayer");
1233// qDebug("add "+s); 1251// qDebug("add "+s);
1234 d->selectedFiles->addToSelection( lnk); 1252 d->selectedFiles->addToSelection( lnk);
1235 } 1253 }
1236 i++; 1254 i++;
1237 } 1255 }
1238 } 1256 }
1239 } 1257 }
1240 } 1258 }
1259 f.close();
1241} 1260}
1242 1261
1243void PlayListWidget::writem3u(const QString &filename) { 1262void PlayListWidget::writem3u(const QString &filename) {
1244 1263
1245} 1264}
1246 1265
1247void PlayListWidget::readPls(const QString &filename) { 1266void PlayListWidget::readPls(const QString &filename) {
1248 1267
1249 qDebug("pls filename is "+filename); 1268 qDebug("pls filename is "+filename);
1250 QFile f(filename); 1269 QFile f(filename);
1251 1270
1252 if(f.open(IO_ReadOnly)) { 1271 if(f.open(IO_ReadOnly)) {
1253 QTextStream t(&f); 1272 QTextStream t(&f);
1254 QString s;//, first, second; 1273 QString s;//, first, second;
1255 int i=0; 1274 int i=0;
1256 while ( !t.atEnd()) { 1275 while ( !t.atEnd()) {
1257 s=t.readLine(); 1276 s=t.readLine();
1258 if(s.left(4) == "File") { 1277 if(s.left(4) == "File") {
1259 s=s.right(s.length() - 6); 1278 s=s.right(s.length() - 6);
1260 s.replace(QRegExp("%20")," "); 1279 s.replace(QRegExp("%20")," ");
1261 qDebug("adding "+s+" to playlist"); 1280 qDebug("adding "+s+" to playlist");
1262// numberofentries=2 1281// numberofentries=2
1263// File1=http 1282// File1=http
1264 // Title 1283 // Title