added configuration support for new property "window_restore"
[psensor.git] / src / cfg.c
index be544bb..b866a8c 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
 #define KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED \
 "/apps/psensor/interface/window_keep_below_enabled"
 
+#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"
+
+#define KEY_INTERFACE_HIDE_ON_STARTUP \
+"/apps/psensor/interface/hide_on_startup"
+
+#define KEY_INTERFACE_WINDOW_RESTORE_ENABLED \
+"/apps/psensor/interface/window_restore_enabled"
+
 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,
@@ -69,10 +81,10 @@ char *config_get_string(char *key, char *default_value)
        return value;
 }
 
-struct color *config_get_background_color()
+static 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);
@@ -85,10 +97,10 @@ struct color *config_get_background_color()
        return c;
 }
 
-struct color *config_get_foreground_color()
+static 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);
 
@@ -100,7 +112,7 @@ struct color *config_get_foreground_color()
        return c;
 }
 
-int config_is_alpha_channel_enabled()
+static int config_is_alpha_channel_enabled()
 {
        gboolean b = gconf_client_get_bool(client,
                                           KEY_ALPHA_CHANNEL_ENABLED,
@@ -109,29 +121,19 @@ int config_is_alpha_channel_enabled()
        return b == TRUE;
 }
 
-void config_set_alpha_channel_enabled(int enabled)
-{
-       if (enabled)
-               gconf_client_set_bool(client,
-                                     KEY_ALPHA_CHANNEL_ENABLED, TRUE, NULL);
-       else
-               gconf_client_set_bool(client,
-                                     KEY_ALPHA_CHANNEL_ENABLED, FALSE, NULL);
-}
-
-int config_get_sensorlist_position()
+static int config_get_sensorlist_position()
 {
        return gconf_client_get_int(client,
                                    KEY_INTERFACE_SENSORLIST_POSITION, NULL);
 }
 
-void config_set_sensorlist_position(int pos)
+static void config_set_sensorlist_position(int pos)
 {
        gconf_client_set_int(client,
                             KEY_INTERFACE_SENSORLIST_POSITION, pos, NULL);
 }
 
-double config_get_graph_background_alpha()
+static double config_get_graph_background_alpha()
 {
        double a = gconf_client_get_float(client,
                                          KEY_GRAPH_BACKGROUND_ALPHA,
@@ -143,12 +145,12 @@ double config_get_graph_background_alpha()
        return a;
 }
 
-void config_set_graph_background_alpha(double alpha)
+static void config_set_graph_background_alpha(double alpha)
 {
        gconf_client_set_float(client, KEY_GRAPH_BACKGROUND_ALPHA, alpha, NULL);
 }
 
-void config_set_background_color(struct color *color)
+static void config_set_background_color(struct color *color)
 {
        char *scolor = color_to_string(color);
 
@@ -161,7 +163,7 @@ void config_set_background_color(struct color *color)
        free(scolor);
 }
 
-void config_set_foreground_color(struct color *color)
+static void config_set_foreground_color(struct color *color)
 {
        char *scolor = color_to_string(color);
 
@@ -174,7 +176,7 @@ void config_set_foreground_color(struct color *color)
        free(scolor);
 }
 
-char *config_get_sensor_key(char *sensor_name)
+static char *config_get_sensor_key(char *sensor_name)
 {
        char *escaped_name = gconf_escape_key(sensor_name, -1);
        /* /apps/psensor/sensors/[sensor_name]/color */
@@ -344,7 +346,7 @@ void config_set_sensor_name(char *sid, const char *name)
        free(escaped_name);
 }
 
-int config_is_window_decoration_enabled()
+static int config_is_window_decoration_enabled()
 {
        gboolean b;
 
@@ -355,7 +357,7 @@ int config_is_window_decoration_enabled()
        return b == FALSE;
 }
 
-int config_is_window_keep_below_enabled()
+static int config_is_window_keep_below_enabled()
 {
        gboolean b;
 
@@ -366,7 +368,7 @@ int config_is_window_keep_below_enabled()
        return b == TRUE;
 }
 
-void config_set_window_decoration_enabled(int enabled)
+static void config_set_window_decoration_enabled(int enabled)
 {
        if (enabled)
                gconf_client_set_bool
@@ -378,7 +380,7 @@ void config_set_window_decoration_enabled(int enabled)
                     KEY_INTERFACE_WINDOW_DECORATION_DISABLED, TRUE, NULL);
 }
 
-void config_set_window_keep_below_enabled(int enabled)
+static void config_set_window_keep_below_enabled(int enabled)
 {
        if (enabled)
                gconf_client_set_bool(client,
@@ -395,62 +397,109 @@ void config_init()
        client = gconf_client_get_default();
 }
 
+void config_cleanup()
+{
+       if (client) {
+               g_object_unref(client);
+               client = NULL;
+       }
+}
+
 struct config *config_load()
 {
-       struct config *cfg = malloc(sizeof(struct config));
+       struct config *c;
 
-       cfg->graph_bgcolor = config_get_background_color();
-       cfg->graph_fgcolor = config_get_foreground_color();
-       cfg->graph_bg_alpha = config_get_graph_background_alpha();
-       cfg->alpha_channel_enabled = config_is_alpha_channel_enabled();
-       cfg->sensorlist_position = config_get_sensorlist_position();
-       cfg->window_decoration_enabled = config_is_window_decoration_enabled();
-       cfg->window_keep_below_enabled = config_is_window_keep_below_enabled();
+       c = malloc(sizeof(struct config));
 
-       cfg->sensor_update_interval
+       c->graph_bgcolor = config_get_background_color();
+       c->graph_fgcolor = config_get_foreground_color();
+       c->graph_bg_alpha = config_get_graph_background_alpha();
+       c->alpha_channel_enabled = config_is_alpha_channel_enabled();
+       c->sensorlist_position = config_get_sensorlist_position();
+       c->window_decoration_enabled = config_is_window_decoration_enabled();
+       c->window_keep_below_enabled = config_is_window_keep_below_enabled();
+
+       c->sensor_update_interval
            = gconf_client_get_int(client, KEY_SENSOR_UPDATE_INTERVAL, NULL);
-       if (cfg->sensor_update_interval < 1)
-               cfg->sensor_update_interval = 1;
+       if (c->sensor_update_interval < 1)
+               c->sensor_update_interval = 1;
 
-       cfg->graph_update_interval
+       c->graph_update_interval
            = gconf_client_get_int(client, KEY_GRAPH_UPDATE_INTERVAL, NULL);
-       if (cfg->graph_update_interval < 1)
-               cfg->graph_update_interval = 1;
+       if (c->graph_update_interval < 1)
+               c->graph_update_interval = 1;
 
-       cfg->graph_monitoring_duration
+       c->graph_monitoring_duration
            = gconf_client_get_int(client, KEY_GRAPH_MONITORING_DURATION, NULL);
 
-       if (cfg->graph_monitoring_duration < 1)
-               cfg->graph_monitoring_duration = 10;
+       if (c->graph_monitoring_duration < 1)
+               c->graph_monitoring_duration = 10;
 
-       cfg->sensor_values_max_length
+       c->sensor_values_max_length
            =
-           (cfg->graph_monitoring_duration * 60) / cfg->sensor_update_interval;
-       if (cfg->sensor_values_max_length < 3)
-               cfg->sensor_values_max_length = 3;
+           (c->graph_monitoring_duration * 60) / c->sensor_update_interval;
+       if (c->sensor_values_max_length < 3)
+               c->sensor_values_max_length = 3;
+
+       c->menu_bar_disabled
+               = gconf_client_get_bool(client,
+                                       KEY_INTERFACE_MENU_BAR_DISABLED,
+                                       NULL);
+
+       c->unity_launcher_count_disabled
+               = gconf_client_get_bool
+               (client,
+                KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
+                NULL);
+
+       c->hide_on_startup
+               = gconf_client_get_bool(client,
+                                       KEY_INTERFACE_HIDE_ON_STARTUP,
+                                       NULL);
+
+       c->window_restore_enabled
+               = gconf_client_get_bool(client,
+                                       KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
+                                       NULL);
 
-       return cfg;
+       return c;
 }
 
-void config_save(struct config *cfg)
+void config_save(struct config *c)
 {
-       config_set_background_color(cfg->graph_bgcolor);
-       config_set_foreground_color(cfg->graph_fgcolor);
-       config_set_graph_background_alpha(cfg->graph_bg_alpha);
-       config_set_sensorlist_position(cfg->sensorlist_position);
-       config_set_window_decoration_enabled(cfg->window_decoration_enabled);
-       config_set_window_keep_below_enabled(cfg->window_keep_below_enabled);
+       config_set_background_color(c->graph_bgcolor);
+       config_set_foreground_color(c->graph_fgcolor);
+       config_set_graph_background_alpha(c->graph_bg_alpha);
+       config_set_sensorlist_position(c->sensorlist_position);
+       config_set_window_decoration_enabled(c->window_decoration_enabled);
+       config_set_window_keep_below_enabled(c->window_keep_below_enabled);
 
        gconf_client_set_int(client,
                             KEY_GRAPH_UPDATE_INTERVAL,
-                            cfg->graph_update_interval, NULL);
+                            c->graph_update_interval, NULL);
 
        gconf_client_set_int(client,
                             KEY_GRAPH_MONITORING_DURATION,
-                            cfg->graph_monitoring_duration, NULL);
+                            c->graph_monitoring_duration, NULL);
 
        gconf_client_set_int(client,
                             KEY_SENSOR_UPDATE_INTERVAL,
-                            cfg->sensor_update_interval, NULL);
+                            c->sensor_update_interval, NULL);
+
+       gconf_client_set_bool(client,
+                             KEY_INTERFACE_MENU_BAR_DISABLED,
+                             c->menu_bar_disabled, NULL);
+
+       gconf_client_set_bool(client,
+                             KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
+                             c->unity_launcher_count_disabled, NULL);
+
+       gconf_client_set_bool(client,
+                             KEY_INTERFACE_HIDE_ON_STARTUP,
+                             c->hide_on_startup, NULL);
 
+       gconf_client_set_bool(client,
+                             KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
+                             c->window_restore_enabled,
+                             NULL);
 }