]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Qt: correctly fallback to filename when empty tags
[vlc] / modules / gui / qt4 / input_manager.cpp
index b589564765165969d2765a3981c975d7de22e6bc..88847dfce8f93444e325f18ad4f4622650ec835f 100644 (file)
@@ -23,6 +23,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#define __STDC_FORMAT_MACROS 1
+#define __STDC_CONSTANT_MACROS 1
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -30,6 +33,9 @@
 #include "input_manager.hpp"
 #include <vlc_keys.h>
 #include <vlc_url.h>
+#include <vlc_strings.h>
+#include <vlc_aout.h>
+#include <vlc_aout_intf.h>
 
 #include <QApplication>
 
@@ -50,14 +56,6 @@ static int VolumeChanged( vlc_object_t *, const char *,
 static int SoundMuteChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
 
-static int RandomChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-static int LoopChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-static int RepeatChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-
-
 static int InputEvent( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
 static int VbiEvent( vlc_object_t *, const char *,
@@ -79,7 +77,7 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     artUrl       = "";
     p_input      = NULL;
     p_input_vbi  = NULL;
-    f_rate       = 0;
+    f_rate       = 0.;
     p_item       = NULL;
     b_video      = false;
     timeA        = 0;
@@ -103,13 +101,14 @@ void InputManager::setInput( input_thread_t *_p_input )
     {
         msg_Dbg( p_intf, "IM: Setting an input" );
         vlc_object_hold( p_input );
-        emit statusChanged( PLAYING_S );
+        addCallbacks();
+        UpdateStatus();
         UpdateName();
         UpdateArt();
         UpdateTeletext();
         UpdateNavigation();
         UpdateVout();
-        addCallbacks();
+
         p_item = input_GetItem( p_input );
         emit rateChanged( var_GetFloat( p_input, "rate" ) );
     }
@@ -138,6 +137,7 @@ void InputManager::delInput()
     b_video              = false;
     timeA                = 0;
     timeB                = 0;
+    f_rate               = 0. ;
 
     if( p_input_vbi )
     {
@@ -153,7 +153,7 @@ void InputManager::delInput()
     emit nameChanged( "" );
     emit chapterChanged( 0 );
     emit titleChanged( 0 );
-    emit statusChanged( END_S );
+    emit playingStatusChanged( END_S );
 
     emit teletextPossible( false );
     emit AtoBchanged( false, false );
@@ -255,6 +255,9 @@ void InputManager::customEvent( QEvent *event )
     case ProgramChanged_Type:
         UpdateProgramEvent();
         break;
+    case EPGEvent_Type:
+        UpdateEPG();
+        break;
     default:
         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
         assert(0);
@@ -277,6 +280,8 @@ inline void InputManager::delCallbacks()
 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
+
     InputManager *im = (InputManager*)param;
     input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
 
@@ -288,6 +293,8 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
 static int InputEvent( vlc_object_t *p_this, const char *,
                        vlc_value_t, vlc_value_t newval, void *param )
 {
+    VLC_UNUSED( p_this );
+
     InputManager *im = (InputManager*)param;
     IMEvent *event;
 
@@ -359,6 +366,11 @@ static int InputEvent( vlc_object_t *p_this, const char *,
         event = new IMEvent( ProgramChanged_Type );
         break;
 
+    case INPUT_EVENT_ITEM_EPG:
+        /* EPG data changed */
+        event = new IMEvent( EPGEvent_Type );
+        break;
+
     case INPUT_EVENT_SIGNAL:
         /* This is for capture-card signals */
         /* event = new IMEvent( SignalChanged_Type );
@@ -389,7 +401,7 @@ void InputManager::UpdatePosition()
     int i_length;
     int64_t i_time;
     float f_pos;
-    i_length = var_GetTime(  p_input , "length" ) / 1000000;
+    i_length = var_GetTime(  p_input , "length" ) / CLOCK_FREQ;
     i_time = var_GetTime(  p_input , "time");
     f_pos = var_GetFloat(  p_input , "position" );
     emit positionUpdated( f_pos, i_time, i_length );
@@ -406,15 +418,14 @@ void InputManager::UpdateNavigation()
 
     if( val.i_int > 0 )
     {
-        emit titleChanged( true );
-        msg_Dbg( p_intf, "Title %i", val.i_int );
         /* p_input != NULL since val.i_int != 0 */
         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
-        emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
-        msg_Dbg( p_intf, "Chapter: %i", val2.i_int );
+
+        emit titleChanged( val.i_int > 1 );
+        emit chapterChanged( val2.i_int > 1 );
     }
     else
-        emit titleChanged( false );
+        emit chapterChanged( false );
 }
 
 void InputManager::UpdateStatus()
@@ -424,7 +435,7 @@ void InputManager::UpdateStatus()
     if( i_old_playing_status != state )
     {
         i_old_playing_status = state;
-        emit statusChanged( state );
+        emit playingStatusChanged( state );
     }
 }
 
@@ -442,50 +453,47 @@ void InputManager::UpdateRate()
 
 void InputManager::UpdateName()
 {
-    /* Update text, name and nowplaying */
-    QString text;
+    assert( p_input );
 
-    /* Try to get the Title, then the Name */
-    char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
+    /* Update text, name and nowplaying */
+    QString name;
 
     /* Try to get the nowplaying */
-    char *psz_nowplaying =
-        input_item_GetNowPlaying( input_GetItem( p_input ) );
-    if( !EMPTY_STR( psz_nowplaying ) )
-    {
-        text.sprintf( "%s - %s", psz_nowplaying, psz_name );
-    }
-    else  /* Do it ourself */
-    {
-        char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
-
-        if( !EMPTY_STR( psz_artist ) )
-            text.sprintf( "%s - %s", psz_artist, psz_name );
-        else
-            text.sprintf( "%s", psz_name );
-
-        free( psz_artist );
-    }
-    /* Free everything */
-    free( psz_name );
-    free( psz_nowplaying );
+    char *format = var_InheritString( p_intf, "input-title-format" );
+    char *formated = str_format_meta( p_input, format );
+    free( format );
+    name = qfu(formated);
+    free( formated );
 
     /* If we have Nothing */
-    if( text.isEmpty() )
+    if( name.simplified().isEmpty() )
     {
-        psz_name = input_item_GetURI( input_GetItem( p_input ) );
-        text.sprintf( "%s", psz_name );
-        text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
-        free( psz_name );
+        char *uri = input_item_GetURI( input_GetItem( p_input ) );
+        char *file = uri ? strrchr( uri, '/' ) : NULL;
+        if( file != NULL )
+        {
+            decode_URI( ++file );
+            name = qfu(file);
+        }
+        else
+            name = qfu(uri);
+        free( uri );
     }
 
-    if( oldName != text )
+    name = name.trimmed();
+
+    if( oldName != name )
     {
-        emit nameChanged( text );
-        oldName = text;
+        emit nameChanged( name );
+        oldName = name;
     }
 }
 
+int InputManager::playingStatus()
+{
+    return i_old_playing_status;
+}
+
 bool InputManager::hasAudio()
 {
     if( hasInput() )
@@ -497,6 +505,25 @@ bool InputManager::hasAudio()
     return false;
 }
 
+bool InputManager::hasVisualisation()
+{
+    if( !p_input )
+        return false;
+
+    audio_output_t *aout = input_GetAout( p_input );
+    if( !aout )
+        return false;
+
+    char *visual = var_InheritString( aout, "visual" );
+    vlc_object_release( aout );
+
+    if( !visual )
+        return false;
+
+    free( visual );
+    return true;
+}
+
 void InputManager::UpdateTeletext()
 {
     if( hasInput() )
@@ -545,12 +572,20 @@ void InputManager::UpdateTeletext()
     }
 }
 
+void InputManager::UpdateEPG()
+{
+    if( hasInput() )
+    {
+       emit epgChanged();
+    }
+}
+
 void InputManager::UpdateVout()
 {
     if( hasInput() )
     {
         /* Get current vout lists from input */
-        int i_vout;
+        size_t i_vout;
         vout_thread_t **pp_vout;
         if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
         {
@@ -568,7 +603,7 @@ void InputManager::UpdateVout()
             emit voutChanged( b_video );
 
         /* Release the vout list */
-        for( int i = 0; i < i_vout; i++ )
+        for( size_t i = 0; i < i_vout; i++ )
             vlc_object_release( (vlc_object_t*)pp_vout[i] );
         free( pp_vout );
     }
@@ -623,7 +658,10 @@ const QString InputManager::decodeArtURL( input_item_t *p_item )
     /* Taglib seems to define a attachment://, It won't work yet */
     url = url.replace( "attachment://", "" );
 #endif
-    return qfu( psz_art ? psz_art : "" );
+
+    QString path = qfu( psz_art ? psz_art : "" );
+    free( psz_art );
+    return path;
 }
 
 void InputManager::UpdateArt()
@@ -644,21 +682,24 @@ void InputManager::UpdateArt()
 
 inline void InputManager::UpdateStats()
 {
+    assert( p_input );
     emit statisticsUpdated( input_GetItem( p_input ) );
 }
 
-inline void InputManager::UpdateMeta( input_item_t *p_item )
+inline void InputManager::UpdateMeta( input_item_t *p_item_ )
 {
-    emit metaChanged( p_item );
+    emit metaChanged( p_item_ );
 }
 
 inline void InputManager::UpdateMeta()
 {
+    assert( p_input );
     emit currentMetaChanged( input_GetItem( p_input ) );
 }
 
 inline void InputManager::UpdateInfo()
 {
+    assert( p_input );
     emit infoChanged( input_GetItem( p_input ) );
 }
 
@@ -687,18 +728,6 @@ void InputManager::sliderUpdate( float new_pos )
     emit seekRequested( new_pos );
 }
 
-/* User togglePlayPause */
-void InputManager::togglePlayPause()
-{
-    if( hasInput() )
-    {
-        int state = var_GetInteger( p_input, "state" );
-        state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
-        var_SetInteger( p_input, "state", state );
-        emit statusChanged( state );
-    }
-}
-
 void InputManager::sectionPrev()
 {
     if( hasInput() )
@@ -799,21 +828,19 @@ void InputManager::reverse()
 {
     if( hasInput() )
     {
-        float f_rate = var_GetFloat( p_input, "rate" );
-        var_SetFloat( p_input, "rate", -f_rate );
+        float f_rate_ = var_GetFloat( p_input, "rate" );
+        var_SetFloat( p_input, "rate", -f_rate_ );
     }
 }
 
 void InputManager::slower()
 {
-    if( hasInput() )
-        var_TriggerCallback( p_input, "rate-slower" );
+    var_TriggerCallback( THEPL, "rate-slower" );
 }
 
 void InputManager::faster()
 {
-    if( hasInput() )
-        var_TriggerCallback( p_input, "rate-faster" );
+    var_TriggerCallback( THEPL, "rate-faster" );
 }
 
 void InputManager::littlefaster()
@@ -828,23 +855,21 @@ void InputManager::littleslower()
 
 void InputManager::normalRate()
 {
-    if( hasInput() )
-        var_SetFloat( p_input, "rate", 1. );
+    var_SetFloat( THEPL, "rate", 1. );
 }
 
 void InputManager::setRate( int new_rate )
 {
-    if( hasInput() )
-        var_SetFloat( p_input, "rate",
-                      (float)INPUT_RATE_DEFAULT / (float)new_rate );
+    var_SetFloat( THEPL, "rate",
+                 (float)INPUT_RATE_DEFAULT / (float)new_rate );
 }
 
 void InputManager::jumpFwd()
 {
     int i_interval = var_InheritInteger( p_input, "short-jump-size" );
-    if( i_interval > 0 )
+    if( i_interval > 0 && hasInput() )
     {
-        mtime_t val = (mtime_t)(i_interval) * 1000000L;
+        mtime_t val = CLOCK_FREQ * i_interval;
         var_SetTime( p_input, "time-offset", val );
     }
 }
@@ -852,9 +877,9 @@ void InputManager::jumpFwd()
 void InputManager::jumpBwd()
 {
     int i_interval = var_InheritInteger( p_input, "short-jump-size" );
-    if( i_interval > 0 )
+    if( i_interval > 0 && hasInput() )
     {
-        mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
+        mtime_t val = -CLOCK_FREQ * i_interval;
         var_SetTime( p_input, "time-offset", val );
     }
 }
@@ -897,10 +922,11 @@ void InputManager::AtoBLoop( float, int64_t i_time, int )
  * take care of updating the main playlist input.
  * Used in the main playlist Dialog
  **********************************************************************/
-MainInputManager * MainInputManager::instance = NULL;
 
 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
-                 : QObject(NULL), p_intf( _p_intf )
+    : QObject(NULL), p_intf( _p_intf ),
+      random( VLC_OBJECT(THEPL), "random" ),
+      repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" )
 {
     p_input = NULL;
     im = new InputManager( this, p_intf );
@@ -911,29 +937,24 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
     var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
-    var_AddCallback( THEPL, "random", RandomChanged, this );
-    var_AddCallback( THEPL, "repeat", RepeatChanged, this );
-    var_AddCallback( THEPL, "loop", LoopChanged, this );
+    random.addCallback( this, SLOT(notifyRandom(bool)) );
+    repeat.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
+    loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
 
-    var_AddCallback( THEPL, "volume-change", VolumeChanged, this );
-    var_AddCallback( THEPL, "volume-muted", SoundMuteChanged, this );
+    var_AddCallback( THEPL, "volume", VolumeChanged, this );
+    var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
 
     /* Warn our embedded IM about input changes */
     DCONNECT( this, inputChanged( input_thread_t * ),
               im, setInput( input_thread_t * ) );
 
-    /* emit check if playlist has already started playing */
-    input_thread_t *p_input = playlist_CurrentInput( THEPL );
+    /* initialize p_input (an input can already be running) */
+    p_input = playlist_CurrentInput( pl_Get(p_intf) );
     if( p_input )
     {
-        input_item_t *p_item = input_GetItem( p_input );
-        if( p_item )
-        {
-            IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
-            customEvent( event );
-            delete event;
-        }
-        vlc_object_release( p_input );
+        if( !p_intf->p_sys->b_isDialogProvider )
+            var_AddCallback( p_input, "state", PLItemChanged, this );
+        emit inputChanged( p_input );
     }
 }
 
@@ -946,8 +967,8 @@ MainInputManager::~MainInputManager()
        vlc_object_release( p_input );
     }
 
-    var_DelCallback( THEPL, "volume-change", VolumeChanged, this );
-    var_DelCallback( THEPL, "volume-muted", SoundMuteChanged, this );
+    var_DelCallback( THEPL, "volume", VolumeChanged, this );
+    var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
 
     var_DelCallback( THEPL, "activity", PLItemChanged, this );
     var_DelCallback( THEPL, "item-change", ItemChanged, im );
@@ -956,10 +977,6 @@ MainInputManager::~MainInputManager()
     var_DelCallback( THEPL, "item-current", PLItemChanged, this );
     var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
-    var_DelCallback( THEPL, "random", RandomChanged, this );
-    var_DelCallback( THEPL, "repeat", RepeatChanged, this );
-    var_DelCallback( THEPL, "loop", LoopChanged, this );
-
 }
 
 vout_thread_t* MainInputManager::getVout()
@@ -967,7 +984,7 @@ vout_thread_t* MainInputManager::getVout()
     return p_input ? input_GetVout( p_input ) : NULL;
 }
 
