-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.cpp | 17 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.h | 8 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 15 |
3 files changed, 40 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.cpp b/noncore/multimedia/opieplayer2/playlistfileview.cpp index cb16415..3ef4d03 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.cpp +++ b/noncore/multimedia/opieplayer2/playlistfileview.cpp @@ -1,78 +1,95 @@ #include "playlistfileview.h" #include <qfile.h> #include <qpe/global.h> #include <qpe/resource.h> PlayListFileView::PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name ) : PlayListView( parent, name ), m_mimeTypePattern( mimeTypePattern ), m_itemPixmapName( itemPixmapName ), m_scannedFiles( false ), m_viewPopulated( false ) { addColumn( tr( "Title" ), 140); addColumn( tr( "Size" ), -1 ); addColumn(tr( "Media" ), 0 ); addColumn(tr( "Path" ), -1 ); setColumnAlignment( 1, Qt::AlignRight ); setColumnAlignment( 2, Qt::AlignRight ); setAllColumnsShowFocus( TRUE ); setSorting( 3, TRUE ); setMultiSelection( TRUE ); setSelectionMode( QListView::Extended ); + + connect( this, SIGNAL( selectionChanged() ), + this, SLOT( checkSelection() ) ); } PlayListFileView::~PlayListFileView() { } +bool PlayListFileView::hasSelection() const +{ + for ( QListViewItemIterator it( const_cast<PlayListFileView *>( this ) ); it.current(); ++it ) + if ( it.current()->isSelected() ) + return true; + + return false; +} + void PlayListFileView::scanFiles() { m_files.detachChildren(); QListIterator<DocLnk> sdit( m_files.children() ); for ( ; sdit.current(); ++sdit ) delete sdit.current(); Global::findDocuments( &m_files, m_mimeTypePattern ); if ( m_viewPopulated ) { m_viewPopulated = false; populateView(); } } 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(); newItem = new QListViewItem( this, dit.current()->name(), QString::number( size ), "" /*storage*/, dit.current()->file() ); newItem->setPixmap( 0, Resource::loadPixmap( m_itemPixmapName ) ); } } } +void PlayListFileView::checkSelection() +{ + emit itemsSelected( hasSelection() ); +} + /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistfileview.h b/noncore/multimedia/opieplayer2/playlistfileview.h index 6eea2fc..5b15526 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.h +++ b/noncore/multimedia/opieplayer2/playlistfileview.h @@ -1,29 +1,37 @@ #ifndef PLAYLISTFILEVIEW_H #define PLAYLISTFILEVIEW_H #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: 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 2df7f27..c05096a 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -483,159 +483,174 @@ void PlayListWidget::loadList( const DocLnk & lnk) { void PlayListWidget::addSelected() { assert( inFileListMode() ); QListView *fileListView = currentFileListView(); QListViewItemIterator it( fileListView ); 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 ); } fileListView->clearSelection(); tabWidget->setCurrentPage( 0 ); writeCurrentM3u(); } 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) { if ( currentTab() == CurrentPlayList ) return; // case 1: { 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 ) ) ); + 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() ); } 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() ); } break; case PlayLists: { if( tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->show(); } playLists->reread(); d->tbAddToList->setEnabled(FALSE); d->tbPlay->setEnabled( false ); } break; }; } 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; }; } void PlayListWidget::playSelected() { btnPlay( TRUE); } QListView *PlayListWidget::currentFileListView() const { switch ( currentTab() ) { case AudioFiles: return audioView; case VideoFiles: return videoView; default: assert( false ); } return 0; } bool PlayListWidget::inFileListMode() const { TabType tab = currentTab(); return tab == AudioFiles || tab == VideoFiles; } void PlayListWidget::openFile() { // http://66.28.164.33:2080 // http://somafm.com/star0242.m3u QString filename, name; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |