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