]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/extended_panels.cpp
Qt: PLModel: move zoom value out of model
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
index 5a9597a604d6e66f230b4ae4304741f37f725010..7bc89986225c6c389270fd3132a45cfa1f743153 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
  * extended_panels.cpp : Extended controls panels
  ****************************************************************************
- * Copyright (C) 2006-2008 the VideoLAN team
+ * Copyright (C) 2006-2012 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *          Antoine Cellerier <dionoea .t videolan d@t org>
+ *          Jean-Baptiste Kempf <jb@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <QString>
 #include <QFont>
 #include <QGridLayout>
-#include <QSignalMapper>
 #include <QComboBox>
 #include <QTimer>
+#include <QFileDialog>
 
 #include "components/extended_panels.hpp"
 #include "dialogs/preferences.hpp"
 #include "qt4.hpp"
 #include "input_manager.hpp"
+#include "util/qt_dirs.hpp"
 
 #include "../../audio_filter/equalizer_presets.h"
-#include <vlc_aout.h>
+#include <vlc_aout_intf.h>
 #include <vlc_intf_strings.h>
 #include <vlc_vout.h>
 #include <vlc_osd.h>
 #include <vlc_modules.h>
+#include <vlc_plugin.h>
 
 #include <vlc_charset.h> /* us_strtod */
 
+static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
+
 #if 0
 class ConfClickHandler : public QObject
 {
@@ -100,29 +105,29 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
             QObject( _parent ), p_intf( _p_intf )
 {
     ui.setupUi( _parent );
-    p_vout = NULL;
 
 #define SETUP_VFILTER( widget ) \
     { \
         vlc_object_t *p_obj = ( vlc_object_t * ) \
             vlc_object_find_name( p_intf->p_libvlc, \
-                                  #widget, \
-                                  FIND_CHILD ); \
+                                  #widget ); \
         QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
         QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
         if( p_obj ) \
         { \
             vlc_object_release( p_obj ); \
             if( checkbox ) checkbox->setChecked( true ); \
-            else groupbox->setChecked( true ); \
+            else if (groupbox) groupbox->setChecked( true ); \
         } \
         else \
         { \
             if( checkbox ) checkbox->setChecked( false ); \
-            else groupbox->setChecked( false ); \
+            else if (groupbox)  groupbox->setChecked( false ); \
         } \
     } \
     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
+
+
 #define SETUP_VFILTER_OPTION( widget, signal ) \
     initComboBoxItems( ui.widget ); \
     setWidgetValue( ui.widget ); \
@@ -140,7 +145,6 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
     SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
 
     SETUP_VFILTER( posterize )
-    SETUP_VFILTER_OPTION( posterizeLevelSpin, valueChanged( int ) )
 
     SETUP_VFILTER( colorthres )
     SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
@@ -162,8 +166,6 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
 
     SETUP_VFILTER( motiondetect )
 
-//    SETUP_VFILTER( noise )
-
     SETUP_VFILTER( psychedelic )
 
     SETUP_VFILTER( sharpen )
@@ -195,15 +197,12 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
 
-    SETUP_VFILTER( panoramix )
-    SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
-    SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
-
 
     SETUP_VFILTER( erase )
     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
+    BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
 
     SETUP_VFILTER( marq )
     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
@@ -214,6 +213,7 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
     SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
     SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
     SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
+    BUTTONACT( ui.logoBrowseBtn, browseLogo() );
 
     SETUP_VFILTER( gradfun )
     SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
@@ -221,6 +221,15 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
     SETUP_VFILTER( grain )
     SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
 
+    SETUP_VFILTER( mirror )
+
+    SETUP_VFILTER( gaussianblur )
+    SETUP_VFILTER_OPTION( gaussianbluSigmaSlider, valueChanged( int ) )
+
+    SETUP_VFILTER( antiflicker )
+    SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
+
+
     if( module_exists( "atmo" ) )
     {
         SETUP_VFILTER( atmo )
@@ -260,7 +269,7 @@ void ExtVideo::cropChange()
     if( ui.leftRightCropSync->isChecked() )
         ui.cropRightPx->setValue( ui.cropLeftPx->value() );
 
-    p_vout = THEMIM->getVout();
+    vout_thread_t *p_vout = THEMIM->getVout();
     if( p_vout )
     {
         var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
@@ -279,7 +288,7 @@ void ExtVideo::clean()
     ui.cropRightPx->setValue( 0 );
 }
 
-void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
+static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
 {
     char *psz_parser, *psz_string;
     const char *psz_filter_type;
@@ -299,17 +308,19 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
     {
         psz_filter_type = "video-filter";
     }
+    else if( module_provides( p_obj, "sub source" ) )
+    {
+        psz_filter_type = "sub-source";
+    }
     else if( module_provides( p_obj, "sub filter" ) )
     {
         psz_filter_type = "sub-filter";
     }
     else
     {
-        module_release (p_obj);
         msg_Err( p_intf, "Unknown video filter type." );
         return;
     }
-    module_release (p_obj);
 
     psz_string = config_GetPsz( p_intf, psz_filter_type );
 
@@ -332,6 +343,7 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
         }
         else
         {
+            free( psz_string );
             return;
         }
     }
@@ -350,10 +362,10 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
             }
 
             /* Remove trailing : : */
-            if( strlen( psz_string ) > 0 &&
-                *( psz_string + strlen( psz_string ) -1 ) == ':' )
+            size_t i_len = strlen( psz_string );
+            if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
             {
-                *( psz_string + strlen( psz_string ) -1 ) = '\0';
+                *( psz_string + i_len - 1 ) = '\0';
             }
         }
         else
