← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/dbusmenu/selective-properties into lp:dbusmenu

 

Ted Gould has proposed merging lp:~ted/dbusmenu/selective-properties into lp:dbusmenu.

Requested reviews:
  DBus Menu Team (dbusmenu-team)

For more details, see:
https://code.launchpad.net/~ted/dbusmenu/selective-properties/+merge/50396

When we do an GetLayout send that we want the type and the label, and make it so that only those come back to us as well.
-- 
https://code.launchpad.net/~ted/dbusmenu/selective-properties/+merge/50396
Your team ayatana-commits is subscribed to branch lp:dbusmenu.
=== modified file 'libdbusmenu-glib/client.c'
--- libdbusmenu-glib/client.c	2011-02-15 17:42:52 +0000
+++ libdbusmenu-glib/client.c	2011-02-18 21:06:40 +0000
@@ -79,6 +79,7 @@
 	GCancellable * menuproxy_cancel;
 
 	GCancellable * layoutcall;
+	GVariant * layout_props;
 
 	gint current_revision;
 	gint my_revision;
@@ -316,6 +317,13 @@
 
 	priv->layoutcall = NULL;
 
+	gchar * layout_props[3];
+	layout_props[0] = DBUSMENU_MENUITEM_PROP_TYPE;
+	layout_props[1] = DBUSMENU_MENUITEM_PROP_LABEL;
+	layout_props[2] = NULL;
+	priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, 2);
+	g_variant_ref_sink(priv->layout_props);
+
 	priv->current_revision = 0;
 	priv->my_revision = 0;
 
@@ -380,6 +388,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) {
@@ -1473,6 +1486,21 @@
 			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;
+			g_variant_iter_init(&iter, g_variant_get_child_value(child, 1));
+			gchar * prop;
+			GVariant * value;
+
+			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++;
 	}
 
@@ -1662,7 +1690,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-15 17:42:52 +0000
+++ libdbusmenu-glib/menuitem.c	2011-02-18 21:06:40 +0000
@@ -1274,7 +1274,7 @@
 
 	GVariant * final_variant = NULL;
 
-	if (g_hash_table_size(priv->properties) > 0) {
+	if (properties == NULL && g_hash_table_size(priv->properties) > 0) {
 		GVariantBuilder builder;
 		g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
 
@@ -1283,6 +1283,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;
 }
 


Follow ups