author | llornkcor <llornkcor> | 2005-08-28 19:53:11 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-28 19:53:11 (UTC) |
commit | f680479965bf13285a955873c48db47bd0c935d3 (patch) (unidiff) | |
tree | 58945d235215685b316c00b62d951bd0b6d4df95 /core/multimedia/opieplayer | |
parent | 43217700cc9b23519776a27661fbf0c29a7d100d (diff) | |
download | opie-f680479965bf13285a955873c48db47bd0c935d3.zip opie-f680479965bf13285a955873c48db47bd0c935d3.tar.gz opie-f680479965bf13285a955873c48db47bd0c935d3.tar.bz2 |
podcast! support.. 1st installment. needs improvements
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 344 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.h | 10 | ||||
-rw-r--r-- | core/multimedia/opieplayer/rssparser.cpp | 201 | ||||
-rw-r--r-- | core/multimedia/opieplayer/rssparser.h | 122 |
4 files changed, 567 insertions, 110 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index c0a0029..146dbb6 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -5,49 +5,54 @@ | |||
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // code added by L. J. Potter Sat 03-02-2002 06:17:54 | 20 | // code added by L. J. Potter Sat 03-02-2002 06:17:54 |
21 | #define QTOPIA_INTERNAL_FSLP | 21 | #define QTOPIA_INTERNAL_FSLP |
22 | 22 | ||
23 | #include "playlistselection.h" | 23 | #include "playlistselection.h" |
24 | #include "playlistwidget.h" | 24 | #include "playlistwidget.h" |
25 | #include "mediaplayerstate.h" | 25 | #include "mediaplayerstate.h" |
26 | #include "inputDialog.h" | 26 | #include "inputDialog.h" |
27 | #include "audiowidget.h" | 27 | #include "audiowidget.h" |
28 | #include "videowidget.h" | 28 | #include "videowidget.h" |
29 | #include "rssparser.h" | ||
29 | 30 | ||
31 | #include <qpe/process.h> | ||
32 | |||
33 | #include <qvector.h> | ||
34 | #include <qxml.h> | ||
30 | /* OPIE */ | 35 | /* OPIE */ |
31 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
32 | #include <qpe/qpemenubar.h> | 37 | #include <qpe/qpemenubar.h> |
33 | #include <qpe/lnkproperties.h> | 38 | #include <qpe/lnkproperties.h> |
34 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
35 | #include <opie2/oresource.h> | 40 | #include <opie2/oresource.h> |
36 | 41 | ||
37 | /* QT */ | 42 | /* QT */ |
38 | #include <qtoolbar.h> | 43 | #include <qtoolbar.h> |
39 | #include <qaction.h> | 44 | #include <qaction.h> |
40 | #include <qlayout.h> | 45 | #include <qlayout.h> |
41 | #include <qmessagebox.h> | 46 | #include <qmessagebox.h> |
42 | //#include <qtimer.h> | 47 | //#include <qtimer.h> |
43 | 48 | ||
44 | /* STD */ | 49 | /* STD */ |
45 | #include <stdlib.h> | 50 | #include <stdlib.h> |
46 | 51 | ||
47 | #include <unistd.h> | 52 | #include <unistd.h> |
48 | #include <sys/file.h> | 53 | #include <sys/file.h> |
49 | #include <sys/ioctl.h> | 54 | #include <sys/ioctl.h> |
50 | #include <sys/soundcard.h> | 55 | #include <sys/soundcard.h> |
51 | 56 | ||
52 | // for setBacklight() | 57 | // for setBacklight() |
53 | #include <linux/fb.h> | 58 | #include <linux/fb.h> |
@@ -469,49 +474,49 @@ void PlayListWidget::addAllMusicToList() { | |||
469 | writeCurrentM3u(); | 474 | writeCurrentM3u(); |
470 | d->selectedFiles->first(); | 475 | d->selectedFiles->first(); |
471 | } | 476 | } |
472 | 477 | ||
473 | 478 | ||
474 | void PlayListWidget::addAllVideoToList() { | 479 | void PlayListWidget::addAllVideoToList() { |
475 | QListIterator<DocLnk> dit( vFiles.children() ); | 480 | QListIterator<DocLnk> dit( vFiles.children() ); |
476 | for ( ; dit.current(); ++dit ) | 481 | for ( ; dit.current(); ++dit ) |
477 | if(QFileInfo( dit.current()->file()).exists()) | 482 | if(QFileInfo( dit.current()->file()).exists()) |
478 | d->selectedFiles->addToSelection( **dit ); | 483 | d->selectedFiles->addToSelection( **dit ); |
479 | tabWidget->setCurrentPage(0); | 484 | tabWidget->setCurrentPage(0); |
480 | 485 | ||
481 | writeCurrentM3u(); | 486 | writeCurrentM3u(); |
482 | d->selectedFiles->first(); | 487 | d->selectedFiles->first(); |
483 | } | 488 | } |
484 | 489 | ||
485 | 490 | ||
486 | void PlayListWidget::setDocument(const QString& fileref) { | 491 | void PlayListWidget::setDocument(const QString& fileref) { |
487 | fromSetDocument = true; | 492 | fromSetDocument = true; |
488 | d->setDocumentUsed = TRUE; | 493 | d->setDocumentUsed = TRUE; |
489 | setDocumentEx(fileref); | 494 | setDocumentEx(fileref); |
490 | } | 495 | } |
491 | 496 | ||
492 | void PlayListWidget::setDocumentEx(const QString& fileref) { | 497 | void PlayListWidget::setDocumentEx(const QString& fileref) { |
493 | odebug << "opieplayer receive "+fileref << oendl; | 498 | owarn << "opieplayer receive "+fileref << oendl; |
494 | clearList(); | 499 | clearList(); |
495 | DocLnk lnk; | 500 | DocLnk lnk; |
496 | QFileInfo fileInfo(fileref); | 501 | QFileInfo fileInfo(fileref); |
497 | if ( !fileInfo.exists() ) { | 502 | if ( !fileInfo.exists() ) { |
498 | QMessageBox::critical( 0, tr( "Invalid File" ), | 503 | QMessageBox::critical( 0, tr( "Invalid File" ), |
499 | tr( "There was a problem in getting the file." ) ); | 504 | tr( "There was a problem in getting the file." ) ); |
500 | return; | 505 | return; |
501 | } | 506 | } |
502 | // odebug << "<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref << oendl; | 507 | // odebug << "<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref << oendl; |
503 | QString extension = fileInfo.extension(false); | 508 | QString extension = fileInfo.extension(false); |
504 | if( extension.find( "m3u", 0, false) != -1) { //is m3u | 509 | if( extension.find( "m3u", 0, false) != -1) { //is m3u |
505 | readm3u( fileref); | 510 | readm3u( fileref); |
506 | } | 511 | } |
507 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls | 512 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls |
508 | readPls( fileref); | 513 | readPls( fileref); |
509 | } | 514 | } |
510 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist | 515 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist |
511 | clearList(); | 516 | clearList(); |
512 | lnk.setName( fileInfo.baseName() ); //sets name | 517 | lnk.setName( fileInfo.baseName() ); //sets name |
513 | lnk.setFile( fileref ); //sets file name | 518 | lnk.setFile( fileref ); //sets file name |
514 | lnk.setIcon("Sound"); | 519 | lnk.setIcon("Sound"); |
515 | //addToSelection( lnk ); | 520 | //addToSelection( lnk ); |
516 | 521 | ||
517 | loadList( lnk); | 522 | loadList( lnk); |
@@ -984,49 +989,49 @@ void PlayListWidget::populateAudioView() { | |||
984 | StorageInfo storageInfo; | 989 | StorageInfo storageInfo; |
985 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 990 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
986 | if(!audioScan) scanForAudio(); | 991 | if(!audioScan) scanForAudio(); |
987 | 992 | ||
988 | QListIterator<DocLnk> dit( files.children() ); | 993 | QListIterator<DocLnk> dit( files.children() ); |
989 | QListIterator<FileSystem> it ( fs ); | 994 | QListIterator<FileSystem> it ( fs ); |
990 | 995 | ||
991 | QString storage; | 996 | QString storage; |
992 | for ( ; dit.current(); ++dit ) { | 997 | for ( ; dit.current(); ++dit ) { |
993 | for( ; it.current(); ++it ){ | 998 | for( ; it.current(); ++it ){ |
994 | const QString name = (*it)->name(); | 999 | const QString name = (*it)->name(); |
995 | const QString path = (*it)->path(); | 1000 | const QString path = (*it)->path(); |
996 | if(dit.current()->file().find(path) != -1 ) storage=name; | 1001 | if(dit.current()->file().find(path) != -1 ) storage=name; |
997 | } | 1002 | } |
998 | 1003 | ||
999 | QListViewItem * newItem; | 1004 | QListViewItem * newItem; |
1000 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { | 1005 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { |
1001 | long size; | 1006 | long size; |
1002 | if( dit.current()->file().left(4) == "http" ) | 1007 | if( dit.current()->file().left(4) == "http" ) |
1003 | size=0; | 1008 | size=0; |
1004 | else | 1009 | else |
1005 | size = QFile( dit.current()->file() ).size(); | 1010 | size = QFile( dit.current()->file() ).size(); |
1006 | // odebug << dit.current()->name() << oendl; | 1011 | // odebug << dit.current()->name() << oendl; |
1007 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1012 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1008 | QString::number(size ), storage, dit.current()->file()); | 1013 | QString::number(size ), storage, dit.current()->file()); |
1009 | newItem->setPixmap(0, Opie::Core::OResource::loadPixmap( "opieplayer/musicfile", Opie::Core::OResource::SmallIcon )); | 1014 | newItem->setPixmap(0, Opie::Core::OResource::loadPixmap( "opieplayer/musicfile", Opie::Core::OResource::SmallIcon )); |
1010 | } | 1015 | } |
1011 | } | 1016 | } |
1012 | 1017 | ||
1013 | } | 1018 | } |
1014 | 1019 | ||
1015 | void PlayListWidget::populateVideoView() { | 1020 | void PlayListWidget::populateVideoView() { |
1016 | videoView->clear(); | 1021 | videoView->clear(); |
1017 | StorageInfo storageInfo; | 1022 | StorageInfo storageInfo; |
1018 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1023 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1019 | 1024 | ||
1020 | if(!videoScan ) scanForVideo(); | 1025 | if(!videoScan ) scanForVideo(); |
1021 | 1026 | ||
1022 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 1027 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
1023 | QListIterator<FileSystem> it ( fs ); | 1028 | QListIterator<FileSystem> it ( fs ); |
1024 | videoView->clear(); | 1029 | videoView->clear(); |
1025 | QString storage; | 1030 | QString storage; |
1026 | for ( ; Vdit.current(); ++Vdit ) { | 1031 | for ( ; Vdit.current(); ++Vdit ) { |
1027 | for( ; it.current(); ++it ){ | 1032 | for( ; it.current(); ++it ){ |
1028 | const QString name = (*it)->name(); | 1033 | const QString name = (*it)->name(); |
1029 | const QString path = (*it)->path(); | 1034 | const QString path = (*it)->path(); |
1030 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 1035 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
1031 | } | 1036 | } |
1032 | 1037 | ||
@@ -1042,175 +1047,86 @@ void PlayListWidget::populateVideoView() { | |||
1042 | 1047 | ||
1043 | void PlayListWidget::openFile() { | 1048 | void PlayListWidget::openFile() { |
1044 | QString filename, name; | 1049 | QString filename, name; |
1045 | InputDialog *fileDlg; | 1050 | InputDialog *fileDlg; |
1046 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 1051 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
1047 | fileDlg->exec(); | 1052 | fileDlg->exec(); |
1048 | if( fileDlg->result() == 1 ) { | 1053 | if( fileDlg->result() == 1 ) { |
1049 | filename = fileDlg->text(); | 1054 | filename = fileDlg->text(); |
1050 | // odebug << "Selected filename is " + filename << oendl; | 1055 | // odebug << "Selected filename is " + filename << oendl; |
1051 | DocLnk lnk; | 1056 | DocLnk lnk; |
1052 | Config cfg( "OpiePlayer" ); | 1057 | Config cfg( "OpiePlayer" ); |
1053 | cfg.setGroup("PlayList"); | 1058 | cfg.setGroup("PlayList"); |
1054 | 1059 | ||
1055 | QString m3uFile; | 1060 | QString m3uFile; |
1056 | m3uFile = filename; | 1061 | m3uFile = filename; |
1057 | if(filename.left(4) == "http") { | 1062 | if(filename.left(4) == "http") { |
1058 | if(filename.find(":",8,TRUE) != -1) { //found a port | 1063 | if(filename.find(":",8,TRUE) != -1) { //found a port |
1059 | 1064 | ||
1060 | m3uFile = filename; | 1065 | m3uFile = filename; |
1061 | if( m3uFile.right( 1 ).find( '/' ) == -1) { | 1066 | if( m3uFile.right( 1 ).find( '/' ) == -1) { |
1062 | m3uFile += "/"; | 1067 | m3uFile += "/"; |
1063 | } | 1068 | } |
1064 | filename = m3uFile; | 1069 | filename = m3uFile; |
1065 | } | 1070 | } |
1066 | lnk.setName( m3uFile ); //sets name | 1071 | if( filename.right(3) == "xml" || |
1067 | lnk.setFile( filename ); //sets file name | 1072 | filename.find("rss" ) !=-1) |
1068 | lnk.setIcon("opieplayer2/musicfile"); | 1073 | { |
1069 | d->selectedFiles->addToSelection( lnk ); | 1074 | // readpodcast(filename ); |
1070 | writeCurrentM3u(); | 1075 | downloadPodcast(filename); |
1076 | } else { | ||
1077 | lnk.setName( m3uFile ); //sets name | ||
1078 | lnk.setFile( filename ); //sets file name | ||
1079 | lnk.setIcon("opieplayer2/musicfile"); | ||
1080 | d->selectedFiles->addToSelection( lnk ); | ||
1081 | writeCurrentM3u(); | ||
1082 | } | ||
1071 | } | 1083 | } |
1072 | else if( filename.right( 3) == "m3u" ) { | 1084 | else if( filename.right( 3) == "m3u" ) { |
1073 | readm3u( filename ); | 1085 | readm3u( filename ); |
1074 | 1086 | ||
1075 | } else if( filename.right(3) == "pls" ) { | 1087 | } else if( filename.right(3) == "pls" ) { |
1076 | readPls( filename ); | 1088 | readPls( filename ); |
1089 | } else if( filename.right(3) == "xml" || | ||
1090 | filename.find("rss" ) !=-1 | ||
1091 | ) { | ||
1092 | readpodcast( filename ); | ||
1077 | } else { | 1093 | } else { |
1078 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 1094 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
1079 | lnk.setFile( filename ); //sets file name | 1095 | lnk.setFile( filename ); //sets file name |
1080 | d->selectedFiles->addToSelection( lnk); | 1096 | d->selectedFiles->addToSelection( lnk); |
1081 | lnk.removeLinkFile(); | 1097 | lnk.removeLinkFile(); |
1082 | writeCurrentM3u(); | 1098 | writeCurrentM3u(); |
1083 | } | 1099 | } |
1084 | } | 1100 | } |
1085 | 1101 | ||
1086 | if( fileDlg ) { | 1102 | if( fileDlg ) { |
1087 | delete fileDlg; | 1103 | delete fileDlg; |
1088 | } | 1104 | } |
1089 | } | 1105 | } |
1090 | 1106 | ||
1091 | 1107 | ||
1092 | /* | 1108 | /* |
1093 | reads m3u and shows files/urls to playlist widget */ | ||
1094 | void PlayListWidget::readm3u( const QString &filename ) { | ||
1095 | // odebug << "read m3u filename " + filename << oendl; | ||
1096 | |||
1097 | Om3u *m3uList; | ||
1098 | QString s, name; | ||
1099 | m3uList = new Om3u( filename, IO_ReadOnly ); | ||
1100 | m3uList->readM3u(); | ||
1101 | DocLnk lnk; | ||
1102 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | ||
1103 | s = *it; | ||
1104 | // odebug << "reading "+ s << oendl; | ||
1105 | if(s.left(4)=="http") { | ||
1106 | lnk.setName( s ); //sets file name | ||
1107 | lnk.setIcon("opieplayer2/musicfile"); | ||
1108 | |||
1109 | // if(s.right(4) != '.' || s.right(5) != '.') | ||
1110 | if(s.right(4) != '.' || s.right(5) != '.' ) | ||
1111 | if( s.right(1) != "/") | ||
1112 | lnk.setFile( s+"/"); //if url with no extension | ||
1113 | else | ||
1114 | lnk.setFile( s ); //sets file name | ||
1115 | |||
1116 | } else { | ||
1117 | // if( QFileInfo( s ).exists() ) { | ||
1118 | lnk.setName( fullBaseName ( QFileInfo(s))); | ||
1119 | // if(s.right(4) == '.') {//if regular file | ||
1120 | if(s.left(1) != "/") { | ||
1121 | // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl; | ||
1122 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | ||
1123 | lnk.setIcon("SoundPlayer"); | ||
1124 | } else { | ||
1125 | // odebug << "set link2 "+s << oendl; | ||
1126 | lnk.setFile( s); | ||
1127 | lnk.setIcon("SoundPlayer"); | ||
1128 | } | ||
1129 | } | ||
1130 | d->selectedFiles->addToSelection( lnk ); | ||
1131 | } | ||
1132 | Config config( "OpiePlayer" ); | ||
1133 | config.setGroup( "PlayList" ); | ||
1134 | |||
1135 | config.writeEntry("CurrentPlaylist",filename); | ||
1136 | config.write(); | ||
1137 | currentPlayList=filename; | ||
1138 | |||
1139 | // m3uList->write(); | ||
1140 | m3uList->close(); | ||
1141 | if(m3uList) delete m3uList; | ||
1142 | |||
1143 | d->selectedFiles->setSelectedItem( s); | ||
1144 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | ||
1145 | |||
1146 | } | ||
1147 | |||
1148 | /* | ||
1149 | reads pls and adds files/urls to playlist */ | ||
1150 | void PlayListWidget::readPls( const QString &filename ) { | ||
1151 | |||
1152 | // odebug << "pls filename is " + filename << oendl; | ||
1153 | Om3u *m3uList; | ||
1154 | QString s, name; | ||
1155 | m3uList = new Om3u( filename, IO_ReadOnly ); | ||
1156 | m3uList->readPls(); | ||
1157 | |||
1158 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | ||
1159 | s = *it; | ||
1160 | // s.replace( QRegExp( "%20" )," " ); | ||
1161 | DocLnk lnk( s ); | ||
1162 | QFileInfo f( s ); | ||
1163 | QString name = fullBaseName ( f); | ||
1164 | |||
1165 | if( name.left( 4 ) == "http" ) { | ||
1166 | name = s.right( s.length() - 7); | ||
1167 | } else { | ||
1168 | name = s; | ||
1169 | } | ||
1170 | |||
1171 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | ||
1172 | |||
1173 | lnk.setName( name ); | ||
1174 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | ||
1175 | lnk.setFile( s ); | ||
1176 | } else { //if its a url | ||
1177 | if( name.right( 1 ).find( '/' ) == -1) { | ||
1178 | s += "/"; | ||
1179 | } | ||
1180 | lnk.setFile( s ); | ||
1181 | } | ||
1182 | lnk.setType( "audio/x-mpegurl" ); | ||
1183 | |||
1184 | lnk.writeLink(); | ||
1185 | d->selectedFiles->addToSelection( lnk ); | ||
1186 | } | ||
1187 | |||
1188 | m3uList->close(); | ||
1189 | if(m3uList) delete m3uList; | ||
1190 | } | ||
1191 | |||
1192 | /* | ||
1193 | writes current playlist to current m3u file */ | 1109 | writes current playlist to current m3u file */ |
1194 | void PlayListWidget::writeCurrentM3u() { | 1110 | void PlayListWidget::writeCurrentM3u() { |
1195 | // odebug << "writing to current m3u" << oendl; | 1111 | // odebug << "writing to current m3u" << oendl; |
1196 | Config cfg( "OpiePlayer" ); | 1112 | Config cfg( "OpiePlayer" ); |
1197 | cfg.setGroup("PlayList"); | 1113 | cfg.setGroup("PlayList"); |
1198 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); | 1114 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); |
1199 | Om3u *m3uList; | 1115 | Om3u *m3uList; |
1200 | m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); | 1116 | m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); |
1201 | 1117 | ||
1202 | if( d->selectedFiles->first()) { | 1118 | if( d->selectedFiles->first()) { |
1203 | do { | 1119 | do { |
1204 | // odebug << "writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; | 1120 | // odebug << "writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; |
1205 | m3uList->add( d->selectedFiles->current()->file() ); | 1121 | m3uList->add( d->selectedFiles->current()->file() ); |
1206 | } | 1122 | } |
1207 | while ( d->selectedFiles->next() ); | 1123 | while ( d->selectedFiles->next() ); |
1208 | // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; | 1124 | // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; |
1209 | m3uList->write(); | 1125 | m3uList->write(); |
1210 | m3uList->close(); | 1126 | m3uList->close(); |
1211 | 1127 | ||
1212 | if(m3uList) delete m3uList; | 1128 | if(m3uList) delete m3uList; |
1213 | } | 1129 | } |
1214 | } | 1130 | } |
1215 | 1131 | ||
1216 | /* | 1132 | /* |
@@ -1441,24 +1357,238 @@ void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { | |||
1441 | // emit moreClicked(); | 1357 | // emit moreClicked(); |
1442 | // emit moreReleased(); | 1358 | // emit moreReleased(); |
1443 | } else if ( msg == "volDown()" ) { //volume less | 1359 | } else if ( msg == "volDown()" ) { //volume less |
1444 | // emit lessClicked(); | 1360 | // emit lessClicked(); |
1445 | // emit lessReleased(); | 1361 | // emit lessReleased(); |
1446 | } else if ( msg == "play(QString)" ) { //play this now | 1362 | } else if ( msg == "play(QString)" ) { //play this now |
1447 | QString file; | 1363 | QString file; |
1448 | stream >> file; | 1364 | stream >> file; |
1449 | setDocumentEx( (const QString &) file); | 1365 | setDocumentEx( (const QString &) file); |
1450 | } else if ( msg == "add(QString)" ) { //add to playlist | 1366 | } else if ( msg == "add(QString)" ) { //add to playlist |
1451 | QString file; | 1367 | QString file; |
1452 | stream >> file; | 1368 | stream >> file; |
1453 | QFileInfo fileInfo(file); | 1369 | QFileInfo fileInfo(file); |
1454 | DocLnk lnk; | 1370 | DocLnk lnk; |
1455 | lnk.setName( fileInfo.baseName() ); //sets name | 1371 | lnk.setName( fileInfo.baseName() ); //sets name |
1456 | lnk.setFile( file ); //sets file name | 1372 | lnk.setFile( file ); //sets file name |
1457 | addToSelection( lnk ); | 1373 | addToSelection( lnk ); |
1458 | } else if ( msg == "rem(QString)" ) { //remove from playlist | 1374 | } else if ( msg == "rem(QString)" ) { //remove from playlist |
1459 | QString file; | 1375 | QString file; |
1460 | stream >> file; | 1376 | stream >> file; |
1461 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop | 1377 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop |
1462 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); | 1378 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); |
1463 | } | 1379 | } |
1464 | } | 1380 | } |
1381 | |||
1382 | /* | ||
1383 | reads m3u and shows files/urls to playlist widget */ | ||
1384 | void PlayListWidget::readm3u( const QString &filename ) { | ||
1385 | // odebug << "read m3u filename " + filename << oendl; | ||
1386 | |||
1387 | Om3u *m3uList; | ||
1388 | QString s, name; | ||
1389 | m3uList = new Om3u( filename, IO_ReadOnly ); | ||
1390 | m3uList->readM3u(); | ||
1391 | DocLnk lnk; | ||
1392 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | ||
1393 | s = *it; | ||
1394 | // odebug << "reading "+ s << oendl; | ||
1395 | if(s.left(4)=="http") { | ||
1396 | lnk.setName( s ); //sets file name | ||
1397 | lnk.setIcon("opieplayer2/musicfile"); | ||
1398 | |||
1399 | // if(s.right(4) != '.' || s.right(5) != '.') | ||
1400 | if(s.right(4) != '.' || s.right(5) != '.' ) | ||
1401 | if( s.right(1) != "/") | ||
1402 | lnk.setFile( s+"/"); //if url with no extension | ||
1403 | else | ||
1404 | lnk.setFile( s ); //sets file name | ||
1405 | |||
1406 | } else { | ||
1407 | // if( QFileInfo( s ).exists() ) { | ||
1408 | lnk.setName( fullBaseName ( QFileInfo(s))); | ||
1409 | // if(s.right(4) == '.') {//if regular file | ||
1410 | if(s.left(1) != "/") { | ||
1411 | // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl; | ||
1412 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | ||
1413 | lnk.setIcon("SoundPlayer"); | ||
1414 | } else { | ||
1415 | // odebug << "set link2 "+s << oendl; | ||
1416 | lnk.setFile( s); | ||
1417 | lnk.setIcon("SoundPlayer"); | ||
1418 | } | ||
1419 | } | ||
1420 | d->selectedFiles->addToSelection( lnk ); | ||
1421 | } | ||
1422 | Config config( "OpiePlayer" ); | ||
1423 | config.setGroup( "PlayList" ); | ||
1424 | |||
1425 | config.writeEntry("CurrentPlaylist",filename); | ||
1426 | config.write(); | ||
1427 | currentPlayList=filename; | ||
1428 | |||
1429 | // m3uList->write(); | ||
1430 | m3uList->close(); | ||
1431 | if(m3uList) delete m3uList; | ||
1432 | |||
1433 | d->selectedFiles->setSelectedItem( s); | ||
1434 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | ||
1435 | |||
1436 | } | ||
1437 | |||
1438 | /* | ||
1439 | reads pls and adds files/urls to playlist */ | ||
1440 | void PlayListWidget::readPls( const QString &filename ) | ||
1441 | { | ||
1442 | // odebug << "pls filename is " + filename << oendl; | ||
1443 | Om3u *m3uList; | ||
1444 | QString s, name; | ||
1445 | m3uList = new Om3u( filename, IO_ReadOnly ); | ||
1446 | m3uList->readPls(); | ||
1447 | |||
1448 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | ||
1449 | s = *it; | ||
1450 | // s.replace( QRegExp( "%20" )," " ); | ||
1451 | DocLnk lnk( s ); | ||
1452 | QFileInfo f( s ); | ||
1453 | QString name = fullBaseName ( f); | ||
1454 | |||
1455 | if( name.left( 4 ) == "http" ) { | ||
1456 | name = s.right( s.length() - 7); | ||
1457 | } else { | ||
1458 | name = s; | ||
1459 | } | ||
1460 | |||
1461 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | ||
1462 | |||
1463 | lnk.setName( name ); | ||
1464 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | ||
1465 | lnk.setFile( s ); | ||
1466 | } else { //if its a url | ||
1467 | if( name.right( 1 ).find( '/' ) == -1) { | ||
1468 | s += "/"; | ||
1469 | } | ||
1470 | lnk.setFile( s ); | ||
1471 | } | ||
1472 | lnk.setType( "audio/x-mpegurl" ); | ||
1473 | |||
1474 | lnk.writeLink(); | ||
1475 | d->selectedFiles->addToSelection( lnk ); | ||
1476 | } | ||
1477 | |||
1478 | m3uList->close(); | ||
1479 | if(m3uList) delete m3uList; | ||
1480 | } | ||
1481 | |||
1482 | bool PlayListWidget::readpodcast( const QString &filename ) | ||
1483 | { | ||
1484 | QStringList latestPodCast; | ||
1485 | //download url | ||
1486 | qWarning("podcast "+filename); | ||
1487 | QFileInfo info(filename); | ||
1488 | if (info.size() > 0) { | ||
1489 | bool result = false; | ||
1490 | // qWarning("parseDoc " + feedFile.name() ); | ||
1491 | QFile file(filename); | ||
1492 | QXmlInputSource source( file); | ||
1493 | QXmlSimpleReader reader; | ||
1494 | // reader.setFeature("http://xml.org/sax/features/namespaces", true); | ||
1495 | // reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); | ||
1496 | // reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false); | ||
1497 | |||
1498 | reader.setContentHandler( &rssHandler); | ||
1499 | reader.setErrorHandler( &rssHandler); | ||
1500 | result = reader.parse( source); | ||
1501 | if (!result) { | ||
1502 | QMessageBox::critical(0, "Error", tr("<p>Error unable to parse file.</p>")); | ||
1503 | // qWarning("Error unable to parse file\n%s", handler.errorMessage.local8Bit().data()); | ||
1504 | return false; | ||
1505 | } else { | ||
1506 | int size = rssHandler.getItems().size(); | ||
1507 | qWarning( rssHandler.getChannelInfo().join("\n")); | ||
1508 | |||
1509 | for(int i = 0; i < size; i++) { | ||
1510 | QList<QStringList> attributesList = rssHandler.getItems().at(i)->attributes; | ||
1511 | QStringList *sList; | ||
1512 | QStringList attList; | ||
1513 | for(sList = attributesList.first(); sList !=0; sList = attributesList.next()) { | ||
1514 | for( QStringList::Iterator it = sList->begin(); it != sList->end(); ++it ) { | ||
1515 | attList << (*it); | ||
1516 | } | ||
1517 | if(i == 0) { //this assumes that the latest is the first | ||
1518 | latestPodCast << attList[2]; //this is our mp3 url | ||
1519 | latestPodCast << rssHandler.getItems().at(i)->title; | ||
1520 | latestPodCast << rssHandler.getItems().at(i)->description; | ||
1521 | latestPodCast << rssHandler.getItems().at(i)->pubdate; | ||
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | QString s = latestPodCast[0]; //this is our mp3 url | ||
1526 | |||
1527 | // http://www.davesipaq.com/podcast.xml | ||
1528 | DocLnk lnk( s ); | ||
1529 | QFileInfo f( s ); | ||
1530 | QString name = fullBaseName ( f); | ||
1531 | |||
1532 | if( name.left( 4 ) == "http" ) { | ||
1533 | name = s.right( s.length() - 7); | ||
1534 | } else { | ||
1535 | name = s; | ||
1536 | } | ||
1537 | |||
1538 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | ||
1539 | |||
1540 | lnk.setName( name ); | ||
1541 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | ||
1542 | lnk.setFile( s ); | ||
1543 | } else { //if its a url | ||
1544 | if( name.right( 1 ).find( '/' ) == -1) { | ||
1545 | s += "/"; | ||
1546 | } | ||
1547 | lnk.setFile( s ); | ||
1548 | } | ||
1549 | lnk.setType( "audio/x-mpegurl" ); | ||
1550 | |||
1551 | lnk.writeLink(); | ||
1552 | d->selectedFiles->addToSelection( lnk ); | ||
1553 | |||
1554 | } | ||
1555 | } else { | ||
1556 | QMessageBox::critical( 0, "Qtopia Rss", tr("<p>Sorry, could not find the requested document.</p>")); | ||
1557 | return false; | ||
1558 | } | ||
1559 | |||
1560 | qWarning( latestPodCast.join("\n")); | ||
1561 | |||
1562 | return true; | ||
1563 | } | ||
1564 | |||
1565 | bool PlayListWidget::downloadPodcast(const QString &url) | ||
1566 | { | ||
1567 | qWarning("download "+url); | ||
1568 | QString localFile; | ||
1569 | localFile = url; | ||
1570 | localFile = localFile.mid(7, localFile.length()-7); | ||
1571 | |||
1572 | localFile = localFile.replace(QRegExp("/"), "_"); | ||
1573 | localFile = localFile.replace(QRegExp("&"), "_"); | ||
1574 | localFile = localFile.replace(QRegExp("="), "_"); | ||
1575 | localFile = localFile.replace(QRegExp("\\?"), "_"); | ||
1576 | localFile = localFile.replace(QRegExp("@"), "_"); | ||
1577 | localFile = QDir::homeDirPath()+"/Settings/"+localFile; | ||
1578 | |||
1579 | #warning FIXME | ||
1580 | QString cmd; | ||
1581 | cmd = "wget "; | ||
1582 | cmd +=" -O "; | ||
1583 | cmd += localFile + " " + url; | ||
1584 | qWarning(cmd); | ||
1585 | system(cmd.latin1()); | ||
1586 | // Process ipkg_status(QStringList()<< "wget" <<"-O" << localFile << url ); | ||
1587 | // QString out; | ||
1588 | // bool r = ipkg_status.exec("",out); | ||
1589 | // if(r) | ||
1590 | // qWarning(out); | ||
1591 | readpodcast(localFile); | ||
1592 | return true; | ||
1593 | } | ||
1594 | |||
diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h index 0c0e367..6e9acc0 100644 --- a/core/multimedia/opieplayer/playlistwidget.h +++ b/core/multimedia/opieplayer/playlistwidget.h | |||
@@ -8,131 +8,135 @@ | |||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef PLAY_LIST_WIDGET_H | 20 | #ifndef PLAY_LIST_WIDGET_H |
21 | #define PLAY_LIST_WIDGET_H | 21 | #define PLAY_LIST_WIDGET_H |
22 | 22 | ||
23 | #include <qmainwindow.h> | 23 | #include <qmainwindow.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qtabwidget.h> | 25 | #include <qtabwidget.h> |
26 | #include <qpe/fileselector.h> | 26 | #include <qpe/fileselector.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | 28 | ||
29 | #include <qpe/qcopenvelope_qws.h> | 29 | #include <qpe/qcopenvelope_qws.h> |
30 | 30 | ||
31 | #include "om3u.h" | 31 | #include "om3u.h" |
32 | #include "rssparser.h" | ||
32 | /* #include <qtimer.h> */ | 33 | /* #include <qtimer.h> */ |
33 | 34 | ||
34 | 35 | ||
35 | class PlayListWidgetPrivate; | 36 | class PlayListWidgetPrivate; |
36 | class Config; | 37 | class Config; |
37 | class QListViewItem; | 38 | class QListViewItem; |
38 | class QListView; | 39 | class QListView; |
39 | class QPoint; | 40 | class QPoint; |
40 | class QAction; | 41 | class QAction; |
41 | class QLabel; | 42 | class QLabel; |
42 | class QPopupMenu; | 43 | class QPopupMenu; |
43 | 44 | ||
44 | class PlayListWidget : public QMainWindow { | 45 | class PlayListWidget : public QMainWindow { |
45 | Q_OBJECT | 46 | Q_OBJECT |
46 | public: | 47 | public: |
47 | PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); | 48 | PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); |
48 | ~PlayListWidget(); | 49 | ~PlayListWidget(); |
49 | QTabWidget * tabWidget; | 50 | QTabWidget * tabWidget; |
50 | QAction *fullScreenButton, *scaleButton; | 51 | QAction *fullScreenButton, *scaleButton; |
51 | DocLnkSet files; | 52 | DocLnkSet files; |
52 | DocLnkSet vFiles; | 53 | DocLnkSet vFiles; |
53 | QListView *audioView, *videoView, *playlistView; | 54 | QListView *audioView, *videoView, *playlistView; |
54 | QLabel *libString; | 55 | QLabel *libString; |
55 | bool fromSetDocument; | 56 | bool fromSetDocument; |
56 | bool insanityBool; | 57 | bool insanityBool; |
57 | QString setDocFileRef, currentPlayList; | 58 | QString setDocFileRef, currentPlayList; |
58 | // retrieve the current playlist entry (media file link) | 59 | // retrieve the current playlist entry (media file link) |
59 | const DocLnk *current(); | 60 | const DocLnk *current(); |
60 | void useSelectedDocument(); | 61 | void useSelectedDocument(); |
61 | /* QTimer * menuTimer; */ | 62 | /* QTimer * menuTimer; */ |
62 | FileSelector* playLists; | 63 | FileSelector* playLists; |
63 | QPushButton *tbDeletePlaylist; | 64 | QPushButton *tbDeletePlaylist; |
64 | int fd, selected; | 65 | int fd, selected; |
65 | public slots: | 66 | public slots: |
66 | bool first(); | 67 | bool first(); |
67 | bool last(); | 68 | bool last(); |
68 | bool next(); | 69 | bool next(); |
69 | bool prev(); | 70 | bool prev(); |
70 | /* void setFullScreen(); */ | 71 | /* void setFullScreen(); */ |
71 | /* void setScaled(); */ | 72 | /* void setScaled(); */ |
72 | protected: | 73 | protected: |
73 | QCopChannel * channel; | 74 | QCopChannel * channel; |
74 | QPopupMenu *skinsMenu; | 75 | QPopupMenu *skinsMenu; |
75 | /* void contentsMousePressEvent( QMouseEvent * e ); */ | 76 | /* void contentsMousePressEvent( QMouseEvent * e ); */ |
76 | /* void contentsMouseReleaseEvent( QMouseEvent * e ); */ | 77 | /* void contentsMouseReleaseEvent( QMouseEvent * e ); */ |
77 | void keyReleaseEvent( QKeyEvent *e); | 78 | void keyReleaseEvent( QKeyEvent *e); |
78 | void keyPressEvent( QKeyEvent *e); | 79 | void keyPressEvent( QKeyEvent *e); |
79 | private: | 80 | private: |
81 | RssParser rssHandler; | ||
80 | int defaultSkinIndex; | 82 | int defaultSkinIndex; |
81 | bool audioScan, videoScan; | 83 | bool audioScan, videoScan; |
82 | void doBlank(); | 84 | void doBlank(); |
83 | void doUnblank(); | 85 | void doUnblank(); |
84 | void readm3u(const QString &); | 86 | void readm3u(const QString &); |
85 | void readPls(const QString &); | 87 | void readPls(const QString &); |
86 | 88 | bool readpodcast(const QString&); | |
87 | 89 | ||
88 | void initializeStates(); | 90 | void initializeStates(); |
89 | void readConfig( Config& cfg ); | 91 | void readConfig( Config& cfg ); |
90 | void writeConfig( Config& cfg ) const; | 92 | void writeConfig( Config& cfg ) const; |
91 | PlayListWidgetPrivate *d; // Private implementation data | 93 | PlayListWidgetPrivate *d; // Private implementation data |
92 | void populateAudioView(); | 94 | void populateAudioView(); |
93 | void populateVideoView(); | 95 | void populateVideoView(); |
94 | private slots: | 96 | private slots: |
95 | 97 | ||
96 | void qcopReceive(const QCString&, const QByteArray&); | 98 | void qcopReceive(const QCString&, const QByteArray&); |
97 | void populateSkinsMenu(); | 99 | void populateSkinsMenu(); |
98 | void skinsMenuActivated(int); | 100 | void skinsMenuActivated(int); |
99 | void writem3u(); | 101 | void writem3u(); |
100 | void writeCurrentM3u(); | 102 | void writeCurrentM3u(); |
101 | void scanForAudio(); | 103 | void scanForAudio(); |
102 | void scanForVideo(); | 104 | void scanForVideo(); |
103 | void openFile(); | 105 | void openFile(); |
104 | void setDocument( const QString& fileref ); | 106 | void setDocument( const QString& fileref ); |
105 | void setDocumentEx( const QString& fileref ); | 107 | void setDocumentEx( const QString& fileref ); |
106 | void addToSelection( const DocLnk& ); // Add a media file to the playlist | 108 | void addToSelection( const DocLnk& ); // Add a media file to the playlist |
107 | void addToSelection( QListViewItem* ); // Add a media file to the playlist | 109 | void addToSelection( QListViewItem* ); // Add a media file to the playlist |
108 | void setActiveWindow(); // need to handle this to show the right view | 110 | void setActiveWindow(); // need to handle this to show the right view |
109 | void setPlaylist( bool ); // Show/Hide the playlist | 111 | void setPlaylist( bool ); // Show/Hide the playlist |
110 | void setView( char ); | 112 | void setView( char ); |
111 | void clearList(); | 113 | void clearList(); |
112 | void addAllToList(); | 114 | void addAllToList(); |
113 | void addAllMusicToList(); | 115 | void addAllMusicToList(); |
114 | void addAllVideoToList(); | 116 | void addAllVideoToList(); |
115 | void saveList(); // Save the playlist | 117 | void saveList(); // Save the playlist |
116 | void loadList( const DocLnk &); // Load a playlist | 118 | void loadList( const DocLnk &); // Load a playlist |
117 | void playIt( QListViewItem *); | 119 | void playIt( QListViewItem *); |
118 | 120 | ||
119 | void btnPlay(bool); | 121 | void btnPlay(bool); |
120 | void deletePlaylist(); | 122 | void deletePlaylist(); |
121 | void addSelected(); | 123 | void addSelected(); |
122 | void removeSelected(); | 124 | void removeSelected(); |
123 | void tabChanged(QWidget*); | 125 | void tabChanged(QWidget*); |
124 | void viewPressed( int, QListViewItem *, const QPoint&, int); | 126 | void viewPressed( int, QListViewItem *, const QPoint&, int); |
125 | void playlistViewPressed( int, QListViewItem *, const QPoint&, int); | 127 | void playlistViewPressed( int, QListViewItem *, const QPoint&, int); |
126 | void playSelected(); | 128 | void playSelected(); |
127 | void listDelete(); | 129 | void listDelete(); |
130 | |||
131 | bool downloadPodcast(const QString &); | ||
128 | 132 | ||
129 | protected slots: | 133 | protected slots: |
130 | /* void cancelMenuTimer(); */ | 134 | /* void cancelMenuTimer(); */ |
131 | /* void showFileMenu(); */ | 135 | /* void showFileMenu(); */ |
132 | 136 | ||
133 | 137 | ||
134 | }; | 138 | }; |
135 | 139 | ||
136 | 140 | ||
137 | #endif // PLAY_LIST_WIDGET_H | 141 | #endif // PLAY_LIST_WIDGET_H |
138 | 142 | ||
diff --git a/core/multimedia/opieplayer/rssparser.cpp b/core/multimedia/opieplayer/rssparser.cpp new file mode 100644 index 0000000..ec81409 --- a/dev/null +++ b/core/multimedia/opieplayer/rssparser.cpp | |||
@@ -0,0 +1,201 @@ | |||
1 | /*************************************************************************** | ||
2 | * Copyright (C) 2004 by ljp * | ||
3 | * lpotter@trolltech.com * | ||
4 | * * | ||
5 | * This program may be distributed under the terms of the Q Public * | ||
6 | * License as defined by Trolltech AS of Norway and appearing in the * | ||
7 | * file LICENSE.QPL included in the packaging of this file. * | ||
8 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * | ||
12 | ***************************************************************************/ | ||
13 | #include "rssparser.h" | ||
14 | |||
15 | #include <qstring.h> | ||
16 | #include <qmessagebox.h> | ||
17 | #include <qlist.h> | ||
18 | |||
19 | RssParser::RssParser() | ||
20 | { | ||
21 | isItem = false; | ||
22 | } | ||
23 | |||
24 | RssParser::~RssParser() | ||
25 | { | ||
26 | int size = channel->rssItems.size(); | ||
27 | for (int i = 0; i < size; i ++) { | ||
28 | delete channel->rssItems.at(i); | ||
29 | } | ||
30 | delete channel; | ||
31 | } | ||
32 | |||
33 | bool RssParser::startElement( const QString &, const QString & /*localName*/,const QString & qName, const QXmlAttributes &atts) | ||
34 | { | ||
35 | if( qName == "rss") { | ||
36 | channel = new rssChannel(); | ||
37 | channel->rssItems.resize( 0); | ||
38 | return true; | ||
39 | } | ||
40 | // qWarning(qName + " %d",atts.length()); | ||
41 | if(qName == "item") { | ||
42 | isItem = true; | ||
43 | tag = NewItemTag; | ||
44 | Item = new rssItem(); | ||
45 | } | ||
46 | |||
47 | if(qName == "image") { | ||
48 | tag = NewItemTag; | ||
49 | image = new rssImage(); | ||
50 | } | ||
51 | |||
52 | if(qName == "title") { | ||
53 | tag = TitleTag; | ||
54 | } | ||
55 | |||
56 | if (qName == "description") { | ||
57 | tag = DescriptionTag; | ||
58 | } | ||
59 | |||
60 | if( qName == "link") { | ||
61 | tag = LinkTag; | ||
62 | } | ||
63 | |||
64 | if( qName == "pubDate") { | ||
65 | tag = pubDateTag; | ||
66 | } | ||
67 | |||
68 | // if( qName == "enclosure") { | ||
69 | // tag = EnclosureTag; | ||
70 | // } | ||
71 | |||
72 | if(atts.length() > 0/* && tag == EnclosureTag*/) { | ||
73 | // qWarning(qName +" attributes %d", atts.length()); | ||
74 | // Item->attributes << qName; | ||
75 | // for(int i=0; i < atts.length(); i++) { | ||
76 | // Item->attributes << atts.qName(i) << atts.value(atts.qName(i)); | ||
77 | // } | ||
78 | |||
79 | QStringList *sList; | ||
80 | sList = new QStringList(); | ||
81 | sList->append(qName); | ||
82 | for(int i=0; i < atts.length(); i++) { | ||
83 | sList->append( atts.qName(i)); | ||
84 | sList->append( atts.value(atts.qName(i))); | ||
85 | } | ||
86 | if(isItem) | ||
87 | Item->attributes.append( sList); | ||
88 | else | ||
89 | channel->attributes.append( sList); | ||
90 | } | ||
91 | |||
92 | return true; | ||
93 | } | ||
94 | |||
95 | bool RssParser::endElement( const QString &, const QString &, const QString & qName ) | ||
96 | { | ||
97 | tag = NoneTag; | ||
98 | if(qName == "item") { | ||
99 | isItem = false; | ||
100 | int size = channel->rssItems.size(); | ||
101 | channel->rssItems.resize( size + 1); | ||
102 | channel->rssItems.insert( channel->rssItems.size() - 1, Item); | ||
103 | } | ||
104 | if(qName == "channel") { | ||
105 | // isItem = false; | ||
106 | // int size = channel->rssItems.size(); | ||
107 | // channel->rssItems.resize( size + 1); | ||
108 | // channel->rssItems.insert( channel->rssItems.size() - 1, Item); | ||
109 | } | ||
110 | return true; | ||
111 | } | ||
112 | |||
113 | bool RssParser::characters( const QString & ch ) | ||
114 | { | ||
115 | if(!ch.isEmpty()) { | ||
116 | if(isItem) { | ||
117 | // qWarning("ch "+ch); | ||
118 | switch(tag) { | ||
119 | case NewItemTag: | ||
120 | break; | ||
121 | case TitleTag: | ||
122 | Item->title = ch; | ||
123 | break; | ||
124 | case DescriptionTag: | ||
125 | Item->description = ch; | ||
126 | break; | ||
127 | case LinkTag: | ||
128 | Item->link = ch; | ||
129 | break; | ||
130 | case pubDateTag: | ||
131 | Item->pubdate = ch; | ||
132 | break; | ||
133 | case NoneTag: | ||
134 | break; | ||
135 | }; | ||
136 | } else { //channel | ||
137 | switch(tag) { | ||
138 | case TitleTag: | ||
139 | channel->title = ch; | ||
140 | break; | ||
141 | case DescriptionTag: | ||
142 | channel->description = ch; | ||
143 | break; | ||
144 | case LinkTag: | ||
145 | channel->link = ch; | ||
146 | break; | ||
147 | case pubDateTag: | ||
148 | channel->pubdate = ch; | ||
149 | break; | ||
150 | case NoneTag: | ||
151 | case NewItemTag: | ||
152 | break; | ||
153 | }; | ||
154 | } | ||
155 | } | ||
156 | return true; | ||
157 | } | ||
158 | |||
159 | bool RssParser::warning(const QXmlParseException &e) | ||
160 | { | ||
161 | errorMessage = e.message(); | ||
162 | // QMessageBox::message("Warning",tr("<p>Sorry, could not find the requested document.</p>")); | ||
163 | qWarning("Warning " + errorMessage); | ||
164 | return true; | ||
165 | } | ||
166 | |||
167 | bool RssParser::error(const QXmlParseException &e) | ||
168 | { | ||
169 | errorMessage = e.message(); | ||
170 | // QMessageBox::message("Error", "<p>" + errorMessage + "</p>"); | ||
171 | qWarning("Error: " + errorMessage); | ||
172 | return true; | ||
173 | } | ||
174 | |||
175 | bool RssParser::fatalError(const QXmlParseException &e) | ||
176 | { | ||
177 | errorMessage = e.message(); | ||
178 | // errorMessage += " line: " + e.lineNumber(); | ||
179 | // errorMessage += " col: " + e.columnNumber(); | ||
180 | qWarning("Fatal Error: "+ errorMessage); | ||
181 | qWarning("line %d, col %d\n", e.lineNumber(), e.columnNumber()); | ||
182 | // QMessageBox::message("Fatal Error", errorMessage ); | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | QVector<rssItem> &RssParser::getItems() | ||
187 | { | ||
188 | return channel->rssItems; | ||
189 | } | ||
190 | |||
191 | int RssParser::getSize() | ||
192 | { | ||
193 | return channel->rssItems.size(); | ||
194 | } | ||
195 | |||
196 | QStringList RssParser::getChannelInfo() | ||
197 | { | ||
198 | QStringList ch; | ||
199 | ch << channel->title << channel->description << channel->link << channel->pubdate << channel->copyright << channel->language; | ||
200 | return ch; | ||
201 | } | ||
diff --git a/core/multimedia/opieplayer/rssparser.h b/core/multimedia/opieplayer/rssparser.h new file mode 100644 index 0000000..669ece5 --- a/dev/null +++ b/core/multimedia/opieplayer/rssparser.h | |||
@@ -0,0 +1,122 @@ | |||
1 | /*************************************************************************** | ||
2 | * Copyright (C) 2004 by ljp * | ||
3 | * lpotter@trolltech.com * | ||
4 | * * | ||
5 | * This program may be distributed under the terms of the Q Public * | ||
6 | * License as defined by Trolltech AS of Norway and appearing in the * | ||
7 | * file LICENSE.QPL included in the packaging of this file. * | ||
8 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * | ||
12 | ***************************************************************************/ | ||
13 | |||
14 | /* RSS required tags: | ||
15 | title,link,description | ||
16 | */ | ||
17 | /* RSS optional tags: | ||
18 | language,copyright,managingEditor,webMaster,pubDate,lastBuildDate,category,generator,docs,cloud,ttl, | ||
19 | image,rating,textInput,skipHours,skipDays | ||
20 | */ | ||
21 | /* | ||
22 | podcast tags | ||
23 | <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0"> | ||
24 | title,link,copyright,pubDate,enclosure,guid,itunes:author,itunes:block,itunes:category,itunes:duration,itunes:explicit,itunes:keywords,itunes:owner,itunes:subtitle,itunes:summary | ||
25 | */ | ||
26 | |||
27 | #ifndef RSSPARSER_H | ||
28 | #define RSSPARSER_H | ||
29 | |||
30 | #include <qxml.h> | ||
31 | #include <qstringlist.h> | ||
32 | #include <qvector.h> | ||
33 | #include <qstringlist.h> | ||
34 | #include <qlist.h> | ||
35 | |||
36 | class QString; | ||
37 | |||
38 | class rssImage { | ||
39 | public: | ||
40 | QString url; | ||
41 | QString title; | ||
42 | int width; | ||
43 | int height; | ||
44 | QString description; | ||
45 | }; | ||
46 | |||
47 | class rssItem { | ||
48 | public: | ||
49 | QString title; | ||
50 | QString description; | ||
51 | QString link; | ||
52 | QString pubdate; | ||
53 | QVector <rssImage> rssImageTags; | ||
54 | QList<QStringList> attributes; //tags with atttributes | ||
55 | }; | ||
56 | |||
57 | class rssChannel { | ||
58 | public: | ||
59 | QString title; | ||
60 | QString description; | ||
61 | QString link; | ||
62 | QString pubdate; | ||
63 | QString copyright; | ||
64 | QString language; | ||
65 | QVector <rssImage> rssImageTags; | ||
66 | QVector <rssItem> rssItems; | ||
67 | QList<QStringList> attributes; //tags with atttributes | ||
68 | }; | ||
69 | |||
70 | class RssParser : public QXmlDefaultHandler | ||
71 | { | ||
72 | public: | ||
73 | RssParser(); | ||
74 | ~RssParser(); | ||
75 | QString errorMessage; | ||
76 | |||
77 | QVector<rssItem> &getItems(); | ||
78 | QStringList getChannelInfo(); | ||
79 | int getSize(); | ||
80 | |||
81 | private: | ||
82 | |||
83 | enum Tag { | ||
84 | NoneTag = 0, | ||
85 | TitleTag = 1, | ||
86 | NewItemTag = 2, | ||
87 | DescriptionTag = 3, | ||
88 | LinkTag = 4, | ||
89 | pubDateTag = 5, | ||
90 | /* | ||
91 | ImageTag = 6, | ||
92 | UrlTag = 7, | ||
93 | WidthTag = 8, | ||
94 | HeightTag = 9, | ||
95 | */ | ||
96 | }; | ||
97 | Tag tag; | ||
98 | |||
99 | // QVector <rssItem> rssItems; | ||
100 | QStringList channelInfo; | ||
101 | rssItem *Item; | ||
102 | rssChannel *channel; | ||
103 | rssImage *image; | ||
104 | |||
105 | bool isItem; | ||
106 | QStringList tokenNames; | ||
107 | QString htmlString; | ||
108 | |||
109 | protected: | ||
110 | |||
111 | bool startElement( const QString&, const QString&, const QString& ,const QXmlAttributes& ); | ||
112 | bool endElement( const QString&, const QString&, const QString& ); | ||
113 | bool characters( const QString &); | ||
114 | |||
115 | bool warning(const QXmlParseException &); | ||
116 | bool error(const QXmlParseException &); | ||
117 | bool fatalError(const QXmlParseException &); | ||
118 | |||
119 | QString itemTitle, itemLink, itemDescription; | ||
120 | }; | ||
121 | |||
122 | #endif | ||