]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Qt: respect font sizes
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
1 /*****************************************************************************
2  * extended_panels.cpp : Extended controls panels
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea .t videolan d@t org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * ( at your option ) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <QLabel>
30 #include <QVariant>
31 #include <QString>
32 #include <QFont>
33 #include <QGridLayout>
34 #include <QSignalMapper>
35 #include <QComboBox>
36
37 #include "components/extended_panels.hpp"
38 #include "dialogs/preferences.hpp"
39 #include "qt4.hpp"
40 #include "input_manager.hpp"
41
42 #include "../../audio_filter/equalizer_presets.h"
43 #include <vlc_aout.h>
44 #include <vlc_intf_strings.h>
45 #include <vlc_vout.h>
46 #include <vlc_osd.h>
47
48 #include <vlc_charset.h> /* us_strtod */
49
50 #if 0
51 class ConfClickHandler : public QObject
52 {
53 public:
54     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
55         e = _e; p_intf = _p_intf;
56     }
57     virtual ~ConfClickHandler() {}
58     bool eventFilter( QObject *obj, QEvent *evt )
59     {
60         if( evt->type() == QEvent::MouseButtonPress )
61         {
62             e->gotoConf( obj );
63             return true;
64         }
65         return false;
66     }
67 private:
68     ExtVideo* e;
69     intf_thread_t *p_intf;
70 };
71 #endif
72
73 QString ModuleFromWidgetName( QObject *obj )
74 {
75     return obj->objectName().replace( "Enable","" );
76 }
77
78 QString OptionFromWidgetName( QObject *obj )
79 {
80     /* Gruik ? ... nah */
81     QString option = obj->objectName().replace( "Slider", "" )
82                                       .replace( "Combo" , "" )
83                                       .replace( "Dial"  , "" )
84                                       .replace( "Check" , "" )
85                                       .replace( "Spin"  , "" )
86                                       .replace( "Text"  , "" );
87     for( char a = 'A'; a <= 'Z'; a++ )
88     {
89         option = option.replace( QString( a ),
90                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
91     }
92     return option;
93 }
94
95 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
96             QObject( _parent ), p_intf( _p_intf )
97 {
98     ui.setupUi( _parent );
99     p_vout = NULL;
100
101 #define SETUP_VFILTER( widget ) \
102     { \
103         vlc_object_t *p_obj = ( vlc_object_t * ) \
104             vlc_object_find_name( p_intf->p_libvlc, \
105                                   #widget, \
106                                   FIND_CHILD ); \
107         QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
108         QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
109         if( p_obj ) \
110         { \
111             vlc_object_release( p_obj ); \
112             if( checkbox ) checkbox->setChecked( true ); \
113             else groupbox->setChecked( true ); \
114         } \
115         else \
116         { \
117             if( checkbox ) checkbox->setChecked( false ); \
118             else groupbox->setChecked( false ); \
119         } \
120     } \
121     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
122 #define SETUP_VFILTER_OPTION( widget, signal ) \
123     initComboBoxItems( ui.widget ); \
124     setWidgetValue( ui.widget ); \
125     CONNECT( ui.widget, signal, this, updateFilterOptions() );
126
127     SETUP_VFILTER( adjust )
128     SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
129     SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
130     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
131     SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
132     SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
133     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
134
135     SETUP_VFILTER( extract )
136     SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
137
138     SETUP_VFILTER( colorthres )
139     SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
140     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
141     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
142
143     SETUP_VFILTER( invert )
144
145     SETUP_VFILTER( gradient )
146     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
147     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
148     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
149
150     SETUP_VFILTER( motionblur )
151     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
152
153     SETUP_VFILTER( motiondetect )
154
155     SETUP_VFILTER( noise )
156
157     SETUP_VFILTER( psychedelic )
158
159     SETUP_VFILTER( sharpen )
160     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
161
162     SETUP_VFILTER( ripple )
163
164     SETUP_VFILTER( wave )
165
166     SETUP_VFILTER( transform )
167     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
168
169     SETUP_VFILTER( rotate )
170     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
171     ui.rotateAngleDial->setWrapping( true );
172     ui.rotateAngleDial->setNotchesVisible( true );
173
174     SETUP_VFILTER( puzzle )
175     SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
176     SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
177     SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
178
179     SETUP_VFILTER( magnify )
180
181     SETUP_VFILTER( clone )
182     SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
183
184     SETUP_VFILTER( wall )
185     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
186     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
187
188     SETUP_VFILTER( panoramix )
189     SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
190     SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
191
192
193     SETUP_VFILTER( erase )
194     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
195     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
196     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
197
198     SETUP_VFILTER( marq )
199     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
200     SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
201
202     SETUP_VFILTER( logo )
203     SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
204     SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
205     SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
206     SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
207
208     if( module_exists( "atmo" ) )
209     {
210         SETUP_VFILTER( atmo )
211         SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
212         SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
213         SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
214         SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
215         SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
216         SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
217         SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
218         SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
219     }
220     else
221     {
222         _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
223     }
224
225 #undef SETUP_VFILTER
226 #undef SETUP_VFILTER_OPTION
227
228     CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
229     CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
230     CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
231     CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
232     CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
233     CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
234     CONNECT( ui.topBotCropSync, toggled( bool ),
235              ui.cropBotPx, setDisabled( bool ) );
236     CONNECT( ui.leftRightCropSync, toggled( bool ),
237              ui.cropRightPx, setDisabled( bool ) );
238 }
239
240 ExtVideo::~ExtVideo()
241 {
242 }
243
244 void ExtVideo::cropChange()
245 {
246     if( ui.topBotCropSync->isChecked() )
247         ui.cropBotPx->setValue( ui.cropTopPx->value() );
248     if( ui.leftRightCropSync->isChecked() )
249         ui.cropRightPx->setValue( ui.cropLeftPx->value() );
250
251     p_vout = THEMIM->getVout();
252     if( p_vout )
253     {
254         var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
255         var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
256         var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
257         var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
258         vlc_object_release( p_vout );
259     }
260 }
261
262 void ExtVideo::clean()
263 {
264     ui.cropTopPx->setValue( 0 );
265     ui.cropBotPx->setValue( 0 );
266     ui.cropLeftPx->setValue( 0 );
267     ui.cropRightPx->setValue( 0 );
268 }
269
270 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
271 {
272     char *psz_parser, *psz_string;
273     const char *psz_filter_type;
274
275     /* FIXME temporary hack */
276     const char *psz_module_name = psz_name;
277     if( !strcmp( psz_name, "magnify" ) ||
278         !strcmp( psz_name, "puzzle" ) ||
279         !strcmp( psz_name, "logo" ) ||
280         !strcmp( psz_name, "wall" ) ||
281         !strcmp( psz_name, "panoramix" ) ||
282         !strcmp( psz_name, "clone" ) )
283         psz_module_name = "video_filter_wrapper";
284
285     module_t *p_obj = module_find( psz_module_name );
286     if( !p_obj )
287     {
288         msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
289         return;
290     }
291
292     if( module_provides( p_obj, "video filter" ) )
293     {
294         psz_filter_type = "vout-filter";
295     }
296     else if( module_provides( p_obj, "video filter2" ) )
297     {
298         psz_filter_type = "video-filter";
299     }
300     else if( module_provides( p_obj, "sub filter" ) )
301     {
302         psz_filter_type = "sub-filter";
303     }
304     else
305     {
306         module_release (p_obj);
307         msg_Err( p_intf, "Unknown video filter type." );
308         return;
309     }
310     module_release (p_obj);
311
312     psz_string = config_GetPsz( p_intf, psz_filter_type );
313
314     if( !psz_string ) psz_string = strdup( "" );
315
316     psz_parser = strstr( psz_string, psz_name );
317
318     if( b_add )
319     {
320         if( !psz_parser )
321         {
322             psz_parser = psz_string;
323             if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
324                             psz_string, psz_name ) == -1 )
325             {
326                 free( psz_parser );
327                 return;
328             }
329             free( psz_parser );
330         }
331         else
332         {
333             return;
334         }
335     }
336     else
337     {
338         if( psz_parser )
339         {
340             if( *( psz_parser + strlen( psz_name ) ) == ':' )
341             {
342                 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
343                          strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
344             }
345             else
346             {
347                 *psz_parser = '\0';
348             }
349
350             /* Remove trailing : : */
351             if( strlen( psz_string ) > 0 &&
352                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
353             {
354                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
355             }
356         }
357         else
358         {
359             free( psz_string );
360             return;
361         }
362     }
363     /* Vout is not kept, so put that in the config */
364     config_PutPsz( p_intf, psz_filter_type, psz_string );
365     if( !strcmp( psz_filter_type, "video-filter" ) )
366         ui.videoFilterText->setText( psz_string );
367     else if( !strcmp( psz_filter_type, "vout-filter" ) )
368         ui.voutFilterText->setText( psz_string );
369     else if( !strcmp( psz_filter_type, "sub-filter" ) )
370         ui.subpictureFilterText->setText( psz_string );
371
372     /* Try to set on the fly */
373     p_vout = THEMIM->getVout();
374     if( p_vout )
375     {
376         if( !strcmp( psz_filter_type, "sub-filter" ) )
377             var_SetString( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
378         else
379             var_SetString( p_vout, psz_filter_type, psz_string );
380         vlc_object_release( p_vout );
381     }
382
383     free( psz_string );
384 }
385
386 void ExtVideo::updateFilters()
387 {
388     QString module = ModuleFromWidgetName( sender() );
389
390     QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
391     QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
392
393     ChangeVFiltersString( qtu( module ),
394                           checkbox ? checkbox->isChecked()
395                                    : groupbox->isChecked() );
396 }
397
398 void ExtVideo::initComboBoxItems( QObject *widget )
399 {
400     QComboBox *combobox = qobject_cast<QComboBox*>( widget );
401     if( !combobox ) return;
402     QString option = OptionFromWidgetName( widget );
403     module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
404                                                  qtu( option ) );
405     if( p_item )
406     {
407         int i_type = p_item->i_type & CONFIG_ITEM;
408         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
409         {
410             if( i_type == CONFIG_ITEM_INTEGER
411              || i_type == CONFIG_ITEM_BOOL )
412                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
413                                    p_item->pi_list[i_index] );
414             else if( i_type == CONFIG_ITEM_STRING )
415                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
416                                    p_item->ppsz_list[i_index] );
417         }
418     }
419     else
420     {
421         msg_Err( p_intf, "Couldn't find option \"%s\".",
422                  qtu( option ) );
423     }
424 }
425
426 void ExtVideo::setWidgetValue( QObject *widget )
427 {
428     QString module = ModuleFromWidgetName( widget->parent() );
429     //std::cout << "Module name: " << module.toStdString() << std::endl;
430     QString option = OptionFromWidgetName( widget );
431     //std::cout << "Option name: " << option.toStdString() << std::endl;
432
433     vlc_object_t *p_obj = ( vlc_object_t * )
434         vlc_object_find_name( p_intf->p_libvlc,
435                               qtu( module ),
436                               FIND_CHILD );
437     int i_type;
438     vlc_value_t val;
439
440     if( !p_obj )
441     {
442 #if 0
443         msg_Dbg( p_intf,
444                  "Module instance %s not found, looking in config values.",
445                  qtu( module ) );
446 #endif
447         i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
448         switch( i_type )
449         {
450             case VLC_VAR_INTEGER:
451             case VLC_VAR_BOOL:
452                 val.i_int = config_GetInt( p_intf, qtu( option ) );
453                 break;
454             case VLC_VAR_FLOAT:
455                 val.f_float = config_GetFloat( p_intf, qtu( option ) );
456                 break;
457             case VLC_VAR_STRING:
458                 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
459                 break;
460         }
461     }
462     else
463     {
464         i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
465         var_Get( p_obj, qtu( option ), &val );
466         vlc_object_release( p_obj );
467     }
468
469     /* Try to cast to all the widgets we're likely to encounter. Only
470      * one of the casts is expected to work. */
471     QSlider        *slider        = qobject_cast<QSlider*>       ( widget );
472     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( widget );
473     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( widget );
474     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
475     QDial          *dial          = qobject_cast<QDial*>         ( widget );
476     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( widget );
477     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( widget );
478
479     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
480     {
481         if( slider )        slider->setValue( val.i_int );
482         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
483                                                               : Qt::Unchecked );
484         else if( spinbox )  spinbox->setValue( val.i_int );
485         else if( dial )     dial->setValue( ( 540-val.i_int )%360 );
486         else if( lineedit )
487         {
488             char str[30];
489             snprintf( str, sizeof(str), "%06X", val.i_int );
490             lineedit->setText( str );
491         }
492         else if( combobox ) combobox->setCurrentIndex(
493                             combobox->findData( val.i_int ) );
494         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
495     }
496     else if( i_type == VLC_VAR_FLOAT )
497     {
498         if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
499         else if( doublespinbox ) doublespinbox->setValue( val.f_float );
500         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
501     }
502     else if( i_type == VLC_VAR_STRING )
503     {
504         if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
505         else if( combobox ) combobox->setCurrentIndex(
506                             combobox->findData( qfu( val.psz_string ) ) );
507         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
508         free( val.psz_string );
509     }
510     else
511         msg_Err( p_intf,
512                  "Module %s's %s variable is of an unsupported type ( %d )",
513                  qtu( module ),
514                  qtu( option ),
515                  i_type );
516 }
517
518 void ExtVideo::updateFilterOptions()
519 {
520     QString module = ModuleFromWidgetName( sender()->parent() );
521     //std::cout << "Module name: " << module.toStdString() << std::endl;
522     QString option = OptionFromWidgetName( sender() );
523     //std::cout << "Option name: " << option.toStdString() << std::endl;
524
525     vlc_object_t *p_obj = ( vlc_object_t * )
526         vlc_object_find_name( p_intf->p_libvlc,
527                               qtu( module ),
528                               FIND_CHILD );
529     int i_type;
530     bool b_is_command;
531     if( !p_obj )
532     {
533         msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
534         i_type = config_GetType( p_intf, qtu( option ) );
535         b_is_command = false;
536     }
537     else
538     {
539         i_type = var_Type( p_obj, qtu( option ) );
540         b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
541     }
542
543     if( !b_is_command )
544     {
545         msg_Warn( p_intf, "Module %s's %s variable isn't a command. You'll need to restart the filter to take change into account.",
546                  qtu( module ),
547                  qtu( option ) );
548         /* FIXME: restart automatically somewhere near the end of this function */
549     }
550
551     /* Try to cast to all the widgets we're likely to encounter. Only
552      * one of the casts is expected to work. */
553     QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
554     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
555     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
556     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
557     QDial          *dial          = qobject_cast<QDial*>         ( sender() );
558     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
559     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
560
561     i_type &= VLC_VAR_CLASS;
562     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
563     {
564         int i_int = 0;
565         if( slider )        i_int = slider->value();
566         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
567         else if( spinbox )  i_int = spinbox->value();
568         else if( dial )     i_int = ( 540-dial->value() )%360;
569         else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
570         else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
571         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
572         config_PutInt( p_intf, qtu( option ), i_int );
573         if( b_is_command )
574         {
575             if( i_type == VLC_VAR_INTEGER )
576                 var_SetInteger( p_obj, qtu( option ), i_int );
577             else
578                 var_SetBool( p_obj, qtu( option ), i_int );
579         }
580     }
581     else if( i_type == VLC_VAR_FLOAT )
582     {
583         double f_float = 0;
584         if( slider )             f_float = ( double )slider->value()
585                                          / ( double )slider->tickInterval(); /* hack alert! */
586         else if( doublespinbox ) f_float = doublespinbox->value();
587         else if( lineedit ) f_float = lineedit->text().toDouble();
588         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
589         config_PutFloat( p_intf, qtu( option ), f_float );
590         if( b_is_command )
591             var_SetFloat( p_obj, qtu( option ), f_float );
592     }
593     else if( i_type == VLC_VAR_STRING )
594     {
595         char *psz_string = NULL;
596         if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
597         else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
598                                        combobox->currentIndex() ).toString() ) );
599         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
600         config_PutPsz( p_intf, qtu( option ), psz_string );
601         if( b_is_command )
602             var_SetString( p_obj, qtu( option ), psz_string );
603         free( psz_string );
604     }
605     else
606         msg_Err( p_intf,
607                  "Module %s's %s variable is of an unsupported type ( %d )",
608                  qtu( module ),
609                  qtu( option ),
610                  i_type );
611
612     if( p_obj ) vlc_object_release( p_obj );
613 }
614
615 #if 0
616 void ExtVideo::gotoConf( QObject* src )
617 {
618 #define SHOWCONF( module ) \
619     if( src->objectName().contains( module ) ) \
620     { \
621         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
622         return; \
623     }
624     SHOWCONF( "clone" );
625     SHOWCONF( "magnify" );
626     SHOWCONF( "wave" );
627     SHOWCONF( "ripple" );
628     SHOWCONF( "invert" );
629     SHOWCONF( "puzzle" );
630     SHOWCONF( "wall" );
631     SHOWCONF( "gradient" );
632     SHOWCONF( "colorthres" )
633 }
634 #endif
635
636 /**********************************************************************
637  * v4l2 controls
638  **********************************************************************/
639
640 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
641     : QWidget( _parent ), p_intf( _p_intf )
642 {
643     ui.setupUi( this );
644
645     BUTTONACT( ui.refresh, Refresh() );
646
647     box = NULL;
648 }
649
650 ExtV4l2::~ExtV4l2()
651 {
652     delete box;
653 }
654
655 void ExtV4l2::showEvent( QShowEvent *event )
656 {
657     QWidget::showEvent( event );
658     Refresh();
659 }
660
661 void ExtV4l2::Refresh( void )
662 {
663     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
664     ui.help->hide();
665     if( box )
666     {
667         ui.vboxLayout->removeWidget( box );
668         delete box;
669         box = NULL;
670     }
671     if( p_obj )
672     {
673         vlc_value_t val, text, name;
674         int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
675                                 &val, &text );
676         if( i_ret < 0 )
677         {
678             msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
679             ui.help->show();
680             vlc_object_release( p_obj );
681             return;
682         }
683
684         box = new QGroupBox( this );
685         ui.vboxLayout->addWidget( box );
686         QVBoxLayout *layout = new QVBoxLayout( box );
687         box->setLayout( layout );
688
689         for( int i = 0; i < val.p_list->i_count; i++ )
690         {
691             const char *psz_var = text.p_list->p_values[i].psz_string;
692             var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
693             const char *psz_label = name.psz_string;
694             msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
695                      val.p_list->p_values[i].i_int, psz_var, name.psz_string );
696
697             int i_type = var_Type( p_obj, psz_var );
698             switch( i_type & VLC_VAR_TYPE )
699             {
700                 case VLC_VAR_INTEGER:
701                 {
702                     QLabel *label = new QLabel( psz_label, box );
703                     QHBoxLayout *hlayout = new QHBoxLayout();
704                     hlayout->addWidget( label );
705                     int i_val = var_GetInteger( p_obj, psz_var );
706                     if( i_type & VLC_VAR_HASCHOICE )
707                     {
708                         QComboBox *combobox = new QComboBox( box );
709                         combobox->setObjectName( psz_var );
710
711                         vlc_value_t val2, text2;
712                         var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
713                                     &val2, &text2 );
714                         for( int j = 0; j < val2.p_list->i_count; j++ )
715                         {
716                             combobox->addItem(
717                                        text2.p_list->p_values[j].psz_string,
718                                        val2.p_list->p_values[j].i_int );
719                             if( i_val == val2.p_list->p_values[j].i_int )
720                                 combobox->setCurrentIndex( j );
721                         }
722                         var_FreeList( &val2, &text2 );
723
724                         CONNECT( combobox, currentIndexChanged( int ), this,
725                                  ValueChange( int ) );
726                         hlayout->addWidget( combobox );
727                     }
728                     else
729                     {
730                         QSlider *slider = new QSlider( box );
731                         slider->setObjectName( psz_var );
732                         slider->setOrientation( Qt::Horizontal );
733                         vlc_value_t val2;
734                         var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
735                                     &val2, NULL );
736                         slider->setMinimum( val2.i_int );
737                         var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
738                                     &val2, NULL );
739                         slider->setMaximum( val2.i_int );
740                         var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
741                                     &val2, NULL );
742                         slider->setSingleStep( val2.i_int );
743                         slider->setValue( i_val );
744
745                         CONNECT( slider, valueChanged( int ), this,
746                                  ValueChange( int ) );
747                         hlayout->addWidget( slider );
748                     }
749                     layout->addLayout( hlayout );
750                     break;
751                 }
752                 case VLC_VAR_BOOL:
753                 {
754                     QCheckBox *button = new QCheckBox( psz_label, box );
755                     button->setObjectName( psz_var );
756                     button->setChecked( var_GetBool( p_obj, psz_var ) );
757
758                     CONNECT( button, clicked( bool ), this,
759                              ValueChange( bool ) );
760                     layout->addWidget( button );
761                     break;
762                 }
763                 case VLC_VAR_VOID:
764                 {
765                     if( i_type & VLC_VAR_ISCOMMAND )
766                     {
767                         QPushButton *button = new QPushButton( psz_label, box );
768                         button->setObjectName( psz_var );
769
770                         CONNECT( button, clicked( bool ), this,
771                                  ValueChange( bool ) );
772                         layout->addWidget( button );
773                     }
774                     else
775                     {
776                         QLabel *label = new QLabel( psz_label, box );
777                         layout->addWidget( label );
778                     }
779                     break;
780                 }
781                 default:
782                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
783                     break;
784             }
785             free( name.psz_string );
786         }
787         var_FreeList( &val, &text );
788         vlc_object_release( p_obj );
789     }
790     else
791     {
792         msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
793         ui.help->show();
794     }
795 }
796
797 void ExtV4l2::ValueChange( bool value )
798 {
799     ValueChange( (int)value );
800 }
801
802 void ExtV4l2::ValueChange( int value )
803 {
804     QObject *s = sender();
805     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
806     if( p_obj )
807     {
808         char *psz_var = strdup( qtu( s->objectName() ) );
809         int i_type = var_Type( p_obj, psz_var );
810         switch( i_type & VLC_VAR_TYPE )
811         {
812             case VLC_VAR_INTEGER:
813                 if( i_type & VLC_VAR_HASCHOICE )
814                 {
815                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
816                     value = combobox->itemData( value ).toInt();
817                 }
818                 var_SetInteger( p_obj, psz_var, value );
819                 break;
820             case VLC_VAR_BOOL:
821                 var_SetBool( p_obj, psz_var, value );
822                 break;
823             case VLC_VAR_VOID:
824                 var_TriggerCallback( p_obj, psz_var );
825                 break;
826         }
827         free( psz_var );
828         vlc_object_release( p_obj );
829     }
830     else
831     {
832         msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
833         Refresh();
834     }
835 }
836
837 /**********************************************************************
838  * Equalizer
839  **********************************************************************/
840
841 static const QString band_frequencies[] =
842 {
843     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
844     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
845 };
846
847 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
848                             QWidget( _parent ) , p_intf( _p_intf )
849 {
850     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
851     smallFont.setPointSize( smallFont.pointSize() - 3 );
852
853     ui.setupUi( this );
854     ui.preampLabel->setFont( smallFont );
855
856     /* Setup of presetsComboBox */
857     presetsComboBox = ui.presetsCombo;
858     CONNECT( presetsComboBox, currentIndexChanged( int ),
859              this, updateUISliderValues( int ) );
860     CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
861
862     /* Add the sliders for the Bands */
863     QGridLayout *grid = new QGridLayout( ui.frame );
864     grid->setMargin( 0 );
865     for( int i = 0 ; i < BANDS ; i++ )
866     {
867         bands[i] = new QSlider( Qt::Vertical );
868         bands[i]->setMaximum( 400 );
869         bands[i]->setValue( 200 );
870         CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
871
872         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
873         band_texts[i]->setFont( smallFont );
874
875         grid->addWidget( bands[i], 0, i );
876         grid->addWidget( band_texts[i], 1, i );
877     }
878
879     /* Add the listed presets */
880     for( int i = 0 ; i < NB_PRESETS ; i ++ )
881     {
882         presetsComboBox->addItem( qtr( preset_list_text[i] ),
883                                   QVariant( preset_list[i] ) );
884     }
885
886     /* Connects */
887     BUTTONACT( ui.enableCheck, enable() );
888     BUTTONACT( ui.eq2PassCheck, set2Pass() );
889     CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
890
891     /* Do the update from the value of the core */
892     updateUIFromCore();
893 }
894
895 Equalizer::~Equalizer()
896 {
897 }
898
899 void Equalizer::clean()
900 {
901     enable();
902 }
903 /* Write down initial values */
904 void Equalizer::updateUIFromCore()
905 {
906     char *psz_af, *psz_pres, *psz_bands;
907     float f_preamp;
908     int i_preset;
909
910     aout_instance_t *p_aout = THEMIM->getAout();
911     if( p_aout )
912     {
913         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
914         psz_pres = var_GetString( p_aout, "equalizer-preset" );
915         if( var_GetBool( p_aout, "equalizer-2pass" ) )
916             ui.eq2PassCheck->setChecked( true );
917         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
918         psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
919         i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
920         vlc_object_release( p_aout );
921     }
922     else
923     {
924         psz_af = config_GetPsz( p_intf, "audio-filter" );
925         psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
926         if( config_GetInt( p_intf, "equalizer-2pass" ) )
927             ui.eq2PassCheck->setChecked( true );
928         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
929         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
930         i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
931     }
932     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
933         ui.enableCheck->setChecked( true );
934     enable( ui.enableCheck->isChecked() );
935
936     presetsComboBox->setCurrentIndex( i_preset );
937
938     ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
939
940     if( psz_bands && strlen( psz_bands ) > 1 )
941     {
942         char *psz_bands_orig = psz_bands;
943         for( int i = 0; i < BANDS; i++ )
944         {
945             const float f = us_strtod(psz_bands, &psz_bands );
946             bands[i]->setValue( (int)( ( f + 20 ) * 10 )  );
947             if( psz_bands == NULL || *psz_bands == '\0' ) break;
948             psz_bands++;
949             if( *psz_bands == '\0' ) break;
950         }
951         free( psz_bands_orig );
952     }
953     else free( psz_bands );
954
955     free( psz_af );
956     free( psz_pres );
957 }
958
959 /* Functin called when enableButton is toggled */
960 void Equalizer::enable()
961 {
962     bool en = ui.enableCheck->isChecked();
963     aout_EnableFilter( THEPL, "equalizer", en );
964 //    aout_EnableFilter( THEPL, "upmixer", en );
965 //     aout_EnableFilter( THEPL, "vsurround", en );
966     enable( en );
967
968     if( presetsComboBox->currentIndex() < 0 )
969         presetsComboBox->setCurrentIndex( 0 );
970
971 }
972
973 void Equalizer::enable( bool en )
974 {
975     ui.eq2PassCheck->setEnabled( en );
976     presetsComboBox->setEnabled( en );
977     ui.presetLabel->setEnabled( en );
978     ui.preampLabel->setEnabled( en );
979     ui.preampSlider->setEnabled( en  );
980     for( int i = 0 ; i< BANDS; i++ )
981     {
982         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
983     }
984 }
985
986 /* Function called when the set2Pass button is activated */
987 void Equalizer::set2Pass()
988 {
989     aout_instance_t *p_aout= THEMIM->getAout();
990     bool b_2p = ui.eq2PassCheck->isChecked();
991
992     if( p_aout )
993     {
994         var_SetBool( p_aout, "equalizer-2pass", b_2p );
995         vlc_object_release( p_aout );
996     }
997     config_PutInt( p_intf, "equalizer-2pass", b_2p );
998 }
999
1000 /* Function called when the preamp slider is moved */
1001 void Equalizer::setPreamp()
1002 {
1003     const float f = ( float )(  ui.preampSlider->value() ) /10 - 20;
1004     aout_instance_t *p_aout = THEMIM->getAout();
1005
1006     ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1007                                                + qtr( "dB" ) );
1008     if( p_aout )
1009     {
1010         //delCallbacks( p_aout );
1011         var_SetFloat( p_aout, "equalizer-preamp", f );
1012         //addCallbacks( p_aout );
1013         vlc_object_release( p_aout );
1014     }
1015     config_PutFloat( p_intf, "equalizer-preamp", f );
1016 }
1017
1018 void Equalizer::setCoreBands()
1019 {
1020     /**\todo smoothing */
1021
1022     QString values;
1023     for( int i = 0; i < BANDS; i++ )
1024     {
1025         const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1026         QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1027
1028         band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1029         values += " " + val;
1030     }
1031     const char *psz_values = values.toAscii().constData();
1032
1033     aout_instance_t *p_aout = THEMIM->getAout();
1034     if( p_aout )
1035     {
1036         //delCallbacks( p_aout );
1037         var_SetString( p_aout, "equalizer-bands", psz_values );
1038         //addCallbacks( p_aout );
1039         vlc_object_release( p_aout );
1040     }
1041 }
1042
1043 void Equalizer::updateUISliderValues( int i_preset )
1044 {
1045     if( i_preset < 0 ) return;
1046
1047     char *p = createValuesFromPreset( i_preset );
1048     char *psz = p;
1049     float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1050
1051     if ( p )
1052     {
1053         for( int i = 0; i < BANDS; i++ )
1054         {
1055             const float f = us_strtod(p, &p );
1056
1057             bands[i]->setValue( (int)( ( f + 20 ) * 10 )  );
1058
1059             band_texts[i]->setText( band_frequencies[i] + "\n"
1060                                   + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1061             if( p == NULL || *p == '\0' )
1062                 break;
1063             p++;
1064             if( *p == '\0' )
1065                 break;
1066         }
1067         free( psz );
1068     }
1069     ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1070     ui.preampLabel->setText( qtr( "Preamp\n" )
1071                    + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1072 }
1073
1074 char * Equalizer::createValuesFromPreset( int i_preset )
1075 {
1076     QString values;
1077
1078     /* Create the QString in Qt */
1079     for( int i = 0 ; i< BANDS ;i++ )
1080         values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1081
1082     /* Convert it to char * */
1083     return strdup( values.toAscii().constData() );
1084 }
1085
1086 void Equalizer::setCorePreset( int i_preset )
1087 {
1088     char *psz_values = createValuesFromPreset( i_preset );
1089     if( !psz_values ) return ;
1090
1091     aout_instance_t *p_aout= THEMIM->getAout();
1092     if( p_aout )
1093     {
1094         var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1095
1096         var_SetString( p_aout, "equalizer-bands", psz_values );
1097         var_SetFloat( p_aout, "equalizer-preamp",
1098                       eqz_preset_10b[i_preset]->f_preamp );
1099         vlc_object_release( p_aout );
1100     }
1101     config_PutPsz( p_intf, "equalizer-bands", psz_values );
1102     config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1103     config_PutFloat( p_intf, "equalizer-preamp",
1104                     eqz_preset_10b[i_preset]->f_preamp );
1105     free( psz_values );
1106 }
1107
1108 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1109                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1110 {
1111     char *psz_preset = newval.psz_string;
1112     Equalizer *eq = ( Equalizer * )p_data;
1113     int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1114     eq->presetsComboBox->setCurrentIndex( i_preset );
1115     return VLC_SUCCESS;
1116 }
1117
1118 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1119 {
1120     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1121     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1122     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1123 }
1124
1125 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1126 {
1127     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1128     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1129     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1130 }
1131
1132 /**********************************************************************
1133  * Audio filters
1134  **********************************************************************/
1135
1136 /**********************************************************************
1137  * Spatializer
1138  **********************************************************************/
1139 static const char *psz_control_names[] =
1140 {
1141     "spatializer-roomsize", "spatializer-width",
1142     "spatializer-wet", "spatializer-dry", "spatializer-damp"
1143 };
1144
1145 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1146     QWidget( _parent ) , p_intf( _p_intf )
1147 {
1148     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1149     smallFont.setPointSize( smallFont.pointSize() - 3 );
1150
1151     QGridLayout *layout = new QGridLayout( this );
1152     layout->setMargin( 0 );
1153
1154     enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1155     layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1156
1157     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1158     {
1159         spatCtrl[i] = new QSlider( Qt::Vertical );
1160         if( i < 2 )
1161         {
1162             spatCtrl[i]->setMaximum( 10 );
1163             spatCtrl[i]->setValue( 2 );
1164         }
1165         else
1166         {
1167             spatCtrl[i]->setMaximum( 10 );
1168             spatCtrl[i]->setValue( 0 );
1169             spatCtrl[i]->setMinimum( -10 );
1170         }
1171         oldControlVars[i] = spatCtrl[i]->value();
1172         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1173         ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1174         ctrl_texts[i]->setFont( smallFont );
1175         ctrl_readout[i] = new QLabel( "" );
1176         ctrl_readout[i]->setFont( smallFont );
1177         layout->addWidget( spatCtrl[i], 1, i );
1178         layout->addWidget( ctrl_readout[i], 2, i );
1179         layout->addWidget( ctrl_texts[i], 3, i );
1180     }
1181
1182     BUTTONACT( enableCheck, enable() );
1183
1184     /* Write down initial values */
1185     aout_instance_t *p_aout = THEMIM->getAout();
1186     char *psz_af;
1187
1188     if( p_aout )
1189     {
1190         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1191         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1192         {
1193             controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1194         }
1195         vlc_object_release( p_aout );
1196     }
1197     else
1198     {
1199         psz_af = config_GetPsz( p_intf, "audio-filter" );
1200         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1201         {
1202             controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1203         }
1204     }
1205     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1206         enableCheck->setChecked( true );
1207     free( psz_af );
1208     enable( enableCheck->isChecked() );
1209     setValues( controlVars );
1210 }
1211
1212 Spatializer::~Spatializer()
1213 {
1214 }
1215
1216 void Spatializer::enable()
1217 {
1218     bool en = enableCheck->isChecked();
1219     aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1220             en ? true : false );
1221     enable( en );
1222 }
1223
1224 void Spatializer::enable( bool en )
1225 {
1226     for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1227     {
1228         spatCtrl[i]->setEnabled( en );
1229         ctrl_texts[i]->setEnabled( en );
1230         ctrl_readout[i]->setEnabled( en );
1231     }
1232 }
1233 void Spatializer::setInitValues()
1234 {
1235     setValues( controlVars );
1236 }
1237
1238 void Spatializer::setValues( float *controlVars )
1239 {
1240     aout_instance_t *p_aout = THEMIM->getAout();
1241
1242     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1243     {
1244         float f = (float)(  spatCtrl[i]->value() );
1245         ctrl_readout[i]->setText( QString::number( f, 'f',  1 ) );
1246     }
1247     if( p_aout )
1248     {
1249         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1250         {
1251             if( oldControlVars[i] != spatCtrl[i]->value() )
1252             {
1253                 var_SetFloat( p_aout, psz_control_names[i],
1254                         ( float )spatCtrl[i]->value() );
1255                 config_PutFloat( p_intf, psz_control_names[i],
1256                         ( float ) spatCtrl[i]->value() );
1257                 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1258             }
1259         }
1260         vlc_object_release( p_aout );
1261     }
1262
1263 }
1264 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1265 {
1266     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1267     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1268 }
1269
1270 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1271 {
1272     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1273     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1274 }
1275
1276 #include <QToolButton>
1277 #include <QGridLayout>
1278
1279 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1280                             QWidget( _parent ) , p_intf( _p_intf )
1281 {
1282     QGroupBox *AVBox, *subsBox;
1283
1284     QToolButton *moinsAV, *plusAV;
1285     QToolButton *moinssubs, *plussubs;
1286     QToolButton *moinssubSpeed, *plussubSpeed;
1287
1288     QToolButton *updateButton;
1289
1290     b_userAction = true;
1291
1292     QGridLayout *mainLayout = new QGridLayout( this );
1293
1294     /* AV sync */
1295     AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1296     QGridLayout *AVLayout = new QGridLayout( AVBox );
1297
1298     moinsAV = new QToolButton;
1299     moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1300     moinsAV->setAutoRaise( true );
1301     moinsAV->setText( "-" );
1302     AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1303
1304     plusAV = new QToolButton;
1305     plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1306     plusAV->setAutoRaise( true );
1307     plusAV->setText( "+" );
1308     AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1309
1310     QLabel *AVLabel = new QLabel;
1311     AVLabel->setText( qtr( "Advance of audio over video:" ) );
1312     AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1313
1314     AVSpin = new QDoubleSpinBox;
1315     AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1316     AVSpin->setDecimals( 3 );
1317     AVSpin->setMinimum( -100.0 );
1318     AVSpin->setMaximum( 100.0 );
1319     AVSpin->setSingleStep( 0.1 );
1320     AVSpin->setToolTip( qtr( "A positive value means that\n"
1321                              "the audio is ahead of the video" ) );
1322     AVSpin->setSuffix( " s" );
1323     AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1324     mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1325
1326
1327     /* Subs */
1328     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1329     QGridLayout *subsLayout = new QGridLayout( subsBox );
1330
1331     moinssubs = new QToolButton;
1332     moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1333     moinssubs->setAutoRaise( true );
1334     moinssubs->setText( "-" );
1335     subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1336
1337     plussubs = new QToolButton;
1338     plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1339     plussubs->setAutoRaise( true );
1340     plussubs->setText( "+" );
1341     subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1342
1343     QLabel *subsLabel = new QLabel;
1344     subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1345     subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1346
1347     subsSpin = new QDoubleSpinBox;
1348     subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1349     subsSpin->setDecimals( 3 );
1350     subsSpin->setMinimum( -100.0 );
1351     subsSpin->setMaximum( 100.0 );
1352     subsSpin->setSingleStep( 0.1 );
1353     subsSpin->setToolTip( qtr( "A positive value means that\n"
1354                              "the subtitles are ahead of the video" ) );
1355     subsSpin->setSuffix( " s" );
1356     subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1357
1358
1359     moinssubSpeed = new QToolButton;
1360     moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1361     moinssubSpeed->setAutoRaise( true );
1362     moinssubSpeed->setText( "-" );
1363     subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1364
1365     plussubSpeed = new QToolButton;
1366     plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1367     plussubSpeed->setAutoRaise( true );
1368     plussubSpeed->setText( "+" );
1369     subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1370
1371     QLabel *subSpeedLabel = new QLabel;
1372     subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1373     subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1374
1375     subSpeedSpin = new QDoubleSpinBox;
1376     subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1377     subSpeedSpin->setDecimals( 3 );
1378     subSpeedSpin->setMinimum( 1 );
1379     subSpeedSpin->setMaximum( 100 );
1380     subSpeedSpin->setSingleStep( 0.2 );
1381     subSpeedSpin->setSuffix( " fps" );
1382     subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1383
1384     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1385
1386     updateButton = new QToolButton;
1387     updateButton->setAutoRaise( true );
1388     mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1389
1390
1391     /* Various Connects */
1392     CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1393     CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1394     CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1395     CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1396     CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1397     CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1398     CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1399     CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1400     CONNECT( subSpeedSpin, valueChanged ( double ),
1401              this, adjustSubsSpeed( double ) );
1402
1403     CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1404     BUTTON_SET_ACT_I( updateButton, "", update,
1405             qtr( "Force update of this dialog's values" ), update() );
1406
1407     /* Set it */
1408     update();
1409 }
1410
1411 void SyncControls::clean()
1412 {
1413     b_userAction = false;
1414     AVSpin->setValue( 0.0 );
1415     subsSpin->setValue( 0.0 );
1416     subSpeedSpin->setValue( 1.0 );
1417     b_userAction = true;
1418 }
1419
1420 void SyncControls::update()
1421 {
1422     b_userAction = false;
1423
1424     int64_t i_delay;
1425     if( THEMIM->getInput() )
1426     {
1427         i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1428         AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1429         i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1430         subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1431         subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1432     }
1433     b_userAction = true;
1434 }
1435
1436 void SyncControls::advanceAudio( double f_advance )
1437 {
1438     if( THEMIM->getInput() && b_userAction )
1439     {
1440         int64_t i_delay = f_advance * 1000000;
1441         var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1442     }
1443 }
1444
1445 void SyncControls::advanceSubs( double f_advance )
1446 {
1447     if( THEMIM->getInput() && b_userAction )
1448     {
1449         int64_t i_delay = f_advance * 1000000;
1450         var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1451     }
1452 }
1453
1454 void SyncControls::adjustSubsSpeed( double f_fps )
1455 {
1456     if( THEMIM->getInput() && b_userAction )
1457     {
1458         var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1459     }
1460 }
1461
1462 /**********************************************************************
1463  * Video filters / Adjust
1464  **********************************************************************/
1465
1466 /**********************************************************************
1467  * Extended playbak controls
1468  **********************************************************************/