added support of enable/disable unity launcher count
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 25 Apr 2011 11:43:56 +0000 (11:43 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 25 Apr 2011 11:43:56 +0000 (11:43 +0000)
src/cfg.c config_get_string renamed to static get_string

NEWS
src/cfg.c
src/cfg.h
src/main.c
src/ui_pref.c
src/unity/ui_unity.c
src/unity/ui_unity.h

diff --git a/NEWS b/NEWS
index 3465c34..3c65747 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@
 ** added missing french translation
 ** added different sizes of psensor.png 
 ** psensor: added menu
+** psensor: added enable/disable unity launcher counter
 
 * v0.6.2.7
 
index 2baadf5..6f3ed3c 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
 #define KEY_INTERFACE_MENU_BAR_DISABLED \
 "/apps/psensor/interface/menu_bar_disabled"
 
+#define KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED \
+"/apps/psensor/interface/unity_launcher_count_disabled"
 
 GConfClient *client;
 
-char *config_get_string(char *key, char *default_value)
+static char *get_string(char *key, char *default_value)
 {
        char *value = gconf_client_get_string(client,
                                              key,
@@ -76,7 +78,7 @@ char *config_get_string(char *key, char *default_value)
 struct color *config_get_background_color()
 {
 
-       char *scolor = config_get_string(KEY_GRAPH_BACKGROUND_COLOR,
+       char *scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR,
                                         DEFAULT_GRAPH_BACKGROUND_COLOR);
 
        struct color *c = string_to_color(scolor);
@@ -91,8 +93,8 @@ struct color *config_get_background_color()
 
 struct color *config_get_foreground_color()
 {
-       char *scolor = config_get_string(KEY_GRAPH_FOREGROUND_COLOR,
-                                        DEFAULT_GRAPH_FOREGROUND_COLOR);
+       char *scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR,
+                                 DEFAULT_GRAPH_FOREGROUND_COLOR);
 
        struct color *c = string_to_color(scolor);
 
@@ -438,6 +440,11 @@ struct config *config_load()
                 KEY_INTERFACE_MENU_BAR_DISABLED,
                 NULL);
 
+       cfg->unity_launcher_count_disabled = gconf_client_get_bool
+               (client,
+                KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
+                NULL);
+
        return cfg;
 }
 
@@ -466,4 +473,7 @@ void config_save(struct config *cfg)
                              KEY_INTERFACE_MENU_BAR_DISABLED,
                              cfg->menu_bar_disabled, NULL);
 
+       gconf_client_set_bool(client,
+                             KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
+                             cfg->unity_launcher_count_disabled, NULL);
 }
index 00331d9..b61a469 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -51,6 +51,8 @@ struct config {
        int sensor_update_interval;
 
        int menu_bar_disabled;
+
+       int unity_launcher_count_disabled;
 };
 
 /*
index 6afbfa2..3ebac43 100644 (file)
@@ -175,7 +175,8 @@ gboolean ui_refresh_thread(gpointer data)
 #endif
 
 #ifdef HAVE_UNITY
-       ui_unity_launcher_entry_update(ui->sensors);
+       ui_unity_launcher_entry_update(ui->sensors,
+                                      !cfg->unity_launcher_count_disabled);
 #endif
 
        if (ui->graph_update_interval != cfg->graph_update_interval) {
index 32cc35f..1f480b8 100644 (file)
@@ -52,7 +52,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                *w_s_update_interval;
        GtkComboBox *w_sensorlist_pos;
        GtkToggleButton *w_hide_window_decoration, *w_keep_window_below,
-               *w_enable_menu;
+               *w_enable_menu, *w_enable_launcher_counter;
 
        cfg = ui->config;
 
@@ -125,6 +125,11 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        gtk_toggle_button_set_active(w_enable_menu,
                                     !cfg->menu_bar_disabled);
 
+       w_enable_launcher_counter = GTK_TOGGLE_BUTTON
+               (gtk_builder_get_object(builder,
+                                       "enable_launcher_counter"));
+       gtk_toggle_button_set_active(w_enable_launcher_counter,
+                                    !cfg->unity_launcher_count_disabled);
 
        result = gtk_dialog_run(diag);
 
@@ -162,6 +167,10 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                cfg->menu_bar_disabled
                        = !gtk_toggle_button_get_active(w_enable_menu);
 
+               cfg->unity_launcher_count_disabled
+                       = !gtk_toggle_button_get_active
+                       (w_enable_launcher_counter);
+
                gtk_window_set_decorated(GTK_WINDOW(ui->main_window),
                                         cfg->window_decoration_enabled);
 
index 8b790f5..cb62458 100644 (file)
 
 static int initialized;
 static UnityLauncherEntry *psensor_entry;
+static unsigned int last_visible = -1;
 
-void ui_unity_launcher_entry_update(struct psensor **sensors)
+void ui_unity_launcher_entry_update(struct psensor **sensors,
+                                   unsigned int show)
 {
        if (!initialized) {
                psensor_entry = unity_launcher_entry_get_for_desktop_file
                        ("psensor.desktop");
-               unity_launcher_entry_set_count_visible(psensor_entry, TRUE);
+
                unity_launcher_entry_set_count(psensor_entry, 0);
                initialized = 1;
        }
 
+       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 (sensors && *sensors) {
                struct psensor *s = *sensors;
                double v = psensor_get_current_value(s);
index be55b3b..9ec3ddf 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "psensor.h"
 
-void ui_unity_launcher_entry_update(struct psensor **sensors);
+void ui_unity_launcher_entry_update(struct psensor **sensors,
+                                   unsigned int show);
 
 #endif