[vlc-devel] [PATCHv2 18/18] qt: save effects and filters on user request

Thomas Guillem thomas at gllm.fr
Tue May 30 18:41:08 CEST 2017


Fixes #6873
---
 modules/gui/qt/components/extended_panels.cpp | 62 ++++++++++---------------
 modules/gui/qt/components/extended_panels.hpp | 27 ++++++-----
 modules/gui/qt/dialogs/extended.cpp           | 66 +++++++++++++++++++++------
 modules/gui/qt/dialogs/extended.hpp           |  5 +-
 4 files changed, 95 insertions(+), 65 deletions(-)

diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index d7cda2d7f5..30edcdc13b 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -288,7 +288,7 @@ void ExtVideo::clean()
 
 static QString ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add )
 {
-    char* psz_chain = config_GetPsz( p_intf, psz_filter_type );
+    char* psz_chain = var_GetString( THEPL, psz_filter_type );
 
     QString const chain = QString( psz_chain ? psz_chain : "" );
     QStringList list = chain.split( ':', QString::SplitBehavior::SkipEmptyParts );
@@ -326,7 +326,7 @@ void ExtVideo::changeVFiltersString( const char *psz_name, bool b_add )
 
     QString result = ChangeFiltersString( p_intf, psz_filter_type, psz_name, b_add );
 
-    config_PutPsz( p_intf, psz_filter_type, qtu( result ) );
+    emit configChanged( qfu( psz_filter_type ), result );
 
     UpdateVFiltersString( p_intf, psz_filter_type, qtu( result ) );
 }
