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