]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Fix play/pause icons
[vlc] / modules / gui / qt4 / input_manager.cpp
index 2ac73afdf1422c89d82d217017530cfced84faaa..f541210463e2dd5d0785d55915bd51c7911125bd 100644 (file)
 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
                            QObject( parent ), p_intf( _p_intf )
 {
+    i_old_playing_status = END_S;
     p_input = NULL;
     /* Subscribe to updates */
-    connect( DialogsProvider::getInstance( p_intf )->fixed_timer,
-             SIGNAL( timeout() ), this, SLOT( update() ) );
+    connect( THEDP->fixed_timer, SIGNAL( timeout() ), this, SLOT( update() ) );
 }
 
 InputManager::~InputManager()
@@ -53,13 +53,13 @@ void InputManager::setInput( input_thread_t *_p_input )
 void InputManager::update()
 {
     /// \todo Emit the signals only if it changed
-    if( !p_input || p_input->b_die ) return;
+    if( !p_input  ) return;
 
-    if( p_input->b_dead )
+    if( p_input->b_dead || p_input->b_die )
     {
         emit positionUpdated( 0.0, 0, 0 );
         emit navigationChanged( 0 );
-        emit statusChanged( 0 ); // 0 = STOPPED, 1 = PAUSE, 2 = PLAY
+        emit statusChanged( 0 ); // 0 = STOPPED, 1 = PLAY, 2 = PAUSE
     }
 
     /* Update position */
@@ -103,6 +103,14 @@ void InputManager::update()
     }
     emit nameChanged( text );
 
+    /* Update playing status */
+    var_Get( p_input, "state", &val );
+    val.i_int = val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S;
+    if( i_old_playing_status != val.i_int )
+    {
+        i_old_playing_status = val.i_int;
+        emit statusChanged(  val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S );
+    }
 }
 
 void InputManager::sliderUpdate( float new_pos )
@@ -111,6 +119,24 @@ void InputManager::sliderUpdate( float new_pos )
         var_SetFloat( p_input, "position", new_pos );
 }
 
+void InputManager::togglePlayPause()
+{
+    vlc_value_t state;
+    var_Get( p_input, "state", &state );
+    if( state.i_int != PAUSE_S )
+    {
+        /* A stream is being played, pause it */
+        state.i_int = PAUSE_S;
+    }
+    else
+    {
+        /* Stream is paused, resume it */
+        state.i_int = PLAYING_S;
+    }
+    var_Set( p_input, "state", state );
+    emit statusChanged( state.i_int );
+}
+
 /**********************************************************************
  * MainInputManager implementation. Wrap an input manager and
  * take care of updating the main playlist input
@@ -130,6 +156,11 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf ) : QObject(NULL),
              im, SLOT( setInput( input_thread_t * ) ) );
 }
 
+MainInputManager::~MainInputManager()
+{
+    if( p_input ) vlc_object_release( p_input );
+}
+
 void MainInputManager::updateInput()
 {
     vlc_mutex_lock( &p_intf->change_lock );
@@ -157,3 +188,13 @@ void MainInputManager::updateInput()
     }
     vlc_mutex_unlock( &p_intf->change_lock );
 }
+
+void MainInputManager::togglePlayPause()
+{
+    if( p_input == NULL )
+    {
+        playlist_Play( THEPL );
+        return;
+    }
+    getIM()->togglePlayPause();
+}