@@ -373,7 +385,7 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
     }
     else
     {
-        p_vout = THEMIM->getVout();
+        vout_thread_t *p_vout = THEMIM->getVout();
         if( p_vout )
         {
             var_SetString( p_vout, psz_filter_type, psz_string );
@@ -391,11 +403,35 @@ void ExtVideo::updateFilters()
     QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
     QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
 
-    ChangeVFiltersString( qtu( module ),
+    ChangeVFiltersString( p_intf, qtu( module ),
                           checkbox ? checkbox->isChecked()
                                    : groupbox->isChecked() );
 }
 
+#define UPDATE_AND_APPLY_TEXT( widget, file ) \
+    CONNECT( ui.widget, textChanged( const QString& ), \
+             this, updateFilterOptions() ); \
+    ui.widget->setText( toNativeSeparators( file ) ); \
+    ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );
+
+void ExtVideo::browseLogo()
+{
+    QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
+                   p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
+
+    UPDATE_AND_APPLY_TEXT( logoFileText, file );
+}
+
+void ExtVideo::browseEraseFile()
+{
+    QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
+                   p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
+
+    UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
+}
+
+#undef UPDATE_AND_APPLY_TEXT
+
 void ExtVideo::initComboBoxItems( QObject *widget )
 {
     QComboBox *combobox = qobject_cast<QComboBox*>( widget );
@@ -406,7 +442,7 @@ void ExtVideo::initComboBoxItems( QObject *widget )
                                                  qtu( option ) );
     if( p_item )
     {
-        int i_type = p_item->i_type & CONFIG_ITEM;
+        int i_type = p_item->i_type;
         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
         {
             if( i_type == CONFIG_ITEM_INTEGER
@@ -420,8 +456,7 @@ void ExtVideo::initComboBoxItems( QObject *widget )
     }
     else
     {
-        msg_Err( p_intf, "Couldn't find option \"%s\".",
-                 qtu( option ) );
+        msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
     }
 }
 
@@ -433,9 +468,7 @@ void ExtVideo::setWidgetValue( QObject *widget )
     //std::cout << "Option name: " << option.toStdString() << std::endl;
 
     vlc_object_t *p_obj = ( vlc_object_t * )
-        vlc_object_find_name( p_intf->p_libvlc,
-                              qtu( module ),
-                              FIND_CHILD );
+        vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
     int i_type;
     vlc_value_t val;
 
@@ -493,20 +526,20 @@ void ExtVideo::setWidgetValue( QObject *widget )
         }
         else if( combobox ) combobox->setCurrentIndex(
                             combobox->findData( qlonglong(val.i_int) ) );
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        else msg_Warn( p_intf, "Could not find the correct Integer widget" );
     }
     else if( i_type == VLC_VAR_FLOAT )
     {
         if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
         else if( doublespinbox ) doublespinbox->setValue( val.f_float );
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        else msg_Warn( p_intf, "Could not find the correct Float widget" );
     }
     else if( i_type == VLC_VAR_STRING )
     {
         if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
         else if( combobox ) combobox->setCurrentIndex(
                             combobox->findData( qfu( val.psz_string ) ) );
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        else msg_Warn( p_intf, "Could not find the correct String widget" );
         free( val.psz_string );
     }
     else
@@ -526,9 +559,7 @@ void ExtVideo::updateFilterOptions()
     //std::cout << "Option name: " << option.toStdString() << std::endl;
 
     vlc_object_t *p_obj = ( vlc_object_t * )
-        vlc_object_find_name( p_intf->p_libvlc,
-                              qtu( module ),
-                              FIND_CHILD );
+        vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
     int i_type;
     bool b_is_command;
     if( !p_obj )
@@ -545,14 +576,6 @@ void ExtVideo::updateFilterOptions()
         b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
     }
 
