From 923dab046564bdfcd7267281b99462f6d866d311 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 7 Mar 2011 17:28:07 +0100 Subject: Add property listing --- test/control.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++--- test/control.glade | 78 +++++++++++++++++++++++++++++++++++++++++++---- test/enum.c | 8 ++--- 3 files changed, 159 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/control.c b/test/control.c index dd71f47..2c08308 100644 --- a/test/control.c +++ b/test/control.c @@ -58,6 +58,76 @@ void *grab_thread(void *args) } } +void get_first_level_root(GtkTreeStore *store, GtkTreeIter *iter, gchar *group) +{ + GtkTreeIter root; + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &root)) { + gchar *str; + gtk_tree_model_get(GTK_TREE_MODEL(store), &root, 0, &str, -1); + if (g_strcmp0(group, str) == 0) { + *iter = root; + return; + } + + /* Iterate through all groups */ + while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &root)) { + gtk_tree_model_get(GTK_TREE_MODEL(store), &root, 0, &str, -1); + if (g_strcmp0(group, str) == 0) { + *iter = root; + g_free(str); + return; + } + } + + /* Not found, append the group */ + g_free(str); + } + + /* Tree is empty or group is not found */ + gtk_tree_store_append(store, iter, NULL); + gtk_tree_store_set(store, iter, 0, group, -1); +} + +void find_recursively(GtkTreeStore *store, GtkTreeIter *root, GtkTreeIter *result, gchar **tokens, int depth) +{ + GtkTreeIter iter; + gchar *str; + gchar *current_token = tokens[depth]; + + if (current_token == NULL) { + *result = *root; + return; + } + + if (!gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store), root)) { + gtk_tree_store_append(store, &iter, root); + if (tokens[depth+1] == NULL) { + *result = iter; + return; + } + else { + gtk_tree_store_set(store, &iter, 0, current_token, -1); + find_recursively(store, &iter, result, tokens, depth+1); + } + } + + gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &iter, root); + do { + gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &str, -1); + if (g_strcmp0(current_token, str) == 0) { + find_recursively(store, &iter, result, tokens, depth+1); + g_free(str); + return; + } + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)); + + g_free(str); + gtk_tree_store_append(store, &iter, root); + gtk_tree_store_set(store, &iter, 0, current_token, -1); + //*result = iter; + find_recursively(store, &iter, result, tokens, depth+1); +} + void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera_t *cam) { GtkTreeIter iter, child; @@ -66,7 +136,6 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera_t *cam) guint8 value_8; guint32 value_32; - gtk_tree_store_append(tree_store, &iter, NULL); for (int prop_id = 0; prop_id < UCA_PROP_LAST; prop_id++) { property = uca_get_full_property(prop_id); switch (property->type) { @@ -84,11 +153,22 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera_t *cam) g_sprintf(value_string, "%d", value_32); break; } - gtk_tree_store_set(tree_store, &iter, - 0, property->name, + + /* Find first level root */ + gchar **tokens = g_strsplit(property->name, ".", 0); + get_first_level_root(tree_store, &iter, tokens[0]); + find_recursively(tree_store, &iter, &child, tokens, 1); + + int count = 0; + while (tokens[count++] != NULL); + + gtk_tree_store_set(tree_store, &child, + 0, tokens[count-2], 1, value_string, + 2, uca_unit_map[property->unit], -1); - gtk_tree_store_append(tree_store, &iter, NULL); + + g_strfreev(tokens); } g_free(value_string); diff --git a/test/control.glade b/test/control.glade index c56ddfe..dd9b829 100644 --- a/test/control.glade +++ b/test/control.glade @@ -8,10 +8,14 @@ + + Camera Control + 800 + 600 True @@ -171,6 +175,45 @@ True + + + True + False + Run + True + gtk-media-play + + + False + True + + + + + True + False + Record + True + gtk-media-record + + + False + True + + + + + True + False + Stop + True + gtk-media-stop + + + False + True + + False @@ -182,13 +225,27 @@ True True - + True - gtk-missing-image + True + automatic + automatic + + + True + queue + + + True + gtk-missing-image + + + + - False - True + True + False @@ -218,9 +275,20 @@ + + + Unit + + + + 2 + + + + - True + False True diff --git a/test/enum.c b/test/enum.c index 4c21f12..8803ec4 100644 --- a/test/enum.c +++ b/test/enum.c @@ -34,10 +34,6 @@ int main(int argc, char *argv[]) uint32_t uint32_value; uint8_t uint8_value; - const char *unit_map[] = { - "px", "bits", "ns", "µs", "ms", "s", "rows", "" - }; - while (cam != NULL) { for (int i = 0; i < UCA_PROP_LAST; i++) { struct uca_property_t *prop = uca_get_full_property(i); @@ -53,14 +49,14 @@ int main(int argc, char *argv[]) break; case uca_uint32t: if (cam->get_property(cam, i, &uint32_value) != UCA_ERR_PROP_INVALID) { - printf("%i %s", uint32_value, unit_map[prop->unit]); + printf("%i %s", uint32_value, uca_unit_map[prop->unit]); } else printf("n/a"); break; case uca_uint8t: if (cam->get_property(cam, i, &uint8_value) != UCA_ERR_PROP_INVALID) { - printf("%i %s", uint8_value, unit_map[prop->unit]); + printf("%i %s", uint8_value, uca_unit_map[prop->unit]); } else printf("n/a"); -- cgit v1.2.3