author | llornkcor <llornkcor> | 2002-05-31 00:24:18 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-05-31 00:24:18 (UTC) |
commit | 294fecd1c15c4940bdab8566e5afaee9f305abb6 (patch) (side-by-side diff) | |
tree | 47860d13c0aeffb0b9afad96d669d8935769fe7a | |
parent | 706841997a5d466f3b873ed79102e4abe0d745ae (diff) | |
download | opie-294fecd1c15c4940bdab8566e5afaee9f305abb6.zip opie-294fecd1c15c4940bdab8566e5afaee9f305abb6.tar.gz opie-294fecd1c15c4940bdab8566e5afaee9f305abb6.tar.bz2 |
sped up startup time, and fixed segfault on exit
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.h | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 70 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.h | 3 |
3 files changed, 53 insertions, 22 deletions
diff --git a/core/multimedia/opieplayer/mediaplayer.h b/core/multimedia/opieplayer/mediaplayer.h index cf9daea..8f9a0ee 100644 --- a/core/multimedia/opieplayer/mediaplayer.h +++ b/core/multimedia/opieplayer/mediaplayer.h @@ -35,27 +35,27 @@ public: MediaPlayer( QObject *parent, const char *name ); ~MediaPlayer(); private slots: void setPlaying( bool ); void pauseCheck( bool ); void play(); void next(); void prev(); void startIncreasingVolume(); void startDecreasingVolume(); void stopChangingVolume(); + void cleanUp(); protected: void timerEvent( QTimerEvent *e ); void keyReleaseEvent( QKeyEvent *e); void doBlank(); void doUnblank(); - void cleanUp(); private: int volumeDirection; const DocLnk *currentFile; }; #endif // MEDIA_PLAYER_H diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 7a79be1..78c2822 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -23,25 +23,24 @@ #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/fileselector.h> #include <qpe/qpeapplication.h> #include <qpe/lnkproperties.h> #include <qpe/storage.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/global.h> #include <qpe/resource.h> - #include <qaction.h> #include <qcursor.h> #include <qimage.h> #include <qfile.h> #include <qdir.h> #include <qlayout.h> #include <qlabel.h> #include <qlist.h> #include <qlistbox.h> #include <qmainwindow.h> #include <qmessagebox.h> #include <qtoolbutton.h> @@ -122,24 +121,26 @@ public: } }; PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { d = new PlayListWidgetPrivate; d->setDocumentUsed = FALSE; d->current = NULL; fromSetDocument = FALSE; insanityBool=FALSE; + audioScan = FALSE; + videoScan = FALSE; // menuTimer = new QTimer( this ,"menu timer"), // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); setBackgroundMode( PaletteButton ); setCaption( tr("OpiePlayer") ); setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); setToolBarsMovable( FALSE ); // Create Toolbar QPEToolBar *toolbar = new QPEToolBar( this ); @@ -172,24 +173,27 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) tbDeletePlaylist->hide(); QPopupMenu *pmPlayList = new QPopupMenu( this ); menu->insertItem( tr( "File" ), pmPlayList ); new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); // pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); + pmPlayList->insertSeparator(-1); + new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); + new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); QPopupMenu *pmView = new QPopupMenu( this ); menu->insertItem( tr( "View" ), pmView ); fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); fullScreenButton->addTo(pmView); scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); scaleButton->addTo(pmView); QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); @@ -245,62 +249,61 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) audioView->setSelectionMode( QListView::Extended); tabWidget->insertTab(aTab,tr("Audio")); QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); 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 *)) ); // audioView - populateAudioView(); +// populateAudioView(); // videowidget QWidget *vTab; vTab = new QWidget( tabWidget, "vTab" ); videoView = new QListView( vTab, "Videoview" ); videoView->setMinimumSize(233,260); videoView->addColumn(tr("Title"),140); videoView->addColumn(tr("Size"),-1); videoView->addColumn(tr("Media"),-1); videoView->setColumnAlignment(1, Qt::AlignRight); videoView->setColumnAlignment(2, Qt::AlignRight); videoView->setAllColumnsShowFocus(TRUE); videoView->setMultiSelection( TRUE ); videoView->setSelectionMode( QListView::Extended); QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); 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 *)) ); tabWidget->insertTab( vTab,tr("Video")); -populateVideoView(); +// populateVideoView(); //playlists list QWidget *LTab; LTab = new QWidget( tabWidget, "LTab" ); playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy - playLists->setMinimumSize(233,260);; + playLists->setMinimumSize(233,260); tabWidget->insertTab(LTab,tr("Lists")); connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); - // add the library area // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), // this, SLOT( fauxPlay( QListViewItem *) ) ); // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), // this, SLOT( fauxPlay( QListViewItem *)) ); // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); @@ -424,26 +427,24 @@ void PlayListWidget::clearList() { void PlayListWidget::addAllToList() { DocLnkSet filesAll; Global::findDocuments(&filesAll, "video/*;audio/*"); QListIterator<DocLnk> Adit( filesAll.children() ); for ( ; Adit.current(); ++Adit ) d->selectedFiles->addToSelection( **Adit ); } void PlayListWidget::addAllMusicToList() { -// DocLnkSet files; -// Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::addAllVideoToList() { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } @@ -518,39 +519,37 @@ const DocLnk *PlayListWidget::current() { // this is fugly return d->selectedFiles->current(); } else if ( d->setDocumentUsed && d->current ) { return d->current; } else { return d->files->selected(); } } break; case 1://audio { qDebug("audioView"); -// Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { qDebug("here"); insanityBool=TRUE; return dit; } } } break; case 2: // video { qDebug("videoView"); -// Global::findDocuments(&vFiles, "video/*"); QListIterator<DocLnk> Vdit( vFiles.children() ); for ( ; Vdit.current(); ++Vdit ) { if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { insanityBool=TRUE; return Vdit; } } } break; }; return 0; } @@ -794,50 +793,53 @@ void PlayListWidget::tabChanged(QWidget *widg) { switch ( tabWidget->currentPageIndex()) { case 0: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); } break; case 1: { + audioView->clear(); + populateAudioView(); + if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 2: { + videoView->clear(); + populateVideoView(); if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 3: { if( tbDeletePlaylist->isHidden()) tbDeletePlaylist->show(); playLists->reread(); } break; }; } - - void PlayListWidget::btnPlay(bool b) { // mediaPlayerState->setPlaying(b); switch ( tabWidget->currentPageIndex()) { case 0: { mediaPlayerState->setPlaying(b); } break; case 1: { // if(audioView->selectedItem()) { @@ -871,25 +873,24 @@ void PlayListWidget::btnPlay(bool b) { 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->selected()->file()); QFile().remove(playLists->selected()->linkFile()); playLists->reread(); break; case 1: // Cancel break; }; - } void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) { switch (mouse) { case 1: break; case 2:{ QPopupMenu m; m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); m.insertSeparator(); @@ -965,70 +966,96 @@ void PlayListWidget::listDelete() { // if( lnk.name() == file ) { // LnkProperties prop( &lnk); // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); // prop.showMaximized(); // prop.exec(); // } // } } break; }; } +void PlayListWidget::scanForAudio() { + qDebug("scan for audio"); + files.detachChildren(); + QListIterator<DocLnk> sdit( files.children() ); + for ( ; sdit.current(); ++sdit ) { + delete sdit.current(); + } + Global::findDocuments(&files, "audio/*"); + audioScan = TRUE; +} +void PlayListWidget::scanForVideo() { + qDebug("scan for video"); + vFiles.detachChildren(); + QListIterator<DocLnk> sdit( vFiles.children() ); + for ( ; sdit.current(); ++sdit ) { + delete sdit.current(); + } + Global::findDocuments(&vFiles, "video/*"); + videoScan = TRUE; +} + void PlayListWidget::populateAudioView() { -// if(files) -// files.~DocLnkSet(); + + audioView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); + if(!audioScan) scanForAudio(); - Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); QListIterator<FileSystem> it ( fs ); - audioView->clear(); + QString storage; for ( ; dit.current(); ++dit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if(dit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; - if ( QFile( dit.current()->file()).exists() ) { - newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); + if ( QFile( dit.current()->file()).exists() ) { +// qDebug(dit.current()->name()); + newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), + QString::number( QFile( dit.current()->file()).size() ), storage); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); } } } void PlayListWidget::populateVideoView() { + videoView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); - Global::findDocuments(&vFiles, "video/*"); + if(!videoScan ) scanForVideo(); + QListIterator<DocLnk> Vdit( vFiles.children() ); QListIterator<FileSystem> it ( fs ); videoView->clear(); QString storage; for ( ; Vdit.current(); ++Vdit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if( Vdit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; if ( QFile( Vdit.current()->file()).exists() ) { - newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); + newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), + QString::number( QFile( Vdit.current()->file()).size() ), storage); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); } } } void PlayListWidget::openFile() { QString filename, name; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { filename = fileDlg->LineEdit1->text(); @@ -1086,25 +1113,25 @@ void PlayListWidget::keyReleaseEvent( QKeyEvent *e) qDebug("Add"); addSelected(); break; case Key_R: //remove from playlist removeSelected(); break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; case Key_Space: qDebug("Play"); - playSelected(); +// playSelected(); puh break; case Key_1: tabWidget->setCurrentPage(0); break; case Key_2: tabWidget->setCurrentPage(1); break; case Key_3: tabWidget->setCurrentPage(2); break; case Key_4: tabWidget->setCurrentPage(3); @@ -1224,12 +1251,13 @@ void PlayListWidget::readPls(const QString &filename) { // QFileInfo f(s); // QString name = f.baseName(); // // name = name.left(name.length()-4); // name = name.right(name.findRev("/",0,TRUE)); // lnk.setName( name); // lnk.setFile( s); // qDebug("add "+name); // d->selectedFiles->addToSelection( lnk); } i++; } } + diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h index 778e3ee..6569f35 100644 --- a/core/multimedia/opieplayer/playlistwidget.h +++ b/core/multimedia/opieplayer/playlistwidget.h @@ -62,38 +62,41 @@ public slots: bool first(); bool last(); bool next(); bool prev(); /* void setFullScreen(); */ /* void setScaled(); */ protected: /* void contentsMousePressEvent( QMouseEvent * e ); */ /* void contentsMouseReleaseEvent( QMouseEvent * e ); */ void keyReleaseEvent( QKeyEvent *e); void keyPressEvent( QKeyEvent *e); private: + bool audioScan, videoScan; void doBlank(); void doUnblank(); void readm3u(const QString &); void writem3u(const QString &); void readPls(const QString &); void initializeStates(); void readConfig( Config& cfg ); void writeConfig( Config& cfg ) const; PlayListWidgetPrivate *d; // Private implementation data void populateAudioView(); void populateVideoView(); private slots: + 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 setActiveWindow(); // need to handle this to show the right view void setPlaylist( bool ); // Show/Hide the playlist void setView( char ); void clearList(); void addAllToList(); void addAllMusicToList(); void addAllVideoToList(); void saveList(); // Save the playlist |