← Back to team overview

ayatana-commits team mailing list archive

[Branch ~dbusmenu-team/dbusmenu/trunk] Rev 226: Allow sending only some properties based on what is requested.

 

Merge authors:
  Ted Gould (ted)
Related merge proposals:
  https://code.launchpad.net/~ted/dbusmenu/selective-properties/+merge/50396
  proposed by: Ted Gould (ted)
  review: Approve - Kalle Valo (kvalo)
------------------------------------------------------------
revno: 226 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Thu 2011-02-24 08:33:38 -0600
message:
  Allow sending only some properties based on what is requested.
modified:
  libdbusmenu-glib/client.c
  libdbusmenu-glib/menuitem.c
  libdbusmenu-glib/server.c


--
lp:dbusmenu
https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk

Your team ayatana-commits is subscribed to branch lp:dbusmenu.
To unsubscribe from this branch go to https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk/+edit-subscription
=== modified file 'libdbusmenu-glib/client.c'
--- libdbusmenu-glib/client.c	2011-02-24 14:33:06 +0000
+++ libdbusmenu-glib/client.c	2011-02-24 14:33:38 +0000
@@ -83,6 +83,7 @@
 	GCancellable * menuproxy_cancel;
 
 	GCancellable * layoutcall;
+	GVariant * layout_props;
 
 	gint current_revision;
 	gint my_revision;
@@ -334,6 +335,15 @@
 
 	priv->layoutcall = NULL;
 
+	gchar * layout_props[5];
+	layout_props[0] = DBUSMENU_MENUITEM_PROP_TYPE;
+	layout_props[1] = DBUSMENU_MENUITEM_PROP_LABEL;
+	layout_props[2] = DBUSMENU_MENUITEM_PROP_VISIBLE;
+	layout_props[3] = DBUSMENU_MENUITEM_PROP_ENABLED;
+	layout_props[4] = NULL;
+	priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, 4);
+	g_variant_ref_sink(priv->layout_props);
+
 	priv->current_revision = 0;
 	priv->my_revision = 0;
 
@@ -401,6 +411,11 @@
 		priv->layoutcall = NULL;
 	}
 
+	if (priv->layout_props != NULL) {
+		g_variant_unref(priv->layout_props);
+		priv->layout_props = NULL;
+	}
+
 	/* Bring down the menu proxy, ensure we're not
 	   looking for one at the same time. */
 	if (priv->menuproxy_cancel != NULL) {
@@ -1571,6 +1586,33 @@
 			parse_layout_update(childmi, client);
 		}
 
+		/* Apply known properties sent in the structure to the
+		   menu item.  Sometimes they may just be copies */
+		if (childmi != NULL) {
+			GVariantIter iter;
+			gchar * prop;
+			GVariant * value;
+
+			/* Set the type first as it can manage the behavior of
+			   all other properties. */
+			g_variant_iter_init(&iter, g_variant_get_child_value(child, 1));
+			while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) {
+				if (g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TYPE) == 0) {
+					dbusmenu_menuitem_property_set_variant(childmi, prop, value);
+				}
+				g_free(prop);
+				g_variant_unref(value);
+			}
+
+			/* Now go through and do all the properties. */
+			g_variant_iter_init(&iter, g_variant_get_child_value(child, 1));
+			while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) {
+				dbusmenu_menuitem_property_set_variant(childmi, prop, value);
+				g_free(prop);
+				g_variant_unref(value);
+			}
+		}
+
 		position++;
 	}
 
@@ -1760,7 +1802,7 @@
 	
 	g_variant_builder_add_value(&tupleb, g_variant_new_int32(0)); // root
 	g_variant_builder_add_value(&tupleb, g_variant_new_int32(-1)); // recurse
-	g_variant_builder_add_value(&tupleb, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); // props
+	g_variant_builder_add_value(&tupleb, priv->layout_props); // props
 
 	GVariant * args = g_variant_builder_end(&tupleb);
 	// g_debug("Args (type: %s): %s", g_variant_get_type_string(args), g_variant_print(args, TRUE));

=== modified file 'libdbusmenu-glib/menuitem.c'
--- libdbusmenu-glib/menuitem.c	2011-02-24 14:18:59 +0000
+++ libdbusmenu-glib/menuitem.c	2011-02-24 14:33:38 +0000
@@ -1346,7 +1346,7 @@
 
 	GVariant * final_variant = NULL;
 
-	if (g_hash_table_size(priv->properties) > 0) {
+	if ((properties == NULL || properties[0] == NULL) && g_hash_table_size(priv->properties) > 0) {
 		GVariantBuilder builder;
 		g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
 
@@ -1355,6 +1355,33 @@
 		final_variant = g_variant_builder_end(&builder);
 	}
 
+	if (properties != NULL) {
+		GVariantBuilder builder;
+		gboolean builder_init = FALSE;
+		int i = 0; const gchar * prop;
+
+		for (prop = properties[i]; prop != NULL; prop = properties[++i]) {
+			GVariant * propvalue = dbusmenu_menuitem_property_get_variant(mi, prop);
+
+			if (propvalue == NULL) {
+				continue;
+			}
+
+			if (!builder_init) {
+				builder_init = TRUE;
+				g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+			}
+
+			GVariant * dict = g_variant_new_dict_entry(g_variant_new_string((gchar *)prop),
+			                                           g_variant_new_variant((GVariant *)propvalue));
+			g_variant_builder_add_value(&builder, dict);
+		}
+
+		if (builder_init) {
+			final_variant = g_variant_builder_end(&builder);
+		}
+	}
+
 	return final_variant;
 }
 

=== modified file 'libdbusmenu-glib/server.c'
--- libdbusmenu-glib/server.c	2011-02-18 21:39:30 +0000
+++ libdbusmenu-glib/server.c	2011-02-24 14:33:38 +0000
@@ -1027,7 +1027,9 @@
 
 	/* If so, we need to swap the value */
 	if (prop != NULL) {
-		g_variant_unref(prop->variant);
+		if (prop->variant != NULL) {
+			g_variant_unref(prop->variant);
+		}
 		prop->variant = variant;
 	} else {
 	/* else we need to add it */