put temperature conversion functions into a separate file.
[psensor.git] / src / ui_sensorpref.c
index f073c04..0fa57e0 100644 (file)
 
 #include <gtk/gtk.h>
 
-#include "cfg.h"
-#include "ui_pref.h"
-#include "ui_sensorlist.h"
-#include "ui_sensorpref.h"
-#include "ui_color.h"
+#include <cfg.h>
+#include <temperature.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"
@@ -38,13 +40,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,18 +64,19 @@ 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 == CELCIUS) {
+       if (cfg->temperature_unit == CELSIUS) {
                p->alarm_high_threshold = s->alarm_high_threshold;
                p->alarm_low_threshold = s->alarm_low_threshold;
        } else {
                p->alarm_high_threshold
-                       = celcius_to_fahrenheit(s->alarm_high_threshold);
+                       = celsius_to_fahrenheit(s->alarm_high_threshold);
                p->alarm_low_threshold
-                       = celcius_to_fahrenheit(s->alarm_low_threshold);
+                       = celsius_to_fahrenheit(s->alarm_low_threshold);
        }
 
        p->appindicator_enabled = s->appindicator_enabled;
@@ -131,7 +135,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)
@@ -209,12 +223,12 @@ 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;
        struct psensor *s;
-       int use_celcius;
+       int use_celsius;
 
        s = p->sensor;
 
@@ -235,7 +249,12 @@ 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);
        w_color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder,
@@ -258,20 +277,19 @@ update_pref(struct sensor_pref *p, struct config *cfg, GtkBuilder *builder)
                                        (builder,
                                         "sensor_alarm_low_threshold_unit"));
 
-       use_celcius = cfg->temperature_unit == CELCIUS ? 1 : 0;
+       use_celsius = cfg->temperature_unit == CELSIUS ? 1 : 0;
        gtk_label_set_text(w_high_threshold_unit,
                           psensor_type_to_unit_str(s->type,
-                                                   use_celcius));
+                                                   use_celsius));
        gtk_label_set_text(w_low_threshold_unit,
                           psensor_type_to_unit_str(s->type,
-                                                   use_celcius));
+                                                   use_celsius));
 
        w_appindicator_enabled = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "indicator_checkbox"));
        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,
@@ -344,16 +362,16 @@ 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) {
                s->alarm_high_threshold
-                       = fahrenheit_to_celcius(p->alarm_high_threshold);
+                       = fahrenheit_to_celsius(p->alarm_high_threshold);
                s->alarm_low_threshold
-                       = fahrenheit_to_celcius(p->alarm_low_threshold);
+                       = fahrenheit_to_celsius(p->alarm_low_threshold);
        } else {
                s->alarm_high_threshold = p->alarm_high_threshold;
                s->alarm_low_threshold = p->alarm_low_threshold;
@@ -379,6 +397,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)
@@ -396,6 +416,7 @@ static void apply_prefs(GtkTreeModel *model, struct config *cfg)
                valid = gtk_tree_model_iter_next(model, &iter);
                i++;
        }
+       config_sync();
 }
 
 void ui_sensorpref_dialog_run(struct psensor *sensor, struct ui_psensor *ui)