-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 83eb83b..98326a8 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -641,256 +641,262 @@ bool PlayListWidget::inFileListMode() const { TabType tab = currentTab(); return tab == AudioFiles || tab == VideoFiles; } void PlayListWidget::openURL() { // http://66.28.164.33:2080 // http://somafm.com/star0242.m3u QString filename, name; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { filename = fileDlg->text(); odebug << "Selected filename is " + filename << oendl; // Om3u *m3uList; DocLnk lnk; 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)); m3uFile = m3uFile.right( 7); } else if(filename.left(4) == "http"){ m3uFile=filename; m3uFile = m3uFile.right( m3uFile.length() - 7); } else{ m3uFile=filename; } lnk.setName( filename ); //sets name lnk.setFile( filename ); //sets file name // lnk.setIcon("opieplayer2/musicfile"); d->selectedFiles->addToSelection( lnk ); writeCurrentM3u(); d->selectedFiles->setSelectedItem( lnk.name()); } else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { readListFromFile( filename ); } else { lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); writeCurrentM3u(); d->selectedFiles->setSelectedItem( lnk.name()); } } delete fileDlg; } static MimeTypes fileSelectorMimeTypes() { MimeTypes types; QStringList audio, video, all; audio << "audio/*"; audio << "playlist/plain"; audio << "audio/x-ogg"; audio << "audio/x-mpegurl"; video << "video/*"; video << "playlist/plain"; all += audio; all += video; types.insert("All Media Files", all ); types.insert("Audio", audio ); types.insert("Video", video ); return types; } void PlayListWidget::openFile() { QString filename, name; Config cfg( "OpiePlayer" ); cfg.setGroup("Dialog"); MimeTypes types = fileSelectorMimeTypes(); QString str = OFileDialog::getOpenFileName( 1, QString::null, QString::null, types, 0, tr("Add File to Playlist") ); if( str.isEmpty() ) return; if(str.left(2) == "//") str=str.right(str.length()-1); if( str.right( 3) == "m3u" || str.right(3) == "pls" ) { readListFromFile( str ); } else { QFileInfo info( str ); DocLnk lnk = addFileToPlaylist( str, info.baseName() ); d->selectedFiles->setSelectedItem( lnk.name() ); } setButtons(); } void PlayListWidget::openDirectory() { QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector, QString::null, 0, tr( "Add Files from Directory")); if(str.isEmpty() ) return; if(str.left(2) == "//") str=str.right(str.length()-1); QDir dir( str ); QStringList lst = dir.entryList(QDir::Files|QDir::Readable); for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { QString filename = str + "/" + *it; if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) readListFromFile( filename ); else { addFileToPlaylist( filename, QFileInfo(*it).baseName() ); } } + + if (!d->selectedFiles->isEmpty()) { + d->selectedFiles->first(); + + setButtons(); + } } void PlayListWidget::readListFromFile( const QString &filename ) { odebug << "read list filename " + filename << oendl; QFileInfo fi(filename); Om3u *m3uList; QString s, name; m3uList = new Om3u( filename, IO_ReadOnly ); if(fi.extension(false).find("m3u",0,false) != -1 ) m3uList->readM3u(); else if(fi.extension(false).find("pls",0,false) != -1 ) m3uList->readPls(); DocLnk lnk; for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { s = *it; // odebug << s << oendl; if(s.left(4)=="http") { lnk.setName( s ); //sets file name lnk.setIcon("opieplayer2/musicfile"); lnk.setFile( s ); //sets file name } else { //is file lnk.setName( QFileInfo(s).baseName()); if(s.left(1) != "/") { lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); } else { lnk.setFile( s); } } d->selectedFiles->addToSelection( lnk ); } Config config( "OpiePlayer" ); config.setGroup( "PlayList" ); config.writeEntry("CurrentPlaylist",filename); config.write(); currentPlayList=filename; m3uList->close(); delete m3uList; d->selectedFiles->setSelectedItem( s); setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); setButtons(); } // writes current playlist to current m3u file */ void PlayListWidget::writeCurrentM3u() { odebug << "writing to current m3u" << oendl; Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); Om3u *m3uList; m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); if( d->selectedFiles->first()) { do { // odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; m3uList->add( d->selectedFiles->current()->file() ); } while ( d->selectedFiles->next() ); // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; m3uList->write(); m3uList->close(); } delete m3uList; } /* writes current playlist to m3u file */ void PlayListWidget::writem3u() { Config cfg( "OpiePlayer" ); cfg.setGroup("Dialog"); MimeTypes types = fileSelectorMimeTypes(); QString str = OFileDialog::getOpenFileName( 1, QString::null, QString::null, types, 0, tr( "Save Playlist" )); if(str.left(2) == "//") str=str.right(str.length()-1); QString name, filename, list; Om3u *m3uList; if( !str.isEmpty() ) { name = str; // 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()) { //ramble through playlist view m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate); do { m3uList->add( d->selectedFiles->current()->file()); } while ( d->selectedFiles->next() ); // odebug << list << oendl; m3uList->write(); m3uList->close(); delete m3uList; //delete fileDlg; DocLnk lnk; lnk.setFile( filename); lnk.setIcon("opieplayer2/playlist2"); lnk.setName( name); //sets file name // odebug << filename << oendl; Config config( "OpiePlayer" ); config.setGroup( "PlayList" ); config.writeEntry("CurrentPlaylist",filename); |