-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index f9192e8..7ada5ee 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -434,85 +434,85 @@ void PlayListWidget::loadList( const DocLnk & lnk) { void PlayListWidget::setPlaylist( bool shown ) { if ( shown ) { d->playListFrame->show(); } else { d->playListFrame->hide(); } } void PlayListWidget::addSelected() { qDebug("addSelected"); 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()) { d->selectedFiles->addToSelection( **dit ); audioView->setSelected( it.current(),FALSE); } } } } } - tabWidget->setCurrentPage(0); +// 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()) { d->selectedFiles->addToSelection( **dit ); videoView->setSelected( it.current(),FALSE); } } } } } - tabWidget->setCurrentPage(0); +// tabWidget->setCurrentPage(0); writeCurrentM3u(); } break; }; } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); writeCurrentM3u(); } 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 ); @@ -739,82 +739,88 @@ void PlayListWidget::openFile() { 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 { d->selectedFiles->addToSelection( DocLnk(filename) ); writeCurrentM3u(); } } if( fileDlg ) { delete fileDlg; } } /* reads m3u and shows files/urls to playlist widget */ void PlayListWidget::readm3u( const QString &filename ) { qDebug( "read m3u filename " + filename ); 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; -// s.replace( QRegExp( "%20" )," " ); // qDebug("reading "+ s); if(s.left(4)=="http") { - lnk.setName( s ); //sets file name + lnk.setName( s ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); + if(s.right(4) != '.' || s.right(5) != '.') + lnk.setFile( s+"/"); //if url with no extension + else lnk.setFile( s ); //sets file name - lnk.setIcon("opieplayer2/musicfile"); + + } else { + // if( QFileInfo( s ).exists() ) { + lnk.setName( QFileInfo(s).baseName()); + // if(s.right(4) == '.') {//if regular file + if(s.left(1) != "/") { + // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); + lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); + lnk.setIcon("SoundPlayer"); + } else { + // qDebug("set link2 "+s); + lnk.setFile( s); + lnk.setIcon("SoundPlayer"); + } } - else { - if( QFileInfo( s ).exists() ) { - lnk.setName( QFileInfo(s).baseName()); -// 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 ); + 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: ")+ QFileInfo(filename).baseName()); } /* 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, 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 ); @@ -830,68 +836,66 @@ void PlayListWidget::readPls( const QString &filename ) { 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("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 ); - - qDebug( d->selectedFiles->current()->file()); do { - qDebug( d->selectedFiles->current()->file()); + qDebug( "writeCurrentM3u " +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"; } |