/srv/mercurial-server/detachablepurple: e664dedc72d5: The GVaria...

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


Changeset: e664dedc72d5b1f50a47fcdf7b8f1ea8cd6e77bc
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-15 00:57 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/e664dedc72d5

Description:

The GVariant to GValue conversion function now handles conversion to types
derived from type G_TYPE_FLAGS and G_TYPE_ENUM, giving uint32 GVariant.
This means we can now export enum and flags properties on D-Bus.

diffstat:

 libpurple/pobject.c |  15 +++++++++++----
 libpurple/pobject.h |   4 ++--
 2 files changed, 13 insertions(+), 6 deletions(-)

diffs (46 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -408,9 +408,12 @@
 	GValue tmp = {0, };
 
 	g_dbus_gvariant_to_gvalue(gvariant, gvalue);
-	/* Convert path names into gobjects. */
-	if (G_TYPE_IS_OBJECT(expected_type)
-	    && G_VALUE_HOLDS_STRING(gvalue))
+	if (/* Convert path names into gobjects. */
+	    (G_TYPE_IS_OBJECT(expected_type)
+	     && G_VALUE_HOLDS_STRING(gvalue)) ||
+	    /* Convert flags/enum into unsigned integers. */
+	    ((G_TYPE_IS_FLAGS(expected_type) || G_TYPE_IS_ENUM(expected_type))
+	     && G_VALUE_HOLDS_UINT(gvalue)))
 	{
 		g_value_init(&tmp, expected_type);
 		g_value_transform(gvalue, &tmp);
@@ -448,7 +451,11 @@
 	if (G_VALUE_HOLDS_OBJECT(&gval)) {
 		/* Convert gobjects into dbus path names. */
 		g_value_init(&gval2, G_TYPE_STRING);
-		g_value_transform(&gval, &gval);
+		g_value_transform(&gval, &gval2);
+	} else if (G_VALUE_HOLDS_FLAGS(&gval) || G_VALUE_HOLDS_ENUM(&gval)) {
+		/* Convert flags/enum into unsigned integers. */
+		g_value_init(&gval2, G_TYPE_UINT);
+		g_value_transform(&gval, &gval2);
 	} else {
 		/* Regular value. */
 		g_value_init(&gval2, G_VALUE_TYPE(&gval));
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -262,8 +262,8 @@
 
 /**
  * Transforms a D-Bus GVariant into a GObject GValue, doing a conversion
- * from a D-Bus type (e.g. object path string) to an expected
- * GType (e.g. respectively object reference), if necessary.
+ * from a D-Bus type (e.g. object path string, integer) to an expected
+ * GType (e.g. respectively object reference, flag), if necessary.
  *
  * @param gvariant A GVariant.
  * @param gvalue Return location pointing to a zero-filled



More information about the Commits mailing list