updated copyright to 2013
[psensor.git] / src / cfg.c
index 5a6f8e8..6fd812a 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2010-2013 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
@@ -21,9 +21,8 @@
 #include <string.h>
 #include <ctype.h>
 
-#include <gconf/gconf-client.h>
-
 #include "cfg.h"
+#include "log.h"
 
 static const char *KEY_SENSORS = "/apps/psensor/sensors";
 
@@ -92,6 +91,7 @@ static const char *KEY_INTERFACE_TEMPERATURE_UNIT
 = "/apps/psensor/interface/temperature_unit";
 
 static const char *KEY_SLOG_ENABLED = "/apps/psensor/slog/enabled";
+static const char *KEY_SLOG_INTERVAL = "/apps/psensor/slog/interval";
 
 static GConfClient *client;
 
@@ -387,7 +387,7 @@ void config_set_appindicator_enabled(const char *sid, bool enabled)
        free(key);
 }
 
-static bool is_slog_enabled()
+bool is_slog_enabled()
 {
        return gconf_client_get_bool(client, KEY_SLOG_ENABLED, NULL);
 }
@@ -397,6 +397,42 @@ static void set_slog_enabled(bool enabled)
        gconf_client_set_bool(client, KEY_SLOG_ENABLED, enabled, NULL);
 }
 
+
+void config_slog_enabled_notify_add(GConfClientNotifyFunc cbk, void *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);
+}
+
+int config_get_slog_interval()
+{
+       int res;
+
+       res = gconf_client_get_int(client, KEY_SLOG_INTERVAL, NULL);
+
+       if (res <= 0)
+               return 300;
+       else
+               return res;
+}
+
+static void set_slog_interval(int interval)
+{
+       if (interval <= 0)
+               interval = 300;
+
+       gconf_client_set_int(client, KEY_SLOG_INTERVAL, interval, NULL);
+}
+
 static bool is_window_decoration_enabled()
 {
        return !gconf_client_get_bool(client,
@@ -458,6 +494,7 @@ struct config *config_load()
        c->window_decoration_enabled = is_window_decoration_enabled();
        c->window_keep_below_enabled = is_window_keep_below_enabled();
        c->slog_enabled = is_slog_enabled();
+       c->slog_interval = config_get_slog_interval();
 
        c->sensor_update_interval
            = gconf_client_get_int(client, KEY_SENSOR_UPDATE_INTERVAL, NULL);
@@ -539,6 +576,7 @@ void config_save(const struct config *c)
        set_window_decoration_enabled(c->window_decoration_enabled);
        set_window_keep_below_enabled(c->window_keep_below_enabled);
        set_slog_enabled(c->slog_enabled);
+       set_slog_interval(c->slog_interval);
 
        gconf_client_set_int(client,
                             KEY_GRAPH_UPDATE_INTERVAL,