author | simon <simon> | 2002-12-11 00:03:47 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 00:03:47 (UTC) |
commit | e9d1213578b83f8380c4681186246a2b32ae6375 (patch) (side-by-side diff) | |
tree | 8d18cd8172ff45c85c8438cf5f16d630a7bb5aeb | |
parent | 7f4bd526d59aacbf750e9ee58337b6cf640ba28b (diff) | |
download | opie-e9d1213578b83f8380c4681186246a2b32ae6375.zip opie-e9d1213578b83f8380c4681186246a2b32ae6375.tar.gz opie-e9d1213578b83f8380c4681186246a2b32ae6375.tar.bz2 |
- added initialize states to MediaPlayerState
- the play button is now of type PlayButton, inheritting from ToolButton
and checking the media player initialization state in setEnabled
6 files changed, 68 insertions, 6 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index 8a3d3e0..5e91561 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp @@ -336,40 +336,41 @@ void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { break; } } void MediaPlayer::cleanUp() {// this happens on closing Config cfg( "OpiePlayer" ); mediaPlayerState.writeConfig( cfg ); playList.writeDefaultPlaylist( ); // QPEApplication::grabKeyboard(); // QPEApplication::ungrabKeyboard(); } void MediaPlayer::recreateAudioAndVideoWidgets() { delete xineControl; delete audioUI; delete videoUI; audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); connect( videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); connect( videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); connect( videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); connect( videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); xineControl = new XineControl( videoUI, videoUI->vidWidget(), mediaPlayerState ); + mediaPlayerState.setBackendInitialized(); } void MediaPlayer::reloadSkins() { audioUI->loadSkin(); videoUI->loadSkin(); } diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp index 40fa1a4..d54d870 100644 --- a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp @@ -24,96 +24,109 @@ : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // this file is based on work by trolltech #include <qpe/qpeapplication.h> #include <qpe/qlibrary.h> #include <qpe/config.h> #include <qvaluelist.h> #include <qobject.h> #include <qdir.h> #include "mediaplayerstate.h" #include <assert.h> //#define MediaPlayerDebug(x) qDebug x #define MediaPlayerDebug(x) MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) : QObject( parent, name ) { Config cfg( "OpiePlayer" ); readConfig( cfg ); streaming = false; seekable = true; + backendInitialized = false; } MediaPlayerState::~MediaPlayerState() { } void MediaPlayerState::readConfig( Config& cfg ) { cfg.setGroup("Options"); fullscreen = cfg.readBoolEntry( "FullScreen" ); scaled = cfg.readBoolEntry( "Scaling" ); looping = cfg.readBoolEntry( "Looping" ); shuffled = cfg.readBoolEntry( "Shuffle" ); videoGamma = cfg.readNumEntry( "VideoGamma" ); playing = FALSE; streaming = FALSE; paused = FALSE; curPosition = 0; curLength = 0; m_displayType = MediaSelection; } void MediaPlayerState::writeConfig( Config& cfg ) const { cfg.setGroup( "Options" ); cfg.writeEntry( "FullScreen", fullscreen ); cfg.writeEntry( "Scaling", scaled ); cfg.writeEntry( "Looping", looping ); cfg.writeEntry( "Shuffle", shuffled ); cfg.writeEntry( "VideoGamma", videoGamma ); } +bool MediaPlayerState::isInitialized() const +{ + return backendInitialized; // for now, more to come (skin stuff) +} + +void MediaPlayerState::setBackendInitialized() +{ + assert( backendInitialized == false ); + backendInitialized = true; + emit initialized(); +} + MediaPlayerState::DisplayType MediaPlayerState::displayType() const { return m_displayType; } // slots void MediaPlayerState::setIsStreaming( bool b ) { streaming = b; } void MediaPlayerState::setIsSeekable( bool b ) { seekable = b; emit isSeekableToggled(b); } void MediaPlayerState::setFullscreen( bool b ) { if ( fullscreen == b ) { return; } fullscreen = b; emit fullscreenToggled(b); } void MediaPlayerState::setBlanked( bool b ) { if ( blanked == b ) { return; } blanked = b; emit blankToggled(b); } diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.h b/noncore/multimedia/opieplayer2/mediaplayerstate.h index c887bb8..6fe6d76 100644 --- a/noncore/multimedia/opieplayer2/mediaplayerstate.h +++ b/noncore/multimedia/opieplayer2/mediaplayerstate.h @@ -32,110 +32,115 @@ */ // this file is based on work by trolltech #ifndef MEDIA_PLAYER_STATE_H #define MEDIA_PLAYER_STATE_H #include <qobject.h> class MediaPlayerDecoder; class Config; class MediaPlayerState : public QObject { Q_OBJECT public: enum DisplayType { Audio, Video, MediaSelection }; MediaPlayerState( QObject *parent, const char *name ); ~MediaPlayerState(); bool isStreaming() const { return streaming; } bool isSeekable() const { return seekable; } bool isFullscreen() const { return fullscreen; } bool isScaled() const { return scaled; } bool isLooping() const { return looping; } bool isShuffled() const { return shuffled; } bool isPaused() const { return paused; } bool isPlaying() const { return playing; } bool isStopped() const { return stopped; } + bool isInitialized() const; long position() const { return curPosition; } long length() const { return curLength; } DisplayType displayType() const; public slots: void setIsStreaming( bool b ); void setIsSeekable( bool b ); void setFullscreen( bool b ); void setScaled( bool b ); void setLooping( bool b ); void setShuffled( bool b ); void setPaused( bool b ); void setPlaying( bool b ); void setStopped( bool b ); void setPosition( long p ); void updatePosition( long p ); void setLength( long l ); void setDisplayType( MediaPlayerState::DisplayType displayType ); void setBlanked( bool b ); void setVideoGamma( int v ); void setPrev(); void setNext(); void setList(); void setVideo(); void setAudio(); void toggleFullscreen(); void toggleScaled(); void toggleLooping(); void toggleShuffled(); void togglePaused(); void togglePlaying(); void toggleBlank(); void writeConfig( Config& cfg ) const; + void setBackendInitialized(); signals: void fullscreenToggled( bool ); void scaledToggled( bool ); void loopingToggled( bool ); void shuffledToggled( bool ); void pausedToggled( bool ); void playingToggled( bool ); void stopToggled( bool ); void positionChanged( long ); // When the slider is moved void positionUpdated( long ); // When the media file progresses void lengthChanged( long ); void displayTypeChanged( MediaPlayerState::DisplayType type ); void isSeekableToggled( bool ); void blankToggled( bool ); void videoGammaChanged( int ); void prev(); void next(); + void initialized(); + private: bool streaming : 1; bool seekable : 1; bool fullscreen: 1; bool scaled : 1; bool blanked : 1; bool looping : 1; bool shuffled : 1; bool usePlaylist : 1; bool paused : 1; bool playing : 1; bool stopped : 1; + bool backendInitialized : 1; long curPosition; long curLength; DisplayType m_displayType; int videoGamma; void readConfig( Config& cfg ); }; #endif // MEDIA_PLAYER_STATE_H diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index cba7b6d..8e4f56d 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -36,65 +36,65 @@ #include <qpe/storage.h> #include <qpe/mimetype.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qdatetime.h> #include <qdir.h> #include <qmessagebox.h> #include <qregexp.h> #include <qtextstream.h> #include "playlistselection.h" #include "playlistwidget.h" #include "mediaplayerstate.h" #include "inputDialog.h" #include "om3u.h" #include "playlistfileview.h" //only needed for the random play #include <stdlib.h> #include <assert.h> PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) : PlayListWidgetGui( mediaPlayerState, parent, name ) , currentFileListView( 0 ) { d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer2/add_to_playlist", this , SLOT(addSelected() ) ); d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer2/remove_from_playlist", this , SLOT(removeSelected() ) ); - d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", + d->tbPlay = new PlayButton( mediaPlayerState, bar, tr( "Play" ), "opieplayer2/play", this , SLOT( btnPlay( bool) ), TRUE ); d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", &mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", &mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); (void)new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); (void)new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); pmPlayList->insertSeparator(-1); // (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), // this, SLOT( saveList() ) ); (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), this, SLOT(writem3u() ) ); pmPlayList->insertSeparator(-1); (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); pmPlayList->insertSeparator(-1); (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), audioView, SLOT( scanFiles() ) ); (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), videoView, SLOT( scanFiles() ) ); pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), &mediaPlayerState, SLOT( toggleFullscreen() ) ); Config cfg( "OpiePlayer" ); bool b= cfg.readBoolEntry("FullScreen", 0); @@ -122,64 +122,66 @@ PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* par 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 populateSkinsMenu(); initializeStates(); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); loadList(DocLnk( currentPlaylist ) ); + + tabWidget->showPage( playListTab ); } 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() ); diff --git a/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp b/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp index 5886458..23b7a70 100644 --- a/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp @@ -92,74 +92,73 @@ PlayListWidgetGui::PlayListWidgetGui( MediaPlayerState &_mediaPlayerState, QWidg pmView->isCheckable(); skinsMenu = new QPopupMenu( this ); pmView->insertItem( tr( "Skins" ), skinsMenu ); skinsMenu->isCheckable(); gammaMenu = new QPopupMenu( this ); pmView->insertItem( tr( "Gamma (Video)" ), gammaMenu ); gammaSlider = new QSlider( QSlider::Vertical, gammaMenu ); gammaSlider->setRange( -40, 40 ); gammaSlider->setTickmarks( QSlider::Left ); gammaSlider->setTickInterval( 20 ); gammaSlider->setFocusPolicy( QWidget::StrongFocus ); gammaSlider->setValue( 0 ); gammaSlider->setMinimumHeight( 50 ); gammaLCD = new QLCDNumber( 3, gammaMenu ); gammaLCD-> setFrameShape ( QFrame::NoFrame ); gammaLCD-> setSegmentStyle ( QLCDNumber::Flat ); gammaMenu->insertItem( gammaSlider ); gammaMenu->insertItem( gammaLCD ); connect( gammaSlider, SIGNAL( valueChanged( int ) ), gammaLCD, SLOT( display( int ) ) ); vbox5 = new QVBox( this ); QVBox *vbox4 = new QVBox( vbox5 ); QHBox *hbox6 = new QHBox( vbox4 ); tabWidget = new QTabWidget( hbox6, "tabWidget" ); - QWidget *pTab; - pTab = new QWidget( tabWidget, "pTab" ); - tabWidget->insertTab( pTab, "Playlist"); + playListTab = new QWidget( tabWidget, "PlayListTab" ); + tabWidget->insertTab( playListTab, "Playlist"); - QGridLayout *Playout = new QGridLayout( pTab ); + QGridLayout *Playout = new QGridLayout( playListTab ); Playout->setSpacing( 2); Playout->setMargin( 2); // Add the playlist area - QVBox *vbox3 = new QVBox( pTab ); + QVBox *vbox3 = new QVBox( playListTab ); d->playListFrame = vbox3; QHBox *hbox2 = new QHBox( vbox3 ); d->selectedFiles = new PlayListSelection( hbox2 ); vbox1 = new QVBox( hbox2 ); QPEApplication::setStylusOperation( d->selectedFiles->viewport(), QPEApplication::RightOnHold ); QVBox *stretch1 = new QVBox( vbox1 ); // add stretch Playout->addMultiCellWidget( vbox3, 0, 0, 0, 1 ); QWidget *aTab; aTab = new QWidget( tabWidget, "aTab" ); QGridLayout *Alayout = new QGridLayout( aTab ); Alayout->setSpacing( 2 ); Alayout->setMargin( 2 ); // no m3u's here please audioView = new PlayListFileView( "audio/mpeg;audio/x-wav;audio/x-ogg", "opieplayer2/musicfile", aTab, "Audioview" ); Alayout->addMultiCellWidget( audioView, 0, 0, 0, 1 ); tabWidget->insertTab( aTab, tr( "Audio" ) ); QPEApplication::setStylusOperation( audioView->viewport(), QPEApplication::RightOnHold ); QWidget *vTab; vTab = new QWidget( tabWidget, "vTab" ); QGridLayout *Vlayout = new QGridLayout( vTab ); Vlayout->setSpacing( 2 ); Vlayout->setMargin( 2 ); videoView = new PlayListFileView( "video/*", "opieplayer2/videofile", vTab, "Videoview" ); Vlayout->addMultiCellWidget( videoView, 0, 0, 0, 1 ); @@ -175,32 +174,55 @@ PlayListWidgetGui::PlayListWidgetGui( MediaPlayerState &_mediaPlayerState, QWidg Llayout->setSpacing( 2 ); Llayout->setMargin( 2 ); playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE ); Llayout->addMultiCellWidget( playLists, 0, 0, 0, 1 ); tabWidget->insertTab( LTab, tr( "Lists" ) ); setCentralWidget( vbox5 ); } PlayListWidgetGui::~PlayListWidgetGui() { } void PlayListWidgetGui::setView( char view ) { if ( view == 'l' ) showMaximized(); else hide(); } void PlayListWidgetGui::setActiveWindow() { // qDebug("SETTING active window"); // When we get raised we need to ensure that it switches views MediaPlayerState::DisplayType origDisplayType = mediaPlayerState.displayType(); mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection ); // invalidate mediaPlayerState.setDisplayType( origDisplayType ); // now switch back } +PlayButton::PlayButton( MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name, + const QString &icon, QObject *handler, const QString &slot, bool t ) + : ToolButton( parent, name, icon, handler, slot, t ), mediaPlayerState( _mediaPlayerState ), + m_lastEnableStatus( true ) +{ + connect( &mediaPlayerState, SIGNAL( initialized() ), + this, SLOT( checkInitializationStatus() ) ); +} + +void PlayButton::setEnabled( bool enable ) +{ + m_lastEnableStatus = enable; + + enable &= mediaPlayerState.isInitialized(); + + ToolButton::setEnabled( enable ); +} + +void PlayButton::checkInitializationStatus() +{ + setEnabled( m_lastEnableStatus ); +} + diff --git a/noncore/multimedia/opieplayer2/playlistwidgetgui.h b/noncore/multimedia/opieplayer2/playlistwidgetgui.h index 0d8af43..1aa8ac8 100644 --- a/noncore/multimedia/opieplayer2/playlistwidgetgui.h +++ b/noncore/multimedia/opieplayer2/playlistwidgetgui.h @@ -41,92 +41,111 @@ #include <qtabwidget.h> #include <qpe/fileselector.h> #include <qpushbutton.h> #include <qpopupmenu.h> #include <qaction.h> #include <qslider.h> #include <qlcdnumber.h> class PlayListWidgetPrivate; class PlayListSelection; class MediaPlayerState; class PlayListFileView; class Config; class QPEToolBar; class QListViewItem; class QListView; class QPoint; class QAction; class QLabel; class PlayListWidgetPrivate { public: QToolButton *tbPlay, *tbFull, *tbLoop, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; QFrame *playListFrame; PlayListSelection *selectedFiles; bool setDocumentUsed; }; class ToolButton : public QToolButton { + Q_OBJECT public: ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) : QToolButton( parent, name ) { setTextLabel( name ); setPixmap( Resource::loadPixmap( icon ) ); setAutoRaise( TRUE ); setFocusPolicy( QWidget::NoFocus ); setToggleButton( t ); connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); QPEMenuToolFocusManager::manager()->addWidget( this ); } }; +class PlayButton : public ToolButton +{ + Q_OBJECT +public: + PlayButton( MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name, + const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ); + +protected: + virtual void setEnabled( bool enable ); + +private slots: + void checkInitializationStatus(); + +private: + MediaPlayerState &mediaPlayerState; + bool m_lastEnableStatus : 1; +}; class MenuItem : public QAction { public: MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) : QAction( text, QString::null, 0, 0 ) { connect( this, SIGNAL( activated() ), handler, slot ); addTo( parent ); } }; class PlayListWidgetGui : public QMainWindow { Q_OBJECT public: PlayListWidgetGui( MediaPlayerState &_mediaPlayerState, QWidget* parent=0, const char* name=0 ); ~PlayListWidgetGui(); protected: QTabWidget * tabWidget; PlayListFileView *audioView, *videoView; QListView *playlistView; QLabel *libString; QPopupMenu *pmView ; QPopupMenu *gammaMenu; QSlider *gammaSlider; QLCDNumber *gammaLCD; bool fromSetDocument; bool insanityBool; QString setDocFileRef; // retrieve the current playlist entry (media file link) QPushButton *tbDeletePlaylist; int selected; QPopupMenu *pmPlayList; FileSelector* playLists; QPopupMenu *skinsMenu; PlayListWidgetPrivate *d; // Private implementation data QVBox *vbox1; QVBox *vbox5; QPEToolBar *bar; + QWidget *playListTab; void setActiveWindow(); // need to handle this to show the right view void setView( char ); MediaPlayerState &mediaPlayerState; }; #endif |