author | simon <simon> | 2002-12-04 11:40:01 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-04 11:40:01 (UTC) |
commit | 6a11cf48019e28006172cfb9a61e865816c3657e (patch) (side-by-side diff) | |
tree | 45634eded135f17fcdba8e4cb706e87f47f6d5f0 | |
parent | 84d5ca934e9cb8950d1efdb90ac3b00ce6d44e95 (diff) | |
download | opie-6a11cf48019e28006172cfb9a61e865816c3657e.zip opie-6a11cf48019e28006172cfb9a61e865816c3657e.tar.gz opie-6a11cf48019e28006172cfb9a61e865816c3657e.tar.bz2 |
- move more view population logic into PlayListFileView
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.cpp | 14 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 30 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.h | 3 |
4 files changed, 20 insertions, 28 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.cpp b/noncore/multimedia/opieplayer2/playlistfileview.cpp index 0ed1061..cb16415 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.cpp +++ b/noncore/multimedia/opieplayer2/playlistfileview.cpp @@ -1,66 +1,78 @@ #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 ) + : 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 ); } PlayListFileView::~PlayListFileView() { } 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 ) ); } } } /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistfileview.h b/noncore/multimedia/opieplayer2/playlistfileview.h index a00349e..448473e 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.h +++ b/noncore/multimedia/opieplayer2/playlistfileview.h @@ -1,33 +1,34 @@ #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(); // both temporarily accessible that way until the caller code has // been migrated into this class DocLnkSet &files() { return m_files; } bool &scannedFiles() { return m_scannedFiles; } public slots: void scanFiles(); void populateView(); 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 460a0bf..eb0606d 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -106,98 +106,96 @@ PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* par bool b= cfg.readBoolEntry("FullScreen", 0); mediaPlayerState.setFullscreen( b ); pmView->setItemChecked( -16, b ); (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", d->selectedFiles, SLOT(moveSelectedUp() ) ); (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", d->selectedFiles, SLOT(removeSelected() ) ); (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", d->selectedFiles, SLOT(moveSelectedDown() ) ); // QVBox *stretch2 = new QVBox( vbox1 ); connect( tbDeletePlaylist, ( SIGNAL( released() ) ), SLOT( deletePlaylist() ) ); connect( pmView, SIGNAL( activated( int ) ), this, SLOT( pmViewActivated( int ) ) ); connect( skinsMenu, SIGNAL( activated( int ) ) , this, SLOT( skinsMenuActivated( int ) ) ); connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), this,SLOT( playIt( QListViewItem *) ) ); connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), this,SLOT( playIt( QListViewItem *) ) ); connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), this, SLOT( tabChanged( QWidget* ) ) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); connect( &mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); connect( &mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); connect ( gammaSlider, SIGNAL( valueChanged( int ) ), &mediaPlayerState, SLOT( setVideoGamma( int ) ) ); // see which skins are installed - audioPopulated=false; - videoPopulated=false; populateSkinsMenu(); initializeStates(); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); loadList(DocLnk( currentPlaylist ) ); } PlayListWidget::~PlayListWidget() { delete d; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState.isPlaying() ); d->tbLoop->setOn( mediaPlayerState.isLooping() ); d->tbShuffle->setOn( mediaPlayerState.isShuffled() ); d->playListFrame->show(); } 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; // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); if( d->selectedFiles->first() ) { m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); do { // qDebug(d->selectedFiles->current()->file()); m3uList->add( d->selectedFiles->current()->file() ); } while ( d->selectedFiles->next() ); m3uList->write(); m3uList->close(); if(m3uList) delete m3uList; } } } void PlayListWidget::addToSelection( const DocLnk& lnk ) { d->setDocumentUsed = FALSE; @@ -209,190 +207,190 @@ void PlayListWidget::addToSelection( const DocLnk& lnk ) { } void PlayListWidget::clearList() { while ( first() ) { d->selectedFiles->removeSelected(); } } void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { switch (mouse) { case 1: break; case 2: { 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 1: break; case 2: { QPopupMenu m; m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); m.exec( QCursor::pos() ); } break; } } void PlayListWidget::addAllToList() { // QTime t; // t.start(); if(!audioView->scannedFiles()) { if(audioView->childCount() < 1) - populateAudioView(); + 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); } if(!videoView->scannedFiles()) { if(videoView->childCount() < 1) - populateVideoView(); + 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); } // d->selectedFiles->addToSelection( ); // if ( it.current()->isSelected() ) // lst->append( audioIt.current() ); // } // if(!audioScan) // scanForAudio(); // if(!videoScan) // scanForVideo(); // DocLnkSet filesAll; // Global::findDocuments(&filesAll, "video/*;"+audioMimes); // QListIterator<DocLnk> Adit( filesAll.children() ); // for ( ; Adit.current(); ++Adit ) { // if( QFileInfo( Adit.current()->file() ).exists() ) { // d->selectedFiles->addToSelection( **Adit ); // } // } // qDebug("elapsed time %d", t.elapsed() ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllMusicToList() { if(!audioView->scannedFiles()) { if(audioView->childCount() < 1) - populateAudioView(); + 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); } /* if(!audioScan) scanForAudio(); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( QFileInfo(dit.current()->file() ).exists() ) { d->selectedFiles->addToSelection( **dit ); } } */ tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllVideoToList() { if(!videoView->scannedFiles()) { if(videoView->childCount() < 1) - populateVideoView(); + 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); } /* if(!videoScan) scanForVideo(); QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { if( QFileInfo( dit.current()->file() ).exists() ) { d->selectedFiles->addToSelection( **dit ); } } */ tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::setDocument( const QString& fileref ) { // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); fromSetDocument = TRUE; if ( fileref.isNull() ) { QMessageBox::warning( this, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } 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( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { readPls( DocLnk( fileref).file() ); } else { clearList(); @@ -527,178 +525,162 @@ void PlayListWidget::removeSelected() { 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 ); 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->clear(); - if(!audioPopulated) populateAudioView(); + audioView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case VideoFiles: { - // videoView->clear(); - if(!videoPopulated) populateVideoView(); + videoView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } 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); } void PlayListWidget::scanForAudio() { audioView->scanFiles(); - audioView->scannedFiles() = true; - populateAudioView(); } void PlayListWidget::scanForVideo() { videoView->scanFiles(); - videoView->scannedFiles() = true; - populateVideoView(); -} - -void PlayListWidget::populateAudioView() { - audioView->populateView(); - audioPopulated = true; -} - -void PlayListWidget::populateVideoView() { - videoView->populateView(); - videoPopulated=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); fileDlg->exec(); if( fileDlg->result() == 1 ) { filename = fileDlg->text(); qDebug( "Selected filename is " + filename ); // 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; } // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); lnk.setName( filename ); //sets name lnk.setFile( filename ); //sets file name diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h index 58efd47..8c22f17 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.h +++ b/noncore/multimedia/opieplayer2/playlistwidget.h @@ -49,96 +49,93 @@ class Config; class QListViewItem; class QListView; class QPoint; class QAction; class QLabel; class PlayListWidget : public PlayListWidgetGui { Q_OBJECT public: enum TabType { CurrentPlayList, AudioFiles, VideoFiles, PlayLists }; enum { TabTypeCount = 4 }; struct Entry { Entry( const QString &_name, const QString &_fileName ) : name( _name ), file( _fileName ) {} Entry( const QString &_fileName ) : name( _fileName ), file( _fileName ) {} QString name; QString file; }; PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent=0, const char* name=0 ); ~PlayListWidget(); // retrieve the current playlist entry (media file link) const DocLnk *current() const; void useSelectedDocument(); TabType currentTab() const; Entry currentEntry() const; public slots: bool first(); bool last(); bool next(); bool prev(); void writeDefaultPlaylist( ); QString currentFileListPathName() const; protected: void keyReleaseEvent( QKeyEvent *e); signals: void skinSelected(); private: int defaultSkinIndex; - bool audioPopulated, videoPopulated; void readm3u(const QString &); void readPls(const QString &); void initializeStates(); - void populateAudioView(); - void populateVideoView(); QListView *currentFileListView() const; bool inFileListMode() const; private slots: void populateSkinsMenu(); void skinsMenuActivated(int); void pmViewActivated(int); void writem3u(); void writeCurrentM3u(); void scanForAudio(); void scanForVideo(); void openFile(); 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: bool fromSetDocument; bool insanityBool; QString setDocFileRef, currentPlayList; int selected; }; #endif // PLAY_LIST_WIDGET_H |