X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_sensorpref.c;h=ff93a02bfa838f212e1799827361390d9067e08a;hb=7fe35c5f020a37c5b54676b98af44cc73fbe48df;hp=abf69baab5df8772dba884f827b942cc67ab255a;hpb=56bf4c7648eabd46e9b118c10120e54181e2177f;p=psensor.git diff --git a/src/ui_sensorpref.c b/src/ui_sensorpref.c index abf69ba..ff93a02 100644 --- a/src/ui_sensorpref.c +++ b/src/ui_sensorpref.c @@ -20,15 +20,14 @@ #include -#include "cfg.h" -#include "ui_pref.h" -#include "ui_sensorlist.h" -#include "ui_sensorpref.h" -#include "ui_color.h" - -#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029) -#include "ui_appindicator.h" -#endif +#include +#include +#include +#include +#include +#include +#include + enum { COL_NAME = 0, @@ -38,13 +37,14 @@ enum { struct sensor_pref { struct psensor *sensor; char *name; - int enabled; + int graph_enabled; struct color *color; int alarm_enabled; int alarm_high_threshold; int alarm_low_threshold; unsigned int appindicator_enabled; unsigned int appindicator_label_enabled; + unsigned int display_enabled; }; struct cb_data { @@ -61,9 +61,10 @@ sensor_pref_new(struct psensor *s, struct config *cfg) p->sensor = s; p->name = strdup(s->name); - p->enabled = s->graph_enabled; + p->graph_enabled = s->graph_enabled; p->alarm_enabled = s->alarm_enabled; p->color = color_dup(s->color); + p->display_enabled = config_is_sensor_enabled(s->id); if (cfg->temperature_unit == CELSIUS) { p->alarm_high_threshold = s->alarm_high_threshold; @@ -85,7 +86,7 @@ sensor_pref_new(struct psensor *s, struct config *cfg) static void sensor_pref_free(struct sensor_pref *p) { if (!p) - return ; + return; free(p->name); free(p->color); @@ -131,7 +132,17 @@ void ui_sensorpref_draw_toggled_cb(GtkToggleButton *btn, gpointer data) p = get_selected_sensor_pref(GTK_TREE_VIEW(data)); if (p) - p->enabled = gtk_toggle_button_get_active(btn); + p->graph_enabled = gtk_toggle_button_get_active(btn); +} + +void ui_sensorpref_display_toggled_cb(GtkToggleButton *btn, gpointer data) +{ + struct sensor_pref *p; + + p = get_selected_sensor_pref(GTK_TREE_VIEW(data)); + + if (p) + p->display_enabled = gtk_toggle_button_get_active(btn); } void ui_sensorpref_alarm_toggled_cb(GtkToggleButton *btn, gpointer data) @@ -170,12 +181,12 @@ ui_sensorpref_appindicator_label_toggled_cb(GtkToggleButton *btn, gpointer data) void ui_sensorpref_color_set_cb(GtkColorButton *widget, gpointer data) { struct sensor_pref *p; - GdkColor color; + GdkRGBA color; p = get_selected_sensor_pref(GTK_TREE_VIEW(data)); if (p) { - gtk_color_button_get_color(widget, &color); + gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &color); color_set(p->color, color.red, color.green, color.blue); } } @@ -209,10 +220,10 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder) *w_chipname; GtkEntry *w_name; GtkToggleButton *w_draw, *w_alarm, *w_appindicator_enabled, - *w_appindicator_label_enabled; + *w_appindicator_label_enabled, *w_display; GtkColorButton *w_color; GtkSpinButton *w_high_threshold, *w_low_threshold; - GdkColor *color; + GdkRGBA color; struct psensor *s; int use_celsius; @@ -235,12 +246,17 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder) w_draw = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "sensor_draw")); - gtk_toggle_button_set_active(w_draw, p->enabled); + gtk_toggle_button_set_active(w_draw, p->graph_enabled); + + w_display = GTK_TOGGLE_BUTTON(gtk_builder_get_object + (builder, + "sensor_enable_checkbox")); + gtk_toggle_button_set_active(w_display, p->display_enabled); - color = color_to_gdkcolor(p->color); + color = color_to_GdkRGBA(p->color); w_color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "sensor_color")); - gtk_color_button_set_color(w_color, color); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w_color), &color); w_alarm = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "sensor_alarm")); @@ -271,24 +287,30 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder) w_appindicator_label_enabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object(builder, "indicator_label_checkbox")); - if (is_temp_type(s->type) || is_fan_type(s->type)) { - gtk_toggle_button_set_active(w_alarm, p->alarm_enabled); - gtk_spin_button_set_value(w_high_threshold, - p->alarm_high_threshold); - gtk_spin_button_set_value(w_low_threshold, - p->alarm_low_threshold); - gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), TRUE); + + if (is_appindicator_supported()) { + gtk_widget_set_has_tooltip + (GTK_WIDGET(w_appindicator_label_enabled), FALSE); + gtk_widget_set_has_tooltip + (GTK_WIDGET(w_appindicator_enabled), FALSE); } else { - gtk_toggle_button_set_active(w_alarm, 0); - gtk_spin_button_set_value(w_high_threshold, 0); - gtk_spin_button_set_value(w_low_threshold, 0); - gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), FALSE); + gtk_widget_set_sensitive + (GTK_WIDGET(w_appindicator_label_enabled), FALSE); + gtk_widget_set_has_tooltip + (GTK_WIDGET(w_appindicator_label_enabled), TRUE); + gtk_widget_set_sensitive + (GTK_WIDGET(w_appindicator_enabled), FALSE); + gtk_widget_set_has_tooltip + (GTK_WIDGET(w_appindicator_enabled), TRUE); } + gtk_toggle_button_set_active(w_alarm, p->alarm_enabled); + gtk_spin_button_set_value(w_high_threshold, p->alarm_high_threshold); + gtk_spin_button_set_value(w_low_threshold, p->alarm_low_threshold); + gtk_widget_set_sensitive(GTK_WIDGET(w_alarm), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(w_high_threshold), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(w_low_threshold), TRUE); + gtk_toggle_button_set_active(w_appindicator_enabled, p->appindicator_enabled); @@ -315,6 +337,7 @@ select_sensor(struct psensor *s, struct psensor **sensors, GtkTreeView *tree) struct psensor **s_cur; int i; GtkTreePath *p; + GtkTreeSelection *sel; p = NULL; for (s_cur = sensors, i = 0; *s_cur; s_cur++, i++) @@ -324,9 +347,9 @@ select_sensor(struct psensor *s, struct psensor **sensors, GtkTreeView *tree) } if (p) { - GtkTreeSelection *s = gtk_tree_view_get_selection(tree); + sel = gtk_tree_view_get_selection(tree); - gtk_tree_selection_select_path(s, p); + gtk_tree_selection_select_path(sel, p); gtk_tree_path_free(p); } } @@ -343,9 +366,9 @@ static void apply_pref(struct sensor_pref *p, int pos, struct config *cfg) config_set_sensor_name(s->id, s->name); } - if (s->graph_enabled != p->enabled) { - s->graph_enabled = p->enabled; - config_set_sensor_enabled(s->id, s->graph_enabled); + if (s->graph_enabled != p->graph_enabled) { + s->graph_enabled = p->graph_enabled; + config_set_sensor_graph_enabled(s->id, s->graph_enabled); } if (is_temp_type(s->type) && cfg->temperature_unit == FAHRENHEIT) { @@ -366,7 +389,10 @@ static void apply_pref(struct sensor_pref *p, int pos, struct config *cfg) config_set_sensor_alarm_enabled(s->id, s->alarm_enabled); } - color_set(s->color, p->color->red, p->color->green, p->color->blue); + color_set(s->color, + p->color->red, + p->color->green, + p->color->blue); config_set_sensor_color(s->id, s->color); if (s->appindicator_enabled != p->appindicator_enabled) { @@ -378,6 +404,8 @@ static void apply_pref(struct sensor_pref *p, int pos, struct config *cfg) p->appindicator_label_enabled); config_set_sensor_position(s->id, pos); + + config_set_sensor_enabled(s->id, p->display_enabled); } static void apply_prefs(GtkTreeModel *model, struct config *cfg) @@ -429,7 +457,7 @@ void ui_sensorpref_dialog_run(struct psensor *sensor, struct ui_psensor *ui) if (!ok) { log_printf(LOG_ERR, error->message); g_error_free(error); - return ; + return; } w_sensors_list @@ -469,7 +497,7 @@ void ui_sensorpref_dialog_run(struct psensor *sensor, struct ui_psensor *ui) if (result == GTK_RESPONSE_ACCEPT) { apply_prefs(model, ui->config); ui_sensorlist_update(ui, 1); -#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029) +#if defined(HAVE_APPINDICATOR) ui_appindicator_update_menu(ui); #endif }