-aout_instance_t * MainInputManager::getAout()
+audio_output_t * MainInputManager::getAout()
 {
     return p_input ? input_GetAout( p_input ) : NULL;
 }
@@ -977,7 +994,6 @@ void MainInputManager::customEvent( QEvent *event )
     int type = event->type();
 
     PLEvent *plEv;
-    IMEvent *imEv;
 
     // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
     switch( type )
@@ -996,16 +1012,14 @@ void MainInputManager::customEvent( QEvent *event )
         plEv = static_cast<PLEvent*>( event );
         emit playlistItemRemoved( plEv->i_item );
         return;
-    case RandomChanged_Type:
-        emit randomChanged( var_GetBool( THEPL, "random" ) );
-        return;
-    case LoopChanged_Type:
-    case RepeatChanged_Type:
-        notifyRepeatLoop();
+    case PLEmpty_Type:
+        plEv = static_cast<PLEvent*>( event );
+        emit playlistNotEmpty( plEv->i_item >= 0 );
         return;
     case LeafToParent_Type:
-        imEv = static_cast<IMEvent*>( event );
-        emit leafBecameParent( imEv->p_item );
+        plEv = static_cast<PLEvent*>( event );
+        emit leafBecameParent( plEv->i_item );
+        return;
     default:
         if( type != ItemChanged_Type ) return;
     }
