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