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