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

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


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

Description:

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

diffstat:

 libpurple/dbus/group.c |  47 ++++++++++++++++++++++++++++-------------------
 libpurple/dbus/group.h |  10 ++--------
 libpurple/group.c      |   9 ++++++---
 3 files changed, 36 insertions(+), 30 deletions(-)

diffs (138 lines):

diff --git a/libpurple/dbus/group.c b/libpurple/dbus/group.c
--- a/libpurple/dbus/group.c
+++ b/libpurple/dbus/group.c
@@ -21,24 +21,22 @@
 
 #include "internal.h"
 #include "core.h"
-#include "group.h"
+#include "dbus/constructor.h"
 #include "dbus/group.h"
-#include "dbus/group-client.h"
-#include "dbus/group-server.h"
+#include "dbus/group.xml.h"
 #include "dbus-purple.h"
 #include "dbus-server.h"
+#include "pobject.h"
 
 static char *
-purple_group_build_dbus_path(const char *name)
+purple_group_build_dbus_path(PurpleObject *pobject)
 {
 	static unsigned int group_id = 0;
+	const char *name;
 	gchar *path;
 	gchar *name_valid;
 
-	/* In remote mode we have no way to build the object path.
-	 * We will set it later. */
-	if (purple_core_is_remote_mode())
-		return NULL;
+	name = purple_group_get_name(PURPLE_GROUP(pobject));
 
 	/* Group names are unique but they can change, whereas dbus path names
 	 * can't. So we use an id, with the group name appended, to make it
@@ -50,23 +48,34 @@
 	return path;
 }
 
-void
-purple_group_class_dbus_init(void)
+static void
+purple_group_dbus_init(gpointer object)
 {
+	PurpleGroup *group = PURPLE_GROUP(object);
+	PurpleObject *pobject = PURPLE_OBJECT(group);
+
+	/* Publish/listen for the object on the bus. */
+	purple_dbus_connect_object(group);
+
 	if (purple_core_is_daemon_mode()) {
-		/* Install method introspection data */
-		purple_object_type_install_dbus_infos(PURPLE_TYPE_GROUP,
-				&dbus_glib_DBUS_purple_group_object_info);
+		/* Tell the clients about this new group. */
+		purple_constructor_announce_pobject_creation(pobject);
+	} else if (purple_core_is_remote_mode()) {
+		g_signal_emit_by_name(G_OBJECT(group), "new");
 	}
 }
 
 void
-purple_group_dbus_init(PurpleGroup *group, const char *name)
+purple_group_class_dbus_init(PurpleGroupClass *klass)
 {
-	char* dbus_path;
+	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
 
-	dbus_path = purple_group_build_dbus_path(name);
-	purple_object_install_dbus_infos(PURPLE_OBJECT(group),
-					DBUS_GROUP_INTERFACE, dbus_path);
-	g_free(dbus_path);	
+	/* Register our interface. */
+	purple_object_class_register_dbus_iface(pobjclass, PURPLE_TYPE_GROUP,
+	                                        &purple_group_interface_info);
+	pobjclass->dbus_init = purple_group_dbus_init;
+	if (purple_core_is_daemon_mode()) {
+		/* Only the daemon has authority on PurpleGroup dbus names. */
+		pobjclass->build_dbus_path = purple_group_build_dbus_path;
+	}
 }
diff --git a/libpurple/dbus/group.h b/libpurple/dbus/group.h
--- a/libpurple/dbus/group.h
+++ b/libpurple/dbus/group.h
@@ -28,19 +28,13 @@
 /**
  * Initialize the dbus data of the group class.
  */
-void purple_group_class_dbus_init(void);
-
-/**
- * Initialize the dbus data of a new group.
- */
-void purple_group_dbus_init(PurpleGroup *group, const char *name);
+void purple_group_class_dbus_init(PurpleGroupClass *klass);
 
 G_END_DECLS
 
 #else /* !HAVE_DBUS */
 
-#define purple_group_class_dbus_init()                            ((void)0)
-#define purple_group_dbus_init(group, name)                       ((void)0)
+#define purple_group_class_dbus_init(klass)                       ((void)0)
 
 #endif /* HAVE_DBUS */
 #endif /* _PURPLE_DBUS_GROUP_H */
diff --git a/libpurple/group.c b/libpurple/group.c
--- a/libpurple/group.c
+++ b/libpurple/group.c
@@ -299,7 +299,8 @@
 
 	g_return_if_fail(group != NULL);
 
-	PURPLE_DBUS_REMOTELY_SET_PROP(group, g_value_set_string, G_TYPE_STRING, PROP_NAME_S, name);
+	purple_object_set_prop_on_dbus(PURPLE_OBJECT(group),
+	                               PROP_NAME_S, &name);
 
 	priv = PURPLE_GROUP_GET_PRIVATE(group);
 	gname = purple_utf8_strip_unprintables(name);
@@ -330,7 +331,9 @@
 	group = g_object_new(PURPLE_TYPE_GROUP,
 			PROP_NAME_S, name,
 			NULL);
-	purple_group_dbus_init(group, name);
+
+	/* Export this new object on D-Bus and propagate any property change. */
+	purple_object_dbus_init(group, TRUE);
 
 	g_signal_emit_by_name(G_OBJECT(group), "new");
 
@@ -427,7 +430,7 @@
 				G_PARAM_READWRITE)
 			);
 
-	purple_group_class_dbus_init();
+	purple_group_class_dbus_init(klass);
 }
 
 static void



More information about the Commits mailing list