diff options
author | Ted Gould <ted@gould.cx> | 2010-06-28 16:19:57 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-06-28 16:19:57 -0500 |
commit | fc3ce0689dacf6396b54e51f6a9c9f24a4a6b9ef (patch) | |
tree | e3943a560aa69f5349312df2c3d4d914dd9b35ce | |
parent | fa34ff87fd2149d3c89c8b00fa8713b8a2b9b563 (diff) | |
download | libdbusmenu-fc3ce0689dacf6396b54e51f6a9c9f24a4a6b9ef.tar.gz libdbusmenu-fc3ce0689dacf6396b54e51f6a9c9f24a4a6b9ef.tar.bz2 libdbusmenu-fc3ce0689dacf6396b54e51f6a9c9f24a4a6b9ef.zip |
Restructuring a bit to make it more reusable.
-rw-r--r-- | tests/json-loader.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/tests/json-loader.c b/tests/json-loader.c index 94df096..aa11aa5 100644 --- a/tests/json-loader.c +++ b/tests/json-loader.c @@ -2,9 +2,27 @@ #include "json-loader.h" static GValue * -handle_complex_types (JsonNode * node) +node2value (JsonNode * node) { + if (node == NULL) { + return NULL; + } + + GValue * value = g_new0(GValue, 1); + if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE) { + json_node_get_value(node, value); + return value; + } + + if (JSON_NODE_TYPE(node) == JSON_NODE_ARRAY) { + } + + + if (JSON_NODE_TYPE(node) == JSON_NODE_OBJECT) { + } + + g_free(value); return NULL; } @@ -21,19 +39,12 @@ set_props (DbusmenuMenuitem * mi, JsonObject * node) if (!g_strcmp0(member, "submenu")) { continue; } JsonNode * lnode = json_object_get_member(node, member); + GValue * value = node2value(lnode); - if (JSON_NODE_TYPE(lnode) != JSON_NODE_VALUE) { - GValue * value = handle_complex_types(lnode); - if (value != NULL) { - dbusmenu_menuitem_property_set_value(mi, member, value); - g_value_unset(value); - g_free(value); - } - } else { - GValue value = {0}; - json_node_get_value(lnode, &value); - dbusmenu_menuitem_property_set_value(mi, member, &value); - g_value_unset(&value); + if (value != NULL) { + dbusmenu_menuitem_property_set_value(mi, member, value); + g_value_unset(value); + g_free(value); } } |