]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Fix play/pause icons
[vlc] / modules / gui / qt4 / input_manager.cpp
index ca884667c70c62929323098fbaaef711c9b8d1a0..f541210463e2dd5d0785d55915bd51c7911125bd 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * input_manager.cpp : Manage an input and interact with its GUI elements
  ****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
- * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include <assert.h>
+
 #include "input_manager.hpp"
 #include "dialogs_provider.hpp"
 #include "qt4.hpp"
 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()
@@ -51,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 */
@@ -101,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 )
@@ -109,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
@@ -128,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 );
@@ -155,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();
+}