cpw.gillux.detachablepurple: 8b2a57ab: Rewritten the D-Bus code of PurpleBuddy,

gillux at soc.pidgin.im gillux at soc.pidgin.im
Sun May 20 13:21:40 EDT 2012


----------------------------------------------------------------------
Revision: 8b2a57abea7719acc42d2309265faca15c46c495
Parent:   71a46ae12e5bb608a5ab78d6e9500033879d0573
Author:   gillux at soc.pidgin.im
Date:     05/20/12 11:43:58
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/8b2a57abea7719acc42d2309265faca15c46c495

Changelog: 

Rewritten the D-Bus code of PurpleBuddy,
according to the new gdbus-based API.

Changes against parent 71a46ae12e5bb608a5ab78d6e9500033879d0573

  patched  libpurple/buddy.c
  patched  libpurple/dbus/buddy.c
  patched  libpurple/dbus/buddy.h

-------------- next part --------------
============================================================
--- libpurple/buddy.c	026851dd2ff1c368db33486ec5ba505e373a33a0
+++ libpurple/buddy.c	dcc4427e96453520bd07aa8d098e68257c57ef3e
@@ -166,7 +166,8 @@ void purple_buddy_set_alias(PurpleBuddy 
 
 	g_return_if_fail(buddy != NULL);
 
-	PURPLE_DBUS_REMOTELY_SET_PROP(buddy, g_value_set_string, G_TYPE_STRING, PROP_ALIAS_S, alias);
+	purple_object_set_prop_on_dbus(PURPLE_OBJECT(buddy),
+	                               PROP_ALIAS_S, &alias);
 
 	if ((alias != NULL) && (*alias != '\0'))
 		new_alias = purple_utf8_strip_unprintables(alias);
@@ -205,8 +206,10 @@ void purple_buddy_set_name(PurpleBuddy *
 {
 	PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
 	g_return_if_fail(buddy);
-	PURPLE_DBUS_REMOTELY_SET_PROP(buddy, g_value_set_string, G_TYPE_STRING, PROP_NAME_S, name);
 
+	purple_object_set_prop_on_dbus(PURPLE_OBJECT(buddy),
+	                               PROP_NAME_S, &name);
+
 	priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
 
 	if(priv->name)
@@ -538,8 +541,10 @@ PurpleBuddy *purple_buddy_new(PurpleAcco
 			PROP_NAME_S, name,
 			PROP_ALIAS_S, alias,
 			NULL);
-	purple_buddy_dbus_init(buddy, name);
 
+	/* Export this new object on D-Bus and propagate any property change. */
+	purple_object_dbus_init(buddy, TRUE);
+
 	if (parent)
 		purple_blist_node_add_child(parent, PURPLE_BLIST_NODE(buddy));
 	g_signal_emit_by_name(G_OBJECT(buddy), "new");
@@ -671,7 +676,7 @@ purple_buddy_class_init(PurpleBuddyClass
 				G_PARAM_READWRITE)
 			);
 
-	purple_buddy_class_dbus_init();
+	purple_buddy_class_dbus_init(klass);
 }
 
 static void
============================================================
--- libpurple/dbus/buddy.c	cf170f12fb8e6f07caef65d441fe04a31d468b08
+++ libpurple/dbus/buddy.c	fdd8c160ab086aa943275b529eaf577716117f1c
@@ -21,20 +21,22 @@
 
 #include "internal.h"
 #include "core.h"
-#include "buddy.h"
+#include "dbus/constructor.h"
 #include "dbus/buddy.h"
-#include "dbus/buddy-client.h"
-#include "dbus/buddy-server.h"
+#include "dbus/buddy.xml.h"
 #include "dbus-purple.h"
 #include "dbus-server.h"
 
 static char *
-purple_buddy_build_dbus_path(const char *name)
+purple_buddy_build_dbus_path(PurpleObject *pobject)
 {
 	static unsigned int buddy_id = 0;
+	const char *name;
 	gchar *path;
 	gchar *name_valid;
 
+	name = purple_buddy_get_name(PURPLE_BUDDY(pobject));
+
 	/* Buddy names arn't unique, so we use an id. We also append the buddy
 	 * name, to make a meaningful path. */
 	name_valid = purple_dbus_sanitize_dbus_path(name);
@@ -44,23 +46,34 @@ purple_buddy_build_dbus_path(const char 
 	return path;
 }
 
-void
-purple_buddy_class_dbus_init(void)
+static void
+purple_buddy_dbus_init(gpointer object)
 {
+	PurpleGroup *buddy = PURPLE_GROUP(object);
+	PurpleObject *pobject = PURPLE_OBJECT(buddy);
+
+	/* Publish/listen for the object on the bus. */
+	purple_dbus_connect_object(buddy);
+
 	if (purple_core_is_daemon_mode()) {
-		/* Install method introspection data */
-		purple_object_type_install_dbus_infos(PURPLE_TYPE_BUDDY,
-				&dbus_glib_DBUS_purple_buddy_object_info);
+		/* Tell the clients about this new buddy. */
+		purple_constructor_announce_pobject_creation(pobject);
+	} else if (purple_core_is_remote_mode()) {
+		g_signal_emit_by_name(G_OBJECT(buddy), "new");
 	}
 }
 
 void
-purple_buddy_dbus_init(PurpleBuddy *buddy, const char *name)
+purple_buddy_class_dbus_init(PurpleBuddyClass *klass)
 {
-	char* dbus_path;
+	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
 
-	dbus_path = purple_buddy_build_dbus_path(name);
-	purple_object_install_dbus_infos(PURPLE_OBJECT(buddy),
-	                                 DBUS_BUDDY_INTERFACE, dbus_path);
-	g_free(dbus_path);	
+	/* Register our interface. */
+	purple_object_class_register_dbus_iface(pobjclass, PURPLE_TYPE_BUDDY,
+	                                        &purple_buddy_interface_info);
+	pobjclass->dbus_init = purple_buddy_dbus_init;
+	if (purple_core_is_daemon_mode()) {
+		/* Only the daemon has authority on PurpleBuddy dbus names. */
+		pobjclass->build_dbus_path = purple_buddy_build_dbus_path;
+	}
 }
============================================================
--- libpurple/dbus/buddy.h	14fe52d8b9c39cf99d40e810dd5149e875afe166
+++ libpurple/dbus/buddy.h	f1169373054903a5ea0d62161c01b8db8eb3eb81
@@ -28,19 +28,13 @@ G_BEGIN_DECLS
 /**
  * Initialize the dbus data of the buddy class.
  */
-void purple_buddy_class_dbus_init(void);
+void purple_buddy_class_dbus_init(PurpleBuddyClass *klass);
 
-/**
- * Initialize the dbus data of a new buddy.
- */
-void purple_buddy_dbus_init(PurpleBuddy *buddy, const char *name);
-
 G_END_DECLS
 
 #else /* !HAVE_DBUS */
 
-#define purple_buddy_class_dbus_init()                            ((void)0)
-#define purple_buddy_dbus_init(buddy, name)                       ((void)0)
+#define purple_buddy_class_dbus_init(klass)                       ((void)0)
 
 #endif /* HAVE_DBUS */
 #endif /* _PURPLE_DBUS_BUDDY_H */


More information about the Commits mailing list