made the setting temperature unit dynamic
authorJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 14 Nov 2014 07:36:39 +0000 (08:36 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 14 Nov 2014 07:36:39 +0000 (08:36 +0100)
12 files changed:
src/cfg.c
src/cfg.h
src/glade/Makefile.in
src/glade/psensor-pref.glade
src/graph.c
src/main.c
src/ui_appindicator.c
src/ui_notify.c
src/ui_pref.c
src/ui_sensorlist.c
src/ui_unity.c
src/ui_unity.h

index 4cf1c7f..96baa27 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -458,8 +458,6 @@ struct config *config_load(void)
                c->window_h = 200;
        }
 
-       c->temperature_unit = get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
-
        c->sensor_values_max_length = compute_values_max_length(c);
 
        return c;
@@ -497,8 +495,6 @@ void config_save(const struct config *c)
        set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
 
        set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
-
-       set_int(KEY_INTERFACE_TEMPERATURE_UNIT, c->temperature_unit);
 }
 
 const char *get_psensor_user_dir(void)
@@ -944,3 +940,8 @@ enum temperature_unit config_get_temperature_unit(void)
 {
        return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
 }
+
+void config_set_temperature_unit(enum temperature_unit u)
+{
+       set_int(KEY_INTERFACE_TEMPERATURE_UNIT, u);
+}
index a029960..6ef7eae 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -69,8 +69,6 @@ struct config {
 
        int hide_on_startup;
 
-       enum temperature_unit temperature_unit;
-
        bool slog_enabled;
        int slog_interval;
 };
@@ -145,6 +143,7 @@ bool config_is_atiadlsdk_enabled(void);
 void config_set_atiadlsdk_enable(bool);
 
 enum temperature_unit config_get_temperature_unit(void);
+void config_set_temperature_unit(enum temperature_unit);
 
 double config_get_default_high_threshold_temperature(void);
 
index d794b5b..69c86cb 100644 (file)
@@ -81,11 +81,7 @@ host_triplet = @host@
 subdir = src/glade
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
-       $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
-       $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
-       $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
-       $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -170,6 +166,7 @@ ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
 EXEEXT = @EXEEXT@
+GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
 GLIB_COMPILE_SCHEMAS = @GLIB_COMPILE_SCHEMAS@
 GMSGFMT = @GMSGFMT@
 GMSGFMT_015 = @GMSGFMT_015@
@@ -228,6 +225,7 @@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 POSUB = @POSUB@
 PTHREAD_LIBS = @PTHREAD_LIBS@
 RANLIB = @RANLIB@
+SED = @SED@
 SENSORS_LIBS = @SENSORS_LIBS@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
@@ -242,6 +240,7 @@ XEXT_CFLAGS = @XEXT_CFLAGS@
 XEXT_LIBS = @XEXT_LIBS@
 XGETTEXT = @XGETTEXT@
 XGETTEXT_015 = @XGETTEXT_015@
+XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
 XMKMF = @XMKMF@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
index 135980e..0b8d540 100644 (file)
                       <item translatable="yes">Celsius</item>
                       <item translatable="yes">Fahrenheit</item>
                     </items>
