-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 2 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.cpp | 25 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 235 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.h | 3 |
4 files changed, 104 insertions, 161 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index 8da7f73..5069a49 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp @@ -340,5 +340,5 @@ void MediaPlayer::cleanUp() {// this happens on closing Config cfg( "OpiePlayer" ); mediaPlayerState->writeConfig( cfg ); - playList->writeConfig( cfg ); + playList->writeDefaultPlaylist( ); // QPEApplication::grabKeyboard(); diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp index c947033..0be727b 100644 --- a/noncore/multimedia/opieplayer2/om3u.cpp +++ b/noncore/multimedia/opieplayer2/om3u.cpp @@ -64,5 +64,5 @@ Om3u::Om3u( const QString &filePath, int mode) Om3u::~Om3u(){} -void Om3u::readM3u() { //it's m3u +void Om3u::readM3u() { // qDebug("<<<<<<reading m3u "+f.name()); QTextStream t(&f); @@ -70,5 +70,5 @@ void Om3u::readM3u() { //it's m3u while ( !t.atEnd() ) { s=t.readLine(); - // qDebug(s); + qDebug(s); if( s.find( "#", 0, TRUE) == -1 ) { if( s.left(2) == "E:" || s.left(2) == "P:" ) { @@ -83,9 +83,9 @@ void Om3u::readM3u() { //it's m3u s.replace( QRegExp( "%20" )," " ); QString name; - if( name.left( 4 ) == "http" ) { - name = s.right( s.length() - 7 ); - } else { +// if( name.left( 4 ) == "http" ) { +// name = s.right( s.length() - 7 ); +// } else { name = s; - } +// } append(name); // qDebug(name); @@ -138,5 +138,5 @@ void Om3u::write() { //writes list to m3u file } f.writeBlock( list, list.length() ); - f.close(); +// f.close(); } @@ -146,8 +146,19 @@ void Om3u::add(const QString &filePath) { //adds to m3u file void Om3u::remove(const QString &filePath) { //removes from m3u list + QString list, currentFile; + for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { + currentFile=*it; +// qDebug(*it); + + if( filePath != currentFile) + list += currentFile+"\n"; + } + f.writeBlock( list, list.length() ); } void Om3u::deleteFile(const QString &filePath) {//deletes m3u file + f.close(); + f.remove(); } diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 897c458..cc4be23 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -177,99 +177,25 @@ void PlayListWidget::initializeStates() { } +void PlayListWidget::writeDefaultPlaylist() { -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; + Config config( "OpiePlayer" ); + config.setGroup( "PlayList" ); + QString filename=QPEApplication::documentDir() + "/default.m3u"; + QString currentString = config.readEntry( "CurrentPlaylist", filename); + if( currentString == filename) { Om3u *m3uList; - name = "default"; - - filename=QPEApplication::documentDir() + "/" + name+".m3u"; - m3uList = new Om3u(filename, IO_ReadWrite); +// qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); + m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); d->selectedFiles->first(); do { - qDebug(d->selectedFiles->current()->file()); +// qDebug(d->selectedFiles->current()->file()); m3uList->add( d->selectedFiles->current()->file() ); } while ( d->selectedFiles->next() ); - // 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); -// 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 ); -// } + } } @@ -361,5 +287,5 @@ void PlayListWidget::addAllVideoToList() { void PlayListWidget::setDocument( const QString& fileref ) { - //qDebug( fileref ); + qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); fromSetDocument = TRUE; if ( fileref.isNull() ) { @@ -369,14 +295,14 @@ void PlayListWidget::setDocument( const QString& fileref ) { } - if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u + clearList(); + if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u readm3u( fileref ); + } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { + readm3u( DocLnk( fileref).file() ); } 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( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { + readPls( DocLnk( fileref).file() ); + } else { clearList(); addToSelection( DocLnk( fileref ) ); @@ -508,5 +434,5 @@ void PlayListWidget::setPlaylist( bool shown ) { void PlayListWidget::addSelected() { - + qDebug("addSelected"); switch (whichList()) { case 0: //playlist @@ -558,4 +484,5 @@ void PlayListWidget::addSelected() { void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); + writeCurrentM3u(); } @@ -571,34 +498,32 @@ void PlayListWidget::playIt( QListViewItem *it) { void PlayListWidget::addToSelection( QListViewItem *it) { d->setDocumentUsed = FALSE; - + qDebug("addToSelection2"); 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(); + 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; + } + break; + case 0: + break; }; tabWidget->setCurrentPage(0); @@ -781,12 +706,12 @@ void PlayListWidget::openFile() { 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; + Config cfg( "OpiePlayer" ); + cfg.setGroup("PlayList"); + if(filename.left(4) == "http") { + QString m3uFile, m3uFilePath; if(filename.find(":",8,TRUE) != -1) { //found a port m3uFile = filename.left( filename.find( ":",8,TRUE)); @@ -798,28 +723,17 @@ void PlayListWidget::openFile() { 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", IO_ReadWrite ); + qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); + m3uList = new Om3u( cfg.readEntry("CurrentPlaylist",""), IO_Append | IO_ReadWrite ); m3uList->add( filename); m3uList->write(); + m3uList->close(); 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" ); - } + lnk.setName( filename ); //sets name + lnk.setFile( filename ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); d->selectedFiles->addToSelection( lnk ); - } - else if( filename.right( 3 ) == "m3u" ) { + else if( filename.right( 3) == "m3u" ) { readm3u( filename ); @@ -827,5 +741,14 @@ void PlayListWidget::openFile() { readPls( filename ); } + else { + m3uList = new Om3u( cfg.readEntry("CurrentPlaylist",""), IO_Append | IO_ReadWrite ); + m3uList->add( filename); + m3uList->write(); + m3uList->close(); + if(m3uList) delete m3uList; + d->selectedFiles->addToSelection( DocLnk(filename) ); + } } + if( fileDlg ) { delete fileDlg; @@ -834,5 +757,5 @@ void PlayListWidget::openFile() { /* -reads m3u and adds files/urls to playlist */ +reads m3u and shows files/urls to playlist widget */ void PlayListWidget::readm3u( const QString &filename ) { qDebug( "read m3u filename " + filename ); @@ -845,8 +768,13 @@ void PlayListWidget::readm3u( const QString &filename ) { for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { s = *it; - s.replace( QRegExp( "%20" )," " ); +// s.replace( QRegExp( "%20" )," " ); // qDebug("reading "+ s); - - if( QFileInfo( s ).exists() ) { + if(s.left(4)=="http") { + lnk.setName( s ); //sets file name + lnk.setFile( s ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); + } + else { + if( QFileInfo( s ).exists() ) { lnk.setName( QFileInfo(s).baseName()); // qDebug("set link "+s); @@ -855,7 +783,7 @@ void PlayListWidget::readm3u( const QString &filename ) { else lnk.setFile( s+"/"); //if url with no extension - - d->selectedFiles->addToSelection( lnk ); + } } + d->selectedFiles->addToSelection( lnk ); } Config config( "OpiePlayer" ); @@ -866,9 +794,10 @@ void PlayListWidget::readm3u( const QString &filename ) { currentPlayList=filename; +// m3uList->write(); m3uList->close(); if(m3uList) delete m3uList; d->selectedFiles->setSelectedItem( s); - setCaption(tr("OpiePlayer: ")+ filename); + setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); } @@ -927,5 +856,5 @@ void PlayListWidget::writeCurrentM3u() { // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); Om3u *m3uList; - m3uList = new Om3u( currentPlaylist, IO_ReadWrite ); + m3uList = new Om3u( currentPlaylist, IO_ReadWrite |IO_Truncate ); d->selectedFiles->first(); @@ -936,4 +865,6 @@ void PlayListWidget::writeCurrentM3u() { // qDebug( list ); m3uList->write(); + m3uList->close(); + if(m3uList) delete m3uList; } @@ -970,4 +901,6 @@ void PlayListWidget::writem3u() { // qDebug( list ); m3uList->write(); + m3uList->close(); + } if(m3uList) delete m3uList; diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h index 8a77619..53be7a7 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.h +++ b/noncore/multimedia/opieplayer2/playlistwidget.h @@ -74,5 +74,5 @@ public slots: bool next(); bool prev(); - void writeConfig( Config& cfg ) const; + void writeDefaultPlaylist( ); QString currentFileListPathName(); protected: @@ -85,5 +85,4 @@ private: void readPls(const QString &); void initializeStates(); - void readConfig( Config& cfg ); void populateAudioView(); void populateVideoView(); |