summaryrefslogtreecommitdiff
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
parent43217700cc9b23519776a27661fbf0c29a7d100d (diff)
downloadopie-f680479965bf13285a955873c48db47bd0c935d3.zip
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.gz
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.bz2
podcast! support.. 1st installment. needs improvements
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp332
-rw-r--r--core/multimedia/opieplayer/playlistwidget.h6
-rw-r--r--core/multimedia/opieplayer/rssparser.cpp201
-rw-r--r--core/multimedia/opieplayer/rssparser.h122
4 files changed, 559 insertions, 102 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
@@ -1,77 +1,82 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** 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>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#define BUTTONS_ON_TOOLBAR
#define SIDE_BUTTONS
#define CAN_SAVE_LOAD_PLAYLISTS
extern AudioWidget *audioUI;
extern VideoWidget *videoUI;
extern MediaPlayerState *mediaPlayerState;
static inline QString fullBaseName ( const QFileInfo &fi )
{
QString str = fi. fileName ( );
return str. left ( str. findRev ( '.' ));
}
QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod";
// class myFileSelector {
// };
class PlayListWidgetPrivate {
@@ -445,97 +450,97 @@ void PlayListWidget::clearList() {
}
void PlayListWidget::addAllToList() {
DocLnkSet filesAll;
Global::findDocuments(&filesAll, "video/*;audio/*");
QListIterator<DocLnk> Adit( filesAll.children() );
for ( ; Adit.current(); ++Adit )
if(QFileInfo(Adit.current()->file()).exists())
d->selectedFiles->addToSelection( **Adit );
tabWidget->setCurrentPage(0);
writeCurrentM3u();
d->selectedFiles->first();
}
void PlayListWidget::addAllMusicToList() {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo(dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
tabWidget->setCurrentPage(0);
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);
d->selectedFiles->first();
} else {
if( fileref.find(".desktop",0,TRUE) != -1) {
lnk = DocLnk(fileref);
} else {
lnk.setName( fileInfo.baseName() ); //sets name
lnk.setFile( fileref ); //sets file name
lnk.setIcon("Sound");
}
addToSelection( lnk );
// addToSelection( DocLnk( fileref ) );
lnk.removeLinkFile();
// qApp->processEvents();
}
setCaption(tr("OpiePlayer"));
d->setDocumentUsed = TRUE;
d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true );
mediaPlayerState->setPlaying( FALSE );
qApp->processEvents();
mediaPlayerState->setPlaying( TRUE );
}
@@ -1018,223 +1023,134 @@ void PlayListWidget::populateVideoView() {
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;
}
QListViewItem * newItem;
if ( QFile( Vdit.current()->file()).exists() ) {
newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(),
QString::number( QFile( Vdit.current()->file() ).size() ),
storage, Vdit.current()->file());
newItem->setPixmap(0, Opie::Core::OResource::loadPixmap( "opieplayer/videofile", Opie::Core::OResource::SmallIcon ));
}
}
}
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;
}
+ 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;
}
}
/*
writes current playlist to m3u file */
void PlayListWidget::writem3u() {
InputDialog *fileDlg;
fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
fileDlg->exec();
QString name, filename, list;
Om3u *m3uList;
if( fileDlg->result() == 1 ) {
name = fileDlg->text();
// odebug << filename << oendl;
if( name.find("/",0,true) != -1) {// assume they specify a file path
filename = name;
name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
}
else //otherwise dump it somewhere noticable
filename = QPEApplication::documentDir() + "/" + name;
if( filename.right( 3 ) != "m3u" ) //needs filename extension
filename += ".m3u";
if( d->selectedFiles->first()) {
m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
@@ -1417,48 +1333,262 @@ void PlayListWidget::skinsMenuActivated( int item ) {
Config cfg( "OpiePlayer" );
cfg.setGroup("Options");
cfg.writeEntry("Skin", skinsMenu->text( item ) );
}
void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
// odebug << "qcop message "+msg << oendl;
QDataStream stream ( data, IO_ReadOnly );
if ( msg == "play()" ) { //plays current selection
btnPlay( true);
} else if ( msg == "stop()" ) {
mediaPlayerState->setPlaying( false);
} else if ( msg == "togglePause()" ) {
mediaPlayerState->togglePaused();
} else if ( msg == "next()" ) { //select next in lis
mediaPlayerState->setNext();
} else if ( msg == "prev()" ) { //select previous in list
mediaPlayerState->setPrev();
} else if ( msg == "toggleLooping()" ) { //loop or not loop
mediaPlayerState->toggleLooping();
} else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled
mediaPlayerState->toggleShuffled();
} else if ( msg == "volUp()" ) { //volume more
// 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;
+}
+
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
@@ -1,138 +1,142 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** 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.
**
**********************************************************************/
#ifndef PLAY_LIST_WIDGET_H
#define PLAY_LIST_WIDGET_H
#include <qmainwindow.h>
#include <qpe/applnk.h>
#include <qtabwidget.h>
#include <qpe/fileselector.h>
#include <qpushbutton.h>
#include <qpe/qcopenvelope_qws.h>
#include "om3u.h"
+#include "rssparser.h"
/* #include <qtimer.h> */
class PlayListWidgetPrivate;
class Config;
class QListViewItem;
class QListView;
class QPoint;
class QAction;
class QLabel;
class QPopupMenu;
class PlayListWidget : public QMainWindow {
Q_OBJECT
public:
PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 );
~PlayListWidget();
QTabWidget * tabWidget;
QAction *fullScreenButton, *scaleButton;
DocLnkSet files;
DocLnkSet vFiles;
QListView *audioView, *videoView, *playlistView;
QLabel *libString;
bool fromSetDocument;
bool insanityBool;
QString setDocFileRef, currentPlayList;
// retrieve the current playlist entry (media file link)
const DocLnk *current();
void useSelectedDocument();
/* QTimer * menuTimer; */
FileSelector* playLists;
QPushButton *tbDeletePlaylist;
int fd, selected;
public slots:
bool first();
bool last();
bool next();
bool prev();
/* void setFullScreen(); */
/* void setScaled(); */
protected:
QCopChannel * channel;
QPopupMenu *skinsMenu;
/* void contentsMousePressEvent( QMouseEvent * e ); */
/* void contentsMouseReleaseEvent( QMouseEvent * e ); */
void keyReleaseEvent( QKeyEvent *e);
void keyPressEvent( QKeyEvent *e);
private:
+ RssParser rssHandler;
int defaultSkinIndex;
bool audioScan, videoScan;
void doBlank();
void doUnblank();
void readm3u(const QString &);
void readPls(const QString &);
-
+ bool readpodcast(const QString&);
void initializeStates();
void readConfig( Config& cfg );
void writeConfig( Config& cfg ) const;
PlayListWidgetPrivate *d; // Private implementation data
void populateAudioView();
void populateVideoView();
private slots:
void qcopReceive(const QCString&, const QByteArray&);
void populateSkinsMenu();
void skinsMenuActivated(int);
void writem3u();
void writeCurrentM3u();
void scanForAudio();
void scanForVideo();
void openFile();
void setDocument( const QString& fileref );
void setDocumentEx( const QString& fileref );
void addToSelection( const DocLnk& ); // Add a media file to the playlist
void addToSelection( QListViewItem* ); // Add a media file to the playlist
void setActiveWindow(); // need to handle this to show the right view
void setPlaylist( bool ); // Show/Hide the playlist
void setView( char );
void clearList();
void addAllToList();
void addAllMusicToList();
void addAllVideoToList();
void saveList(); // Save the playlist
void loadList( const DocLnk &); // Load a playlist
void playIt( QListViewItem *);
void btnPlay(bool);
void deletePlaylist();
void addSelected();
void removeSelected();
void tabChanged(QWidget*);
void viewPressed( int, QListViewItem *, const QPoint&, int);
void playlistViewPressed( int, QListViewItem *, const QPoint&, int);
void playSelected();
void listDelete();
+ bool downloadPodcast(const QString &);
+
protected slots:
/* void cancelMenuTimer(); */
/* void showFileMenu(); */
};
#endif // PLAY_LIST_WIDGET_H
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 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ljp *
+ * lpotter@trolltech.com *
+ * *
+ * This program may be distributed under the terms of the Q Public *
+ * License as defined by Trolltech AS of Norway and appearing in the *
+ * file LICENSE.QPL included in the packaging of this file. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ ***************************************************************************/
+#include "rssparser.h"
+
+#include <qstring.h>
+#include <qmessagebox.h>
+#include <qlist.h>
+
+RssParser::RssParser()
+{
+ isItem = false;
+}
+
+RssParser::~RssParser()
+{
+ int size = channel->rssItems.size();
+ for (int i = 0; i < size; i ++) {
+ delete channel->rssItems.at(i);
+ }
+ delete channel;
+}
+
+bool RssParser::startElement( const QString &, const QString & /*localName*/,const QString & qName, const QXmlAttributes &atts)
+{
+ if( qName == "rss") {
+ channel = new rssChannel();
+ channel->rssItems.resize( 0);
+ return true;
+ }
+// qWarning(qName + " %d",atts.length());
+ if(qName == "item") {
+ isItem = true;
+ tag = NewItemTag;
+ Item = new rssItem();
+ }
+
+ if(qName == "image") {
+ tag = NewItemTag;
+ image = new rssImage();
+ }
+
+ if(qName == "title") {
+ tag = TitleTag;
+ }
+
+ if (qName == "description") {
+ tag = DescriptionTag;
+ }
+
+ if( qName == "link") {
+ tag = LinkTag;
+ }
+
+ if( qName == "pubDate") {
+ tag = pubDateTag;
+ }
+
+// if( qName == "enclosure") {
+// tag = EnclosureTag;
+// }
+
+ if(atts.length() > 0/* && tag == EnclosureTag*/) {
+// qWarning(qName +" attributes %d", atts.length());
+// Item->attributes << qName;
+// for(int i=0; i < atts.length(); i++) {
+// Item->attributes << atts.qName(i) << atts.value(atts.qName(i));
+// }
+
+ QStringList *sList;
+ sList = new QStringList();
+ sList->append(qName);
+ for(int i=0; i < atts.length(); i++) {
+ sList->append( atts.qName(i));
+ sList->append( atts.value(atts.qName(i)));
+ }
+ if(isItem)
+ Item->attributes.append( sList);
+ else
+ channel->attributes.append( sList);
+ }
+
+ return true;
+}
+
+bool RssParser::endElement( const QString &, const QString &, const QString & qName )
+{
+ tag = NoneTag;
+ if(qName == "item") {
+ isItem = false;
+ int size = channel->rssItems.size();
+ channel->rssItems.resize( size + 1);
+ channel->rssItems.insert( channel->rssItems.size() - 1, Item);
+ }
+ if(qName == "channel") {
+// isItem = false;
+// int size = channel->rssItems.size();
+// channel->rssItems.resize( size + 1);
+// channel->rssItems.insert( channel->rssItems.size() - 1, Item);
+ }
+ return true;
+}
+
+bool RssParser::characters( const QString & ch )
+{
+ if(!ch.isEmpty()) {
+ if(isItem) {
+// qWarning("ch "+ch);
+ switch(tag) {
+ case NewItemTag:
+ break;
+ case TitleTag:
+ Item->title = ch;
+ break;
+ case DescriptionTag:
+ Item->description = ch;
+ break;
+ case LinkTag:
+ Item->link = ch;
+ break;
+ case pubDateTag:
+ Item->pubdate = ch;
+ break;
+ case NoneTag:
+ break;
+ };
+ } else { //channel
+ switch(tag) {
+ case TitleTag:
+ channel->title = ch;
+ break;
+ case DescriptionTag:
+ channel->description = ch;
+ break;
+ case LinkTag:
+ channel->link = ch;
+ break;
+ case pubDateTag:
+ channel->pubdate = ch;
+ break;
+ case NoneTag:
+ case NewItemTag:
+ break;
+ };
+ }
+ }
+ return true;
+}
+
+bool RssParser::warning(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// QMessageBox::message("Warning",tr("<p>Sorry, could not find the requested document.</p>"));
+ qWarning("Warning " + errorMessage);
+ return true;
+}
+
+bool RssParser::error(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// QMessageBox::message("Error", "<p>" + errorMessage + "</p>");
+ qWarning("Error: " + errorMessage);
+ return true;
+}
+
+bool RssParser::fatalError(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// errorMessage += " line: " + e.lineNumber();
+// errorMessage += " col: " + e.columnNumber();
+ qWarning("Fatal Error: "+ errorMessage);
+ qWarning("line %d, col %d\n", e.lineNumber(), e.columnNumber());
+// QMessageBox::message("Fatal Error", errorMessage );
+ return false;
+}
+
+QVector<rssItem> &RssParser::getItems()
+{
+ return channel->rssItems;
+}
+
+int RssParser::getSize()
+{
+ return channel->rssItems.size();
+}
+
+QStringList RssParser::getChannelInfo()
+{
+ QStringList ch;
+ ch << channel->title << channel->description << channel->link << channel->pubdate << channel->copyright << channel->language;
+ return ch;
+}
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 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ljp *
+ * lpotter@trolltech.com *
+ * *
+ * This program may be distributed under the terms of the Q Public *
+ * License as defined by Trolltech AS of Norway and appearing in the *
+ * file LICENSE.QPL included in the packaging of this file. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ ***************************************************************************/
+
+/* RSS required tags:
+ title,link,description
+*/
+/* RSS optional tags:
+ language,copyright,managingEditor,webMaster,pubDate,lastBuildDate,category,generator,docs,cloud,ttl,
+ image,rating,textInput,skipHours,skipDays
+*/
+/*
+ podcast tags
+ <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
+ title,link,copyright,pubDate,enclosure,guid,itunes:author,itunes:block,itunes:category,itunes:duration,itunes:explicit,itunes:keywords,itunes:owner,itunes:subtitle,itunes:summary
+*/
+
+#ifndef RSSPARSER_H
+#define RSSPARSER_H
+
+#include <qxml.h>
+#include <qstringlist.h>
+#include <qvector.h>
+#include <qstringlist.h>
+#include <qlist.h>
+
+class QString;
+
+class rssImage {
+public:
+ QString url;
+ QString title;
+ int width;
+ int height;
+ QString description;
+};
+
+class rssItem {
+ public:
+ QString title;
+ QString description;
+ QString link;
+ QString pubdate;
+ QVector <rssImage> rssImageTags;
+ QList<QStringList> attributes; //tags with atttributes
+};
+
+class rssChannel {
+ public:
+ QString title;
+ QString description;
+ QString link;
+ QString pubdate;
+ QString copyright;
+ QString language;
+ QVector <rssImage> rssImageTags;
+ QVector <rssItem> rssItems;
+ QList<QStringList> attributes; //tags with atttributes
+};
+
+class RssParser : public QXmlDefaultHandler
+{
+public:
+ RssParser();
+ ~RssParser();
+ QString errorMessage;
+
+ QVector<rssItem> &getItems();
+ QStringList getChannelInfo();
+ int getSize();
+
+private:
+
+ enum Tag {
+ NoneTag = 0,
+ TitleTag = 1,
+ NewItemTag = 2,
+ DescriptionTag = 3,
+ LinkTag = 4,
+ pubDateTag = 5,
+/*
+ ImageTag = 6,
+ UrlTag = 7,
+ WidthTag = 8,
+ HeightTag = 9,
+ */
+ };
+ Tag tag;
+
+// QVector <rssItem> rssItems;
+ QStringList channelInfo;
+ rssItem *Item;
+ rssChannel *channel;
+ rssImage *image;
+
+ bool isItem;
+ QStringList tokenNames;
+ QString htmlString;
+
+protected:
+
+ bool startElement( const QString&, const QString&, const QString& ,const QXmlAttributes& );
+ bool endElement( const QString&, const QString&, const QString& );
+ bool characters( const QString &);
+
+ bool warning(const QXmlParseException &);
+ bool error(const QXmlParseException &);
+ bool fatalError(const QXmlParseException &);
+
+ QString itemTitle, itemLink, itemDescription;
+};
+
+#endif