aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-06-28 11:36:35 -0500
committerTed Gould <ted@gould.cx>2010-06-28 11:36:35 -0500
commita359a31ffc36630c385ac9ebdf06b6f20e8401f6 (patch)
treebfc6b46b4975be55b5d8249dc79d42aacc795da4
parent84e7a884a2f3c6bd480060235478beb50a38841e (diff)
downloadlibdbusmenu-a359a31ffc36630c385ac9ebdf06b6f20e8401f6.tar.gz
libdbusmenu-a359a31ffc36630c385ac9ebdf06b6f20e8401f6.tar.bz2
libdbusmenu-a359a31ffc36630c385ac9ebdf06b6f20e8401f6.zip
Now iterating through the collection and printing those entries out.
-rw-r--r--tools/dbusmenu-dumper.c41
1 files changed, 38 insertions, 3 deletions
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);