summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp16
-rw-r--r--noncore/multimedia/opieplayer2/om3u.h2
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp180
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h1
4 files changed, 76 insertions, 123 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
index d378145..c947033 100644
--- a/noncore/multimedia/opieplayer2/om3u.cpp
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -19,106 +19,106 @@
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "playlistwidget.h"
#include "om3u.h"
#include <qpe/applnk.h>
#include <qpe/qpeapplication.h>
#include <qpe/storage.h>
#include <qpe/mimetype.h>
#include <qpe/global.h>
#include <qpe/resource.h>
#include <qdir.h>
#include <qregexp.h>
#include <qstring.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <qcstring.h>
//extern PlayListWidget *playList;
-Om3u::Om3u( const QString &filePath)
+Om3u::Om3u( const QString &filePath, int mode)
: QStringList (){
//filePath is path name to m3u
//qDebug("<<<<<<<new m3u "+filePath);
f.setName(filePath);
- if(f.exists())
- f.open( IO_ReadWrite );
- else
- f.open( IO_ReadWrite | IO_Truncate);
+// if(f.exists())
+// f.open( IO_ReadWrite);
+// else
+// f.open( IO_ReadWrite | IO_Truncate);
+ f.open(mode);
+
}
Om3u::~Om3u(){}
void Om3u::readM3u() { //it's m3u
// qDebug("<<<<<<reading m3u "+f.name());
QTextStream t(&f);
QString s;
while ( !t.atEnd() ) {
s=t.readLine();
-
+ // qDebug(s);
if( s.find( "#", 0, TRUE) == -1 ) {
- if( s.find( " ", 0, TRUE) == -1 ) {
if( s.left(2) == "E:" || s.left(2) == "P:" ) {
s = s.right( s.length() -2 );
QFileInfo f( s );
QString name = f.baseName();
name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
s=s.replace( QRegExp( "\\" ), "/" );
append(s);
// qDebug(s);
} else { // is url
s.replace( QRegExp( "%20" )," " );
QString name;
if( name.left( 4 ) == "http" ) {
name = s.right( s.length() - 7 );
} else {
name = s;
}
append(name);
// qDebug(name);
}
- }
}
}
}
void Om3u::readPls() { //it's a pls file
QTextStream t( &f );
QString s;
while ( !t.atEnd() ) {
s = t.readLine();
if( s.left(4) == "File" ) {
s = s.right( s.length() - 6 );
s.replace( QRegExp( "%20" )," ");
// qDebug( "adding " + s + " to playlist" );
// numberofentries=2
// File1=http
// Title
// Length
// Version
// File2=http
s = s.replace( QRegExp( "\\" ), "/" );
QFileInfo f( s );
QString name = f.baseName();
if( name.left( 4 ) == "http" ) {
name = s.right( s.length() - 7);
} else {
name = s;
}
name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
if( s.at( s.length() - 4) == '.') // if this is probably a file
append(s);
else { //if its a url
if( name.right( 1 ).find( '/' ) == -1) {
diff --git a/noncore/multimedia/opieplayer2/om3u.h b/noncore/multimedia/opieplayer2/om3u.h
index 392980e..9c7cf9a 100644
--- a/noncore/multimedia/opieplayer2/om3u.h
+++ b/noncore/multimedia/opieplayer2/om3u.h
@@ -24,56 +24,56 @@
  -_. . .   )=.  = General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OM3U_H
#define OM3U_H
#include "playlistwidget.h"
#include <qpe/applnk.h>
#include <qpe/qpeapplication.h>
#include <qpe/storage.h>
#include <qpe/mimetype.h>
#include <qpe/global.h>
#include <qpe/resource.h>
#include <qdir.h>
#include <qregexp.h>
#include <qstring.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <qcstring.h>
#include <qfile.h>
class Om3u : public QStringList {
// Q_OBJECT
public:
- Om3u( const QString &filePath);
+ Om3u( const QString &filePath, int mode);
~Om3u();
void readM3u();
void readPls();
void write();
void add(const QString &);
void remove(const QString &);
void deleteFile(const QString &);
void close();
public slots:
protected:
private:
QFile f;
private slots:
};
#endif// M3U_H
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 26c2896..b6525e1 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -119,311 +119,298 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
this, SLOT( skinsMenuActivated( int ) ) );
connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
this,SLOT( playIt( QListViewItem *) ) );
connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
this, SLOT( addToSelection( QListViewItem *) ) );
connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
this,SLOT( playIt( QListViewItem *) ) );
connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
this, SLOT( addToSelection( QListViewItem *) ) );
connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
this, SLOT( loadList( const DocLnk & ) ) );
connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
this, SLOT( tabChanged( QWidget* ) ) );
connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ),
d->tbPlay, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
d->tbLoop, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
d->tbShuffle, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ),
this, SLOT( setPlaylist( bool ) ) );
connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
this, SLOT( playIt( QListViewItem *) ) );
connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
mediaPlayerState, SLOT( setVideoGamma( int ) ) );
-// cfg.setGroup( "PlayList" );
-// if( cfg.readBoolEntry("newPlaylist") ){
- QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
- loadList(DocLnk( currentPlaylist ) );
- setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
-// } else {
-// readConfig( cfg );
-
-// }
// see which skins are installed
videoScan=FALSE;
audioScan=FALSE;
populateSkinsMenu();
initializeStates();
+
+ QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
+ loadList(DocLnk( currentPlaylist ) );
+ setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
}
PlayListWidget::~PlayListWidget() {
- // WTF?!@?!
-
if ( d->current ) {
delete d->current;
}
delete d;
}
void PlayListWidget::initializeStates() {
d->tbPlay->setOn( mediaPlayerState->playing() );
d->tbLoop->setOn( mediaPlayerState->looping() );
d->tbShuffle->setOn( mediaPlayerState->shuffled() );
setPlaylist( true );
}
void PlayListWidget::readConfig( Config& cfg ) {
cfg.setGroup( "PlayList" );
QString currentString = cfg.readEntry( "current", "" );
int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 );
for ( int i = 0; i < noOfFiles; i++ ) {
QString entryName;
entryName.sprintf( "File%i", i + 1 );
QString linkFile = cfg.readEntry( entryName );
qDebug("reading "+linkFile);
if( QFileInfo( linkFile ).exists() ) {
DocLnk lnk( linkFile );
if ( QFileInfo( lnk.file() ).exists() ||
linkFile.find( "http" , 0, TRUE) != -1) {
d->selectedFiles->addToSelection( lnk );
-
}
}
}
d->selectedFiles->setSelectedItem( currentString );
-
}
void PlayListWidget::writeConfig( Config& cfg ) const {
Config config( "OpiePlayer" );
config.setGroup( "PlayList" );
// if(config.readBoolEntry("newPlaylist")) {
// new for testing
QString name, filename, list;
Om3u *m3uList;
name = "default";
filename=QPEApplication::documentDir() + "/" + name+".m3u";
-
- m3uList = new Om3u(filename);
-
+ m3uList = new Om3u(filename, IO_ReadWrite);
d->selectedFiles->first();
do {
- m3uList->add( d->selectedFiles->current()->file());
+ qDebug(d->selectedFiles->current()->file());
+ m3uList->add( d->selectedFiles->current()->file() );
}
while ( d->selectedFiles->next() );
+ // qDebug( list );
- qDebug( list );
-
- m3uList->write();
+ // m3uList->write();
m3uList->close();
if(m3uList) delete m3uList;
DocLnk lnk;
lnk.setFile( filename);
lnk.setIcon("opieplayer2/playlist2");
lnk.setName( name); //sets file name
qDebug("writing default playlist "+filename);
- config.writeEntry("CurrentPlaylist", filename);
+ config.writeEntry("CurrentPlaylist", filename);
// currentPlayList=filename;
-
if(!lnk.writeLink()) {
qDebug("Writing doclink did not work");
}
-
// } else {
// d->selectedFiles->writeCurrent( cfg );
// int noOfFiles = 0;
// d->selectedFiles->first();
// do {
// const DocLnk *lnk = d->selectedFiles->current();
// if ( lnk ) {
// QString entryName;
// entryName.sprintf( "File%i", noOfFiles + 1 );
// cfg.writeEntry( entryName, lnk->linkFile() );
// // if this link does exist, add it so we have the file
// // next time...
// if ( !QFile::exists( lnk->linkFile() ) ) {
// lnk->writeLink();
// }
// }
// noOfFiles++;
// }
// while ( d->selectedFiles->next() );
// cfg.writeEntry("NumberOfFiles", noOfFiles );
// }
}
-
void PlayListWidget::addToSelection( const DocLnk& lnk ) {
d->setDocumentUsed = FALSE;
if ( mediaPlayerState->playlist() ) {
if( QFileInfo( lnk.file() ).exists() ||
lnk.file().left(4) == "http" )
d->selectedFiles->addToSelection( lnk );
+ writeCurrentM3u();
}
else
mediaPlayerState->setPlaying( TRUE );
}
void PlayListWidget::clearList() {
while ( first() ) {
d->selectedFiles->removeSelected();
}
}
-
void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
switch (mouse) {
case 1:
break;
case 2:
{
QPopupMenu m;
m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
m.exec( QCursor::pos() );
}
break;
}
}
void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
switch (mouse) {
case 1:
break;
case 2:
{
QPopupMenu m;
m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
m.exec( QCursor::pos() );
}
break;
}
}
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 );
}
}
+ writeCurrentM3u();
}
void PlayListWidget::addAllMusicToList() {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if( QFileInfo(dit.current()->file() ).exists() ) {
d->selectedFiles->addToSelection( **dit );
}
}
+ writeCurrentM3u();
}
void PlayListWidget::addAllVideoToList() {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit ) {
if( QFileInfo( dit.current()->file() ).exists() ) {
d->selectedFiles->addToSelection( **dit );
}
}
+ writeCurrentM3u();
}
void PlayListWidget::setDocument( const QString& fileref ) {
//qDebug( fileref );
fromSetDocument = TRUE;
if ( fileref.isNull() ) {
QMessageBox::critical( 0, tr( "Invalid File" ),
tr( "There was a problem in getting the file." ) );
return;
}
if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u
readm3u( fileref );
} else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls
readPls( fileref );
- } else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist
- clearList();
- loadList( DocLnk( fileref ) );
- d->selectedFiles->first();
- } else {
+ }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist
+// clearList();
+// loadList( DocLnk( fileref ) );
+// d->selectedFiles->first();
+// }
+ else {
clearList();
addToSelection( DocLnk( fileref ) );
d->setDocumentUsed = TRUE;
mediaPlayerState->setPlaying( FALSE );
-// qApp->processEvents();
mediaPlayerState->setPlaying( TRUE );
-// qApp->processEvents();
- setCaption( tr("OpiePlayer") );
}
}
void PlayListWidget::useSelectedDocument() {
d->setDocumentUsed = FALSE;
}
const DocLnk *PlayListWidget::current() { // this is fugly
switch ( whichList() ) {
case 0: //playlist
{
// qDebug("playlist");
if ( mediaPlayerState->playlist() ) {
return d->selectedFiles->current();
} else if ( d->setDocumentUsed && d->current ) {
return d->current;
} else {
return &(d->files->selectedDocument());
}
}
break;
};
return 0;
}
bool PlayListWidget::prev() {
if ( mediaPlayerState->playlist() ) {
if ( mediaPlayerState->shuffled() ) {
const DocLnk *cur = current();
@@ -462,229 +449,181 @@ bool PlayListWidget::next() {
if ( !d->selectedFiles->next() ) {
if ( mediaPlayerState->looping() ) {
return d->selectedFiles->first();
} else {
return FALSE;
}
}
return TRUE;
}
} else {
return mediaPlayerState->looping();
}
}
bool PlayListWidget::first() {
if ( mediaPlayerState->playlist() )
return d->selectedFiles->first();
else
return mediaPlayerState->looping();
}
bool PlayListWidget::last() {
if ( mediaPlayerState->playlist() )
return d->selectedFiles->last();
else
return mediaPlayerState->looping();
}
void PlayListWidget::saveList() {
-// Config config( "OpiePlayer" );
-// config.setGroup( "PlayList" );
-
-// if(config.readBoolEntry("newPlaylist") ){
- writem3u();
-
-// } else {
-
-// QString filename;
-// InputDialog *fileDlg = 0l;
-// fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
-// fileDlg->exec();
-// if( fileDlg->result() == 1 ) {
-// if ( d->current )
-// delete d->current;
-// filename = fileDlg->text();//+".playlist";
-// // qDebug("saving playlist "+filename+".playlist");
-
-// Config cfg( filename +".playlist");
-// writeConfig( cfg );
-
-// DocLnk lnk;
-// lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf");
-// //sets File property
-// lnk.setType("playlist/plain");
-// lnk.setIcon("opieplayer2/playlist2");
-// lnk.setName( filename); //sets file name
-// // qDebug(filename);
-// if(!lnk.writeLink()) {
-// qDebug("Writing doclink did not work");
-// }
-// }
-
-// config.writeEntry("CurrentPlaylist",filename);
-// setCaption(tr("OpiePlayer: ")+filename);
-// d->selectedFiles->first();
-// if(fileDlg) {
-// delete fileDlg;
-// }
-// }
+ writem3u();
}
void PlayListWidget::loadList( const DocLnk & lnk) {
QString name = lnk.name();
- qDebug("currentList is "+name);
+ // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
if( name.length()>0) {
setCaption("OpiePlayer: "+name);
- qDebug("<<<<<<<<<<<<load list "+ lnk.file());
+ qDebug("<<<<<<<<<<<<load list "+ lnk.file());
clearList();
-
-// if(name.right(3) == "m3u") {
-
readm3u(lnk.file());
-// } else {
-// / Config cfg( name+".playlist");
-// readConfig(cfg);
-
tabWidget->setCurrentPage(0);
-
- Config config( "OpiePlayer" );
- config.setGroup( "PlayList" );
- config.writeEntry("CurrentPlaylist", lnk.file());
-// // d->selectedFiles->first();
-// }
}
}
void PlayListWidget::setPlaylist( bool shown ) {
if ( shown ) {
d->playListFrame->show();
} else {
d->playListFrame->hide();
}
}
void PlayListWidget::addSelected() {
- Config cfg( "OpiePlayer" );
- cfg.setGroup("PlayList");
- QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
- // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
-
switch (whichList()) {
case 0: //playlist
break;
case 1: { //audio
QListViewItemIterator it( audioView );
// iterate through all items of the listview
for ( ; it.current(); ++it ) {
if ( it.current()->isSelected() ) {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it.current()->text(0) ) {
- if(QFileInfo( dit.current()->file()).exists())
+ if( QFileInfo( dit.current()->file()).exists()) {
d->selectedFiles->addToSelection( **dit );
+ audioView->setSelected( it.current(),FALSE);
+ }
}
}
- audioView->setSelected( it.current(),FALSE);
}
}
tabWidget->setCurrentPage(0);
+ writeCurrentM3u();
}
break;
case 2: { // video
QListViewItemIterator it( videoView );
// iterate through all items of the listview
for ( ; it.current(); ++it ) {
if ( it.current()->isSelected() ) {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it.current()->text(0) ) {
- if(QFileInfo( dit.current()->file()).exists())
+ if(QFileInfo( dit.current()->file()).exists()) {
d->selectedFiles->addToSelection( **dit );
+ videoView->setSelected( it.current(),FALSE);
+ }
}
}
- videoView->setSelected( it.current(),FALSE);
}
}
tabWidget->setCurrentPage(0);
+ writeCurrentM3u();
}
break;
};
}
void PlayListWidget::removeSelected() {
d->selectedFiles->removeSelected( );
}
void PlayListWidget::playIt( QListViewItem *it) {
if(!it) return;
mediaPlayerState->setPlaying(FALSE);
mediaPlayerState->setPlaying(TRUE);
d->selectedFiles->unSelect();
}
void PlayListWidget::addToSelection( QListViewItem *it) {
d->setDocumentUsed = FALSE;
if(it) {
switch ( whichList()) {
case 1: {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it->text(0)) {
if(QFileInfo( dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
}
}
+ writeCurrentM3u();
+
}
+
break;
case 2: {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it->text(0)) {
if( QFileInfo( dit.current()->file()).exists() )
d->selectedFiles->addToSelection( **dit );
}
}
+ writeCurrentM3u();
+
}
break;
case 0:
break;
};
tabWidget->setCurrentPage(0);
}
}
void PlayListWidget::tabChanged(QWidget *) {
switch ( whichList()) {
case 0:
{
if( !tbDeletePlaylist->isHidden() ) {
tbDeletePlaylist->hide();
}
d->tbRemoveFromList->setEnabled(TRUE);
d->tbAddToList->setEnabled(FALSE);
}
break;
case 1:
{
audioView->clear();
populateAudioView();
if( !tbDeletePlaylist->isHidden() ) {
tbDeletePlaylist->hide();
}
d->tbRemoveFromList->setEnabled(FALSE);
d->tbAddToList->setEnabled(TRUE);
@@ -821,230 +760,243 @@ void PlayListWidget::populateVideoView() {
pathName=path;
}
}
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, Resource::loadPixmap( "opieplayer2/videofile" ) );
}
}
}
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();
qDebug( "Selected filename is " + filename );
if(filename.left(4) == "http") { //if http, lets write a new m3u
Om3u *m3uList;
DocLnk lnk;
QString m3uFile, m3uFilePath;
if(filename.find(":",8,TRUE) != -1) { //found a port
m3uFile = filename.left( filename.find( ":",8,TRUE));
-
m3uFile = m3uFile.right( 7);
-
} else if(filename.left(4) == "http"){
-
m3uFile=filename;
m3uFile = m3uFile.right( m3uFile.length() - 7);
-
} else{
m3uFile=filename;
}
-
// qDebug( m3uFile);
//this is where this new m3u is going to live at
m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u";
// m3uFile += ".m3u";
- m3uList = new Om3u( m3uFile+".m3u");
-
+ m3uList = new Om3u( m3uFile+".m3u", IO_ReadWrite );
m3uList->add( filename);
m3uList->write();
if(m3uList) delete m3uList;
-
// qDebug( m3uFile);
lnk.setName( filename ); //sets file name
lnk.setFile( m3uFilePath ); //sets File property
lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() );
lnk.setExec( "opieplayer2" );
lnk.setIcon("opieplayer2/playlist2");
if( !lnk.writeLink() ) {
qDebug( "Writing doclink did not work" );
}
d->selectedFiles->addToSelection( lnk );
}
else if( filename.right( 3 ) == "m3u" ) {
readm3u( filename );
} else if( filename.right(3) == "pls" ) {
readPls( filename );
}
}
if( fileDlg ) {
delete fileDlg;
}
}
/*
reads m3u and adds files/urls to playlist */
void PlayListWidget::readm3u( const QString &filename ) {
qDebug( "read m3u filename " + filename );
Om3u *m3uList;
QString s, name;
- m3uList = new Om3u( filename);
+ m3uList = new Om3u( filename, IO_ReadOnly );
m3uList->readM3u();
DocLnk lnk;
for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
s = *it;
s.replace( QRegExp( "%20" )," " );
- qDebug("reading "+ s);
+// qDebug("reading "+ s);
if( QFileInfo( s ).exists() ) {
lnk.setName( QFileInfo(s).baseName());
- qDebug("set link "+s);
+// qDebug("set link "+s);
if(s.at(s.length()-4) == '.') //if regular file
lnk.setFile( s);
else
lnk.setFile( s+"/"); //if url with no extension
d->selectedFiles->addToSelection( lnk );
}
}
Config config( "OpiePlayer" );
config.setGroup( "PlayList" );
config.writeEntry("CurrentPlaylist",filename);
+ config.write();
currentPlayList=filename;
m3uList->close();
if(m3uList) delete m3uList;
d->selectedFiles->setSelectedItem( s);
- setCaption(tr("OpiePlayer: ")+ QFileInfo(s).baseName());
+ setCaption(tr("OpiePlayer: ")+ filename);
}
/*
reads pls and adds files/urls to playlist */
void PlayListWidget::readPls( const QString &filename ) {
qDebug( "pls filename is " + filename );
Om3u *m3uList;
QString s, name;
- m3uList = new Om3u( filename);
+ m3uList = new Om3u( filename, IO_ReadOnly );
m3uList->readPls();
for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
s = *it;
- s.replace( QRegExp( "%20" )," " );
+ // s.replace( QRegExp( "%20" )," " );
DocLnk lnk( s );
QFileInfo f( s );
QString name = f.baseName();
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() {
+ qDebug("writting to current m3u");
+ Config cfg( "OpiePlayer" );
+ cfg.setGroup("PlayList");
+ QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
+ // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
+ Om3u *m3uList;
+ m3uList = new Om3u( currentPlaylist, IO_ReadWrite );
+ d->selectedFiles->first();
+
+ do {
+ m3uList->add( d->selectedFiles->current()->file());
+ }
+ while ( d->selectedFiles->next() );
+ // qDebug( list );
+ m3uList->write();
+ 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();
qDebug( filename );
if( name.left( 1) != "/" ) {
filename = QPEApplication::documentDir() + "/" + name;
}
if( name.right( 3 ) != "m3u" ) {
filename = QPEApplication::documentDir() + "/" +name+".m3u";
}
- m3uList = new Om3u(filename);
+ m3uList = new Om3u(filename, IO_ReadWrite);
d->selectedFiles->first();
do {
m3uList->add( d->selectedFiles->current()->file());
}
while ( d->selectedFiles->next() );
// qDebug( list );
-
m3uList->write();
- m3uList->close();
}
if(m3uList) delete m3uList;
if(fileDlg) delete fileDlg;
DocLnk lnk;
lnk.setFile( filename);
lnk.setIcon("opieplayer2/playlist2");
lnk.setName( name); //sets file name
// qDebug(filename);
Config config( "OpiePlayer" );
config.setGroup( "PlayList" );
config.writeEntry("CurrentPlaylist",filename);
currentPlayList=filename;
if(!lnk.writeLink()) {
qDebug("Writing doclink did not work");
}
setCaption(tr("OpiePlayer: ") + name);
}
void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
switch ( e->key() ) {
////////////////////////////// Zaurus keys
case Key_F9: //activity
// if(audioUI->isHidden())
// audioUI->showMaximized();
break;
case Key_F10: //contacts
// if( videoUI->isHidden())
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h
index 428821a..8a77619 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.h
+++ b/noncore/multimedia/opieplayer2/playlistwidget.h
@@ -64,58 +64,59 @@ public:
QString setDocFileRef, currentPlayList;
// retrieve the current playlist entry (media file link)
const DocLnk *current();
void useSelectedDocument();
int selected;
int whichList();
public slots:
bool first();
bool last();
bool next();
bool prev();
void writeConfig( Config& cfg ) const;
QString currentFileListPathName();
protected:
void keyReleaseEvent( QKeyEvent *e);
private:
int defaultSkinIndex;
bool audioScan, videoScan;
void readm3u(const QString &);
void readPls(const QString &);
void initializeStates();
void readConfig( Config& cfg );
void populateAudioView();
void populateVideoView();
private slots:
void populateSkinsMenu();
void skinsMenuActivated(int);
void pmViewActivated(int);
void writem3u();
+ void writeCurrentM3u();
void scanForAudio();
void scanForVideo();
void openFile();
void setDocument( 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 setPlaylist( bool ); // Show/Hide the playlist
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();
};
#endif // PLAY_LIST_WIDGET_H