@@ -1065,13 +1079,21 @@ void MainInputManager::prev()
    playlist_Prev( THEPL );
 }
 
+void MainInputManager::prevOrReset()
+{
+    if( !p_input || var_GetTime(  p_input , "time") < 10000 )
+        playlist_Prev( THEPL );
+    else
+        getIM()->sliderUpdate( 0.0 );
+}
+
 void MainInputManager::togglePlayPause()
 {
     /* No input, play */
     if( !p_input )
         playlist_Play( THEPL );
     else
-        getIM()->togglePlayPause();
+        playlist_Pause( THEPL );
 }
 
 void MainInputManager::play()
@@ -1083,7 +1105,7 @@ void MainInputManager::play()
     {
         if( PLAYING_S != var_GetInteger( p_input, "state" ) )
         {
-            getIM()->togglePlayPause();
+            playlist_Pause( THEPL );
         }
     }
 }
@@ -1092,19 +1114,24 @@ void MainInputManager::pause()
 {
     if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
     {
-        getIM()->togglePlayPause();
+        playlist_Pause( THEPL );
     }
 }
 
 void MainInputManager::toggleRandom()
 {
-    var_ToggleBool( THEPL, "random" );
+    config_PutInt( p_intf, "random", var_ToggleBool( THEPL, "random" ) );
 }
 