@@ -505,7 +505,7 @@ void ExtVideo::setFilterOption( const char *psz_module, const char *psz_option,
     {
         if( i_int == -1 )
             msg_Warn( p_intf, "Could not find the correct Integer widget" );
-        config_PutInt( p_intf, psz_option, i_int );
+        emit configChanged( qfu( psz_option ), QVariant( i_int ) );
         if( i_type == VLC_VAR_INTEGER )
         {
             val.i_int = i_int;
@@ -521,7 +521,7 @@ void ExtVideo::setFilterOption( const char *psz_module, const char *psz_option,
     {
         if( f_float == -1 )
             msg_Warn( p_intf, "Could not find the correct Float widget" );
-        config_PutFloat( p_intf, psz_option, f_float );
+        emit configChanged( qfu( psz_option ), QVariant( f_float ) );
         var_SetFloat( THEPL, psz_option, f_float );
         val.f_float = f_float;
     }
@@ -532,7 +532,7 @@ void ExtVideo::setFilterOption( const char *psz_module, const char *psz_option,
             msg_Warn( p_intf, "Could not find the correct String widget" );
             psz_string = "";
         }
-        config_PutPsz( p_intf, psz_option, psz_string );
+        emit configChanged( qfu( psz_option ), QVariant( psz_string ) );
         var_SetString( THEPL, psz_option, psz_string );
         val.psz_string = (char *) psz_string;
     }
@@ -831,7 +831,6 @@ void ExtV4l2::ValueChange( int value )
 FilterSliderData::FilterSliderData( QObject *parent, QSlider *_slider ) :
     QObject( parent ), slider( _slider )
 {
-    b_save_to_config = false;
 }
 
 FilterSliderData::FilterSliderData( QObject *parent,
@@ -842,7 +841,6 @@ FilterSliderData::FilterSliderData( QObject *parent,
     QObject( parent ), slider( _slider ), valueLabel( _label ),
     nameLabel( _nameLabel ), p_data( _p_data ), p_intf( _p_intf )
 {
-    b_save_to_config = false;
     slider->setMinimum( p_data->f_min / p_data->f_resolution );
     slider->setMaximum( p_data->f_max / p_data->f_resolution );
     nameLabel->setText( p_data->descs );
@@ -894,7 +892,7 @@ float FilterSliderData::initialValue()
     return f;
 }
 
-void FilterSliderData::onValueChanged( int i ) const
+void FilterSliderData::onValueChanged( int i )
 {
     float f = ((float) i) * p_data->f_resolution;
     vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
@@ -906,16 +904,10 @@ void FilterSliderData::onValueChanged( int i ) const
     writeToConfig();
 }
 
-void FilterSliderData::writeToConfig() const
+void FilterSliderData::writeToConfig()
 {
-    if ( !b_save_to_config ) return;
     float f = ((float) slider->value()) * p_data->f_resolution;
-    config_PutFloat( p_intf, qtu(p_data->name), f );
-}
-
-void FilterSliderData::setSaveToConfig( bool b )
-{
-    b_save_to_config = b;
+    emit configChanged( p_data->name, QVariant( f ) );
 }
 
 AudioFilterControlWidget::AudioFilterControlWidget
@@ -923,6 +915,12 @@ AudioFilterControlWidget::AudioFilterControlWidget
     QWidget( parent ), p_intf( _p_intf ), name( _name ), i_smallfont(0)
 {}
 
+void AudioFilterControlWidget::connectConfigChanged( FilterSliderData *slider )
+{
+    connect( slider, SIGNAL( configChanged(QString, QVariant) ),
+             this, SIGNAL( configChanged(QString, QVariant) ) );
+}
+
 void AudioFilterControlWidget::build()
 {
     QFont smallFont = QApplication::font();
@@ -953,6 +951,7 @@ void AudioFilterControlWidget::build()
         ctrlLayout->addWidget( nameLabel, 2, i, Qt::AlignHCenter );
         i++;
         sliderDatas << filter;
+        connectConfigChanged( filter );
     }
 
     vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
@@ -974,7 +973,7 @@ void AudioFilterControlWidget::build()
     free( psz_af );
 }
 
-void AudioFilterControlWidget::enable( bool b_enable ) const
+void AudioFilterControlWidget::enable( bool b_enable )
 {
     module_t *p_obj = module_find( qtu(name) );
     if( !p_obj )
@@ -985,16 +984,10 @@ void AudioFilterControlWidget::enable( bool b_enable ) const
 
     QString result = ChangeFiltersString( p_intf, "audio-filter", qtu(name),
                                           b_enable );
-    config_PutPsz( p_intf, "audio-filter", qtu( result ) );
+    emit configChanged( qfu("audio-filter"), result );
     playlist_EnableAudioFilter( THEPL, qtu(name), b_enable );
 }
 
-void AudioFilterControlWidget::setSaveToConfig( bool b_save )
-{
-    foreach( FilterSliderData *f, sliderDatas )
-        f->setSaveToConfig( b_save );
-}
-
 /**********************************************************************
  * Equalizer
  **********************************************************************/
@@ -1064,7 +1057,7 @@ float EqualizerSliderData::initialValue()
     return f;
 }
 
-void EqualizerSliderData::onValueChanged( int i ) const
+void EqualizerSliderData::onValueChanged( int i )
 {
     QStringList bands = getBandsFromAout();
     if ( bands.count() > index )
@@ -1081,15 +1074,14 @@ void EqualizerSliderData::onValueChanged( int i ) const
     }
 }
 
-void EqualizerSliderData::writeToConfig() const
+void EqualizerSliderData::writeToConfig()
 {
-    if ( !b_save_to_config ) return;
     QStringList bands = getBandsFromAout();
     if ( bands.count() > index )
     {
         float f = (float) slider->value() * p_data->f_resolution;
         bands[ index ] = QLocale( QLocale::C ).toString( f );
-        config_PutPsz( p_intf, qtu(p_data->name), qtu(bands.join( " " )) );
+        emit configChanged( p_data->name, QVariant( bands.join( " " ) ) );
     }
 }
 
@@ -1148,6 +1140,7 @@ void Equalizer::build()
     ui.preampValue->setFont( smallFont );
     preamp = new FilterSliderData( this, p_intf,
         ui.preampSlider, ui.preampValue, ui.preampLabel, & preamp_values );
+    connectConfigChanged( preamp );
 
     /* fix sliders spacing accurately */
     int i_width = qMax( QFontMetrics( smallFont ).width( "500 Hz" ),
@@ -1171,6 +1164,7 @@ void Equalizer::build()
         ctrlLayout->addWidget( nameLabel, 1, i, Qt::AlignHCenter );
         sliderDatas << filter; /* keep track for applying presets */
         i++;
+        connectConfigChanged( filter );
     }
 
     /* Add the listed presets */
@@ -1235,12 +1229,6 @@ void Equalizer::build()
     CONNECT( ui.eq2PassCheck, toggled(bool), this, enable2Pass(bool) );
 }
 
-void Equalizer::setSaveToConfig( bool b_save )
-{
-    AudioFilterControlWidget::setSaveToConfig( b_save );
-    preamp->setSaveToConfig( b_save );
-}
-
 void Equalizer::setCorePreset( int i_preset )
 {
     if( i_preset < 1 )
@@ -1259,11 +1247,11 @@ void Equalizer::setCorePreset( int i_preset )
         var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
         vlc_object_release( p_aout );
     }
-    config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
+    emit configChanged( qfu( "equalizer-preset" ), QVariant( qfu( preset_list[i_preset] ) ) );
 }
 
 /* Function called when the set2Pass button is activated */
-void Equalizer::enable2Pass( bool b_enable ) const
+void Equalizer::enable2Pass( bool b_enable )
 {
     vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
 
@@ -1272,7 +1260,7 @@ void Equalizer::enable2Pass( bool b_enable ) const
         var_SetBool( p_aout, "equalizer-2pass", b_enable );
         vlc_object_release( p_aout );
     }
