support of fahrenheit option
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 8 Apr 2012 11:41:10 +0000 (11:41 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 8 Apr 2012 11:41:10 +0000 (11:41 +0000)
src/cfg.c
src/cfg.h
src/graph.c
src/lib/psensor.c
src/lib/psensor.h
src/ui.c
src/ui_pref.c
src/ui_sensorlist.c

index d1a3bed..99181ee 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -71,6 +71,9 @@
 #define KEY_INTERFACE_WINDOW_DIVIDER_POS \
 "/apps/psensor/interface/window_divider_pos"
 
+#define KEY_INTERFACE_TEMPERATURE_UNIT \
+"/apps/psensor/interface/temperature_unit"
+
 GConfClient *client;
 
 static char *get_string(char *key, char *default_value)
@@ -490,6 +493,9 @@ struct config *config_load()
                c->window_h = 200;
        }
 
+       c->temperature_unit = gconf_client_get_int
+               (client, KEY_INTERFACE_TEMPERATURE_UNIT, NULL);
+
        return c;
 }
 
@@ -552,4 +558,10 @@ void config_save(struct config *c)
                             KEY_INTERFACE_WINDOW_DIVIDER_POS,
                             c->window_divider_pos,
                             NULL);
+
+       gconf_client_set_int(client,
+                            KEY_INTERFACE_TEMPERATURE_UNIT,
+                            c->temperature_unit,
+                            NULL);
+
 }
index f7d4df1..11a8f6b 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
 
 #include "color.h"
 
+enum temperature_unit {
+       CELCIUS,
+       FAHRENHEIT
+};
+
 enum sensorlist_position {
        SENSORLIST_POSITION_RIGHT,
        SENSORLIST_POSITION_LEFT,
@@ -64,6 +69,8 @@ struct config {
        int unity_launcher_count_disabled;
 
        int hide_on_startup;
+
+       enum temperature_unit temperature_unit;
 };
 
 /*
index 3dd18d5..06d7c8b 100644 (file)
@@ -240,10 +240,15 @@ graph_update(struct psensor **sensors,
        max_rpm = get_max_rpm(sensors);
 
        mint = get_min_temp(sensors);
-       strmin = psensor_value_to_string(SENSOR_TYPE_TEMP, mint);
+
+       strmin = psensor_value_to_string(SENSOR_TYPE_TEMP,
+                                        mint,
+                                        config->temperature_unit == CELCIUS);
 
        maxt = get_max_temp(sensors);
-       strmax = psensor_value_to_string(SENSOR_TYPE_TEMP, maxt);
+       strmax = psensor_value_to_string(SENSOR_TYPE_TEMP,
+                                        maxt,
+                                        config->temperature_unit == CELCIUS);
 
        str_btime = time_to_str(get_graph_begin_time_s(config));
        str_etime = time_to_str(get_graph_end_time_s());
index 1973c53..138b19f 100644 (file)
@@ -198,7 +198,14 @@ int is_fan_type(unsigned int type)
        return type & SENSOR_TYPE_FAN;
 }
 
-char *psensor_value_to_string(unsigned int type, double value)
+static double celcius_to_fahrenheit(double c)
+{
+       return c * (9.0/5.0) + 32;
+}
+
+char *psensor_value_to_string(unsigned int type,
+                             double value,
+                             int use_celcius)
 {
        /* should not be possible to exceed 20 characters with temp or
           rpm values the .x part is never displayed */
@@ -207,7 +214,12 @@ char *psensor_value_to_string(unsigned int type, double value)
        char *unit;
 
        if (is_temp_type(type))
-               unit = "C";
+               if (use_celcius) {
+                       unit = "C";
+               } else {
+                       unit = "F";
+                       value = celcius_to_fahrenheit(value);
+               }
        else if (type & SENSOR_TYPE_CPU_USAGE)
                unit = "%";
        else
index 093bc6d..27dacac 100644 (file)
@@ -156,7 +156,9 @@ psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
   or SENSOR_TYPE_LMSENSOR_FAN
 */
-char *psensor_value_to_string(unsigned int type, double value);
+char *psensor_value_to_string(unsigned int type,
+                             double value,
+                             int use_celcius);
 
 struct psensor **get_all_sensors(int use_libatasmart, int values_max_length);
 
index ee75c33..f1c84b2 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -195,7 +195,8 @@ void ui_enable_alpha_channel(struct ui_psensor *ui)
 
        screen = gtk_widget_get_screen(ui->main_window);
 
-       log_debug("Config alpha channel enabled: %d", cfg->alpha_channel_enabled);
+       log_debug("Config alpha channel enabled: %d",
+                 cfg->alpha_channel_enabled);
        if (cfg->alpha_channel_enabled && gdk_screen_is_composited(screen)) {
                log_debug("Screen is composited");
                visual = gdk_screen_get_rgba_visual(screen);
index 8005e04..cc4be17 100644 (file)
@@ -53,6 +53,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        GtkToggleButton *w_hide_window_decoration, *w_keep_window_below,
                *w_enable_menu, *w_enable_launcher_counter, *w_hide_on_startup,
                *w_win_restore;
+       GtkComboBoxText *w_temp_unit;
 
        cfg = ui->config;
 
@@ -136,6 +137,13 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        gtk_toggle_button_set_active(w_win_restore,
                                     cfg->window_restore_enabled);
 
+       w_temp_unit
+               = GTK_COMBO_BOX_TEXT(gtk_builder_get_object
+                                    (builder, "temperature_unit"));
+       gtk_combo_box_set_active(GTK_COMBO_BOX(w_temp_unit),
+                                cfg->temperature_unit);
+
+
        result = gtk_dialog_run(diag);
 
        if (result == GTK_RESPONSE_ACCEPT) {
@@ -202,6 +210,9 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                cfg->window_restore_enabled
                        = gtk_toggle_button_get_active(w_win_restore);
 
+               cfg->temperature_unit
+                       = gtk_combo_box_get_active(GTK_COMBO_BOX(w_temp_unit));
+
                config_save(cfg);
 
                g_mutex_unlock(ui->sensors_mutex);
index d5a0240..b4ac650 100644 (file)
@@ -56,32 +56,36 @@ static int col_index_to_col(int idx)
 
 void ui_sensorlist_update(struct ui_psensor *ui)
 {
+       char *str;
+       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;
+       int use_celcius;
 
-       while (valid && *sensor) {
-               struct psensor *s = *sensor;
+       use_celcius = ui->config->temperature_unit == CELCIUS;
 
-               char *str;
+       while (valid && *sensor) {
+               s = *sensor;
 
                str = psensor_value_to_string(s->type,
                                              s->measures[s->values_max_length -
-                                                         1].value.d_num);
+                                                         1].value.d_num,
+                                             use_celcius);
 
                gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_TEMP, str,
                                   -1);
                free(str);
 
-               str = psensor_value_to_string(s->type, s->min);
+               str = psensor_value_to_string(s->type, s->min, use_celcius);
                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                                   COL_TEMP_MIN, str, -1);
                free(str);
 
-               str = psensor_value_to_string(s->type, s->max);
+               str = psensor_value_to_string(s->type, s->max, use_celcius);
                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                                   COL_TEMP_MAX, str, -1);
                free(str);