-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.cpp | 13 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 56 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.h | 1 |
4 files changed, 59 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.cpp b/noncore/multimedia/opieplayer2/playlistfileview.cpp index 3ef4d03..3094876 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.cpp +++ b/noncore/multimedia/opieplayer2/playlistfileview.cpp @@ -56,40 +56,51 @@ void PlayListFileView::populateView() { if ( m_viewPopulated ) return; clear(); if( !m_scannedFiles ) { m_viewPopulated = false; // avoid a recursion :) scanFiles(); m_scannedFiles = true; } m_viewPopulated = true; QString storage; QListIterator<DocLnk> dit( m_files.children() ); for ( ; dit.current(); ++dit ) { QListViewItem *newItem; if ( QFile::exists( dit.current()->file() ) || dit.current()->file().left( 4 ) == "http" ) { unsigned long size = QFile( dit.current()->file() ).size(); + QString sizestr; + fileSize(size, sizestr); newItem = new QListViewItem( this, dit.current()->name(), - QString::number( size ), "" /*storage*/, + sizestr, "" /*storage*/, dit.current()->file() ); newItem->setPixmap( 0, Resource::loadPixmap( m_itemPixmapName ) ); } } } void PlayListFileView::checkSelection() { emit itemsSelected( hasSelection() ); } +void PlayListFileView::fileSize(unsigned long size, QString &str) { + if( size > 1048576 ) + str.sprintf( "%.0fM", size / 1048576.0 ); + else if( size > 1024 ) + str.sprintf( "%.0fK", size / 1024.0 ); + else + str.sprintf( "%d", size ); +} + /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistfileview.h b/noncore/multimedia/opieplayer2/playlistfileview.h index 5b15526..d92f258 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.h +++ b/noncore/multimedia/opieplayer2/playlistfileview.h @@ -4,34 +4,35 @@ #include "playlistview.h" #include <qpe/applnk.h> class PlayListFileView : public PlayListView { Q_OBJECT public: PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name = 0 ); virtual ~PlayListFileView(); bool hasSelection() const; public slots: void scanFiles(); void populateView(); signals: void itemsSelected( bool selected ); private slots: void checkSelection(); private: + void fileSize(unsigned long size, QString &str); QString m_mimeTypePattern; QString m_itemPixmapName; DocLnkSet m_files; bool m_scannedFiles; bool m_viewPopulated; }; #endif // PLAYLISTFILEVIEW_H /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 5f4159c..83eb83b 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -159,88 +159,121 @@ PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl ) this, SLOT( qcopReceive(const QCString&,const QByteArray&)) ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); loadList(DocLnk( currentPlaylist ) ); tabWidget->showPage( playListTab ); } PlayListWidget::~PlayListWidget() { delete d; delete m_mp; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState->isPlaying() ); d->tbLoop->setOn( mediaPlayerState->isLooping() ); d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); d->playListFrame->show(); } +void PlayListWidget::setButtons(void) { + bool hasitem; + + switch ( currentTab() ) { + case CurrentPlayList: + { + hasitem = !d->selectedFiles->isEmpty(); + d->tbPlay->setEnabled( hasitem ); + d->tbRemoveFromList->setEnabled( hasitem ); + } + break; + case AudioFiles: + { + d->tbPlay->setEnabled( audioView->hasSelection() ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + case VideoFiles: + { + d->tbPlay->setEnabled( videoView->hasSelection() ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + case PlayLists: + { + d->tbPlay->setEnabled( false ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + }; +} + 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; if( d->selectedFiles->first() ) { m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); do { m3uList->add( d->selectedFiles->current()->file() ); } while ( d->selectedFiles->next() ); m3uList->write(); m3uList->close(); delete m3uList; } } } void PlayListWidget::addToSelection( const DocLnk& lnk ) { d->setDocumentUsed = FALSE; if( QFileInfo( lnk.file() ).exists() || lnk.file().left(4) == "http" ) { d->selectedFiles->addToSelection( lnk ); } } void PlayListWidget::clearList() { while ( first() ) { d->selectedFiles->removeSelected(); } Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); cfg.writeEntry("CurrentPlaylist","default"); setCaption("OpiePlayer"); + setButtons(); } void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { switch (mouse) { case LeftButton: break; case RightButton: { 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 LeftButton: break; case RightButton: { @@ -263,88 +296,94 @@ void PlayListWidget::addAllToList() { DocLnk lnk; QString filename; // iterate through all items of the listview for ( ; audioIt.current(); ++audioIt ) { filename = audioIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } videoView->populateView(); QListViewItemIterator videoIt( videoView ); for ( ; videoIt.current(); ++videoIt ) { filename = videoIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::addAllMusicToList() { audioView->populateView(); QListViewItemIterator audioIt( audioView ); DocLnk lnk; QString filename; // iterate through all items of the listview for ( ; audioIt.current(); ++audioIt ) { filename = audioIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::addAllVideoToList() { videoView->populateView(); QListViewItemIterator videoIt( videoView ); DocLnk lnk; QString filename; for ( ; videoIt.current(); ++videoIt ) { filename = videoIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::setDocument( const QString& _fileref ) { // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl; QString fileref = _fileref; fromSetDocument = TRUE; DocLnk lnk(_fileref); if(lnk.isValid()) fileref = lnk.file(); QFileInfo fileInfo(fileref); if ( !fileInfo.exists() ) { QMessageBox::warning( this, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } clearList(); QString extension = fileInfo.extension(false); if( extension.find( "m3u", 0, false) != -1 @@ -455,150 +494,142 @@ void PlayListWidget::loadList( const DocLnk & lnk) { void PlayListWidget::addSelected() { assert( inFileListMode() ); QListViewItemIterator it( currentFileListView ); for ( ; it.current(); ++it ) if ( it.current()->isSelected() ) { QString filename = it.current()->text(3); DocLnk lnk; lnk.setName( QFileInfo( filename ).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk ); } currentFileListView->clearSelection(); writeCurrentM3u(); } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); writeCurrentM3u(); + setButtons(); } 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) { if ( currentTab() == CurrentPlayList ) return; DocLnk lnk; QString filename; filename=it->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); writeCurrentM3u(); // tabWidget->setCurrentPage(0); } } void PlayListWidget::tabChanged(QWidget *) { - d->tbPlay->setEnabled( true ); - disconnect( audioView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); disconnect( videoView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); currentFileListView = 0; switch ( currentTab() ) { case CurrentPlayList: { if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); - d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); } break; case AudioFiles: { audioView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); connect( audioView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); - d->tbPlay->setEnabled( audioView->hasSelection() ); - currentFileListView = audioView; } break; case VideoFiles: { videoView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); connect( videoView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); - d->tbPlay->setEnabled( videoView->hasSelection() ); - currentFileListView = videoView; } break; case PlayLists: { if( tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->show(); } playLists->reread(); d->tbAddToList->setEnabled(FALSE); - d->tbPlay->setEnabled( false ); } break; }; + + setButtons(); } void PlayListWidget::btnPlay(bool b) { // mediaPlayerState->setPlaying(false); mediaPlayerState->setPlaying(b); insanityBool=FALSE; } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), (tr("Yes")), (tr("No")), 0 )){ case 0: // Yes clicked, QFile().remove(playLists->selectedDocument().file()); QFile().remove(playLists->selectedDocument().linkFile()); playLists->reread(); break; case 1: // Cancel break; }; } @@ -689,48 +720,50 @@ 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() ); } } } @@ -758,48 +791,49 @@ void PlayListWidget::readListFromFile( const QString &filename ) { } 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; diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h index 1f5ba92..7db0029 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.h +++ b/noncore/multimedia/opieplayer2/playlistwidget.h @@ -111,35 +111,36 @@ private slots: void openFile(); void openURL(); void openDirectory(); 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 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(); private: DocLnk addFileToPlaylist(const QString& directory, const QString& name); + void setButtons(void); bool fromSetDocument; bool insanityBool; QString setDocFileRef, currentPlayList; int selected; QListView *currentFileListView; MediaPlayer *m_mp; }; #endif // PLAY_LIST_WIDGET_H |