From 62b0fccd725b4e3c7b01e39258fd64dfa1d6064d Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 10:54:48 -0500
Subject: Changing from using a transform to getting the contents

---
 tools/dbusmenu-dumper.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 55d631e..68a21d9 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -36,11 +36,10 @@ print_menuitem (DbusmenuMenuitem * item, int depth)
 	GList * properties = dbusmenu_menuitem_properties_list(item);
 	GList * property;
 	for (property = properties; property != NULL; property = g_list_next(property)) {
-		GValue value = {0};
-		g_value_init(&value, G_TYPE_STRING);
-		g_value_transform(dbusmenu_menuitem_property_get_value(item, (gchar *)property->data), &value);
-		g_print(",\n%s\"%s\": \"%s\"", space, (gchar *)property->data, g_value_get_string(&value));
-		g_value_unset(&value);
+		const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
+		gchar * str = g_strdup_value_contents(value);
+		g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str);
+		g_free(str);
 	}
 	g_list_free(properties);
 
-- 
cgit v1.2.3


From e7ef77f7498d95f1f752aaca73f2dfdd935a0f44 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:07:31 -0500
Subject: Splitting out the collection printing.

---
 tools/dbusmenu-dumper.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 68a21d9..38284b1 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -25,8 +25,16 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <libdbusmenu-glib/client.h>
 #include <libdbusmenu-glib/menuitem.h>
 
+#include <dbus/dbus-gtype-specialized.h>
+
 static GMainLoop * mainloop = NULL;
 
+static gchar *
+collection_dumper (const GValue * value)
+{
+	return g_strdup("<collection>");
+}
+
 static void
 print_menuitem (DbusmenuMenuitem * item, int depth)
 {
@@ -37,7 +45,12 @@ print_menuitem (DbusmenuMenuitem * item, int depth)
 	GList * property;
 	for (property = properties; property != NULL; property = g_list_next(property)) {
 		const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
-		gchar * str = g_strdup_value_contents(value);
+		gchar * str = NULL;
+		if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
+			str = collection_dumper(value);
+		} else {
+			str = g_strdup_value_contents(value);
+		}
 		g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str);
 		g_free(str);
 	}
-- 
cgit v1.2.3


From b13fe82d9d489e0c77cd4e8a9e09fce934d40865 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:14:28 -0500
Subject: Giving the depth as well so this can look nice.

---
 tools/dbusmenu-dumper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 38284b1..5790828 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -30,7 +30,7 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 static GMainLoop * mainloop = NULL;
 
 static gchar *
-collection_dumper (const GValue * value)
+collection_dumper (const GValue * value, int depth)
 {
 	return g_strdup("<collection>");
 }
@@ -47,7 +47,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth)
 		const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
 		gchar * str = NULL;
 		if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
-			str = collection_dumper(value);
+			str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2);
 		} else {
 			str = g_strdup_value_contents(value);
 		}
-- 
cgit v1.2.3


From 84e7a884a2f3c6bd480060235478beb50a38841e Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:22:07 -0500
Subject: Printing more like we'd want a collection to print.

---
 tools/dbusmenu-dumper.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 5790828..1bf6e43 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -32,7 +32,19 @@ static GMainLoop * mainloop = NULL;
 static gchar *
 collection_dumper (const GValue * value, int depth)
 {
-	return g_strdup("<collection>");
+	gchar * space = g_strnfill(depth, ' ');
+	GPtrArray * array = g_ptr_array_new_with_free_func(g_free);
+
+	g_ptr_array_add(array, g_strdup("[\n"));
+	g_ptr_array_add(array, g_strdup_printf("%s<collection>\n", space));
+	g_ptr_array_add(array, g_strdup_printf("%s]", space));
+
+	g_free(space);
+	
+	gchar * retstr = g_strjoinv(NULL, (gchar **)array->pdata);
+	g_ptr_array_free(array, TRUE);
+
+	return retstr;
 }
 
 static void
@@ -47,7 +59,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth)
 		const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
 		gchar * str = NULL;
 		if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
