/srv/mercurial-server/detachablepurple: 4c7a88ebfd71: Rewritten ...

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


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

Description:

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

diffstat:

 libpurple/contact.c      |   5 +++--
 libpurple/dbus/contact.c |  41 +++++++++++++++++++++--------------------
 libpurple/dbus/contact.h |  10 ++--------
 3 files changed, 26 insertions(+), 30 deletions(-)

diffs (117 lines):

diff --git a/libpurple/contact.c b/libpurple/contact.c
--- a/libpurple/contact.c
+++ b/libpurple/contact.c
@@ -212,7 +212,8 @@
 	PurpleContact *contact;
 
 	contact = g_object_new(PURPLE_TYPE_CONTACT, NULL);
-	purple_contact_dbus_init(contact);
+	/* Export this new object on D-Bus and propagate any property change. */
+	purple_object_dbus_init(contact, TRUE);
 
 	return contact;
 }
@@ -512,7 +513,7 @@
 	parent_class = g_type_class_peek_parent(klass);
 	obj_class->finalize = purple_contact_finalize;
 
-	purple_contact_class_dbus_init();
+	purple_contact_class_dbus_init(klass);
 }
 
 static void
diff --git a/libpurple/dbus/contact.c b/libpurple/dbus/contact.c
--- a/libpurple/dbus/contact.c
+++ b/libpurple/dbus/contact.c
@@ -21,45 +21,46 @@
 
 #include "internal.h"
 #include "core.h"
-#include "contact.h"
+#include "dbus/constructor.h"
 #include "dbus/contact.h"
-#include "dbus/contact-client.h"
-#include "dbus/contact-server.h"
+#include "dbus/contact.xml.h"
 #include "dbus-purple.h"
 #include "dbus-server.h"
+#include "pobject.h"
 
 static char *
-purple_contact_build_dbus_path(void)
+purple_contact_build_dbus_path(PurpleObject *pobj)
 {
 	static unsigned int contact_id = 0;
 
-	/* 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;
-
 	/* Contacts have nothing unique nor that identify themselves
 	 * at the time they are created. So we use a poor id. */
 	return g_strdup_printf(DBUS_CONTACT_PATH "/%u", contact_id++);
 }
 
-void
-purple_contact_class_dbus_init(void)
+static void
+purple_contact_dbus_init(gpointer object)
 {
+	PurpleContact *contact = PURPLE_CONTACT(object);
+	PurpleObject *pobject = PURPLE_OBJECT(contact);
+
 	if (purple_core_is_daemon_mode()) {
-		/* Install method introspection data */
-		purple_object_type_install_dbus_infos(PURPLE_TYPE_CONTACT,
-				&dbus_glib_DBUS_purple_contact_object_info);
+		/* Tell the clients about this new contact. */
+		purple_constructor_announce_pobject_creation(pobject);
 	}
 }
 
 void
-purple_contact_dbus_init(PurpleContact *contact)
+purple_contact_class_dbus_init(PurpleContactClass *klass)
 {
-	char* dbus_path;
+	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
 
-	dbus_path = purple_contact_build_dbus_path();
-	purple_object_install_dbus_infos(PURPLE_OBJECT(contact),
-					DBUS_CONTACT_INTERFACE, dbus_path);
-	g_free(dbus_path);	
+	/* Register our interface. */
+	purple_object_class_register_dbus_iface(pobjclass, PURPLE_TYPE_CONTACT,
+	                                       &purple_contact_interface_info);
+	pobjclass->dbus_init = purple_contact_dbus_init;
+	if (purple_core_is_daemon_mode()) {
+		/* Only the daemon has authority on PurpleContact dbus names. */
+		pobjclass->build_dbus_path = purple_contact_build_dbus_path;
+	}
 }
diff --git a/libpurple/dbus/contact.h b/libpurple/dbus/contact.h
--- a/libpurple/dbus/contact.h
+++ b/libpurple/dbus/contact.h
@@ -28,19 +28,13 @@
 /**
  * Initialize the dbus data of the contact class.
  */
-void purple_contact_class_dbus_init(void);
-
-/**
- * Initialize the dbus data of a new contact.
- */
-void purple_contact_dbus_init(PurpleContact *contact);
+void purple_contact_class_dbus_init(PurpleContactClass *klass);
 
 G_END_DECLS
 
 #else /* !HAVE_DBUS */
 
-#define purple_contact_class_dbus_init()                            ((void)0)
-#define purple_contact_dbus_init(contact)                           ((void)0)
+#define purple_contact_class_dbus_init(klass)                       ((void)0)
 
 #endif /* HAVE_DBUS */
 #endif /* _PURPLE_DBUS_CONTACT_H */



More information about the Commits mailing list