-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 92 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.h | 22 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 120 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.h | 14 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayerstate.cpp | 13 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayerstate.h | 6 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 2 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidgetgui.cpp | 22 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidgetgui.h | 18 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/xinecontrol.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/xinecontrol.h | 6 |
11 files changed, 84 insertions, 241 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index 20fd1e2..1e0dc21 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp @@ -59,331 +59,243 @@ extern "C" { void null_set_show_video( const xine_vo_driver_t* self, int show ); int null_is_fullscreen( const xine_vo_driver_t* self ); void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); int null_is_scaling( const xine_vo_driver_t* self ); void null_set_scaling( const xine_vo_driver_t* self, int scale ); void null_set_gui_width( const xine_vo_driver_t* self, int width ); void null_set_gui_height( const xine_vo_driver_t* self, int height ); void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); void null_set_videoGamma( const xine_vo_driver_t* self , int value ); void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); } using namespace XINE; Lib::Lib( XineVideoWidget* widget ) { - ThreadUtil::AutoLock lock( m_initGuard ); - m_initialized = false; m_video = false; m_wid = widget; printf("Lib"); QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; // get the configuration // not really OO, should be an extra class, later if ( !QFile::exists(configPath) ) { QFile f(configPath); f.open(IO_WriteOnly); QTextStream ts( &f ); ts << "misc.memcpy_method:glibc\n"; f.close(); } - start(); -} - -void Lib::run() -{ - initialize(); -} - -void Lib::initialize() -{ m_xine = xine_new( ); - QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; xine_config_load( m_xine, QFile::encodeName( configPath ) ); xine_init( m_xine ); // allocate oss for sound // and fb for framebuffer m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this ); //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); // null_display_handler( m_videoOutput, xine_display_frame, this ); m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); if (m_wid != 0 ) { printf( "!0\n" ); resize ( m_wid-> size ( ) ); ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); // m_wid->repaint(); } m_queue = xine_event_new_queue (m_stream); xine_event_create_listener_thread (m_queue, xine_event_handler, this); - - ThreadUtil::AutoLock lock( m_initGuard ); - m_initialized = true; - - send( new ThreadUtil::ChannelMessage( InitializationMessageType ), OneWay ); } Lib::~Lib() { - ThreadUtil::AutoLock lock( m_initGuard ); - - assert( m_initialized ); - // free( m_config ); xine_close( m_stream ); xine_event_dispose_queue( m_queue ); xine_dispose( m_stream ); xine_exit( m_xine ); /* FIXME either free or delete but valgrind bitches against both */ //free( m_videoOutput ); //delete m_audioOutput; } -void Lib::assertInitialized() const -{ - ThreadUtil::AutoLock lock( m_initGuard ); - - if ( m_initialized ) - return; - - qDebug( "LibXine: xine function called while not being initialized, yet! Fix the caller!" ); - assert( m_initialized ); -} - void Lib::resize ( const QSize &s ) { if ( s. width ( ) && s. height ( ) ) { ::null_set_gui_width( m_videoOutput, s. width() ); ::null_set_gui_height( m_videoOutput, s. height() ); } } int Lib::majorVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return major; } int Lib::minorVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return minor; } int Lib::subVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return sub; } int Lib::play( const QString& fileName, int startPos, int start_time ) { - assertInitialized(); - QString str = fileName.stripWhiteSpace(); if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { return 0; } return xine_play( m_stream, startPos, start_time); } void Lib::stop() { - assertInitialized(); - qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); xine_stop( m_stream ); } void Lib::pause( bool toggle ) { - assertInitialized(); - xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); } int Lib::speed() const { - assertInitialized(); - return xine_get_param ( m_stream, XINE_PARAM_SPEED ); } void Lib::setSpeed( int speed ) { - assertInitialized(); - xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); } int Lib::status() const { - assertInitialized(); - return xine_get_status( m_stream ); } int Lib::currentPosition() const { - assertInitialized(); - int pos, time, length; xine_get_pos_length( m_stream, &pos, &time, &length ); return pos; } int Lib::currentTime() const { - assertInitialized(); - int pos, time, length; xine_get_pos_length( m_stream, &pos, &time, &length ); return time/1000; } int Lib::length() const { - assertInitialized(); - int pos, time, length; xine_get_pos_length( m_stream, &pos, &time, &length ); return length/1000; } bool Lib::isSeekable() const { - assertInitialized(); - return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); } void Lib::seekTo( int time ) { - assertInitialized(); - //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( // since its now milliseconds we need *1000 xine_play( m_stream, 0, time*1000 ); } Frame Lib::currentFrame() const { - assertInitialized(); - Frame frame; return frame; }; QString Lib::metaInfo( int number) const { - assertInitialized(); - return xine_get_meta_info( m_stream, number ); } int Lib::error() const { - assertInitialized(); - return xine_get_error( m_stream ); }; void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) { assert( sendType == ThreadUtil::Channel::OneWay ); - switch ( msg->type() ) { - case XineMessageType: - handleXineEvent( static_cast<XineMessage *>( msg )->xineEvent ); - break; - case InitializationMessageType: - emit initialized(); - break; - } + handleXineEvent( msg->type() ); delete msg; } void Lib::handleXineEvent( const xine_event_t* t ) { - send( new XineMessage( t->type ), OneWay ); + send( new ThreadUtil::ChannelMessage( t->type ), OneWay ); } void Lib::handleXineEvent( int type ) { - assertInitialized(); - if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { emit stopped(); } } void Lib::setShowVideo( bool video ) { - assertInitialized(); - m_video = video; ::null_set_show_video( m_videoOutput, video ); } bool Lib::isShowingVideo() const { - assertInitialized(); - return ::null_is_showing_video( m_videoOutput ); } bool Lib::hasVideo() const { - assertInitialized(); - return xine_get_stream_info( m_stream, 18 ); } void Lib::showVideoFullScreen( bool fullScreen ) { - assertInitialized(); - ::null_set_fullscreen( m_videoOutput, fullScreen ); } bool Lib::isVideoFullScreen() const { - assertInitialized(); - return ::null_is_fullscreen( m_videoOutput ); } void Lib::setScaling( bool scale ) { - assertInitialized(); - ::null_set_scaling( m_videoOutput, scale ); } void Lib::setGamma( int value ) { - assertInitialized(); - //qDebug( QString( "%1").arg(value) ); /* int gammaValue = ( 100 + value ); */ ::null_set_videoGamma( m_videoOutput, value ); } bool Lib::isScaling() const { - assertInitialized(); - return ::null_is_scaling( m_videoOutput ); } void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { ( (Lib*)user_data)->handleXineEvent( t ); } void Lib::xine_display_frame( void* user_data, uint8_t *frame, int width, int height, int bytes ) { ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); } void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { - assertInitialized(); - if ( !m_video ) { qWarning("not showing video now"); return; } m_wid-> setVideoFrame ( frame, width, height, bytes ); } diff --git a/noncore/multimedia/opieplayer2/lib.h b/noncore/multimedia/opieplayer2/lib.h index 34b85b9..aba2ec9 100644 --- a/noncore/multimedia/opieplayer2/lib.h +++ b/noncore/multimedia/opieplayer2/lib.h @@ -42,33 +42,33 @@ //#include "xine.h" #include "threadutil.h" class XineVideoWidget; namespace XINE { /** * Lib wrapps the simple interface * of libxine for easy every day use * This will become a full C++ Wrapper * It supports playing, pausing, info, * stooping, seeking. */ class Frame; - class Lib : public ThreadUtil::Channel, private ThreadUtil::Thread + class Lib : public ThreadUtil::Channel { Q_OBJECT public: Lib(XineVideoWidget* = 0); ~Lib(); static int majorVersion(); static int minorVersion(); static int subVersion(); void resize ( const QSize &s ); int play( const QString& fileName, int startPos = 0, int start_time = 0 ); void stop(); @@ -170,53 +170,33 @@ namespace XINE { * XINE_ERROR_NONE 0 * XINE_ERROR_NO_INPUT_PLUGIN 1 * XINE_ERROR_NO_DEMUXER_PLUGIN 2 * XINE_ERROR_DEMUXER_FAILED 3 */ int error() const; signals: void stopped(); void initialized(); protected: virtual void receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ); - virtual void run(); - private: - void initialize(); - - void assertInitialized() const; - - enum { XineMessageType = 1, InitializationMessageType }; - - struct XineMessage : public ThreadUtil::ChannelMessage - { - XineMessage( int _xineEvent ) : ThreadUtil::ChannelMessage( XineMessageType ), - xineEvent( _xineEvent ) - {} - - int xineEvent; - }; - - mutable ThreadUtil::Mutex m_initGuard; - bool m_initialized : 1; - int m_bytes_per_pixel; bool m_video:1; XineVideoWidget *m_wid; xine_t *m_xine; xine_stream_t *m_stream; xine_cfg_entry_t *m_config; xine_vo_driver_t *m_videoOutput; xine_ao_driver_t* m_audioOutput; xine_event_queue_t *m_queue; void handleXineEvent( const xine_event_t* t ); void handleXineEvent( int type ); void drawFrame( uint8_t* frame, int width, int height, int bytes ); // C -> C++ bridge for the event system static void xine_event_handler( void* user_data, const xine_event_t* t); static void xine_display_frame( void* user_data, uint8_t* frame , diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index c230d6f..bbc60dd 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp @@ -18,64 +18,63 @@ #include "mediaplayerstate.h" // for setBacklight() #include <linux/fb.h> #include <sys/file.h> #include <sys/ioctl.h> #define FBIOBLANK 0x4611 MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { - audioUI = 0; - videoUI = 0; - xineControl = 0; - recreateAudioAndVideoWidgets(); + m_audioUI = 0; + m_videoUI = 0; + m_xineControl = 0; fd=-1;fl=-1; playList.setCaption( tr( "OpiePlayer: Initializating" ) ); qApp->processEvents(); // QPEApplication::grabKeyboard(); // EVIL connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); // What is pauseCheck good for? (Simon) // connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); volControl = new VolumeControl; Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); } MediaPlayer::~MediaPlayer() { - delete xineControl; - delete audioUI; - delete videoUI; + delete m_xineControl; + delete m_audioUI; + delete m_videoUI; delete volControl; } void MediaPlayer::pauseCheck( bool b ) { if ( b && !mediaPlayerState.isPlaying() ) { mediaPlayerState.setPaused( FALSE ); } } void MediaPlayer::play() { mediaPlayerState.setPlaying( FALSE ); mediaPlayerState.setPlaying( TRUE ); } void MediaPlayer::setPlaying( bool play ) { if ( !play ) { @@ -90,52 +89,52 @@ void MediaPlayer::setPlaying( bool play ) { QString tickerText, time, fileName; if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { //if playing in file list.. play in a different way // random and looping settings enabled causes problems here, // since there is no selected file in the playlist, but a selected file in the file list, // so we remember and shutoff l = mediaPlayerState.isLooping(); if(l) { mediaPlayerState.setLooping( false ); } r = mediaPlayerState.isShuffled(); mediaPlayerState.setShuffled( false ); } PlayListWidget::Entry playListEntry = playList.currentEntry(); fileName = playListEntry.name; - xineControl->play( playListEntry.file ); + xineControl()->play( playListEntry.file ); long seconds = mediaPlayerState.length(); time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); if( fileName.left(4) == "http" ) { fileName = QFileInfo( fileName ).baseName(); - if ( xineControl->getMetaInfo().isEmpty() ) { + if ( xineControl()->getMetaInfo().isEmpty() ) { tickerText = tr( " File: " ) + fileName; } else { - tickerText = xineControl->getMetaInfo(); + tickerText = xineControl()->getMetaInfo(); } } else { - if ( xineControl->getMetaInfo().isEmpty() ) { + if ( xineControl()->getMetaInfo().isEmpty() ) { tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; } else { - tickerText = xineControl->getMetaInfo() + " Length: " + time + " "; + tickerText = xineControl()->getMetaInfo() + " Length: " + time + " "; } } - audioUI->setTickerText( tickerText ); + audioUI()->setTickerText( tickerText ); } void MediaPlayer::prev() { if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist if ( playList.prev() ) { play(); } else if ( mediaPlayerState.isLooping() ) { if ( playList.last() ) { play(); } } else { mediaPlayerState.setList(); } } } @@ -176,103 +175,103 @@ void MediaPlayer::startIncreasingVolume() { startTimer( 100 ); volControl->incVol(2); } bool drawnOnScreenDisplay = FALSE; unsigned int onScreenDisplayVolume = 0; const int yoff = 110; void MediaPlayer::stopChangingVolume() { killTimers(); // Get rid of the on-screen display stuff drawnOnScreenDisplay = FALSE; onScreenDisplayVolume = 0; int w=0; int h=0; - if( !xineControl->hasVideo() ) { - w = audioUI->width(); - h = audioUI->height(); - audioUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); + if( !xineControl()->hasVideo() ) { + w = audioUI()->width(); + h = audioUI()->height(); + audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); } else { - w = videoUI->width(); - h = videoUI->height(); - videoUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); + w = videoUI()->width(); + h = videoUI()->height(); + videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); } } void MediaPlayer::timerEvent( QTimerEvent * ) { if ( volumeDirection == +1 ) { volControl->incVol( 2 ); } else if ( volumeDirection == -1 ) { volControl->decVol( 2 ); } // TODO FIXME // huh?? unsigned int v= 0; v = volControl->volume(); v = v / 10; if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { return; } int w=0; int h=0; - if( !xineControl->hasVideo() ) { - w = audioUI->width(); - h = audioUI->height(); + if( !xineControl()->hasVideo() ) { + w = audioUI()->width(); + h = audioUI()->height(); if ( drawnOnScreenDisplay ) { if ( onScreenDisplayVolume > v ) { - audioUI->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); + audioUI()->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); } } drawnOnScreenDisplay = TRUE; onScreenDisplayVolume = v; - QPainter p( audioUI ); + QPainter p( audioUI() ); p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); QFont f; f.setPixelSize( 20 ); f.setBold( TRUE ); p.setFont( f ); p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); for ( unsigned int i = 0; i < 10; i++ ) { if ( v > i ) { p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); } else { p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); } } } else { - w = videoUI->width(); - h = videoUI->height(); + w = videoUI()->width(); + h = videoUI()->height(); if ( drawnOnScreenDisplay ) { if ( onScreenDisplayVolume > v ) { - videoUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); + videoUI()->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); } } drawnOnScreenDisplay = TRUE; onScreenDisplayVolume = v; - QPainter p( videoUI ); + QPainter p( videoUI() ); p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); QFont f; f.setPixelSize( 20 ); f.setBold( TRUE ); p.setFont( f ); p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) ); for ( unsigned int i = 0; i < 10; i++ ) { if ( v > i ) { p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); } else { p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); } } @@ -333,45 +332,64 @@ void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { case Key_F13: //mail qDebug("Blank here"); // mediaPlayerState->toggleBlank(); break; } } void MediaPlayer::cleanUp() {// this happens on closing Config cfg( "OpiePlayer" ); mediaPlayerState.writeConfig( cfg ); playList.writeDefaultPlaylist( ); // QPEApplication::grabKeyboard(); // QPEApplication::ungrabKeyboard(); } -void MediaPlayer::recreateAudioAndVideoWidgets() +void MediaPlayer::recreateAudioAndVideoWidgets() const { - 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->vidWidget(), mediaPlayerState ); - connect( xineControl, SIGNAL( initialized() ), - &mediaPlayerState, SLOT( setBackendInitialized() ) ); + delete m_xineControl; + delete m_audioUI; + delete m_videoUI; + m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); + m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); + + connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); + connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); + connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); + connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); + + connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); + connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); + connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); + connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); + + m_xineControl = new XineControl( m_videoUI->vidWidget(), mediaPlayerState ); +} + +AudioWidget *MediaPlayer::audioUI() const +{ + if ( !m_audioUI ) + recreateAudioAndVideoWidgets(); + return m_audioUI; +} + +VideoWidget *MediaPlayer::videoUI() const +{ + if ( !m_videoUI ) + recreateAudioAndVideoWidgets(); + return m_videoUI; +} + +XineControl *MediaPlayer::xineControl() const +{ + if ( !m_xineControl ) + recreateAudioAndVideoWidgets(); + return m_xineControl; } void MediaPlayer::reloadSkins() { - audioUI->loadSkin(); - videoUI->loadSkin(); + audioUI()->loadSkin(); + videoUI()->loadSkin(); } diff --git a/noncore/multimedia/opieplayer2/mediaplayer.h b/noncore/multimedia/opieplayer2/mediaplayer.h index 6b316f6..5975731 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.h +++ b/noncore/multimedia/opieplayer2/mediaplayer.h @@ -41,50 +41,56 @@ #include "playlistwidget.h" class DocLnk; class VolumeControl; class MediaPlayerState; class AudioWidget; class VideoWidget; class MediaPlayer : public QObject { Q_OBJECT public: MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ); ~MediaPlayer(); public slots: - void recreateAudioAndVideoWidgets(); void reloadSkins(); private slots: void setPlaying( bool ); void pauseCheck( bool ); void play(); void next(); void prev(); void startIncreasingVolume(); void startDecreasingVolume(); void stopChangingVolume(); void cleanUp(); void blank( bool ); protected: void timerEvent( QTimerEvent *e ); void keyReleaseEvent( QKeyEvent *e); + private: + AudioWidget *audioUI() const; + VideoWidget *videoUI() const; + XineControl *xineControl() const; bool isBlanked, l, r; int fd, fl; int volumeDirection; - XineControl *xineControl; VolumeControl *volControl; MediaPlayerState &mediaPlayerState; PlayListWidget &playList; - AudioWidget *audioUI; - VideoWidget *videoUI; + + void recreateAudioAndVideoWidgets() const; + + mutable XineControl *m_xineControl; + mutable AudioWidget *m_audioUI; + mutable VideoWidget *m_videoUI; }; #endif // MEDIA_PLAYER_H diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp index d54d870..40fa1a4 100644 --- a/noncore/multimedia/opieplayer2/mediaplayerstate.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayerstate.cpp @@ -40,77 +40,64 @@ #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); } diff --git a/noncore/multimedia/opieplayer2/mediaplayerstate.h b/noncore/multimedia/opieplayer2/mediaplayerstate.h index 6fe6d76..7408fdc 100644 --- a/noncore/multimedia/opieplayer2/mediaplayerstate.h +++ b/noncore/multimedia/opieplayer2/mediaplayerstate.h @@ -48,33 +48,32 @@ 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 ); @@ -85,62 +84,57 @@ public slots: 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 8e4f56d..c35e03d 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -52,33 +52,33 @@ #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 PlayButton( mediaPlayerState, bar, tr( "Play" ), "opieplayer2/play", + d->tbPlay = new ToolButton( 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() ) ); diff --git a/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp b/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp index 23b7a70..5fc0c39 100644 --- a/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidgetgui.cpp @@ -190,39 +190,17 @@ 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 1aa8ac8..c965b0d 100644 --- a/noncore/multimedia/opieplayer2/playlistwidgetgui.h +++ b/noncore/multimedia/opieplayer2/playlistwidgetgui.h @@ -71,50 +71,32 @@ public: 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(); diff --git a/noncore/multimedia/opieplayer2/xinecontrol.cpp b/noncore/multimedia/opieplayer2/xinecontrol.cpp index e791c3b..ee2cd83 100644 --- a/noncore/multimedia/opieplayer2/xinecontrol.cpp +++ b/noncore/multimedia/opieplayer2/xinecontrol.cpp @@ -42,33 +42,33 @@ XineControl::XineControl( XineVideoWidget *xineWidget, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) : QObject( parent, name ), mediaPlayerState( _mediaPlayerState ), xineVideoWidget( xineWidget ) { libXine = new XINE::Lib( xineWidget ); connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pause( bool ) ) ); connect( this, SIGNAL( positionChanged( long ) ), &mediaPlayerState, SLOT( updatePosition( long ) ) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( stop( bool ) ) ); connect( &mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), this, SLOT( setFullscreen( bool ) ) ); connect( &mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( seekTo( long ) ) ); connect( &mediaPlayerState, SIGNAL( videoGammaChanged( int ) ), this, SLOT( setGamma( int ) ) ); connect( libXine, SIGNAL( stopped() ), this, SLOT( nextMedia() ) ); - connect( libXine, SIGNAL( initialized() ), this, SLOT( xineInitialized() ) ); + connect( xineVideoWidget, SIGNAL( videoResized( const QSize & ) ), this, SLOT( videoResized ( const QSize & ) ) ); disabledSuspendScreenSaver = FALSE; } XineControl::~XineControl() { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( disabledSuspendScreenSaver ) { disabledSuspendScreenSaver = FALSE; // Re-enable the suspend mode QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif delete libXine; } void XineControl::play( const QString& fileName ) { @@ -113,40 +113,32 @@ void XineControl::play( const QString& fileName ) { << ( displayType == MediaPlayerState::Video ? QPEApplication::Disable : QPEApplication::DisableSuspend ); } #endif length(); position(); } void XineControl::nextMedia() { mediaPlayerState.setNext(); } void XineControl::setGamma( int value ) { libXine->setGamma( value ); } -void XineControl::xineInitialized() -{ - connect( xineVideoWidget, SIGNAL( videoResized( const QSize & ) ), this, SLOT( videoResized ( const QSize & ) ) ); - libXine->resize( xineVideoWidget->videoSize() ); - - emit initialized(); -} - void XineControl::stop( bool isSet ) { if ( !isSet ) { libXine->stop(); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( disabledSuspendScreenSaver ) { disabledSuspendScreenSaver = FALSE; // Re-enable the suspend mode QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif } } /** * Pause playback diff --git a/noncore/multimedia/opieplayer2/xinecontrol.h b/noncore/multimedia/opieplayer2/xinecontrol.h index 085de3f..fdc5d2b 100644 --- a/noncore/multimedia/opieplayer2/xinecontrol.h +++ b/noncore/multimedia/opieplayer2/xinecontrol.h @@ -87,40 +87,34 @@ public slots: /** * get the error code and "translate" it for the user * */ QString getErrorCode(); void videoResized ( const QSize &s ); /** * Set the gamma value of the video output * @param int value between -100 and 100, 0 is original */ void setGamma( int ); - -private slots: - void xineInitialized(); - private: XINE::Lib *libXine; long m_currentTime; long m_position; int m_length; QString m_fileName; bool disabledSuspendScreenSaver : 1; bool hasVideoChannel : 1; bool hasAudioChannel : 1; MediaPlayerState &mediaPlayerState; XineVideoWidget *xineVideoWidget; signals: void positionChanged( long ); - - void initialized(); }; #endif |