-			str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2);
+			str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */);
 		} else {
 			str = g_strdup_value_contents(value);
 		}
-- 
cgit v1.2.3


From a359a31ffc36630c385ac9ebdf06b6f20e8401f6 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:36:35 -0500
Subject: Now iterating through the collection and printing those entries out.

---
 tools/dbusmenu-dumper.c | 41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 1bf6e43..724ee25 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -29,15 +29,50 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 static GMainLoop * mainloop = NULL;
 
+typedef struct _collection_iterator_t collection_iterator_t;
+struct _collection_iterator_t {
+	gchar * space;
+	GPtrArray * array;
+	gboolean first;
+};
+
+static void
+collection_iterate (const GValue * value, gpointer user_data)
+{
+	collection_iterator_t * iter = (collection_iterator_t *)user_data;
+
+	gchar * str = g_strdup_value_contents(value);
+	gchar * retval = NULL;
+
+	if (iter->first) {
+		iter->first = FALSE;
+		retval = g_strdup_printf("\n%s%s", iter->space, str);
+	} else {
+		retval = g_strdup_printf(",\n%s%s", iter->space, str);
+	}
+
+	g_ptr_array_add(iter->array, retval);
+	g_free(str);
+
+	return;
+}
+
 static gchar *
 collection_dumper (const GValue * value, int depth)
 {
 	gchar * space = g_strnfill(depth, ' ');
 	GPtrArray * array = g_ptr_array_new_with_free_func(g_free);
 
-	g_ptr_array_add(array, g_strdup("[\n"));
-	g_ptr_array_add(array, g_strdup_printf("%s<collection>\n", space));
-	g_ptr_array_add(array, g_strdup_printf("%s]", space));
+	g_ptr_array_add(array, g_strdup("["));
+
+	collection_iterator_t iter;
+	iter.space = space;
+	iter.array = array;
+	iter.first = TRUE;
+
+	dbus_g_type_collection_value_iterate(value, collection_iterate, &iter);
+
+	g_ptr_array_add(array, g_strdup_printf("\n%s]", space));
 
 	g_free(space);
 	
-- 
cgit v1.2.3


From 84437fefcfda6157063210bbd9677298d62899b8 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:45:56 -0500
Subject: Handling the printing of strv's as well.

---
 tools/dbusmenu-dumper.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 724ee25..4ce1374 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -29,6 +29,17 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 static GMainLoop * mainloop = NULL;
 
+static gchar *
+strv_dumper(const GValue * value)
+{
+	gchar ** strv = (gchar **)g_value_get_boxed(value);
+
+	gchar * joined = g_strjoinv("\", \"", strv);
+	gchar * retval = g_strdup_printf("[\"%s\"]", joined);
+	g_free(joined);
+	return retval;
+}
+
 typedef struct _collection_iterator_t collection_iterator_t;
 struct _collection_iterator_t {
 	gchar * space;
@@ -41,7 +52,13 @@ collection_iterate (const GValue * value, gpointer user_data)
 {
 	collection_iterator_t * iter = (collection_iterator_t *)user_data;
 
-	gchar * str = g_strdup_value_contents(value);
+	gchar * str;
+	if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
+		str = strv_dumper(value);
+	} else {
+		str = g_strdup_value_contents(value);
+	}
+
 	gchar * retval = NULL;
 
 	if (iter->first) {
-- 
cgit v1.2.3


From 057503a47f2dff7ea4863ffc1df939556cc1753f Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:51:19 -0500
Subject: Abstracting out the choosing of how to dump the value.

---
 tools/dbusmenu-dumper.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 4ce1374..6af344d 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -29,6 +29,8 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 static GMainLoop * mainloop = NULL;
 
+static gchar * value2string (const GValue * value, int depth);
+
 static gchar *
 strv_dumper(const GValue * value)
 {
@@ -45,6 +47,7 @@ struct _collection_iterator_t {
 	gchar * space;
 	GPtrArray * array;
 	gboolean first;
+	int depth;
 };
 
 static void
@@ -52,13 +55,7 @@ collection_iterate (const GValue * value, gpointer user_data)
 {
 	collection_iterator_t * iter = (collection_iterator_t *)user_data;
 
-	gchar * str;
-	if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
-		str = strv_dumper(value);
-	} else {
-		str = g_strdup_value_contents(value);
-	}
-
+	gchar * str = value2string(value, iter->depth);
 	gchar * retval = NULL;
 
 	if (iter->first) {
@@ -86,6 +83,7 @@ collection_dumper (const GValue * value, int depth)
 	iter.space = space;
 	iter.array = array;
 	iter.first = TRUE;
+	iter.depth = depth + 2;
 
 	dbus_g_type_collection_value_iterate(value, collection_iterate, &iter);
 
@@ -99,6 +97,22 @@ collection_dumper (const GValue * value, int depth)
 	return retstr;
 }
 
+static gchar *
+value2string (const GValue * value, int depth)
+{
+	gchar * str = NULL;
+
+	if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
+		str = collection_dumper(value, depth);
+	} else if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
+		str = strv_dumper(value);
+	} else {
+		str = g_strdup_value_contents(value);
+	}
+
+	return str;
+}
+
 static void
 print_menuitem (DbusmenuMenuitem * item, int depth)
 {
@@ -109,12 +123,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth)
 	GList * property;
 	for (property = properties; property != NULL; property = g_list_next(property)) {
 		const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
-		gchar * str = NULL;
-		if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
-			str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */);
-		} else {
-			str = g_strdup_value_contents(value);
-		}
+		gchar * str = value2string(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */);
 		g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str);
 		g_free(str);
 	}
