]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/controller_widget.cpp
Qt4: simplify and partly fix mute tracking
[vlc] / modules / gui / qt4 / components / controller_widget.cpp
index f0df35353793f73cd40be3ea2c0235a845bd532f..90b36a1efa4141ce34a888134a671cd0546b6841 100644 (file)
@@ -31,6 +31,7 @@
 #include "input_manager.hpp"         /* Get notification of Volume Change */
 #include "util/input_slider.hpp"     /* SoundSlider */
 
+#include <math.h>
 #include <vlc_aout_intf.h>           /* Volume functions */
 
 #include <QLabel>
@@ -109,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()
@@ -151,8 +153,7 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
     /* Only if volume is set by user action on slider */
     setMuted( false );
     playlist_t *p_playlist = pl_Get( p_intf );
-    int i_res = i_sliderVolume * (AOUT_VOLUME_DEFAULT * 2) / VOLUME_MAX;
-    aout_VolumeSet( p_playlist, i_res );
+    aout_VolumeSet( p_playlist, i_sliderVolume / 100.f );
     refreshLabels();
 }
 
@@ -160,11 +161,8 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
 void SoundWidget::libUpdateVolume()
 {
     /* Audio part */
-    audio_volume_t i_volume;
     playlist_t *p_playlist = pl_Get( p_intf );
-
-    i_volume = aout_VolumeGet( p_playlist );
-    i_volume = (i_volume * VOLUME_MAX ) / (AOUT_VOLUME_DEFAULT * 2);
+    long i_volume = lroundf(aout_VolumeGet( p_playlist ) * 100.f);
 
     if ( i_volume - volumeSlider->value() != 0 )
     {
@@ -182,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();
 }