X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_sensorlist.c;h=b51de4dc107116d3f82e419e18efdadb1f3a7593;hb=781b933c5e5b678f9be3efb25291dee8a8f43f3e;hp=53235fbcb249a01fbc9ba1a1ff08bf826379181c;hpb=ee42be45e376e9be700247aefdea61f9d4bd4ff7;p=psensor.git diff --git a/src/ui_sensorlist.c b/src/ui_sensorlist.c index 53235fb..b51de4d 100644 --- a/src/ui_sensorlist.c +++ b/src/ui_sensorlist.c @@ -1,23 +1,21 @@ /* - Copyright (C) 2010-2011 jeanfi@gmail.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - - + * Copyright (C) 2010-2013 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ #include #include @@ -38,6 +36,7 @@ enum { COL_COLOR_STR, COL_ENABLED, COL_EMPTY, + COL_SENSOR, COLS_COUNT }; @@ -56,39 +55,58 @@ static int col_index_to_col(int idx) return idx; } -void ui_sensorlist_update(struct ui_psensor *ui) +void ui_sensorlist_update(struct ui_psensor *ui, bool complete) { + char *scolor, *value, *min, *max; + struct psensor *s; GtkTreeIter iter; - struct ui_sensorlist *ui_sl = ui->ui_sensorlist; - GtkTreeModel *model - = gtk_tree_view_get_model(ui_sl->treeview); - gboolean valid = gtk_tree_model_get_iter_first(model, &iter); - struct psensor **sensor = ui->sensors; + GtkTreeModel *model; + gboolean valid; + int use_celcius; + GdkColor color; + GtkListStore *store; - while (valid && *sensor) { - struct psensor *s = *sensor; + model = gtk_tree_view_get_model(ui->sensors_tree); + store = GTK_LIST_STORE(model); - char *str; + use_celcius = ui->config->temperature_unit == CELCIUS; - str = psensor_value_to_string(s->type, - s->measures[s->values_max_length - - 1].value); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_TEMP, str, - -1); - free(str); + valid = gtk_tree_model_get_iter_first(model, &iter); + while (valid) { + gtk_tree_model_get(model, &iter, COL_SENSOR, &s, -1); - str = psensor_value_to_string(s->type, s->min); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - COL_TEMP_MIN, str, -1); - free(str); + value = psensor_value_to_str(s->type, + s->measures[s->values_max_length - + 1].value, + use_celcius); + min = psensor_value_to_str(s->type, s->min, use_celcius); + max = psensor_value_to_str(s->type, s->max, use_celcius); - str = psensor_value_to_string(s->type, s->max); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - COL_TEMP_MAX, str, -1); - free(str); + gtk_list_store_set(store, &iter, + COL_TEMP, value, + COL_TEMP_MIN, min, + COL_TEMP_MAX, max, + -1); + free(value); + 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); - sensor++; } } @@ -141,40 +159,6 @@ static int get_col_index_at_pos(GtkTreeView *view, int x) return -1; } -void ui_sensorlist_update_sensors_preferences(struct ui_psensor *ui) -{ - GtkTreeIter iter; - GtkTreeModel *model - = gtk_tree_view_get_model(ui->ui_sensorlist->treeview); - gboolean valid = gtk_tree_model_get_iter_first(model, &iter); - struct psensor **sensor = ui->ui_sensorlist->sensors; - - while (valid && *sensor) { - GdkColor color; - gchar *scolor; - - color.red = (*sensor)->color->red; - color.green = (*sensor)->color->green; - color.blue = (*sensor)->color->blue; - - scolor = gdk_color_to_string(&color); - - gtk_list_store_set(GTK_LIST_STORE(model), - &iter, COL_NAME, (*sensor)->name, -1); - - gtk_list_store_set(GTK_LIST_STORE(model), - &iter, COL_COLOR_STR, scolor, -1); - - gtk_list_store_set(GTK_LIST_STORE(model), - &iter, COL_ENABLED, (*sensor)->enabled, -1); - - free(scolor); - - valid = gtk_tree_model_iter_next(model, &iter); - sensor++; - } -} - static void on_preferences_activated(GtkWidget *menu_item, gpointer data) { struct cb_data *cb_data = data; @@ -216,9 +200,13 @@ static GtkWidget *create_sensor_popup(struct ui_psensor *ui, static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data) { + GtkWidget *menu; struct ui_psensor *ui = (struct ui_psensor *)data; GtkTreeView *view = ui->ui_sensorlist->treeview; + if (event->button != 3) + return FALSE; + struct psensor *sensor = get_sensor_at_pos(view, event->x, event->y, @@ -231,21 +219,19 @@ static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data) if (coli == COL_COLOR) { if (ui_change_color(_("Select foreground color"), sensor->color)) { - ui_sensorlist_update_sensors_preferences(ui); + ui_sensorlist_update(ui, 1); config_set_sensor_color(sensor->id, sensor->color); } } else if (coli >= 0 && coli != COL_ENABLED) { - GtkWidget *menu = create_sensor_popup(ui, - sensor); + menu = create_sensor_popup(ui, sensor); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); - } } - return FALSE; + return TRUE; } static void @@ -287,21 +273,9 @@ static void create_widget(struct ui_psensor *ui) struct psensor **s_cur = ui->sensors; struct ui_sensorlist *ui_sl = ui->ui_sensorlist; - store = gtk_list_store_new(COLS_COUNT, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_BOOLEAN, G_TYPE_STRING); + store = ui->sensors_store; - ui_sl->treeview = GTK_TREE_VIEW - (gtk_tree_view_new_with_model(GTK_TREE_MODEL(store))); - - gtk_tree_selection_set_mode - (gtk_tree_view_get_selection(ui_sl->treeview), - GTK_SELECTION_NONE); + ui_sl->treeview = ui->sensors_tree; renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(ui_sl->treeview, @@ -312,7 +286,7 @@ static void create_widget(struct ui_psensor *ui) gtk_tree_view_insert_column_with_attributes(ui_sl->treeview, -1, - _("Current"), + _("Value"), renderer, "text", COL_TEMP, NULL); @@ -343,7 +317,7 @@ static void create_widget(struct ui_psensor *ui) renderer = gtk_cell_renderer_toggle_new(); gtk_tree_view_insert_column_with_attributes(ui_sl->treeview, -1, - _("Enabled"), + _("Graph"), renderer, "active", COL_ENABLED, NULL); @@ -376,22 +350,18 @@ static void create_widget(struct ui_psensor *ui) COL_TEMP_MIN, _("N/A"), COL_TEMP_MAX, _("N/A"), COL_COLOR_STR, scolor, - COL_ENABLED, s->enabled, -1); + COL_ENABLED, s->enabled, + COL_SENSOR, s, -1); free(scolor); s_cur++; } - - ui_sl->widget = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui_sl->widget), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(ui_sl->widget), - GTK_WIDGET(ui_sl->treeview)); } void ui_sensorlist_create(struct ui_psensor *ui) { + log_debug("ui_sensorlist_create()"); ui->ui_sensorlist = malloc(sizeof(struct ui_sensorlist)); ui->ui_sensorlist->sensors = ui->sensors;