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