-    if( !b_is_command )
-    {
-        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.",
-                 qtu( module ),
-                 qtu( option ) );
-        /* FIXME: restart automatically somewhere near the end of this function */
-    }
-
     /* Try to cast to all the widgets we're likely to encounter. Only
      * one of the casts is expected to work. */
     QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
@@ -573,7 +596,7 @@ void ExtVideo::updateFilterOptions()
         else if( dial )     i_int = ( 540-dial->value() )%360;
         else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
         else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        else msg_Warn( p_intf, "Could not find the correct Integer widget" );
         config_PutInt( p_intf, qtu( option ), i_int );
         if( b_is_command )
         {
@@ -590,22 +613,23 @@ void ExtVideo::updateFilterOptions()
                                          / ( double )slider->tickInterval(); /* hack alert! */
         else if( doublespinbox ) f_float = doublespinbox->value();
         else if( lineedit ) f_float = lineedit->text().toDouble();
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        else msg_Warn( p_intf, "Could not find the correct Float widget" );
         config_PutFloat( p_intf, qtu( option ), f_float );
         if( b_is_command )
             var_SetFloat( p_obj, qtu( option ), f_float );
     }
     else if( i_type == VLC_VAR_STRING )
     {
-        char *psz_string = NULL;
-        if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
-        else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
-                                       combobox->currentIndex() ).toString() ) );
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
-        config_PutPsz( p_intf, qtu( option ), psz_string );
+        QString val;
+        if( lineedit )
+            val = lineedit->text();
+        else if( combobox )
+            val = combobox->itemData( combobox->currentIndex() ).toString();
+        else
+            msg_Warn( p_intf, "Could not find the correct String widget" );
+        config_PutPsz( p_intf, qtu( option ), qtu( val ) );
         if( b_is_command )
-            var_SetString( p_obj, qtu( option ), psz_string );
-        free( psz_string );
+            var_SetString( p_obj, qtu( option ), qtu( val ) );
     }
     else
         msg_Err( p_intf,
@@ -614,6 +638,15 @@ void ExtVideo::updateFilterOptions()
                  qtu( option ),
                  i_type );
 
+    if( !b_is_command )
+    {
+        msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
+                 qtu( module ),
+                 qtu( option ) );
+        ChangeVFiltersString( p_intf, qtu( module ), false );
+        ChangeVFiltersString( p_intf, qtu( module ), true );
+    }
+
     if( p_obj ) vlc_object_release( p_obj );
 }
 
@@ -663,7 +696,7 @@ void ExtV4l2::showEvent( QShowEvent *event )
 
 void ExtV4l2::Refresh( void )
 {
-    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
+    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
     help->hide();
     if( box )
     {
@@ -673,7 +706,7 @@ void ExtV4l2::Refresh( void )
     }
     if( p_obj )
     {
-        vlc_value_t val, text, name;
+        vlc_value_t val, text;
         int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
                                 &val, &text );
         if( i_ret < 0 )
@@ -691,25 +724,30 @@ void ExtV4l2::Refresh( void )
 
         for( int i = 0; i < val.p_list->i_count; i++ )
         {
+            vlc_value_t vartext;
             const char *psz_var = text.p_list->p_values[i].psz_string;
-            var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
-            const char *psz_label = name.psz_string;
+
+            if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
+                continue;
+
+            QString name = qtr( vartext.psz_string );
+            free( vartext.psz_string );
             msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
-                     val.p_list->p_values[i].i_int, psz_var, name.psz_string );
+                     val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
 
             int i_type = var_Type( p_obj, psz_var );
             switch( i_type & VLC_VAR_TYPE )
             {
                 case VLC_VAR_INTEGER:
                 {
-                    QLabel *label = new QLabel( qtr( psz_label ), box );
+                    QLabel *label = new QLabel( name, box );
                     QHBoxLayout *hlayout = new QHBoxLayout();
                     hlayout->addWidget( label );
                     int i_val = var_GetInteger( p_obj, psz_var );
                     if( i_type & VLC_VAR_HASCHOICE )
                     {
                         QComboBox *combobox = new QComboBox( box );
-                        combobox->setObjectName( qtr( psz_var ) );
+                        combobox->setObjectName( qfu( psz_var ) );
 
                         vlc_value_t val2, text2;
                         var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
@@ -729,33 +767,48 @@ void ExtV4l2::Refresh( void )
                         hlayout->addWidget( combobox );
                     }
                     else
+                    if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
                     {
                         QSlider *slider = new QSlider( box );
-                        slider->setObjectName( qtr( psz_var ) );
+                        slider->setObjectName( qfu( psz_var ) );
                         slider->setOrientation( Qt::Horizontal );
                         vlc_value_t val2;
                         var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
                                     &val2, NULL );
+                        if( val2.i_int < INT_MIN )
+                            val2.i_int = INT_MIN; /* FIXME */
                         slider->setMinimum( val2.i_int );
                         var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
                                     &val2, NULL );
+                        if( val2.i_int > INT_MAX )
+                            val2.i_int = INT_MAX; /* FIXME */
                         slider->setMaximum( val2.i_int );
-                        var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
-                                    &val2, NULL );
-                        slider->setSingleStep( val2.i_int );
+                        if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
+                                         &val2, NULL ) )
+                            slider->setSingleStep( val2.i_int );
                         slider->setValue( i_val );
