[vlc-devel] [PATCH 11/11] qt: save effects and filters on user request
Thomas Guillem
thomas at gllm.fr
Mon May 29 18:53:05 CEST 2017
Fixes #6873
---
modules/gui/qt/components/extended_panels.cpp | 64 +++++++++++---------------
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, 96 insertions(+), 66 deletions(-)
diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index 5f3c974582..e695c38389 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -277,7 +277,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 );
@@ -315,7 +315,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 ) );
}
@@ -493,7 +493,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 ) );
var_SetInteger( THEPL, psz_option, i_int );
if( b_is_command )
var_SetInteger( p_vout, psz_option, i_int );
@@ -502,7 +502,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 Bool widget" );
- config_PutInt( p_intf, psz_option, i_int );
+ emit configChanged( qfu( psz_option ), QVariant( i_int ) );
var_SetBool( THEPL, psz_option, i_int );
if( b_is_command )
var_SetBool( p_vout, psz_option, i_int );
@@ -511,7 +511,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 );
if( b_is_command )
var_SetFloat( p_vout, psz_option, f_float );
@@ -520,7 +520,7 @@ void ExtVideo::setFilterOption( const char *psz_module, const char *psz_option,
{
if( val.isNull() )
msg_Warn( p_intf, "Could not find the correct String widget" );
- config_PutPsz( p_intf, psz_option, qtu( val ) );
+ emit configChanged( qfu( psz_option ), QVariant( val ) );
var_SetString( THEPL, psz_option, qtu( val ) );
if( b_is_command )
var_SetString( p_vout, psz_option, qtu( val ) );
@@ -804,7 +804,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,
@@ -815,7 +814,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 );
@@ -867,7 +865,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();
@@ -879,16 +877,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
@@ -896,6 +888,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();
@@ -926,6 +924,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();
@@ -947,7 +946,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 )
@@ -958,16 +957,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
**********************************************************************/
@@ -1037,7 +1030,7 @@ float EqualizerSliderData::initialValue()
return f;
}
-void EqualizerSliderData::onValueChanged( int i ) const
+void EqualizerSliderData::onValueChanged( int i )
{
QStringList bands = getBandsFromAout();
if ( bands.count() > index )
@@ -1054,15 +1047,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( " " ) ) );
}
}
@@ -1121,6 +1113,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" ),
@@ -1144,6 +1137,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 */
@@ -1208,12 +1202,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 )
@@ -1232,11 +1220,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();
@@ -1245,7 +1233,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 eece04b47a..a45e1ef795 100644
--- a/modules/gui/qt/components/extended_panels.hpp
+++ b/modules/gui/qt/components/extended_panels.hpp
@@ -63,6 +63,8 @@ private slots:
void cropChange();
void browseLogo();
void browseEraseFile();
+signals:
+ void configChanged( QString name, QVariant value );
};
class ExtV4l2 : public QWidget
@@ -109,18 +111,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
@@ -132,6 +135,7 @@ public:
protected:
virtual void build();
+ void connectConfigChanged( FilterSliderData *slider );
QVector<FilterSliderData::slider_data_t> controls;
QVector<FilterSliderData *> sliderDatas;
QGroupBox *slidersBox;
@@ -140,8 +144,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
@@ -158,10 +164,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
@@ -174,16 +180,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