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