25
25
#include <libdbusmenu-glib/client.h>
26
26
#include <libdbusmenu-glib/menuitem.h>
28
#include <dbus/dbus-gtype-specialized.h>
28
30
static GMainLoop * mainloop = NULL;
32
static gchar * value2string (const GValue * value, int depth);
35
strv_dumper(const GValue * value)
37
gchar ** strv = (gchar **)g_value_get_boxed(value);
39
gchar * joined = g_strjoinv("\", \"", strv);
40
gchar * retval = g_strdup_printf("[\"%s\"]", joined);
45
typedef struct _collection_iterator_t collection_iterator_t;
46
struct _collection_iterator_t {
54
collection_iterate (const GValue * value, gpointer user_data)
56
collection_iterator_t * iter = (collection_iterator_t *)user_data;
58
gchar * str = value2string(value, iter->depth);
59
gchar * retval = NULL;
63
retval = g_strdup_printf("\n%s%s", iter->space, str);
65
retval = g_strdup_printf(",\n%s%s", iter->space, str);
68
g_ptr_array_add(iter->array, retval);
75
collection_dumper (const GValue * value, int depth)
77
gchar * space = g_strnfill(depth, ' ');
78
GPtrArray * array = g_ptr_array_new_with_free_func(g_free);
80
g_ptr_array_add(array, g_strdup("["));
82
collection_iterator_t iter;
86
iter.depth = depth + 2;
88
dbus_g_type_collection_value_iterate(value, collection_iterate, &iter);
90
g_ptr_array_add(array, g_strdup_printf("\n%s]", space));
94
gchar * retstr = NULL;
95
if (array->len == 3) {
96
retstr = g_strdup_printf("[%s]", ((gchar *)array->pdata[1]) + depth + 1/*for newline*/);
98
retstr = g_strjoinv(NULL, (gchar **)array->pdata);
101
g_ptr_array_free(array, TRUE);
107
value2string (const GValue * value, int depth)
112
return g_strdup("(null)");
115
if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) {
116
str = collection_dumper(value, depth);
117
} else if (G_VALUE_TYPE(value) == G_TYPE_STRV) {
118
str = strv_dumper(value);
119
} else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) {
120
if (g_value_get_boolean(value)) {
121
str = g_strdup("true");
123
str = g_strdup("false");
126
str = g_strdup_value_contents(value);
31
133
print_menuitem (DbusmenuMenuitem * item, int depth)
36
138
GList * properties = dbusmenu_menuitem_properties_list(item);
38
140
for (property = properties; property != NULL; property = g_list_next(property)) {
40
g_value_init(&value, G_TYPE_STRING);
41
g_value_transform(dbusmenu_menuitem_property_get_value(item, (gchar *)property->data), &value);
42
g_print(",\n%s\"%s\": \"%s\"", space, (gchar *)property->data, g_value_get_string(&value));
43
g_value_unset(&value);
141
const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data);
142
gchar * str = value2string(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */);
143
g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str);
45
146
g_list_free(properties);