D-Bus control module
authorMirsal Ennaime <mirsal.ennaime@gmail.com>
Sun, 9 Mar 2008 10:40:54 +0000 (11:40 +0100)
committerRafaël Carré <funman@videolan.org>
Sun, 9 Mar 2008 16:58:58 +0000 (17:58 +0100)
Add the TrackListChange signal

Signed-off-by: Mirsal Ennaime <mirsal.ennaime@gmail.com>
Signed-off-by: Rafaël Carré <funman@videolan.org>
modules/control/dbus.c
modules/control/dbus.h

index f2dd61a..aa97d42 100644 (file)
@@ -2,7 +2,7 @@
  * dbus.c : D-Bus control interface
  *****************************************************************************
  * Copyright © 2006-2008 Rafaël Carré
- * Copyright © 2007 Mirsal Ennaime
+ * Copyright © 2007-2008 Mirsal Ennaime
  * $Id$
  *
  * Authors:    Rafaël Carré <funman at videolanorg>
@@ -73,6 +73,9 @@ static int TrackChange( vlc_object_t *, const char *, vlc_value_t,
 static int StatusChangeEmit( vlc_object_t *, const char *, vlc_value_t,
                         vlc_value_t, void * );
 
+static int TrackListChangeEmit( vlc_object_t *, const char *, vlc_value_t,
+                        vlc_value_t, void * );
+
 static int GetInputMeta ( input_item_t *, DBusMessageIter * );
 static int MarshalStatus ( intf_thread_t *, DBusMessageIter *, vlc_bool_t );
 
@@ -749,6 +752,9 @@ static int Open( vlc_object_t *p_this )
     p_playlist = pl_Yield( p_intf );
     PL_LOCK;
     var_AddCallback( p_playlist, "playlist-current", TrackChange, p_intf );
+    var_AddCallback( p_playlist, "intf-change", TrackListChangeEmit, p_intf );
+    var_AddCallback( p_playlist, "item-append", TrackListChangeEmit, p_intf );
+    var_AddCallback( p_playlist, "item-deleted", TrackListChangeEmit, p_intf );
     var_AddCallback( p_playlist, "random", StatusChangeEmit, p_intf );
     var_AddCallback( p_playlist, "repeat", StatusChangeEmit, p_intf );
     var_AddCallback( p_playlist, "loop", StatusChangeEmit, p_intf );
@@ -776,6 +782,9 @@ static void Close   ( vlc_object_t *p_this )
 
     PL_LOCK;
     var_DelCallback( p_playlist, "playlist-current", TrackChange, p_intf );
+    var_DelCallback( p_playlist, "intf-change", TrackListChangeEmit, p_intf );
+    var_DelCallback( p_playlist, "item-append", TrackListChangeEmit, p_intf );
+    var_DelCallback( p_playlist, "item-deleted", TrackListChangeEmit, p_intf );
     var_DelCallback( p_playlist, "random", StatusChangeEmit, p_intf );
     var_DelCallback( p_playlist, "repeat", StatusChangeEmit, p_intf );
     var_DelCallback( p_playlist, "loop", StatusChangeEmit, p_intf );
@@ -809,6 +818,40 @@ static void Run          ( intf_thread_t *p_intf )
     }
 }
 
+/******************************************************************************
+ * TrackListChange: tracklist order / length change signal 
+ *****************************************************************************/
+DBUS_SIGNAL( TrackListChangeSignal )
+{ /* emit the new tracklist lengh */
+    SIGNAL_INIT("TrackListChange");
+    OUT_ARGUMENTS;
+
+    playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_data );
+    dbus_int32_t i_elements = p_playlist->items.i_size / 2;
+    pl_Release( p_playlist );
+
+    ADD_INT32( &i_elements );
+    SIGNAL_SEND;
+}
+
+/*****************************************************************************
+ * TrackListChangeEmit: Emits the TrackListChange signal
+ *****************************************************************************/
+/* FIXME: It is not called on tracklist reorder and seems to be called
+ * twice on element addition / removal */
+static int TrackListChangeEmit( vlc_object_t *p_this, const char *psz_var,
+            vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    VLC_UNUSED(p_this); VLC_UNUSED(psz_var);
+    VLC_UNUSED(oldval); VLC_UNUSED(newval);
+    intf_thread_t *p_intf = p_data;
+
+    if( p_intf->b_dead )
+        return VLC_SUCCESS;
+
+    TrackListChangeSignal( p_intf->p_sys->p_conn, p_data );
+    return VLC_SUCCESS;
+}
 /*****************************************************************************
  * TrackChange: Playlist item change callback
  *****************************************************************************/
index 7763370..bc39fa0 100644 (file)
@@ -190,6 +190,9 @@ const char* psz_introspection_xml_data_tracklist =
 "    <method name=\"Random\">\n"
 "      <arg type=\"b\" direction=\"in\" />\n"
 "    </method>\n"
+"    <signal name=\"TrackListChange\">\n"
+"      <arg type=\"i\" />\n"
+"    </signal>\n"
 "  </interface>\n"
 "</node>\n"
 ;