-    config_PutInt( p_intf, "equalizer-2pass", b_enable );
+    emit configChanged( qfu( "equalizer-2pass" ), QVariant( b_enable ) );
 }
 
 /**********************************************************************
diff --git a/modules/gui/qt/components/extended_panels.hpp b/modules/gui/qt/components/extended_panels.hpp
index 872b872f1d..e44dc29dd6 100644
--- a/modules/gui/qt/components/extended_panels.hpp
+++ b/modules/gui/qt/components/extended_panels.hpp
@@ -64,6 +64,8 @@ private slots:
     void cropChange();
     void browseLogo();
     void browseEraseFile();
+signals:
+    void configChanged( QString name, QVariant value );
 };
 
 class ExtV4l2 : public QWidget
@@ -110,18 +112,19 @@ public:
 protected:
     FilterSliderData( QObject *parent, QSlider *slider );
     virtual float initialValue();
+    virtual void writeToConfig();
     QSlider *slider;
     QLabel *valueLabel;
     QLabel *nameLabel;
     const slider_data_t *p_data;
     intf_thread_t *p_intf;
-    bool b_save_to_config;
 
 public slots:
-    virtual void onValueChanged( int i ) const;
+    virtual void onValueChanged( int i );
     virtual void updateText( int i );
-    virtual void writeToConfig() const;
-    void setSaveToConfig( bool );
+
+signals:
+    void configChanged( QString name, QVariant value );
 };
 
 class AudioFilterControlWidget : public QWidget
@@ -133,6 +136,7 @@ public:
 
 protected:
     virtual void build();
+    void connectConfigChanged( FilterSliderData *slider );
     QVector<FilterSliderData::slider_data_t> controls;
     QVector<FilterSliderData *> sliderDatas;
     QGroupBox *slidersBox;
@@ -141,8 +145,10 @@ protected:
     int i_smallfont;
 
 protected slots:
-    void enable( bool ) const;
-    virtual void setSaveToConfig( bool );
+    void enable( bool );
+
+signals:
+    void configChanged( QString name, QVariant value );
 };
 
 class EqualizerSliderData : public FilterSliderData
@@ -159,10 +165,10 @@ protected:
     float initialValue() Q_DECL_OVERRIDE;
     int index;
     QStringList getBandsFromAout() const;
+    void writeToConfig();
 
 public slots:
-    void onValueChanged( int i ) const Q_DECL_OVERRIDE;
-    void writeToConfig() const Q_DECL_OVERRIDE;
+    void onValueChanged( int i ) Q_DECL_OVERRIDE;
 };
 
 class Equalizer: public AudioFilterControlWidget
@@ -175,16 +181,13 @@ public:
 protected:
     void build() Q_DECL_OVERRIDE;
 
-protected slots:
-    void setSaveToConfig( bool ) Q_DECL_OVERRIDE;
-
 private:
     FilterSliderData *preamp;
     FilterSliderData::slider_data_t preamp_values;
 
 private slots:
     void setCorePreset( int );
-    void enable2Pass( bool ) const;
+    void enable2Pass( bool );
 };
 
 class Compressor: public AudioFilterControlWidget
diff --git a/modules/gui/qt/dialogs/extended.cpp b/modules/gui/qt/dialogs/extended.cpp
index 6f6a9fa57f..53321f9271 100644
--- a/modules/gui/qt/dialogs/extended.cpp
+++ b/modules/gui/qt/dialogs/extended.cpp
@@ -25,6 +25,8 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include "dialogs/extended.hpp"
 
 #include "main_interface.hpp" /* Needed for external MI size */
@@ -61,16 +63,20 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf )
     QTabWidget *audioTab = new QTabWidget( audioWidget );
 
     equal = new Equalizer( p_intf, audioTab );
+    CONNECT( equal, configChanged(QString, QVariant), this, putConfig(QString, QVariant) );
     audioTab->addTab( equal, qtr( "Equalizer" ) );
 
     Compressor *compres = new Compressor( p_intf, audioTab );
+    CONNECT( compres, configChanged(QString, QVariant), this, putConfig(QString, QVariant) );
     audioTab->addTab( compres, qtr( "Compressor" ) );
 
     Spatializer *spatial = new Spatializer( p_intf, audioTab );
+    CONNECT( spatial, configChanged(QString, QVariant), this, putConfig(QString, QVariant) );
     audioTab->addTab( spatial, qtr( "Spatializer" ) );
     audioLayout->addWidget( audioTab );
 
     StereoWidener *stereowiden = new StereoWidener( p_intf, audioTab );
+    CONNECT( stereowiden, configChanged(QString, QVariant), this, putConfig(QString, QVariant) );
     audioTab->addTab( stereowiden, qtr( "Stereo Widener" ) );
     audioLayout->addWidget( audioTab );
 
