]> git.sesse.net Git - vlc/commitdiff
Pass pointer rather than ID for playlist item-current
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 16 May 2009 17:10:06 +0000 (20:10 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 16 May 2009 17:10:06 +0000 (20:10 +0300)
modules/gui/qt4/input_manager.cpp
modules/gui/skins2/src/vlcproc.cpp
modules/misc/lua/libs/playlist.c
modules/misc/notify/telepathy.c
src/playlist/engine.c
src/playlist/thread.c

index c89f5b921d3a5e64a3f2facec7f41f595ae1ecbb..e26acf193984111fcc8edad49799724c492caeab 100644 (file)
@@ -255,8 +255,9 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
     InputManager *im = (InputManager*)param;
+    input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type, p_item->i_id );
     QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
@@ -884,10 +885,18 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
              im, setInput( input_thread_t * ) );
 
     /* emit check if playlist has already started playing */
-    IMEvent *event = new IMEvent( ItemChanged_Type,
-                                  var_GetInteger( THEPL, "item-current" ) );
-    customEvent( event );
-    delete event;
+    input_thread_t *p_input = playlist_CurrentInput( THEPL );
+    if( p_input )
+    {
+        input_item_t *p_item = input_GetItem( p_input );
+        if( p_item )
+        {
+            IMEvent *event = new IMEvent( ItemChanged_Type, p_item->i_id );
+            customEvent( event );
+            delete event;
+        }
+        vlc_object_release( p_input );
+    }
 }
 
 MainInputManager::~MainInputManager()
@@ -1003,11 +1012,11 @@ void MainInputManager::activatePlayQuit( bool b_exit )
 
 /* Static callbacks for MIM */
 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *param )
+                        vlc_value_t oldval, vlc_value_t, void *param )
 {
     MainInputManager *mim = (MainInputManager*)param;
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type, 0 );
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
index 8558f398eda53ab8da35820166aff88f27a92d15..806bee7948377ae96fdb77619e86feebc0675048 100644 (file)
@@ -479,6 +479,7 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
                                void *pParam )
 {
     VlcProc *pThis = (VlcProc*)pParam;
+    input_item_t *p_item = newval.p_address;
 
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
@@ -486,10 +487,13 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
     pThis->updateStreamName();
 
     // Create two playtree notify commands: one for old item, one for new
+#if 0 /* FIXME: Heck, no! You cannot do that.
+         There is no warranty that the old item is still valid. */
     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                          oldVal.i_int );
     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
-    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
+#endif
+    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), p_item->i_id );
     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
 
     return VLC_SUCCESS;
index 58ce8c0bccdc456dbb87a75e82fab7d4c3acdaab..9e839a7947cc3d7476af849ccd984fcbfcec91ec 100644 (file)
@@ -318,7 +318,19 @@ static int vlclua_playlist_search( lua_State *L )
 static int vlclua_playlist_current( lua_State *L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    lua_pushinteger( L, var_GetInteger( p_playlist, "item-current" ) );
+    input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+    int id = -1;
+
+    if( p_input )
+    {
+        input_item_t *p_item = input_GetItem( p_input );
+        if( p_item )
+            id = p_item->i_id;
+        vlc_object_release( p_input );
+    }
+
+#warning Indexing input items by ID is unsafe,
+    lua_pushinteger( L, id );
     vlclua_release_playlist_internal( p_playlist );
     return 1;
 }
index b6c01c89a9f7d63b37ae3d84d9ec59ca0f19017b..c89c58792e96a998ac2a69e467ea80f67fd227e5 100644 (file)
@@ -173,17 +173,17 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     playlist_t* p_playlist = (playlist_t*) p_this;
     char *psz_buf = NULL;
     input_thread_t *p_input;
+    input_item_t *p_item = newval.p_address;
     bool b_is_item_current = !strcmp( "item-current", psz_var );
 
     /* Don't update Telepathy presence each time an item has been preparsed */
     if( b_is_item_current )
     { /* stores the current input item id */
-        p_intf->p_sys->i_id = newval.i_int;
+        p_intf->p_sys->i_id = p_item->i_id;
         p_intf->p_sys->i_item_changes = 0;
     }
     else
     {
-        input_item_t *p_item = newval.p_address;
 
         if( p_item->i_id != p_intf->p_sys->i_id ) /* "item-change" */
             return VLC_SUCCESS;
index f5139faa4bf4f974293158b98a9ddfb1476b526c..5b068b4083b086510056700f8ffaedeb5c426669 100644 (file)
@@ -279,8 +279,7 @@ static void VariablesInit( playlist_t *p_playlist )
 
     var_Create( p_playlist, "playlist-item-append", VLC_VAR_ADDRESS );
 
-    var_Create( p_playlist, "item-current", VLC_VAR_INTEGER );
-    var_SetInteger( p_playlist, "item-current", -1 );
+    var_Create( p_playlist, "item-current", VLC_VAR_ADDRESS );
 
     var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
     var_SetInteger( p_playlist, "activity", 0 );
index eacfd379f37ff5b52fd86a79efa340e543b574de..3e7bf06ed0e06cfdb0ab55d019f7c658cdbd85d6 100644 (file)
@@ -297,7 +297,7 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
     }
 
     PL_UNLOCK;
-    var_SetInteger( p_playlist, "item-current", p_input->i_id );
+    var_SetAddress( p_playlist, "item-current", p_input );
     PL_LOCK;
 
     return VLC_SUCCESS;