-
                         CONNECT( slider, valueChanged( int ), this,
                                  ValueChange( int ) );
                         hlayout->addWidget( slider );
                     }
+                    else
+                    {
+                        QSpinBox *spinBox = new QSpinBox( box );
+                        spinBox->setObjectName( qfu( psz_var ) );
+                        spinBox->setMinimum( INT_MIN );
+                        spinBox->setMaximum( INT_MAX );
+                        spinBox->setValue( i_val );
+                        CONNECT( spinBox, valueChanged( int ), this,
+                                 ValueChange( int ) );
+                        hlayout->addWidget( spinBox );
+                    }
                     layout->addLayout( hlayout );
                     break;
                 }
                 case VLC_VAR_BOOL:
                 {
-                    QCheckBox *button = new QCheckBox( qtr( psz_label ), box );
-                    button->setObjectName( qtr( psz_var ) );
+                    QCheckBox *button = new QCheckBox( name, box );
+                    button->setObjectName( qfu( psz_var ) );
                     button->setChecked( var_GetBool( p_obj, psz_var ) );
 
                     CONNECT( button, clicked( bool ), this,
@@ -767,8 +820,8 @@ void ExtV4l2::Refresh( void )
                 {
                     if( i_type & VLC_VAR_ISCOMMAND )
                     {
-                        QPushButton *button = new QPushButton( qtr( psz_label ), box );
-                        button->setObjectName( qtr( psz_var ) );
+                        QPushButton *button = new QPushButton( name, box );
+                        button->setObjectName( qfu( psz_var ) );
 
                         CONNECT( button, clicked( bool ), this,
                                  ValueChange( bool ) );
@@ -776,7 +829,7 @@ void ExtV4l2::Refresh( void )
                     }
                     else
                     {
-                        QLabel *label = new QLabel( qtr( psz_label ), box );
+                        QLabel *label = new QLabel( name, box );
                         layout->addWidget( label );
                     }
                     break;
@@ -785,7 +838,6 @@ void ExtV4l2::Refresh( void )
                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
                     break;
             }
-            free( name.psz_string );
         }
         var_FreeList( &val, &text );
         vlc_object_release( p_obj );
@@ -807,11 +859,11 @@ void ExtV4l2::ValueChange( bool value )
 void ExtV4l2::ValueChange( int value )
 {
     QObject *s = sender();
-    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
+    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
     if( p_obj )
     {
-        char *psz_var = strdup( qtu( s->objectName() ) );
-        int i_type = var_Type( p_obj, psz_var );
+        QString var = s->objectName();
+        int i_type = var_Type( p_obj, qtu( var ) );
         switch( i_type & VLC_VAR_TYPE )
         {
             case VLC_VAR_INTEGER:
@@ -820,16 +872,15 @@ void ExtV4l2::ValueChange( int value )
                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
                     value = combobox->itemData( value ).toInt();
                 }
-                var_SetInteger( p_obj, psz_var, value );
+                var_SetInteger( p_obj, qtu( var ), value );
                 break;
             case VLC_VAR_BOOL:
-                var_SetBool( p_obj, psz_var, value );
+                var_SetBool( p_obj, qtu( var ), value );
                 break;
             case VLC_VAR_VOID:
-                var_TriggerCallback( p_obj, psz_var );
+                var_TriggerCallback( p_obj, qtu( var ) );
                 break;
         }
-        free( psz_var );
         vlc_object_release( p_obj );
     }
     else
@@ -843,12 +894,18 @@ void ExtV4l2::ValueChange( int value )
  * Equalizer
  **********************************************************************/
 
-static const QString band_frequencies[] =
+static const QString vlc_band_frequencies[] =
 {
     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
 };
 
+static const QString iso_band_frequencies[] =
+{
+    " 31.25 Hz ", " 62.5 Hz ", " 125 Hz ", " 250 Hz ", " 500 Hz ",
+    "    1 kHz ", "   2 kHz ", "  4 kHz ", "  8 kHz ", " 16 kHz "
+};
+
 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
                             QWidget( _parent ) , p_intf( _p_intf )
 {
@@ -862,6 +919,8 @@ Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
     presetsComboBox = ui.presetsCombo;
     CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
 
+    b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
+
     /* Add the sliders for the Bands */
     QGridLayout *grid = new QGridLayout( ui.frame );
     grid->setMargin( 0 );
@@ -870,9 +929,12 @@ Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
         bands[i] = new QSlider( Qt::Vertical );
         bands[i]->setMaximum( 400 );
         bands[i]->setValue( 200 );
+        bands[i]->setMinimumWidth(36);
         CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
 
-        band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
+        QString val = QString("%1").arg( 0.0, 5, 'f', 1 );
+        band_texts[i] = new QLabel( (b_vlcBands ? vlc_band_frequencies[i]
+                                               : iso_band_frequencies[i]) + "\n" + val + "dB" );
         band_texts[i]->setFont( smallFont );
 
         grid->addWidget( bands[i], 0, i );
@@ -902,7 +964,7 @@ void Equalizer::updateUIFromCore()
     float f_preamp;
     int i_preset;
 
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     if( p_aout )
     {
         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
@@ -951,7 +1013,23 @@ void Equalizer::updateUIFromCore()
     free( psz_pres );
 }
 
-/* Functin called when enableButton is toggled */
+void Equalizer::changeFreqLabels( bool b_useVlcBands )
+{
+    b_vlcBands = b_useVlcBands;
+
+    const QString *band_frequencies = b_vlcBands
+                                    ? vlc_band_frequencies
+                                    : iso_band_frequencies;
+
+    for( int i = 0; i < BANDS; i++ )
+    {
+        const float f_val = (float)( bands[i]->value() ) / 10 - 20;
+        QString val = QString("%1").arg( f_val, 5, 'f', 1 );
+        band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
+    }
+}
+
+/* Function called when enableButton is toggled */
 void Equalizer::enable()
 {
     bool en = ui.enableCheck->isChecked();
@@ -981,7 +1059,7 @@ void Equalizer::enable( bool en )
 /* Function called when the set2Pass button is activated */
 void Equalizer::set2Pass()
 {
-    aout_instance_t *p_aout= THEMIM->getAout();
+    vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
     bool b_2p = ui.eq2PassCheck->isChecked();
 
     if( p_aout )
@@ -996,7 +1074,7 @@ void Equalizer::set2Pass()
 void Equalizer::setPreamp()
 {
     const float f = ( float )(  ui.preampSlider->value() ) /10 - 20;
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
 
     ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
                                                + qtr( "dB" ) );
@@ -1014,6 +1092,10 @@ void Equalizer::setCoreBands()
 {
     /**\todo smoothing */
 
+    const QString *band_frequencies = b_vlcBands
+                                    ? vlc_band_frequencies
+                                    : iso_band_frequencies;
+
     QString values;
     for( int i = 0; i < BANDS; i++ )
     {
@@ -1023,13 +1105,12 @@ void Equalizer::setCoreBands()
         band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
         values += " " + val;
     }
-    const char *psz_values = values.toAscii().constData();
 
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     if( p_aout )
     {
         //delCallbacks( p_aout );
-        var_SetString( p_aout, "equalizer-bands", psz_values );
+        var_SetString( p_aout, "equalizer-bands", qtu( values ) );
         //addCallbacks( p_aout );
         vlc_object_release( p_aout );
     }
@@ -1041,7 +1122,7 @@ char * Equalizer::createValuesFromPreset( int i_preset )
 
     /* Create the QString in Qt */
     for( int i = 0 ; i< BANDS ;i++ )
-        values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
+        values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
 
     /* Convert it to char * */
     return strdup( values.toAscii().constData() );
@@ -1053,7 +1134,7 @@ void Equalizer::setCorePreset( int i_preset )
         return;
 
     /* Update pre-amplification in the UI */
-    float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
+    float f_preamp = eqz_preset_10b[i_preset].f_preamp;
     ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
     ui.preampLabel->setText( qtr( "Preamp\n" )
                    + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
@@ -1061,6 +1142,10 @@ void Equalizer::setCorePreset( int i_preset )
     char *psz_values = createValuesFromPreset( i_preset );
     if( !psz_values ) return ;
 
+    const QString *band_frequencies = b_vlcBands
+                                    ? vlc_band_frequencies
+                                    : iso_band_frequencies;
+
     char *p = psz_values;
     for( int i = 0; i < BANDS && *p; i++ )
     {
@@ -1074,26 +1159,28 @@ void Equalizer::setCorePreset( int i_preset )
     }
 
     /* Apply presets to audio output */
-    aout_instance_t *p_aout= THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     if( p_aout )
     {
         var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
 
         var_SetString( p_aout, "equalizer-bands", psz_values );
         var_SetFloat( p_aout, "equalizer-preamp",
-                      eqz_preset_10b[i_preset]->f_preamp );
+                      eqz_preset_10b[i_preset].f_preamp );
         vlc_object_release( p_aout );
     }
     config_PutPsz( p_intf, "equalizer-bands", psz_values );
     config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
     config_PutFloat( p_intf, "equalizer-preamp",
-                    eqz_preset_10b[i_preset]->f_preamp );
+                    eqz_preset_10b[i_preset].f_preamp );
     free( psz_values );
 }
 
 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
+
     char *psz_preset = newval.psz_string;
     Equalizer *eq = ( Equalizer * )p_data;
     int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
@@ -1101,14 +1188,14 @@ static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
-void Equalizer::delCallbacks( aout_instance_t *p_aout )
+void Equalizer::delCallbacks( vlc_object_t *p_aout )
 {
     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
 }
 
-void Equalizer::addCallbacks( aout_instance_t *p_aout )
+void Equalizer::addCallbacks( vlc_object_t *p_aout )
 {
     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
@@ -1149,7 +1236,7 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
            : QWidget( _parent ) , p_intf( _p_intf )
 {
     QFont smallFont = QApplication::font();
-    smallFont.setPointSize( smallFont.pointSize() - 3 );
+    smallFont.setPointSize( smallFont.pointSize() - 2 );
 
     QGridLayout *layout = new QGridLayout( this );
 
@@ -1190,7 +1277,7 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
     BUTTONACT( enableCheck, enable() );
 
     /* Write down initial values */
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     char *psz_af;
 
     if( p_aout )
@@ -1219,7 +1306,7 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
     free( psz_af );
     enable( enableCheck->isChecked() );
     updateSliders( controlVars );
-    setValues( controlVars );
+    setValues();
 }
 
 void Compressor::enable()
@@ -1239,26 +1326,26 @@ void Compressor::enable( bool en )
     }
 }
 
-void Compressor::updateSliders( float * controlVars )
+void Compressor::updateSliders( float * p_controlVars )
 {
     for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
     {
-        if( oldControlVars[i] != controlVars[i] )
+        if( oldControlVars[i] != p_controlVars[i] )
         {
             compCtrl[i]->setValue(
-                    (int)( controlVars[i] / comp_controls[i].f_resolution ) );
+                    (int)( p_controlVars[i] / comp_controls[i].f_resolution ) );
         }
     }
 }
 
 void Compressor::setInitValues()
 {
-    setValues( controlVars );
+    setValues();
 }
 
-void Compressor::setValues( float * controlVars )
+void Compressor::setValues()
 {
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
 
     for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
     {
@@ -1303,7 +1390,7 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
             : QWidget( _parent ) , p_intf( _p_intf )
 {
     QFont smallFont = QApplication::font();
-    smallFont.setPointSize( smallFont.pointSize() - 3 );
+    smallFont.setPointSize( smallFont.pointSize() - 1 );
 
     QGridLayout *layout = new QGridLayout( this );
 
@@ -1313,18 +1400,7 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
     {
         spatCtrl[i] = new QSlider( Qt::Vertical );
-        if( i < 2 )
-        {
-            spatCtrl[i]->setMaximum( 10 );
-            spatCtrl[i]->setValue( 2 );
-        }
-        else
-        {
-            spatCtrl[i]->setMaximum( 10 );
-            spatCtrl[i]->setValue( 0 );
-            spatCtrl[i]->setMinimum( -10 );
-        }
-
+        spatCtrl[i]->setValue( (int)var_InheritFloat( p_intf, spat_controls[i].psz_name ) * 10. );
         oldControlVars[i] = spatCtrl[i]->value();
 
         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
@@ -1338,12 +1414,14 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
         layout->addWidget( spatCtrl[i],     1, i, Qt::AlignHCenter );
         layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
         layout->addWidget( ctrl_texts[i],   3, i, Qt::AlignHCenter );
+        spatCtrl[i]->setRange( 0, 10 );
     }
+    spatCtrl[0]->setRange( 0, 11 );
 
     BUTTONACT( enableCheck, enable() );
 
     /* Write down initial values */
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     char *psz_af;
 
     if( p_aout )
@@ -1367,7 +1445,7 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
         enableCheck->setChecked( true );
     free( psz_af );
     enable( enableCheck->isChecked() );
-    setValues( controlVars );
+    setValues();
 }
 
 void Spatializer::enable()
@@ -1388,43 +1466,45 @@ void Spatializer::enable( bool en )
 }
 void Spatializer::setInitValues()
 {
-    setValues( controlVars );
+    setValues();
 }
 
-void Spatializer::setValues( float *controlVars )
+void Spatializer::setValues()
 {
-    aout_instance_t *p_aout = THEMIM->getAout();
+    vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
 
     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
     {
-        float f = (float)(  spatCtrl[i]->value() );
+        float f = (float)( spatCtrl[i]->value() ) / 10;
         ctrl_readout[i]->setText( QString::number( f, 'f',  1 ) );
     }
+
     if( p_aout )
     {
         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
         {
+            float f = (float)( spatCtrl[i]->value() ) / 10 ;
             if( oldControlVars[i] != spatCtrl[i]->value() )
             {
-                var_SetFloat( p_aout, spat_controls[i].psz_name,
-                        ( float )spatCtrl[i]->value() );
-                config_PutFloat( p_intf, spat_controls[i].psz_name,
-                        ( float ) spatCtrl[i]->value() );
-                oldControlVars[i] = ( float ) spatCtrl[i]->value();
+                var_SetFloat( p_aout, spat_controls[i].psz_name, f );
+                config_PutFloat( p_intf, spat_controls[i].psz_name, f );
+                oldControlVars[i] = spatCtrl[i]->value();
             }
         }
         vlc_object_release( p_aout );
     }
 
 }
-void Spatializer::delCallbacks( aout_instance_t *p_aout )
+void Spatializer::delCallbacks( vlc_object_t *p_aout )
 {
+    VLC_UNUSED( p_aout );
     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
 }
 
-void Spatializer::addCallbacks( aout_instance_t *p_aout )
+void Spatializer::addCallbacks( vlc_object_t *p_aout )
 {
+    VLC_UNUSED( p_aout );
     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
 }
@@ -1432,15 +1512,49 @@ void Spatializer::addCallbacks( aout_instance_t *p_aout )
 #include <QToolButton>
 #include <QGridLayout>
 
+#define SUBSDELAY_CFG_MODE                     "subsdelay-mode"
+#define SUBSDELAY_CFG_FACTOR                   "subsdelay-factor"
+#define SUBSDELAY_MODE_ABSOLUTE                0
+#define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY   1
+#define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
+
+SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
+{
+    QHBoxLayout *layout = new QHBoxLayout;
+    spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+    spinBox.setDecimals( 3 );
+    spinBox.setMinimum( -600.0 );
+    spinBox.setMaximum( 600.0 );
+    spinBox.setSingleStep( 0.1 );
+    spinBox.setSuffix( " s" );
+    spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
+    CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
+    layout->addWidget( &spinBox );
+    layout->addWidget( &spinLabel );
+    layout->setContentsMargins( 0, 0, 0, 0 );
+    setLayout( layout );
+}
+
+void SyncWidget::valueChangedHandler( double d )
+{
+    if ( d < 0 )
+        spinLabel.setText( qtr("(Hastened)") );
+    else if ( d > 0 )
+        spinLabel.setText( qtr("(Delayed)") );
+    else
+        spinLabel.setText( "" );
+    emit valueChanged( d );
+}
+
+void SyncWidget::setValue( double d )
+{
+    spinBox.setValue( d );
+}
+
 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
                             QWidget( _parent ) , p_intf( _p_intf )
 {
     QGroupBox *AVBox, *subsBox;
-
-    QToolButton *moinsAV, *plusAV;
-    QToolButton *moinssubs, *plussubs;
-    QToolButton *moinssubSpeed, *plussubSpeed;
-
     QToolButton *updateButton;
 
     b_userAction = true;
@@ -1451,81 +1565,27 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
     AVBox = new QGroupBox( qtr( "Audio/Video" ) );
     QGridLayout *AVLayout = new QGridLayout( AVBox );
 
-    moinsAV = new QToolButton;
-    moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    moinsAV->setAutoRaise( true );
-    moinsAV->setText( "-" );
-    AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
-
-    plusAV = new QToolButton;
-    plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    plusAV->setAutoRaise( true );
-    plusAV->setText( "+" );
-    AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
-
     QLabel *AVLabel = new QLabel;
-    AVLabel->setText( qtr( "Advance of audio over video:" ) );
+    AVLabel->setText( qtr( "Audio track synchronization:" ) );
     AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
 
-    AVSpin = new QDoubleSpinBox;
-    AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
-    AVSpin->setDecimals( 3 );
-    AVSpin->setMinimum( -600.0 );
-    AVSpin->setMaximum( 600.0 );
-    AVSpin->setSingleStep( 0.1 );
-    AVSpin->setToolTip( qtr( "A positive value means that\n"
-                             "the audio is ahead of the video" ) );
-    AVSpin->setSuffix( " s" );
+    AVSpin = new SyncWidget( this );
     AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
     mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
 
-
     /* Subs */
     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
     QGridLayout *subsLayout = new QGridLayout( subsBox );
 
-    moinssubs = new QToolButton;
-    moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    moinssubs->setAutoRaise( true );
-    moinssubs->setText( "-" );
-    subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
-
-    plussubs = new QToolButton;
-    plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    plussubs->setAutoRaise( true );
-    plussubs->setText( "+" );
-    subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
-
     QLabel *subsLabel = new QLabel;
-    subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
+    subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
     subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
 
-    subsSpin = new QDoubleSpinBox;
-    subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
-    subsSpin->setDecimals( 3 );
-    subsSpin->setMinimum( -600.0 );
-    subsSpin->setMaximum( 600.0 );
-    subsSpin->setSingleStep( 0.1 );
-    subsSpin->setToolTip( qtr( "A positive value means that\n"
-                             "the subtitles are ahead of the video" ) );
-    subsSpin->setSuffix( " s" );
+    subsSpin = new SyncWidget( this );
     subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
 
-
-    moinssubSpeed = new QToolButton;
-    moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    moinssubSpeed->setAutoRaise( true );
-    moinssubSpeed->setText( "-" );
-    subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
-
-    plussubSpeed = new QToolButton;
-    plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
-    plussubSpeed->setAutoRaise( true );
-    plussubSpeed->setText( "+" );
-    subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
-
     QLabel *subSpeedLabel = new QLabel;
-    subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
+    subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
     subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
 
     subSpeedSpin = new QDoubleSpinBox;
@@ -1535,41 +1595,58 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
     subSpeedSpin->setMaximum( 100 );
     subSpeedSpin->setSingleStep( 0.2 );
     subSpeedSpin->setSuffix( " fps" );
+    subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
     subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
 
+    QLabel *subDurationLabel = new QLabel;
+    subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
+    subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
+
+    subDurationSpin = new QDoubleSpinBox;
+    subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+    subDurationSpin->setDecimals( 3 );
+    subDurationSpin->setMinimum( 0 );
+    subDurationSpin->setMaximum( 20 );
+    subDurationSpin->setSingleStep( 0.2 );
+    subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
+    subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
+
     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
 
     updateButton = new QToolButton;
     updateButton->setAutoRaise( true );
     mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
 
-
     /* Various Connects */
-    CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
-    CONNECT( plusAV, clicked(), AVSpin, stepUp () );
-    CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
-    CONNECT( plussubs, clicked(), subsSpin, stepUp () );
-    CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
-    CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
     CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
     CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
     CONNECT( subSpeedSpin, valueChanged ( double ),
              this, adjustSubsSpeed( double ) );
+    CONNECT( subDurationSpin, valueChanged ( double ),
+             this, adjustSubsDuration( double ) );
 
     CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
     BUTTON_SET_ACT_I( updateButton, "", update,
             qtr( "Force update of this dialog's values" ), update() );
 
+    initSubsDuration();
+
     /* Set it */
     update();
 }
 
+SyncControls::~SyncControls()
+{
+    subsdelayClean();
+}
+
 void SyncControls::clean()
 {
     b_userAction = false;
     AVSpin->setValue( 0.0 );
     subsSpin->setValue( 0.0 );
     subSpeedSpin->setValue( 1.0 );
+    subsdelayClean();
     b_userAction = true;
 }
 
@@ -1585,6 +1662,7 @@ void SyncControls::update()
         i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
         subsSpin->setValue( ( (double)i_delay ) / 1000000 );
         subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
+        subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
     }
     b_userAction = true;
 }
