summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/control.c88
-rw-r--r--test/control.glade78
-rw-r--r--test/enum.c8
3 files changed, 159 insertions, 15 deletions
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 @@
<column type="gchararray"/>
<!-- column-name PropertyValue -->
<column type="gchararray"/>
+ <!-- column-name PropertyUnit -->
+ <column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">Camera Control</property>
+ <property name="default_width">800</property>
+ <property name="default_height">600</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
@@ -171,6 +175,45 @@
<child>
<object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
+ <child>
+ <object class="GtkToolButton" id="toolbutton_run">
+ <property name="visible">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Run</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-media-play</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToolButton" id="toolbutton_record">
+ <property name="visible">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Record</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-media-record</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToolButton" id="toolbutton_stop">
+ <property name="visible">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Stop</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-media-stop</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -182,13 +225,27 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
- <object class="GtkImage" id="image">
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
- <property name="stock">gtk-missing-image</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkViewport" id="viewport1">
+ <property name="visible">True</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="visible">True</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
<packing>
- <property name="resize">False</property>
- <property name="shrink">True</property>
+ <property name="resize">True</property>
+ <property name="shrink">False</property>
</packing>
</child>
<child>
@@ -218,9 +275,20 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkTreeViewColumn" id="unitcolumn">
+ <property name="title" translatable="yes">Unit</property>
+ <child>
+ <object class="GtkCellRendererText" id="unitcell"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
<packing>
- <property name="resize">True</property>
+ <property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
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");