/srv/mercurial-server/detachablepurple: b721f5ab2a8d: Rewritten ...

Gilles Bedel gillux at cpw.pidgin.im
Fri Jun 15 22:01:44 EDT 2012


Changeset: b721f5ab2a8dc9f16700116047d3c68b55db1988
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-20 15:43 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/b721f5ab2a8d

Description:

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

diffstat:

 libpurple/buddy.c      |  13 +++++++++----
 libpurple/dbus/buddy.c |  43 ++++++++++++++++++++++++++++---------------
 libpurple/dbus/buddy.h |  10 ++--------
 3 files changed, 39 insertions(+), 27 deletions(-)

diffs (145 lines):

diff --git a/libpurple/buddy.c b/libpurple/buddy.c
--- a/libpurple/buddy.c
+++ b/libpurple/buddy.c
@@ -166,7 +166,8 @@
 
 	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,7 +206,9 @@
 {
 	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);
 
@@ -538,7 +541,9 @@
 			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));
@@ -671,7 +676,7 @@
 				G_PARAM_READWRITE)
 			);
 
-	purple_buddy_class_dbus_init();
+	purple_buddy_class_dbus_init(klass);
 }
 
 static void
diff --git a/libpurple/dbus/buddy.c b/libpurple/dbus/buddy.c
--- a/libpurple/dbus/buddy.c
+++ b/libpurple/dbus/buddy.c
@@ -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 @@
 	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;
+	}
 }
diff --git a/libpurple/dbus/buddy.h b/libpurple/dbus/buddy.h
--- a/libpurple/dbus/buddy.h
+++ b/libpurple/dbus/buddy.h
@@ -28,19 +28,13 @@
 /**
  * Initialize the dbus data of the buddy class.
  */
-void purple_buddy_class_dbus_init(void);
-
-/**
- * Initialize the dbus data of a new buddy.
- */
-void purple_buddy_dbus_init(PurpleBuddy *buddy, const char *name);
+void purple_buddy_class_dbus_init(PurpleBuddyClass *klass);
 
 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