@@ -1615,6 +1693,62 @@ void SyncControls::adjustSubsSpeed( double f_fps )
     }
 }
 
+void SyncControls::adjustSubsDuration( double f_factor )
+{
+    if( THEMIM->getInput() && b_userAction )
+    {
+        subsdelaySetFactor( f_factor );
+        ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
+    }
+}
+
+void SyncControls::initSubsDuration()
+{
+    int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
+
+    switch (i_mode)
+    {
+    default:
+    case SUBSDELAY_MODE_ABSOLUTE:
+        subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
+                                          "Set 0 to disable." ) );
+        subDurationSpin->setSuffix( " s" );
+        break;
+    case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
+        subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
+                                          "Set 0 to disable." ) );
+        subDurationSpin->setSuffix( "" );
+        break;
+    case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
+        subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
+                                          "to their content and this value.\n"
+                                          "Set 0 to disable." ) );
+        subDurationSpin->setSuffix( "" );
+        break;
+    }
+}
+
+void SyncControls::subsdelayClean()
+{
+    /* Remove subsdelay filter */
+    ChangeVFiltersString( p_intf, "subsdelay", false );
+}
+
+void SyncControls::subsdelaySetFactor( double f_factor )
+{
+    /* Set the factor in the preferences */
+    config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
+
+    /* Try to find an instance of subsdelay, and set its factor */
+    vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
+    if( p_obj )
+    {
+        var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
+        vlc_object_release( p_obj );
+    }
+}
+
+
 /**********************************************************************
  * Video filters / Adjust
  **********************************************************************/