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