slog-enabled cbk use gsettings.
[psensor.git] / src / cfg.c
index ae14ce4..42e5701 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -50,7 +50,7 @@ static const char *ATT_SENSOR_POSITION = "position";
 
 /* Update interval of the measures of the sensors */
 static const char *KEY_SENSOR_UPDATE_INTERVAL
-= "/apps/psensor/sensor/update_interval";
+= "sensor-update-interval";
 
 /* Graph settings */
 static const char *KEY_GRAPH_UPDATE_INTERVAL = "graph-update-interval";
@@ -110,7 +110,6 @@ static const char *KEY_SLOG_INTERVAL = "slog-interval";
 /* Path to the script called when a notification is raised */
 static const char *KEY_NOTIFICATION_SCRIPT = "notif-script";
 
-static GConfClient *client;
 static GSettings *settings;
 
 static char *user_dir;
@@ -119,6 +118,8 @@ static GKeyFile *key_file;
 
 static char *sensor_config_path;
 
+static void (*slog_enabled_cbk)(void *);
+
 static char *get_string(const char *key)
 {
        return g_settings_get_string(settings, key);
@@ -278,19 +279,26 @@ static void set_slog_enabled(bool enabled)
        set_bool(KEY_SLOG_ENABLED, enabled);
 }
 
-void config_slog_enabled_notify_add(GConfClientNotifyFunc cbk, void *data)
+static void slog_enabled_changed_cbk(GSettings *settings,
+                                    gchar *key,
+                                    gpointer data)
 {
-       log_debug("config_slog_enabled_notify_add");
-       gconf_client_add_dir(client,
-                            KEY_SLOG_ENABLED,
-                            GCONF_CLIENT_PRELOAD_NONE,
-                            NULL);
-       gconf_client_notify_add(client,
-                               KEY_SLOG_ENABLED,
-                               cbk,
-                               data,
-                               NULL,
-                               NULL);
+       if (slog_enabled_cbk)
+               slog_enabled_cbk(data);
+}
+
+void config_set_slog_enabled_changed_cbk(void (*cbk)(void *), void *data)
+{
+       log_fct_enter();
+
+       slog_enabled_cbk = cbk;
+
+       g_signal_connect_after(settings,
+                              "changed::slog-enabled",
+                              G_CALLBACK(slog_enabled_changed_cbk),
+                              data);
+
+       log_fct_exit();
 }
 
 int config_get_slog_interval()
@@ -326,14 +334,8 @@ static void set_window_keep_below_enabled(bool enabled)
        set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
 }
 
-/*
- * Initializes the GConf client.
- */
 static void init()
 {
-       if (!client)
-               client = gconf_client_get_default();
-
        if (!settings)
                settings = g_settings_new("psensor");
 }
@@ -342,11 +344,6 @@ void config_cleanup()
 {
        config_sync();
 
-       if (client) {
-               g_object_unref(client);
-               client = NULL;
-       }
-
        if (settings) {
                g_settings_sync();
                g_object_unref(settings);
@@ -367,6 +364,8 @@ void config_cleanup()
                free(sensor_config_path);
                sensor_config_path = NULL;
        }
+
+       slog_enabled_cbk = NULL;
 }
 
 struct config *config_load()
@@ -388,7 +387,7 @@ struct config *config_load()
        c->slog_interval = config_get_slog_interval();
 
        c->sensor_update_interval
-           = gconf_client_get_int(client, KEY_SENSOR_UPDATE_INTERVAL, NULL);
+           = get_int(KEY_SENSOR_UPDATE_INTERVAL);
        if (c->sensor_update_interval < 1)
                c->sensor_update_interval = 1;
 
@@ -450,9 +449,7 @@ void config_save(const struct config *c)
 
        set_int(KEY_GRAPH_MONITORING_DURATION, c->graph_monitoring_duration);
 
-       gconf_client_set_int(client,
-                            KEY_SENSOR_UPDATE_INTERVAL,
-                            c->sensor_update_interval, NULL);
+       set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
 
        set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, c->menu_bar_disabled);
 
@@ -536,14 +533,13 @@ static GKeyFile *get_sensor_key_file()
                                                &err);
 
                if (!ret) {
-                       if (err->code == G_KEY_FILE_ERROR_NOT_FOUND) {
+                       if (err->code == G_KEY_FILE_ERROR_NOT_FOUND)
                                log_fct(_("The configuration file "
                                          "does not exist."));
-                       } else {
+                       else
                                log_err(_("Failed to parse configuration "
                                          "file: %s"),
                                        path);
-                       }
                }
        }