summaryrefslogtreecommitdiff
path: root/noncore/multimedia
Side-by-side diff
Diffstat (limited to 'noncore/multimedia') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp29
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp64
2 files changed, 47 insertions, 46 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
index 0be727b..039f3b1 100644
--- a/noncore/multimedia/opieplayer2/om3u.cpp
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -29,57 +29,51 @@
*/
#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, 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);
- f.open(mode);
-
+ f.setName(filePath);
+ f.open(mode);
}
Om3u::~Om3u(){}
void Om3u::readM3u() {
// 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.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" ) {
@@ -110,59 +104,62 @@ void Om3u::readPls() { //it's a pls file
// 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) {
s += "/";
}
append(s);
}
}
}
}
void Om3u::write() { //writes list to m3u file
- QString list;
+ QString list;
+ if(count()>0) {
for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
- qDebug(*it);
- list += *it+"\n";
+ qDebug(*it);
+ list += *it+"\n";
}
f.writeBlock( list, list.length() );
+ }
// f.close();
}
void Om3u::add(const QString &filePath) { //adds to m3u file
append(filePath);
}
void Om3u::remove(const QString &filePath) { //removes from m3u list
- QString list, currentFile;
+ QString list, currentFile;
+ if(count()>0) {
for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
- currentFile=*it;
-// qDebug(*it);
+ currentFile=*it;
+ // qDebug(*it);
- if( filePath != currentFile)
+ if( filePath != currentFile)
list += currentFile+"\n";
}
f.writeBlock( list, list.length() );
-
+ }
}
void Om3u::deleteFile(const QString &filePath) {//deletes m3u file
f.close();
f.remove();
}
void Om3u::close() { //closes m3u file
f.close();
}
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index e28efd0..f9192e8 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -164,61 +164,63 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
PlayListWidget::~PlayListWidget() {
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::writeDefaultPlaylist() {
Config config( "OpiePlayer" );
config.setGroup( "PlayList" );
QString filename=QPEApplication::documentDir() + "/default.m3u";
QString currentString = config.readEntry( "CurrentPlaylist", filename);
if( currentString == filename) {
- Om3u *m3uList;
-// qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
+ Om3u *m3uList;
+ // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
+ if( d->selectedFiles->first() ) {
m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
- d->selectedFiles->first();
do {
-// qDebug(d->selectedFiles->current()->file());
- m3uList->add( d->selectedFiles->current()->file() );
+ // qDebug(d->selectedFiles->current()->file());
+ m3uList->add( d->selectedFiles->current()->file() );
}
while ( d->selectedFiles->next() );
m3uList->write();
m3uList->close();
if(m3uList) delete m3uList;
+
+ }
}
}
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) {
@@ -832,119 +834,121 @@ void PlayListWidget::readPls( const QString &filename ) {
} 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("writing to current m3u");
Config cfg( "OpiePlayer" );
cfg.setGroup("PlayList");
QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
+ if( d->selectedFiles->first()) {
Om3u *m3uList;
m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
- d->selectedFiles->first();
+
+
qDebug( d->selectedFiles->current()->file());
do {
qDebug( d->selectedFiles->current()->file());
m3uList->add( d->selectedFiles->current()->file() );
}
while ( d->selectedFiles->next() );
qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" );
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();
// qDebug( filename );
if( name.left( 1) != "/" ) {
filename = QPEApplication::documentDir() + "/" + name;
}
if( name.right( 3 ) != "m3u" ) {
filename = QPEApplication::documentDir() + "/" +name+".m3u";
}
+ if( d->selectedFiles->first()) {
m3uList = new Om3u(filename, IO_ReadWrite);
-
- d->selectedFiles->first();
- do {
+ do {
m3uList->add( d->selectedFiles->current()->file());
- }
- while ( d->selectedFiles->next() );
-// qDebug( list );
- m3uList->write();
- m3uList->close();
- if(m3uList) delete m3uList;
+ }
+ while ( d->selectedFiles->next() );
+ // qDebug( list );
+ m3uList->write();
+ m3uList->close();
+ if(m3uList) delete m3uList;
- if(fileDlg) delete fileDlg;
+ if(fileDlg) delete fileDlg;
- DocLnk lnk;
- lnk.setFile( filename);
- lnk.setIcon("opieplayer2/playlist2");
- lnk.setName( name); //sets file name
+ DocLnk lnk;
+ lnk.setFile( filename);
+ lnk.setIcon("opieplayer2/playlist2");
+ lnk.setName( name); //sets file name
-// qDebug(filename);
- Config config( "OpiePlayer" );
- config.setGroup( "PlayList" );
+ // qDebug(filename);
+ Config config( "OpiePlayer" );
+ config.setGroup( "PlayList" );
- config.writeEntry("CurrentPlaylist",filename);
- currentPlayList=filename;
+ config.writeEntry("CurrentPlaylist",filename);
+ currentPlayList=filename;
- if(!lnk.writeLink()) {
- qDebug("Writing doclink did not work");
- }
+ if(!lnk.writeLink()) {
+ qDebug("Writing doclink did not work");
+ }
- setCaption(tr("OpiePlayer: ") + name);
+ 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())
// videoUI->showMaximized();
break;
case Key_F11: //menu
break;
case Key_F12: //home
// doBlank();
break;
case Key_F13: //mail
// doUnblank();
break;
case Key_Q: //add to playlist
addSelected();
break;