Diffstat (limited to 'core/multimedia/opieplayer/playlistwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 332 |
1 files changed, 231 insertions, 101 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 @@ -17,25 +17,30 @@ ** not clear to you. ** **********************************************************************/ // code added by L. J. Potter Sat 03-02-2002 06:17:54 #define QTOPIA_INTERNAL_FSLP #include "playlistselection.h" #include "playlistwidget.h" #include "mediaplayerstate.h" #include "inputDialog.h" #include "audiowidget.h" #include "videowidget.h" +#include "rssparser.h" +#include <qpe/process.h> + +#include <qvector.h> +#include <qxml.h> /* OPIE */ #include <qpe/qpeapplication.h> #include <qpe/qpemenubar.h> #include <qpe/lnkproperties.h> #include <opie2/odebug.h> #include <opie2/oresource.h> /* QT */ #include <qtoolbar.h> #include <qaction.h> #include <qlayout.h> #include <qmessagebox.h> @@ -481,25 +486,25 @@ void PlayListWidget::addAllVideoToList() { writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::setDocument(const QString& fileref) { fromSetDocument = true; d->setDocumentUsed = TRUE; setDocumentEx(fileref); } void PlayListWidget::setDocumentEx(const QString& fileref) { - odebug << "opieplayer receive "+fileref << oendl; + owarn << "opieplayer receive "+fileref << oendl; clearList(); DocLnk lnk; QFileInfo fileInfo(fileref); if ( !fileInfo.exists() ) { QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } // odebug << "<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref << oendl; QString extension = fileInfo.extension(false); if( extension.find( "m3u", 0, false) != -1) { //is m3u readm3u( fileref); @@ -1054,151 +1059,62 @@ void PlayListWidget::openFile() { QString m3uFile; m3uFile = filename; if(filename.left(4) == "http") { if(filename.find(":",8,TRUE) != -1) { //found a port m3uFile = filename; if( m3uFile.right( 1 ).find( '/' ) == -1) { m3uFile += "/"; } filename = m3uFile; } + if( filename.right(3) == "xml" || + filename.find("rss" ) !=-1) + { + // readpodcast(filename ); + downloadPodcast(filename); + } else { lnk.setName( m3uFile ); //sets name lnk.setFile( filename ); //sets file name lnk.setIcon("opieplayer2/musicfile"); d->selectedFiles->addToSelection( lnk ); writeCurrentM3u(); } + } else if( filename.right( 3) == "m3u" ) { readm3u( filename ); } else if( filename.right(3) == "pls" ) { readPls( filename ); + } else if( filename.right(3) == "xml" || + filename.find("rss" ) !=-1 + ) { + readpodcast( filename ); } else { lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); lnk.removeLinkFile(); writeCurrentM3u(); } } if( fileDlg ) { delete fileDlg; } } /* -reads m3u and shows files/urls to playlist widget */ -void PlayListWidget::readm3u( const QString &filename ) { - // odebug << "read m3u filename " + filename << oendl; - - Om3u *m3uList; - QString s, name; - m3uList = new Om3u( filename, IO_ReadOnly ); - m3uList->readM3u(); - DocLnk lnk; - for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { - s = *it; - // odebug << "reading "+ s << oendl; - if(s.left(4)=="http") { - lnk.setName( s ); //sets file name - lnk.setIcon("opieplayer2/musicfile"); - - // if(s.right(4) != '.' || s.right(5) != '.') - if(s.right(4) != '.' || s.right(5) != '.' ) - if( s.right(1) != "/") - lnk.setFile( s+"/"); //if url with no extension - else - lnk.setFile( s ); //sets file name - - } else { - // if( QFileInfo( s ).exists() ) { - lnk.setName( fullBaseName ( QFileInfo(s))); - // if(s.right(4) == '.') {//if regular file - if(s.left(1) != "/") { - // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl; - lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); - lnk.setIcon("SoundPlayer"); - } else { - // odebug << "set link2 "+s << oendl; - lnk.setFile( s); - lnk.setIcon("SoundPlayer"); - } - } - d->selectedFiles->addToSelection( lnk ); - } - Config config( "OpiePlayer" ); - config.setGroup( "PlayList" ); - - config.writeEntry("CurrentPlaylist",filename); - config.write(); - currentPlayList=filename; - -// m3uList->write(); - m3uList->close(); - if(m3uList) delete m3uList; - - d->selectedFiles->setSelectedItem( s); - setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); - -} - -/* -reads pls and adds files/urls to playlist */ -void PlayListWidget::readPls( const QString &filename ) { - - // odebug << "pls filename is " + filename << oendl; - Om3u *m3uList; - QString s, name; - m3uList = new Om3u( filename, IO_ReadOnly ); - m3uList->readPls(); - - for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { - s = *it; - // s.replace( QRegExp( "%20" )," " ); - DocLnk lnk( s ); - QFileInfo f( s ); - QString name = fullBaseName ( f); - - if( name.left( 4 ) == "http" ) { - name = s.right( s.length() - 7); - } else { - name = s; - } - - name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); - - lnk.setName( name ); - if( s.at( s.length() - 4) == '.') {// if this is probably a file - lnk.setFile( s ); - } else { //if its a url - if( name.right( 1 ).find( '/' ) == -1) { - s += "/"; - } - lnk.setFile( s ); - } - lnk.setType( "audio/x-mpegurl" ); - - lnk.writeLink(); - d->selectedFiles->addToSelection( lnk ); - } - - m3uList->close(); - if(m3uList) delete m3uList; -} - -/* writes current playlist to current m3u file */ void PlayListWidget::writeCurrentM3u() { // odebug << "writing to current m3u" << oendl; Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); currentPlayList = cfg.readEntry("CurrentPlaylist",""); Om3u *m3uList; m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); if( d->selectedFiles->first()) { do { // odebug << "writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; @@ -1453,12 +1369,226 @@ void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { QFileInfo fileInfo(file); DocLnk lnk; lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( file ); //sets file name addToSelection( lnk ); } else if ( msg == "rem(QString)" ) { //remove from playlist QString file; stream >> file; } else if ( msg == "setDocument(QString)" ) { //loop or not loop QCopEnvelope h("QPE/Application/opieplayer", "raise()"); } } + +/* +reads m3u and shows files/urls to playlist widget */ +void PlayListWidget::readm3u( const QString &filename ) { + // odebug << "read m3u filename " + filename << oendl; + + Om3u *m3uList; + QString s, name; + m3uList = new Om3u( filename, IO_ReadOnly ); + m3uList->readM3u(); + DocLnk lnk; + for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { + s = *it; + // odebug << "reading "+ s << oendl; + if(s.left(4)=="http") { + lnk.setName( s ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); + + // if(s.right(4) != '.' || s.right(5) != '.') + if(s.right(4) != '.' || s.right(5) != '.' ) + if( s.right(1) != "/") + lnk.setFile( s+"/"); //if url with no extension + else + lnk.setFile( s ); //sets file name + + } else { + // if( QFileInfo( s ).exists() ) { + lnk.setName( fullBaseName ( QFileInfo(s))); + // if(s.right(4) == '.') {//if regular file + if(s.left(1) != "/") { + // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl; + lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); + lnk.setIcon("SoundPlayer"); + } else { + // odebug << "set link2 "+s << oendl; + lnk.setFile( s); + lnk.setIcon("SoundPlayer"); + } + } + d->selectedFiles->addToSelection( lnk ); + } + Config config( "OpiePlayer" ); + config.setGroup( "PlayList" ); + + config.writeEntry("CurrentPlaylist",filename); + config.write(); + currentPlayList=filename; + +// m3uList->write(); + m3uList->close(); + if(m3uList) delete m3uList; + + d->selectedFiles->setSelectedItem( s); + setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); + +} + +/* +reads pls and adds files/urls to playlist */ +void PlayListWidget::readPls( const QString &filename ) +{ + // odebug << "pls filename is " + filename << oendl; + Om3u *m3uList; + QString s, name; + m3uList = new Om3u( filename, IO_ReadOnly ); + m3uList->readPls(); + + for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { + s = *it; + // s.replace( QRegExp( "%20" )," " ); + DocLnk lnk( s ); + QFileInfo f( s ); + QString name = fullBaseName ( f); + + if( name.left( 4 ) == "http" ) { + name = s.right( s.length() - 7); + } else { + name = s; + } + + name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); + + lnk.setName( name ); + if( s.at( s.length() - 4) == '.') {// if this is probably a file + lnk.setFile( s ); + } else { //if its a url + if( name.right( 1 ).find( '/' ) == -1) { + s += "/"; + } + lnk.setFile( s ); + } + lnk.setType( "audio/x-mpegurl" ); + + lnk.writeLink(); + d->selectedFiles->addToSelection( lnk ); + } + + m3uList->close(); + if(m3uList) delete m3uList; +} + +bool PlayListWidget::readpodcast( const QString &filename ) +{ + QStringList latestPodCast; + //download url + qWarning("podcast "+filename); + QFileInfo info(filename); + if (info.size() > 0) { + bool result = false; + // qWarning("parseDoc " + feedFile.name() ); + QFile file(filename); + QXmlInputSource source( file); + QXmlSimpleReader reader; + // reader.setFeature("http://xml.org/sax/features/namespaces", true); + // reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); + // reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false); + + reader.setContentHandler( &rssHandler); + reader.setErrorHandler( &rssHandler); + result = reader.parse( source); + if (!result) { + QMessageBox::critical(0, "Error", tr("<p>Error unable to parse file.</p>")); +// qWarning("Error unable to parse file\n%s", handler.errorMessage.local8Bit().data()); + return false; + } else { + int size = rssHandler.getItems().size(); + qWarning( rssHandler.getChannelInfo().join("\n")); + + for(int i = 0; i < size; i++) { + QList<QStringList> attributesList = rssHandler.getItems().at(i)->attributes; + QStringList *sList; + QStringList attList; + for(sList = attributesList.first(); sList !=0; sList = attributesList.next()) { + for( QStringList::Iterator it = sList->begin(); it != sList->end(); ++it ) { + attList << (*it); + } + if(i == 0) { //this assumes that the latest is the first + latestPodCast << attList[2]; //this is our mp3 url + latestPodCast << rssHandler.getItems().at(i)->title; + latestPodCast << rssHandler.getItems().at(i)->description; + latestPodCast << rssHandler.getItems().at(i)->pubdate; + } + } + } + QString s = latestPodCast[0]; //this is our mp3 url + +// http://www.davesipaq.com/podcast.xml + DocLnk lnk( s ); + QFileInfo f( s ); + QString name = fullBaseName ( f); + + if( name.left( 4 ) == "http" ) { + name = s.right( s.length() - 7); + } else { + name = s; + } + + name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); + + lnk.setName( name ); + if( s.at( s.length() - 4) == '.') {// if this is probably a file + lnk.setFile( s ); + } else { //if its a url + if( name.right( 1 ).find( '/' ) == -1) { + s += "/"; + } + lnk.setFile( s ); + } + lnk.setType( "audio/x-mpegurl" ); + + lnk.writeLink(); + d->selectedFiles->addToSelection( lnk ); + + } + } else { + QMessageBox::critical( 0, "Qtopia Rss", tr("<p>Sorry, could not find the requested document.</p>")); + return false; + } + + qWarning( latestPodCast.join("\n")); + + return true; +} + +bool PlayListWidget::downloadPodcast(const QString &url) +{ + qWarning("download "+url); + QString localFile; + localFile = url; + localFile = localFile.mid(7, localFile.length()-7); + + localFile = localFile.replace(QRegExp("/"), "_"); + localFile = localFile.replace(QRegExp("&"), "_"); + localFile = localFile.replace(QRegExp("="), "_"); + localFile = localFile.replace(QRegExp("\\?"), "_"); + localFile = localFile.replace(QRegExp("@"), "_"); + localFile = QDir::homeDirPath()+"/Settings/"+localFile; + +#warning FIXME + QString cmd; + cmd = "wget "; + cmd +=" -O "; + cmd += localFile + " " + url; + qWarning(cmd); + system(cmd.latin1()); +// Process ipkg_status(QStringList()<< "wget" <<"-O" << localFile << url ); + // QString out; +// bool r = ipkg_status.exec("",out); +// if(r) +// qWarning(out); + readpodcast(localFile); + return true; +} + |