]> git.sesse.net Git - vlc/commitdiff
Qt4: simplify and partly fix mute tracking
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 3 Jul 2012 14:42:56 +0000 (17:42 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 3 Jul 2012 15:04:09 +0000 (18:04 +0300)
This fixes a race between requesting mute and the aout actually muting.

There are still at least two known bugs with the mute widget:
 - Qt tries to sets the LibVLC status when LibVLC status changes
   (there is a hack around this for volume but not for mute).
 - Qt tracks the playlist "mute" variable instead of the aout one.

modules/gui/qt4/components/controller_widget.cpp
modules/gui/qt4/components/controller_widget.hpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp

index bdd154a9fe5c9efe21eb0bd01a0478bd7cfcbc83..90b36a1efa4141ce34a888134a671cd0546b6841 100644 (file)
@@ -110,15 +110,16 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
 
     /* Set the volume from the config */
     libUpdateVolume();
-    /* Force the update at build time in order to have a muted icon if needed */
-    updateMuteStatus();
+    /* Sync mute status */
+    if( aout_MuteGet( THEPL ) > 0 )
+        updateMuteStatus( true );
 
     /* Volume control connection */
     volumeSlider->setTracking( true );
     CONNECT( volumeSlider, valueChanged( int ), this, valueChangedFilter( int ) );
     CONNECT( this, valueReallyChanged( int ), this, userUpdateVolume( int ) );
     CONNECT( THEMIM, volumeChanged( void ), this, libUpdateVolume( void ) );
-    CONNECT( THEMIM, soundMuteChanged( void ), this, updateMuteStatus( void ) );
+    CONNECT( THEMIM, soundMuteChanged( bool ), this, updateMuteStatus( bool ) );
 }
 
 SoundWidget::~SoundWidget()
@@ -179,14 +180,13 @@ void SoundWidget::valueChangedFilter( int i_val )
 }
 
 /* libvlc mute/unmute event slot */
-void SoundWidget::updateMuteStatus()
+void SoundWidget::updateMuteStatus( bool mute )
 {
-    playlist_t *p_playlist = pl_Get( p_intf );
-    b_is_muted = aout_MuteGet( p_playlist ) > 0;
+    b_is_muted = mute;
 
     SoundSlider *soundSlider = qobject_cast<SoundSlider *>(volumeSlider);
     if( soundSlider )
-        soundSlider->setMuted( b_is_muted );
+        soundSlider->setMuted( mute );
     refreshLabels();
 }
 
index fa13ee02e665907504a99f0d1b1d4a8ca0171d60..49de57b076db3c692c0065cf0c000c60b17acb3b 100644 (file)
@@ -118,7 +118,7 @@ private:
 protected slots:
     void userUpdateVolume( int );
     void libUpdateVolume( void );
-    void updateMuteStatus( void );
+    void updateMuteStatus( bool );
     void refreshLabels( void );
     void showVolumeMenu( QPoint pos );
     void valueChangedFilter( int );
index b4ec7efec3c8e7f9e91bcf430490ec0aee137a77..bfeafce2a9e843c98bd32b32e0ec3ad600d3475c 100644 (file)
@@ -53,8 +53,6 @@ static int PLItemRemoved( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
 static int VolumeChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
-static int SoundMuteChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
 
 static int InputEvent( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
@@ -946,7 +944,8 @@ void InputManager::AtoBLoop( float, int64_t i_time, int )
 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     : QObject(NULL), p_intf( _p_intf ),
       random( VLC_OBJECT(THEPL), "random" ),
-      repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" )
+      repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" ),
+      mute( VLC_OBJECT(THEPL), "mute" )
 {
     p_input = NULL;
     im = new InputManager( this, p_intf );
@@ -962,7 +961,7 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
 
     var_AddCallback( THEPL, "volume", VolumeChanged, this );
-    var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
+    mute.addCallback( this, SLOT(notifyMute(bool)) );
 
     /* Warn our embedded IM about input changes */
     DCONNECT( this, inputChanged( input_thread_t * ),
@@ -988,7 +987,6 @@ MainInputManager::~MainInputManager()
     }
 
     var_DelCallback( THEPL, "volume", VolumeChanged, this );
-    var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
 
     var_DelCallback( THEPL, "activity", PLItemChanged, this );
     var_DelCallback( THEPL, "item-change", ItemChanged, im );
@@ -1021,9 +1019,6 @@ void MainInputManager::customEvent( QEvent *event )
     case VolumeChanged_Type:
         emit volumeChanged();
         return;
-    case SoundMuteChanged_Type:
-        emit soundMuteChanged();
-        return;
     case PLItemAppended_Type:
         plEv = static_cast<PLEvent*>( event );
         emit playlistItemAppended( plEv->i_item, plEv->i_parent );
@@ -1241,16 +1236,9 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
     return VLC_SUCCESS;
 }
 
-static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *param )
+void MainInputManager::notifyMute( bool mute )
 {
-    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
-
-    MainInputManager *mim = (MainInputManager*)param;
-
-    IMEvent *event = new IMEvent( SoundMuteChanged_Type );
-    QApplication::postEvent( mim, event );
-    return VLC_SUCCESS;
+    emit soundMuteChanged(mute);
 }
 
 static int PLItemAppended
index b7dabddaeb7e9b212da11c52d80e4aab035da791..31165a29e40946514b6e3b91eef8a39f63c1fa35 100644 (file)
@@ -46,7 +46,6 @@ enum {
     ItemTitleChanged_Type,
     ItemRateChanged_Type,
     VolumeChanged_Type,
-    SoundMuteChanged_Type,
     ItemEsChanged_Type,
     ItemTeletextChanged_Type,
     InterfaceVoutUpdate_Type,
@@ -277,6 +276,7 @@ private:
     input_thread_t          *p_input;
     intf_thread_t           *p_intf;
     QVLCBool random, repeat, loop;
+    QVLCBool mute;
 
 public slots:
     void togglePlayPause();
@@ -293,10 +293,11 @@ public slots:
 private slots:
     void notifyRandom( bool );
     void notifyRepeatLoop( bool );
+    void notifyMute( bool );
 signals:
     void inputChanged( input_thread_t * );
     void volumeChanged();
-    void soundMuteChanged();
+    void soundMuteChanged(bool);
     void playlistItemAppended( int itemId, int parentId );
     void playlistItemRemoved( int itemId );
     void playlistNotEmpty( bool );