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