-void MainInputManager::notifyRepeatLoop()
+void MainInputManager::notifyRandom(bool value)
 {
-    int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
-              + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
+    emit randomChanged(value);
+}
+
+void MainInputManager::notifyRepeatLoop(bool)
+{
+    int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
+              + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
 
     emit repeatLoopChanged( i_value );
 }
@@ -1112,15 +1139,29 @@ void MainInputManager::notifyRepeatLoop()
 void MainInputManager::loopRepeatLoopStatus()
 {
     /* Toggle Normal -> Loop -> Repeat -> Normal ... */
-    if( var_GetBool( THEPL, "repeat" ) )
-        var_SetBool( THEPL, "repeat", false );
-    else if( var_GetBool( THEPL, "loop" ) )
+    bool loop = var_GetBool( THEPL, "loop" );
+    bool repeat = var_GetBool( THEPL, "repeat" );
+
+    if( repeat )
     {
-        var_SetBool( THEPL, "loop", false );
-        var_SetBool( THEPL, "repeat", true );
+        loop = false;
+        repeat = false;
+    }
+    else if( loop )
+    {
+        loop = false;
+        repeat = true;
     }
     else
-        var_SetBool( THEPL, "loop", true );
+    {
+        loop = true;
+        //repeat = false;
+    }
+
+    var_SetBool( THEPL, "loop", loop );
+    var_SetBool( THEPL, "repeat", repeat );
+    config_PutInt( p_intf, "loop", loop );
+    config_PutInt( p_intf, "repeat", repeat );
 }
 
 void MainInputManager::activatePlayQuit( bool b_exit )
