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