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