-- 
cgit v1.2.3


From aea8d2664195b8d5b6b77817a70c5955f9f32a8c Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 11:55:22 -0500
Subject: Optimizing the one item in the collection case (common for shortcuts)

---
 tools/dbusmenu-dumper.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index 6af344d..f0f4ba0 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -90,8 +90,14 @@ collection_dumper (const GValue * value, int depth)
 	g_ptr_array_add(array, g_strdup_printf("\n%s]", space));
 
 	g_free(space);
-	
-	gchar * retstr = g_strjoinv(NULL, (gchar **)array->pdata);
+
+	gchar * retstr = NULL;
+	if (array->len == 3) {
+		retstr = g_strdup_printf("[%s]", ((gchar *)array->pdata[1]) + depth + 1/*for newline*/);
+	} else {
+		retstr = g_strjoinv(NULL, (gchar **)array->pdata);
+	}
+
 	g_ptr_array_free(array, TRUE);
 
 	return retstr;
-- 
cgit v1.2.3


From a2d820e83b57e71a0b1305b52b1aff8162d6930d Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 12:55:51 -0500
Subject: Adding an explicit null check.

---
 tools/dbusmenu-dumper.c | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index f0f4ba0..f2e2bec 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -108,6 +108,10 @@ value2string (const GValue * value, int depth)
 {
 	gchar * str = NULL;
 
+	if (value == NULL) {
+		return g_strdup("(null)");
+	}
+
 	if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
 		str = collection_dumper(value, depth);
 	} else if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
-- 
cgit v1.2.3


From 3d291c9bd937b20511efbebb938b3a6b059e8b14 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 28 Jun 2010 18:04:06 -0500
Subject: Have the proper case for booleans

---
 tools/dbusmenu-dumper.c | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'tools')

diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c
index f2e2bec..6ce9655 100644
--- a/tools/dbusmenu-dumper.c
+++ b/tools/dbusmenu-dumper.c
@@ -116,6 +116,12 @@ value2string (const GValue * value, int depth)
 		str = collection_dumper(value, depth);
 	} else if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
 		str = strv_dumper(value);
+	} else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) {
+		if (g_value_get_boolean(value)) {
+			str = g_strdup("true");
+		} else {
+			str = g_strdup("false");
+		}
 	} else {
 		str = g_strdup_value_contents(value);
 	}
-- 
cgit v1.2.3