X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_sensorlist.c;h=f21a82e660ad98b69bba481a78384ed5ae688a91;hb=1410f23801330c83c83caf21353860ff2bc18399;hp=f4aa6ecf6c30ee7613ea97f987e63b7f8146bbb2;hpb=bf5b907924e3bfcde06287168119a2b9b4dc7418;p=psensor.git diff --git a/src/ui_sensorlist.c b/src/ui_sensorlist.c index f4aa6ec..f21a82e 100644 --- a/src/ui_sensorlist.c +++ b/src/ui_sensorlist.c @@ -53,19 +53,56 @@ static int col_index_to_col(int idx) return idx; } +static void populate(struct ui_psensor *ui) +{ + GtkTreeIter iter; + GtkListStore *store; + GdkColor color; + char *scolor; + struct psensor **ordered_sensors, **s_cur, *s; + + ordered_sensors = ui_get_sensors_ordered_by_position(ui); + store = ui->sensors_store; + + gtk_list_store_clear(store); + + for (s_cur = ordered_sensors; *s_cur; s_cur++) { + s = *s_cur; + + gtk_list_store_append(store, &iter); + + color.red = s->color->red; + color.green = s->color->green; + color.blue = s->color->blue; + + scolor = gdk_color_to_string(&color); + + gtk_list_store_set(store, &iter, + COL_NAME, s->name, + COL_COLOR_STR, scolor, + COL_ENABLED, s->graph_enabled, + COL_SENSOR, s, + -1); + free(scolor); + } + free(ordered_sensors); +} + void ui_sensorlist_update(struct ui_psensor *ui, bool complete) { - char *scolor, *value, *min, *max; + char *value, *min, *max; struct psensor *s; GtkTreeIter iter; GtkTreeModel *model; gboolean valid; int use_celcius; - GdkColor color; GtkListStore *store; + if (complete) + populate(ui); + model = gtk_tree_view_get_model(ui->sensors_tree); - store = GTK_LIST_STORE(model); + store = ui->sensors_store; use_celcius = ui->config->temperature_unit == CELCIUS; @@ -88,21 +125,6 @@ void ui_sensorlist_update(struct ui_psensor *ui, bool complete) free(min); free(max); - if (complete) { - color.red = s->color->red; - color.green = s->color->green; - color.blue = s->color->blue; - - scolor = gdk_color_to_string(&color); - - gtk_list_store_set(store, &iter, - COL_NAME, s->name, - COL_COLOR_STR, scolor, - COL_ENABLED, s->enabled, - -1); - free(scolor); - } - valid = gtk_tree_model_iter_next(model, &iter); } } @@ -163,15 +185,15 @@ static int get_col_index_at_pos(GtkTreeView *view, int x) return -1; } -static void on_preferences_activated(GtkWidget *menu_item, gpointer data) +static void preferences_activated_cbk(GtkWidget *menu_item, gpointer data) { struct cb_data *cb_data = data; ui_sensorpref_dialog_run(cb_data->sensor, cb_data->ui); } -static GtkWidget *create_sensor_popup(struct ui_psensor *ui, - struct psensor *sensor) +static GtkWidget * +create_sensor_popup(struct ui_psensor *ui, struct psensor *sensor) { GtkWidget *menu, *item, *separator; struct cb_data *data; @@ -193,14 +215,14 @@ static GtkWidget *create_sensor_popup(struct ui_psensor *ui, g_signal_connect(item, "activate", - G_CALLBACK(on_preferences_activated), data); + G_CALLBACK(preferences_activated_cbk), data); gtk_widget_show_all(menu); return menu; } -static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data) +static int clicked_cbk(GtkWidget *widget, GdkEventButton *event, gpointer data) { GtkWidget *menu; struct ui_psensor *ui; @@ -253,36 +275,18 @@ toggled_cbk(GtkCellRendererToggle *cell, gchar *path_str, gpointer data) gtk_tree_model_get(model, &iter, COL_SENSOR, &s, -1); - s->enabled ^= 1; - config_set_sensor_enabled(s->id, s->enabled); + s->graph_enabled ^= 1; + config_set_sensor_enabled(s->id, s->graph_enabled); gtk_list_store_set(GTK_LIST_STORE(model), &iter, - COL_ENABLED, s->enabled, -1); + COL_ENABLED, s->graph_enabled, -1); gtk_tree_path_free(path); } -static int cmp_sensors(const void *p1, const void *p2) -{ - const struct psensor *s1, *s2; - int pos1, pos2; - - s1 = *(void **)p1; - s2 = *(void **)p2; - - pos1 = config_get_sensor_position(s1->id); - pos2 = config_get_sensor_position(s2->id); - - return pos1 - pos2; -} - void ui_sensorlist_create(struct ui_psensor *ui) { - GtkListStore *store; GtkCellRenderer *renderer; - struct psensor **s_cur; - GtkTreeIter iter; - struct psensor **ordered_sensors; log_debug("ui_sensorlist_create()"); @@ -321,7 +325,7 @@ void ui_sensorlist_create(struct ui_psensor *ui) NULL); g_signal_connect(ui->sensors_tree, - "button-press-event", (GCallback) on_clicked, ui); + "button-press-event", (GCallback)clicked_cbk, ui); renderer = gtk_cell_renderer_toggle_new(); gtk_tree_view_insert_column_with_attributes(ui->sensors_tree, @@ -340,18 +344,5 @@ void ui_sensorlist_create(struct ui_psensor *ui) renderer, "text", COL_EMPTY, NULL); - ordered_sensors = psensor_list_copy(ui->sensors); - qsort(ordered_sensors, - psensor_list_size(ordered_sensors), - sizeof(struct psensor *), - cmp_sensors); - - store = ui->sensors_store; - for (s_cur = ordered_sensors; *s_cur; s_cur++) { - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, COL_SENSOR, *s_cur, -1); - } - free(ordered_sensors); - ui_sensorlist_update(ui, 1); }