@@ -82,6 +88,7 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf )
     QTabWidget *videoTab = new QTabWidget( videoWidget );
 
     videoEffect = new ExtVideo( p_intf, videoTab );
+    CONNECT( videoEffect, configChanged(QString, QVariant), this, putConfig(QString, QVariant) );
     videoLayout->addWidget( videoTab );
     videoTab->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
 
@@ -97,24 +104,20 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf )
     }
 
     layout->addWidget( mainTabW );
-
-    /* Bottom buttons / checkbox line */
-    QHBoxLayout *buttonsLayout = new QHBoxLayout();
-    layout->addLayout( buttonsLayout );
-
-    writeChangesBox = new QCheckBox( qtr("&Write changes to config") );
-    buttonsLayout->addWidget( writeChangesBox );
-    CONNECT( writeChangesBox, toggled(bool), compres, setSaveToConfig(bool) );
-    CONNECT( writeChangesBox, toggled(bool), spatial, setSaveToConfig(bool) );
-    CONNECT( writeChangesBox, toggled(bool), equal, setSaveToConfig(bool) );
     CONNECT( mainTabW, currentChanged(int), this, currentTabChanged(int) );
 
-    QDialogButtonBox *closeButtonBox = new QDialogButtonBox( Qt::Horizontal, this );
-    closeButtonBox->addButton(
+    /* Bottom buttons */
+
+    QDialogButtonBox *buttonBox = new QDialogButtonBox( Qt::Horizontal, this );
+    m_applyButton = new QPushButton( qtr("&Save to config"), this );
+    m_applyButton->setEnabled( false );
+    buttonBox->addButton( m_applyButton, QDialogButtonBox::ApplyRole );
+    buttonBox->addButton(
         new QPushButton( qtr("&Close"), this ), QDialogButtonBox::RejectRole );
-    buttonsLayout->addWidget( closeButtonBox );
+    layout->addWidget( buttonBox );
 
-    CONNECT( closeButtonBox, rejected(), this, close() );
+    CONNECT( buttonBox, rejected(), this, close() );
+    CONNECT( m_applyButton, clicked(), this, saveToConfig() );
 
     /* Restore geometry or move this dialog on the left pane of the MI */
     if( !restoreGeometry( getSettings()->value("EPanel/geometry").toByteArray() ) )
@@ -156,5 +159,38 @@ void ExtendedDialog::changedItem( int i_status )
 
 void ExtendedDialog::currentTabChanged( int i )
 {
-    writeChangesBox->setVisible( i == AUDIO_TAB );
+    m_applyButton->setVisible( i == AUDIO_TAB || i == VIDEO_TAB );
+}
+
+void ExtendedDialog::putConfig( const QString& name, const QVariant value )
+{
+    m_hashConfig.insert( name, value );
+    m_applyButton->setEnabled( true );
+}
+
+void ExtendedDialog::saveToConfig()
+{
+    for( QHash<QString, QVariant>::iterator i = m_hashConfig.begin();
+         i != m_hashConfig.end(); ++i )
+    {
+        QVariant &value = i.value();
+        switch( static_cast<QMetaType::Type>(value.type()) )
+        {
+            case QMetaType::QString:
+                config_PutPsz( p_intf, qtu(i.key()), qtu(value.toString()) );
+                break;
+            case QMetaType::Int:
+                config_PutInt( p_intf, qtu(i.key()), value.toInt() ) ;
+                break;
+            case QMetaType::Double:
+            case QMetaType::Float:
+                config_PutFloat( p_intf, qtu(i.key()), value.toFloat() ) ;
+                break;
+            default:
+                vlc_assert_unreachable();
+        }
+    }
+    config_SaveConfigFile( p_intf );
+    m_hashConfig.clear();
+    m_applyButton->setEnabled( false );
 }
diff --git a/modules/gui/qt/dialogs/extended.hpp b/modules/gui/qt/dialogs/extended.hpp
index 3fd359651a..dd1142a0b3 100644
--- a/modules/gui/qt/dialogs/extended.hpp
+++ b/modules/gui/qt/dialogs/extended.hpp
@@ -52,10 +52,13 @@ private:
     ExtVideo *videoEffect;
     Equalizer *equal;
     QTabWidget *mainTabW;
-    QCheckBox *writeChangesBox;
+    QPushButton *m_applyButton;
+    QHash<QString, QVariant> m_hashConfig;
 private slots:
     void changedItem( int );
     void currentTabChanged( int );
+    void saveToConfig();
+    void putConfig( const QString& name, const QVariant value );
 
     friend class    Singleton<ExtendedDialog>;
 };
-- 
2.11.0



More information about the vlc-devel mailing list