made count visible setting change dynamic
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 15 Nov 2014 13:49:34 +0000 (14:49 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 15 Nov 2014 13:49:34 +0000 (14:49 +0100)
src/cfg.c
src/cfg.h
src/glade/psensor-pref.glade
src/main.c
src/ui_pref.c
src/ui_unity.c
src/ui_unity.h

index fb24085..14267dc 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -951,3 +951,13 @@ void config_set_menu_bar_enabled(bool enabled)
 {
        set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, !enabled);
 }
+
+bool config_is_count_visible(void)
+{
+       return !get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
+}
+
+void config_set_count_visible(bool visible)
+{
+       set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED, !visible);
+}
index 2ca0fbf..bde8af4 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -154,6 +154,9 @@ void config_set_window_keep_below_enabled(bool);
 bool config_is_menu_bar_enabled(void);
 void config_set_menu_bar_enabled(bool);
 
+bool config_is_count_visible(void);
+void config_set_count_visible(bool);
+
 /*
  * Returns the user directory containing psensor data (configuration
  * and log).
index fa164dd..eb05a71 100644 (file)
                     <property name="margin_bottom">4</property>
                     <property name="xalign">0</property>
                     <property name="draw_indicator">True</property>
+                    <signal name="toggled" handler="ui_pref_count_visible_toggled_cbk" swapped="no"/>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
index 484addd..defc60d 100644 (file)
@@ -203,9 +203,7 @@ static gboolean ui_refresh_thread(gpointer data)
                use_celsius = 1;
        else
                use_celsius = 0;
-       ui_unity_launcher_entry_update(ui->sensors,
-                                      !cfg->unity_launcher_count_disabled,
-                                      use_celsius);
+       ui_unity_launcher_entry_update(ui->sensors);
 
        if (ui->graph_update_interval != cfg->graph_update_interval) {
                ui->graph_update_interval = cfg->graph_update_interval;
@@ -538,6 +536,7 @@ int main(int argc, char **argv)
        g_timeout_add(1000 * ui.graph_update_interval, ui_refresh_thread, &ui);
 
        ui_appindicator_init(&ui);
+       ui_unity_init();
 
        gdk_notify_startup_complete();
 
index 40c4dcc..3a181c3 100644 (file)
@@ -55,6 +55,11 @@ void ui_pref_menu_toggled_cbk(GtkToggleButton *btn, gpointer data)
        config_set_menu_bar_enabled(gtk_toggle_button_get_active(btn));
 }
 
+void ui_pref_count_visible_toggled_cbk(GtkToggleButton *btn, gpointer data)
+{
+       config_set_count_visible(gtk_toggle_button_get_active(btn));
+}
+
 GdkRGBA color_to_GdkRGBA(struct color *color)
 {
        GdkRGBA c;
index 9f9bd04..570567d 100644 (file)
 #include <temperature.h>
 #include <ui_unity.h>
 
-static int initialized;
 static UnityLauncherEntry *psensor_entry;
-static unsigned int last_visible = -1;
+static bool count_visible;
+
+static void
+count_visible_changed_cbk(GSettings *settings, gchar *key, gpointer data)
+{
+       count_visible = config_is_count_visible();
+
+       if (count_visible) {
+               unity_launcher_entry_set_count(psensor_entry, 0);
+               unity_launcher_entry_set_count_visible(psensor_entry, TRUE);
+       } else {
+               unity_launcher_entry_set_count_visible(psensor_entry, FALSE);
+       }
+}
 
 static double get_max_current_value(struct psensor **sensors, unsigned int type)
 {
@@ -48,42 +60,39 @@ static double get_max_current_value(struct psensor **sensors, unsigned int type)
        return m;
 }
 
-void ui_unity_launcher_entry_update(struct psensor **sensors,
-                                   unsigned int show,
-                                   int use_celsius)
+void ui_unity_launcher_entry_update(struct psensor **sensors)
 {
        double v;
 
-       if (!initialized) {
-               psensor_entry = unity_launcher_entry_get_for_desktop_file
-                       (PSENSOR_DESKTOP_FILE);
+       if (!count_visible || !sensors || !*sensors)
+               return;
 
-               unity_launcher_entry_set_count(psensor_entry, 0);
-               initialized = 1;
-       }
+       v = get_max_current_value(sensors, SENSOR_TYPE_TEMP);
 
-       if (last_visible != show) {
-               if (show)
-                       unity_launcher_entry_set_count_visible(psensor_entry,
-                                                              TRUE);
-               else
-                       unity_launcher_entry_set_count_visible(psensor_entry,
-                                                              FALSE);
-               last_visible = show;
-       }
+       if (v != UNKNOWN_DBL_VALUE) {
+               if (config_get_temperature_unit() == FAHRENHEIT)
+                       v = celsius_to_fahrenheit(v);
 
-       if (show && sensors && *sensors) {
-               v = get_max_current_value(sensors, SENSOR_TYPE_TEMP);
-
-               if (v != UNKNOWN_DBL_VALUE) {
-                       if (!use_celsius)
-                               v = celsius_to_fahrenheit(v);
-
-                       unity_launcher_entry_set_count(psensor_entry, v);
-               }
+               unity_launcher_entry_set_count(psensor_entry, v);
        }
 }
 
 void ui_unity_init(void)
 {
+       psensor_entry = unity_launcher_entry_get_for_desktop_file
+               (PSENSOR_DESKTOP_FILE);
+
+       count_visible = config_is_count_visible();
+
+       if (count_visible) {
+               unity_launcher_entry_set_count(psensor_entry, 0);
+               unity_launcher_entry_set_count_visible(psensor_entry, TRUE);
+       } else {
+               unity_launcher_entry_set_count_visible(psensor_entry, FALSE);
+       }
+
+       g_signal_connect_after(config_get_GSettings(),
+                              "changed::interface-unity-launcher-count-disabled",
+                              G_CALLBACK(count_visible_changed_cbk),
+                              NULL);
 }
index 50ffa1d..641c7ea 100644 (file)
@@ -26,7 +26,7 @@
 
 static inline bool ui_unity_is_supported(void) { return true; }
 
-void ui_unity_launcher_entry_update(struct psensor **, unsigned int, int);
+void ui_unity_launcher_entry_update(struct psensor **);
 
 void ui_unity_init(void);
 
@@ -35,9 +35,7 @@ void ui_unity_init(void);
 static inline bool ui_unity_is_supported(void) { return false; }
 
 static inline void
-ui_unity_launcher_entry_update(struct psensor **s,
-                              unsigned int show,
-                              int use_celsius) {}
+ui_unity_launcher_entry_update(struct psensor **s) {}
 
 static inline void ui_unity_init(void) {}