Fixed restoration of the panel divider position.
[psensor.git] / src / cfg.c
index 14267dc..d903478 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
+ * Copyright (C) 2010-2016 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -237,12 +237,12 @@ static void set_alpha_channeld_enabled(bool b)
        set_bool(KEY_ALPHA_CHANNEL_ENABLED, b);
 }
 
-static enum sensorlist_position get_sensorlist_position(void)
+enum sensorlist_position config_get_sensorlist_position(void)
 {
        return get_int(KEY_INTERFACE_SENSORLIST_POSITION);
 }
 
-static void set_sensorlist_position(enum sensorlist_position pos)
+void config_set_sensorlist_position(enum sensorlist_position pos)
 {
        set_int(KEY_INTERFACE_SENSORLIST_POSITION, pos);
 }
@@ -418,7 +418,6 @@ struct config *config_load(void)
        c->graph_fgcolor = get_foreground_color();
        c->graph_bg_alpha = get_graph_background_alpha();
        c->alpha_channel_enabled = is_alpha_channel_enabled();
-       c->sensorlist_position = get_sensorlist_position();
        c->slog_enabled = is_slog_enabled();
        c->slog_interval = config_get_slog_interval();
 
@@ -436,11 +435,6 @@ struct config *config_load(void)
        if (c->graph_monitoring_duration < 1)
                c->graph_monitoring_duration = 10;
 
-       c->unity_launcher_count_disabled
-               = get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
-
-       c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
-
        c->window_restore_enabled
                = get_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED);
 
@@ -451,6 +445,8 @@ struct config *config_load(void)
 
        c->window_divider_pos = get_int(KEY_INTERFACE_WINDOW_DIVIDER_POS);
 
+       c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
+
        if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
                c->window_w = 800;
                c->window_h = 200;
@@ -467,7 +463,6 @@ void config_save(const struct config *c)
        set_background_color(c->graph_bgcolor);
        set_foreground_color(c->graph_fgcolor);
        set_graph_background_alpha(c->graph_bg_alpha);
-       set_sensorlist_position(c->sensorlist_position);
        set_slog_enabled(c->slog_enabled);
        set_slog_interval(c->slog_interval);
 
@@ -477,9 +472,6 @@ void config_save(const struct config *c)
 
        set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
 
-       set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
-                c->unity_launcher_count_disabled);
-
        set_bool(KEY_INTERFACE_HIDE_ON_STARTUP, c->hide_on_startup);
 
        set_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
@@ -612,7 +604,10 @@ static char *sensor_get_str(const char *sid, const char *att)
        return g_key_file_get_string(kfile, sid, att, NULL);
 }
 
-static bool sensor_get_double(const char *sid, const char *att, double *d)
+static bool sensor_get_double(const char *sid,
+                             const char *att,
+                             double *d,
+                             double d_default)
 {
        GKeyFile *kfile;
        GError *err;
@@ -621,6 +616,18 @@ static bool sensor_get_double(const char *sid, const char *att, double *d)
        kfile = get_sensor_key_file();
 
        err = NULL;
+       if (!g_key_file_has_key(kfile, sid, att, &err)) {
+               if (err) {
+                       log_err(err->message);
+                       g_error_free(err);
+                       return false;
+               }
+
+               *d = d_default;
+               return true;
+       }
+
+       err = NULL;
        v = g_key_file_get_double(kfile, sid, att, &err);
 
        if (err) {
@@ -708,7 +715,8 @@ void config_set_sensor_color(const char *sid, const GdkRGBA *color)
 static const char *next_default_color(void)
 {
        /* copied from the default colors of the gtk color color
-        * chooser. */
+        * chooser.
+        */
        const char *default_colors[27] = {
                "#ef2929",  /* Scarlet Red */
                "#fcaf3e",  /* Orange */
@@ -779,9 +787,11 @@ void config_set_sensor_graph_enabled(const char *sid, bool enabled)
        sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
 }
 
-bool config_get_sensor_alarm_high_threshold(const char *sid, double *v)
+bool config_get_sensor_alarm_high_threshold(const char *sid,
+                                           double *v,
+                                           double d)
 {
-       return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v);
+       return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v, d);
 }
 
 void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
@@ -789,9 +799,9 @@ void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
        sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
 }
 
-bool config_get_sensor_alarm_low_threshold(const char *sid, double *v)
+bool config_get_sensor_alarm_low_threshold(const char *sid, double *v, double d)
 {
-       return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v);
+       return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v, d);
 }
 
 void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)