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