@@ -1128,6 +1169,18 @@ void MainInputManager::activatePlayQuit( bool b_exit )
     var_SetBool( THEPL, "play-and-exit", b_exit );
 }
 
+bool MainInputManager::getPlayExitState()
+{
+    return var_GetBool( THEPL, "play-and-exit" );
+}
+
+bool MainInputManager::hasEmptyPlaylist()
+{
+    playlist_Lock( THEPL );
+    bool b_empty = playlist_IsEmpty( THEPL );
+    playlist_Unlock( THEPL );
+    return b_empty;
+}
 
 /****************************
  * Static callbacks for MIM *
@@ -1135,6 +1188,8 @@ void MainInputManager::activatePlayQuit( bool b_exit )
 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
+
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( ItemChanged_Type );
@@ -1145,10 +1200,11 @@ static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
     MainInputManager *mim = (MainInputManager*)param;
 
-    IMEvent *event = new IMEvent( LeafToParent_Type,
-                                  static_cast<input_item_t*>( newval.p_address ) );
+    PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
+
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
@@ -1156,6 +1212,8 @@ static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
+
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( VolumeChanged_Type );
@@ -1166,6 +1224,8 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
+
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( SoundMuteChanged_Type );
@@ -1176,50 +1236,31 @@ static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
 static int PLItemAppended
 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
 {
+    VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
     MainInputManager *mim = static_cast<MainInputManager*>(data);
     playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
 
     PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node  );
     QApplication::postEvent( mim, event );
-    return VLC_SUCCESS;
-}
-static int PLItemRemoved
-( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
-{
-    MainInputManager *mim = static_cast<MainInputManager*>(data);
-
-    PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0  );
-    QApplication::postEvent( mim, event );
-    return VLC_SUCCESS;
-}
-
-static int RandomChanged
-( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
-{
-    MainInputManager *mim = static_cast<MainInputManager*>(data);
-
-    IMEvent *event = new IMEvent( RandomChanged_Type );
+    event = new PLEvent( PLEmpty_Type, p_add->i_item, 0  );
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
-
-/* Probably could be merged with next callback */
-static int LoopChanged
+static int PLItemRemoved
 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
 {
-    MainInputManager *mim = static_cast<MainInputManager*>(data);
-
-    IMEvent *event = new IMEvent( LoopChanged_Type );
-    QApplication::postEvent( mim, event );
-    return VLC_SUCCESS;
-}
+    VLC_UNUSED( var ); VLC_UNUSED( old );
 
-static int RepeatChanged
-( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
-{
+    playlist_t *pl = (playlist_t *) obj;
     MainInputManager *mim = static_cast<MainInputManager*>(data);
 
-    IMEvent *event = new IMEvent( RepeatChanged_Type );
+    PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0  );
     QApplication::postEvent( mim, event );
+    // can't use playlist_IsEmpty(  ) as it isn't true yet
+    if ( pl->items.i_size == 1 ) // lock is held
+    {
+        event = new PLEvent( PLEmpty_Type, -1, 0 );
+        QApplication::postEvent( mim, event );
+    }
     return VLC_SUCCESS;
 }