cpw.gillux.detachablepurple: 72f7290a: Going multi-interface. Adapted the D-Bus...

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


----------------------------------------------------------------------
Revision: 72f7290ae890b0d08a1e9dfae7c5337074fbb1cc
Parent:   3bd19521f44ac3540bcce65108dcd18871538581
Author:   gillux at soc.pidgin.im
Date:     05/20/12 09:30:49
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/72f7290ae890b0d08a1e9dfae7c5337074fbb1cc

Changelog: 

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).

Changes against parent 3bd19521f44ac3540bcce65108dcd18871538581

  patched  libpurple/pobject.c

-------------- next part --------------
============================================================
--- libpurple/pobject.c	c1d5be4a6b69be9403bb3e8320de3900b160bcec
+++ libpurple/pobject.c	9fd7246b259f7bbde83ebc4676d3ded38498e79b
@@ -431,6 +431,39 @@ purple_dbus_gvariant_to_gvalue(GVariant 
 	}
 }
 
+/* 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 @@ purple_object_get_dbus_property(PurpleOb
 		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 @@ purple_object_set_dbus_property(PurpleOb
 		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 @@ purple_object_set_prop_on_dbus(PurpleObj
 		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