From f7db63b4b32df0bcb433d12c446f8413fafe319f Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Mon, 17 Mar 2008 21:40:12 +0100 Subject: [PATCH] cleanup? --- tdc_store.c | 12 ++++++++++-- tdc_store.h | 5 +++-- tdcproto.h | 2 ++ variable_tab.c | 20 +++++++++++++++----- variable_tab.h | 2 +- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/tdc_store.c b/tdc_store.c index 1a67239..90a2a95 100644 --- a/tdc_store.c +++ b/tdc_store.c @@ -15,7 +15,7 @@ static struct tdc_var * var_map[256]; static GByteArray *stream; -void get_varvalue(struct tdc_var *var, char *buf, int size, int viewmode) +void tdc_store_get_varvalue(struct tdc_var *var, char *buf, int size, int viewmode) { switch ((var->flags & TDC_TYPEMASK) | ((viewmode & 0x01) << 8)) { case TDC_UNSIGNED: @@ -122,7 +122,7 @@ void get_varvalue(struct tdc_var *var, char *buf, int size, int viewmode) } } -void get_vartype(struct tdc_var *var, char *buf, int size) +void tdc_store_get_vartype(struct tdc_var *var, char *buf, int size) { int pos; int width = (var->flags & TDC_SIZEMASK); @@ -160,6 +160,10 @@ void get_vartype(struct tdc_var *var, char *buf, int size) pos = snprintf(buf + pos, size - pos, " (ro)"); } +void tdc_store_update_graphlist(void) +{ +} + static void destroy_var(int id) { g_free(var_map[id]); @@ -186,6 +190,8 @@ static void create_var(int id, uint32_t flags, char *name, int len) static void update_var(int id, uint8_t *data, int len) { memcpy(&(var_map[id & 0xFF]->data_uint8), data, len); + + vartab_update_var(var_map[id & 0xFF]); } #if 0 @@ -394,6 +400,8 @@ int tdc_parse_data(int fd) void tdc_flush_vars(void) { + vartab_remove_all_vars(); + int i; for (i = 0; i < ARRAY_SIZE(var_map); i++) { if (var_map[i] == NULL) diff --git a/tdc_store.h b/tdc_store.h index 6eb7e5c..0a5c158 100644 --- a/tdc_store.h +++ b/tdc_store.h @@ -17,8 +17,9 @@ struct tdc_var { char name[0]; }; -void get_varvalue(struct tdc_var *var, char *buf, int size, int viewmode); -void get_vartype(struct tdc_var *var, char *buf, int size); +void tdc_store_get_varvalue(struct tdc_var *var, char *buf, int size, int viewmode); +void tdc_store_get_vartype(struct tdc_var *var, char *buf, int size); +void tdc_store_update_graphlist(void); int tdc_parse_data(int fd); void tdc_flush_vars(void); diff --git a/tdcproto.h b/tdcproto.h index 71c8ad5..0e18be6 100644 --- a/tdcproto.h +++ b/tdcproto.h @@ -98,4 +98,6 @@ struct tdc_reqvalues_reply { #define TDC_READONLY 0x0100 +#define TDC_GUI_GRAPH 0x8000 + #endif /* TDCPROTO_H_ */ diff --git a/variable_tab.c b/variable_tab.c index 688f748..da5d622 100644 --- a/variable_tab.c +++ b/variable_tab.c @@ -22,14 +22,23 @@ static void cell_graph_toggle(GtkCellRendererToggle *cell, gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(user_data), &it, path_string); gboolean toggle; + struct tdc_var *var; gtk_tree_model_get(GTK_TREE_MODEL(user_data), &it, COL_GRAPH, &toggle, + COL_VALUE, &var, -1); + if (var->flags & TDC_GUI_GRAPH) + var->flags &= ~TDC_GUI_GRAPH; + else + var->flags |= TDC_GUI_GRAPH; + gtk_list_store_set(GTK_LIST_STORE(user_data), &it, COL_GRAPH, !toggle, -1); + + tdc_store_update_graphlist(); } static gboolean header_toggle_update(GtkTreeModel *model, @@ -103,7 +112,7 @@ static void cell_value_func(GtkTreeViewColumn *column, gtk_tree_model_get(model, iter, COL_VALUE, &var, -1); char buf[32]; - get_varvalue(var, buf, sizeof(buf), viewmode); + tdc_store_get_varvalue(var, buf, sizeof(buf), viewmode); g_object_set(cell, "text", buf, NULL); } @@ -175,7 +184,7 @@ void vartab_add_var(struct tdc_var *var) gtk_list_store_append(list_store, &it); char typestr[32]; - get_vartype(var, typestr, sizeof(typestr)); + tdc_store_get_vartype(var, typestr, sizeof(typestr)); gtk_list_store_set(list_store, &it, COL_ID, var->id, @@ -189,10 +198,11 @@ void vartab_add_var(struct tdc_var *var) void vartab_update_var(struct tdc_var *var) { - + // FIXME: don't update *all* columns when *one* value changed + gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), header_toggle_update, NULL); } -void vartab_remove_var(struct tdc_var *var) +void vartab_remove_all_vars(void) { - + gtk_list_store_clear(list_store); } diff --git a/variable_tab.h b/variable_tab.h index 3c1e5c3..d323a09 100644 --- a/variable_tab.h +++ b/variable_tab.h @@ -8,6 +8,6 @@ gint variable_tab_init(GtkNotebook *notebook); void vartab_add_var(struct tdc_var *var); void vartab_update_var(struct tdc_var *var); -void vartab_remove_var(struct tdc_var *var); +void vartab_remove_all_vars(void); #endif /* VARIABLE_TAB_H_ */