/srv/mercurial-server/detachablepurple: 5a5545b7cd46: Going mult...

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


Changeset: 5a5545b7cd4661e2b499577d600df3756c5fa313
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-20 13:30 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/5a5545b7cd46

Description:

Going multi-interface. Adapted the D-Bus property getter and setter,
so that they check for the given property on every interface.
This allows setting a property on a parent class (this will become
useful for the PurpleBlistNode).

diffstat:

 libpurple/pobject.c |  43 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 7 deletions(-)

diffs (74 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -431,6 +431,39 @@
 	}
 }
 
+/* Looks for a given property on a given PurpleObject.
+ * Eventually fills found_iface with the interface on which the
+ * property was found. */
+static GDBusPropertyInfo *
+find_property_in_ifaceinfos(PurpleObject *pobject, const gchar *prop_name,
+                            GDBusInterfaceInfo **found_iface)
+{
+	GDBusInterfaceInfo *ifaceinfo;
+	GDBusPropertyInfo *prop_info = NULL;
+	PurpleObjectClass *pobjclass = PURPLE_OBJECT_GET_CLASS(pobject);
+	GType type;
+
+	/* Step from the most derived type to PurpleObject's direct child
+	 * type and retreive each D-Bus interface info. */
+	for (type = G_OBJECT_TYPE(pobject);
+	     type != PURPLE_TYPE_OBJECT && type != 0;
+	     type = g_type_parent(type))
+	{
+		ifaceinfo = g_datalist_id_get_data(&pobjclass->dbus_ifaceinfos,
+		                                   g_type_qname(type));
+		if (!ifaceinfo)
+			continue;
+		prop_info = g_dbus_interface_info_lookup_property(ifaceinfo,
+		                                                  prop_name);
+		if (prop_info) {
+			if (found_iface)
+				*found_iface = ifaceinfo;
+			break;
+		}
+	}
+	return prop_info;
+}
+
 GVariant *
 purple_object_get_dbus_property(PurpleObject *pobj, const gchar *prop_name)
 {
@@ -447,9 +480,7 @@
 		return NULL;
 
 	/* Check if we export this property over D-Bus. */
-	prop_info = g_dbus_interface_info_lookup_property
-	             (PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo,
-	              prop_name);
+	prop_info = find_property_in_ifaceinfos(pobj, prop_name, NULL);
 	if (!prop_info)
 		return NULL;
 
@@ -491,8 +522,7 @@
 		return FALSE;
 
 	/* Check if we export this property over D-Bus. */
-	prop_info = g_dbus_interface_info_lookup_property
-	             (PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo, prop_name);
+	prop_info = find_property_in_ifaceinfos(pobj, prop_name, NULL);
 	if (!prop_info)
 		return FALSE;
 
@@ -1087,8 +1117,7 @@
 		return;
 
 	/* Prepare the parameters. */
-	iface = PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo;
-	prop_info = g_dbus_interface_info_lookup_property(iface, prop_name);
+	prop_info = find_property_in_ifaceinfos(pobj, prop_name, &iface);
 	va_start(ap, prop_name);
 	prop_value = g_variant_new_va(prop_info->signature, NULL, &ap);
 	va_end(ap);



More information about the Commits mailing list