+                    <signal name="changed" handler="ui_pref_temperature_unit_changed_cbk" swapped="no"/>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
index 0ac3143..862ac86 100644 (file)
@@ -466,7 +466,7 @@ graph_update(struct psensor **sensors,
        double min_rpm, max_rpm, mint, maxt, min, max;
        char *strmin, *strmax;
        /* horizontal and vertical offset of the graph */
-       int g_xoff, g_yoff, no_graphs;
+       int g_xoff, g_yoff, no_graphs, use_celsius;
        cairo_surface_t *cst;
        cairo_t *cr, *cr_pixmap;
        char *str_btime, *str_etime;
@@ -484,15 +484,16 @@ graph_update(struct psensor **sensors,
        min_rpm = get_min_rpm(enabled_sensors);
        max_rpm = get_max_rpm(enabled_sensors);
 
+       if (config_get_temperature_unit() == CELSIUS)
+               use_celsius = 1;
+       else
+               use_celsius = 0;
+
        mint = get_min_temp(enabled_sensors);
-       strmin = psensor_value_to_str(SENSOR_TYPE_TEMP,
-                                     mint,
-                                     config->temperature_unit == CELSIUS);
+       strmin = psensor_value_to_str(SENSOR_TYPE_TEMP, mint, use_celsius);
 
        maxt = get_max_temp(enabled_sensors);
-       strmax = psensor_value_to_str(SENSOR_TYPE_TEMP,
-                                     maxt,
-                                     config->temperature_unit == CELSIUS);
+       strmax = psensor_value_to_str(SENSOR_TYPE_TEMP, maxt, use_celsius);
 
        et = get_graph_end_time_s(enabled_sensors);
        bt = get_graph_begin_time_s(config, et);
index 6d23b80..484addd 100644 (file)
@@ -185,6 +185,7 @@ static gboolean ui_refresh_thread(gpointer data)
        struct config *cfg;
        gboolean ret;
        struct ui_psensor *ui = (struct ui_psensor *)data;
+       int use_celsius;
 
        ret = TRUE;
        cfg = ui->config;
@@ -198,9 +199,13 @@ static gboolean ui_refresh_thread(gpointer data)
        if (is_appindicator_supported() || is_status_supported())
                indicators_update(ui);
 
+       if (config_get_temperature_unit() == CELSIUS)
+               use_celsius = 1;
+       else
+               use_celsius = 0;
        ui_unity_launcher_entry_update(ui->sensors,
                                       !cfg->unity_launcher_count_disabled,
-                                      cfg->temperature_unit == CELSIUS);
+                                      use_celsius);
 
        if (ui->graph_update_interval != cfg->graph_update_interval) {
                ui->graph_update_interval = cfg->graph_update_interval;
index 2776882..5d301bf 100644 (file)
@@ -96,7 +96,10 @@ create_sensor_menu_items(const struct ui_psensor *ui, GtkMenu *menu)
        const char *name;
        struct psensor **sorted_sensors;
 
-       celsius  = ui->config->temperature_unit == CELSIUS;
+       if (config_get_temperature_unit() == CELSIUS)
+               celsius = 1;
+       else
+               celsius = 0;
 
        sorted_sensors = ui_get_sensors_ordered_by_position(ui->sensors);
        n = psensor_list_size(sorted_sensors);
@@ -165,14 +168,20 @@ static void update_label(struct ui_psensor *ui)
 {
        char *label, *str, *tmp, *guide;
        struct psensor **p;
+       int use_celsius;
 
        p =  ui_get_sensors_ordered_by_position(ui->sensors);
        label = NULL;
        guide = NULL;
+
+       if (config_get_temperature_unit() == CELSIUS)
+               use_celsius = 1;
+       else
+               use_celsius = 0;
+
        while (*p) {
                if (config_is_appindicator_label_enabled((*p)->id)) {
-                       str = psensor_current_value_to_str
-                               (*p, ui->config->temperature_unit == CELSIUS);
+                       str = psensor_current_value_to_str(*p, use_celsius);
 
                        if (label == NULL) {
                                label = str;
@@ -232,7 +241,10 @@ void ui_appindicator_update(struct ui_psensor *ui, bool attention)
                app_indicator_set_status(indicator,
                APP_INDICATOR_STATUS_ATTENTION);
 
-       update_menu_items(ui->config->temperature_unit == CELSIUS);
+       if (config_get_temperature_unit() == CELSIUS)
+               update_menu_items(1);
+       else
+               update_menu_items(0);
 }
 
 static GtkStatusIcon *unity_fallback(AppIndicator *indicator)
index a668014..dcea39f 100644 (file)
@@ -59,7 +59,7 @@ void ui_notify(struct psensor *sensor, struct ui_psensor *ui)
                notify_init("psensor");
 
        if (notify_is_initted() == TRUE) {
-               if (ui->config->temperature_unit == CELSIUS)
+               if (config_get_temperature_unit() == CELSIUS)
                        use_celsius = 1;
                else
                        use_celsius = 0;
index 596bb41..6594966 100644 (file)
@@ -45,6 +45,11 @@ void ui_pref_keep_below_toggled_cbk(GtkToggleButton *btn, gpointer data)
                (!config_is_window_keep_below_enabled());
 }
 
+void ui_pref_temperature_unit_changed_cbk(GtkComboBox *combo, gpointer data)
+{
+       config_set_temperature_unit(gtk_combo_box_get_active(combo));
+}
+
 GdkRGBA color_to_GdkRGBA(struct color *color)
 {
        GdkRGBA c;
@@ -71,11 +76,10 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        GtkSpinButton *w_update_interval, *w_monitoring_duration,
                *w_s_update_interval, *w_slog_interval;
        GtkComboBox *w_sensorlist_pos;
-       GtkToggleButton
-               *w_enable_menu, *w_enable_launcher_counter, *w_hide_on_startup,
-               *w_win_restore, *w_slog_enabled, *w_autostart, *w_smooth_curves,
-               *w_atiadlsdk, *w_lmsensors, *w_nvctrl, *w_gtop2, *w_hddtemp,
-               *w_libatasmart, *w_udisks2;
+       GtkToggleButton *w_enable_menu, *w_enable_launcher_counter,
+               *w_hide_on_startup, *w_win_restore, *w_slog_enabled,
+               *w_autostart, *w_smooth_curves, *w_atiadlsdk, *w_lmsensors,
+               *w_nvctrl, *w_gtop2, *w_hddtemp, *w_libatasmart, *w_udisks2;
        GtkComboBoxText *w_temp_unit;
        GtkEntry *w_notif_script;
        char *notif_script;
@@ -191,7 +195,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                = 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);
+                                config_get_temperature_unit());
 
        /* providers */
        w_lmsensors
@@ -343,9 +347,6 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                cfg->slog_interval
                        = gtk_spin_button_get_value_as_int(w_slog_interval);
 
-               cfg->temperature_unit
-                       = gtk_combo_box_get_active(GTK_COMBO_BOX(w_temp_unit));
-
                cfg->sensor_values_max_length = compute_values_max_length(cfg);
 
                config_save(cfg);
index f9b5fba..bb9a4ec 100644 (file)
@@ -110,7 +110,10 @@ void ui_sensorlist_update(struct ui_psensor *ui, bool complete)
 
        store = ui->sensors_store;
 
-       use_celsius = ui->config->temperature_unit == CELSIUS;
+       if (config_get_temperature_unit() == CELSIUS)
+               use_celsius = 1;
+       else
+               use_celsius = 0;
 
        valid = gtk_tree_model_get_iter_first(model, &iter);
        while (valid) {
index 2b949c8..9f9bd04 100644 (file)
@@ -83,3 +83,7 @@ void ui_unity_launcher_entry_update(struct psensor **sensors,
                }
        }
 }
+
+void ui_unity_init(void)
+{
+}
index cf8fa7d..50ffa1d 100644 (file)
@@ -28,6 +28,8 @@ static inline bool ui_unity_is_supported(void) { return true; }
 
 void ui_unity_launcher_entry_update(struct psensor **, unsigned int, int);
 
+void ui_unity_init(void);
+
 #else
 
 static inline bool ui_unity_is_supported(void) { return false; }
@@ -37,6 +39,8 @@ ui_unity_launcher_entry_update(struct psensor **s,
                               unsigned int show,
                               int use_celsius) {}
 
+static inline void ui_unity_init(void) {}
+
 #endif
 
 #endif