summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/playlistwidget.cpp
authorllornkcor <llornkcor>2005-08-28 19:53:11 (UTC)
committer llornkcor <llornkcor>2005-08-28 19:53:11 (UTC)
commitf680479965bf13285a955873c48db47bd0c935d3 (patch) (side-by-side diff)
tree58945d235215685b316c00b62d951bd0b6d4df95 /core/multimedia/opieplayer/playlistwidget.cpp
parent43217700cc9b23519776a27661fbf0c29a7d100d (diff)
downloadopie-f680479965bf13285a955873c48db47bd0c935d3.zip
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.gz
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.bz2
podcast! support.. 1st installment. needs improvements
Diffstat (limited to 'core/multimedia/opieplayer/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp344
1 files changed, 237 insertions, 107 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 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** 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>
//#include <qtimer.h>
/* STD */
#include <stdlib.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
// for setBacklight()
#include <linux/fb.h>
@@ -469,49 +474,49 @@ void PlayListWidget::addAllMusicToList() {
writeCurrentM3u();
d->selectedFiles->first();
}
void PlayListWidget::addAllVideoToList() {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo( dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
tabWidget->setCurrentPage(0);
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);
}
else if( extension.find( "pls", 0, false) != -1 ) { //is pls
readPls( fileref);
}
else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist
clearList();
lnk.setName( fileInfo.baseName() ); //sets name
lnk.setFile( fileref ); //sets file name
lnk.setIcon("Sound");
//addToSelection( lnk );
loadList( lnk);
@@ -984,49 +989,49 @@ void PlayListWidget::populateAudioView() {
StorageInfo storageInfo;
const QList<FileSystem> &fs = storageInfo.fileSystems();
if(!audioScan) scanForAudio();
QListIterator<DocLnk> dit( files.children() );
QListIterator<FileSystem> it ( fs );
QString storage;
for ( ; dit.current(); ++dit ) {
for( ; it.current(); ++it ){
const QString name = (*it)->name();
const QString path = (*it)->path();
if(dit.current()->file().find(path) != -1 ) storage=name;
}
QListViewItem * newItem;
if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) {
long size;
if( dit.current()->file().left(4) == "http" )
size=0;
else
size = QFile( dit.current()->file() ).size();
// odebug << dit.current()->name() << oendl;
newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(),
- QString::number(size ), storage, dit.current()->file());
+ QString::number(size ), storage, dit.current()->file());
newItem->setPixmap(0, Opie::Core::OResource::loadPixmap( "opieplayer/musicfile", Opie::Core::OResource::SmallIcon ));
}
}
}
void PlayListWidget::populateVideoView() {
videoView->clear();
StorageInfo storageInfo;
const QList<FileSystem> &fs = storageInfo.fileSystems();
if(!videoScan ) scanForVideo();
QListIterator<DocLnk> Vdit( vFiles.children() );
QListIterator<FileSystem> it ( fs );
videoView->clear();
QString storage;
for ( ; Vdit.current(); ++Vdit ) {
for( ; it.current(); ++it ){
const QString name = (*it)->name();
const QString path = (*it)->path();
if( Vdit.current()->file().find(path) != -1 ) storage=name;
}
@@ -1042,175 +1047,86 @@ void PlayListWidget::populateVideoView() {
void PlayListWidget::openFile() {
QString filename, name;
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
filename = fileDlg->text();
// odebug << "Selected filename is " + filename << oendl;
DocLnk lnk;
Config cfg( "OpiePlayer" );
cfg.setGroup("PlayList");
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;
}
- lnk.setName( m3uFile ); //sets name
- lnk.setFile( filename ); //sets file name
- lnk.setIcon("opieplayer2/musicfile");
- d->selectedFiles->addToSelection( lnk );
- writeCurrentM3u();
+ 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;
m3uList->add( d->selectedFiles->current()->file() );
}
while ( d->selectedFiles->next() );
// odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl;
m3uList->write();
m3uList->close();
if(m3uList) delete m3uList;
}
}
/*
@@ -1441,24 +1357,238 @@ void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
// emit moreClicked();
// emit moreReleased();
} else if ( msg == "volDown()" ) { //volume less
// emit lessClicked();
// emit lessReleased();
} else if ( msg == "play(QString)" ) { //play this now
QString file;
stream >> file;
setDocumentEx( (const QString &) file);
} else if ( msg == "add(QString)" ) { //add to playlist
QString file;
stream >> file;
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;
+}
+