/*
- * Copyright (C) 2010-2013 jeanfi@gmail.com
+ * Copyright (C) 2010-2014 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
-#include "cfg.h"
-#include "log.h"
+#include <cfg.h>
+#include <pio.h>
+#include <plog.h>
static const char *KEY_SENSORS = "/apps/psensor/sensors";
static const char *ATT_SENSOR_ENABLED = "enabled";
static const char *ATT_SENSOR_NAME = "name";
static const char *ATT_SENSOR_APPINDICATOR_DISABLED = "appindicator/disabled";
+static const char *ATT_SENSOR_APPINDICATOR_LABEL_ENABLED
+= "appindicator/menu/enabled";
+
static const char *ATT_SENSOR_POSITION = "position";
static const char *KEY_SENSOR_UPDATE_INTERVAL
static const char *KEY_SLOG_ENABLED = "/apps/psensor/slog/enabled";
static const char *KEY_SLOG_INTERVAL = "/apps/psensor/slog/interval";
+static const char *KEY_NOTIFICATION_SCRIPT = "/apps/psensor/notif_script";
+
static GConfClient *client;
+static char *user_dir;
+
static char *get_string(const char *key, const char *default_value)
{
char *value;
return value;
}
+char *config_get_notif_script()
+{
+ char *str;
+
+ str = gconf_client_get_string(client, KEY_NOTIFICATION_SCRIPT, NULL);
+ if (str && !strlen(str)) {
+ free(str);
+ str = NULL;
+ }
+
+ return str;
+}
+
+void config_set_notif_script(const char *str)
+{
+ if (str && strlen(str) > 0)
+ gconf_client_set_string(client,
+ KEY_NOTIFICATION_SCRIPT, str, NULL);
+ else
+ gconf_client_set_string(client,
+ KEY_NOTIFICATION_SCRIPT, "", NULL);
+}
+
static struct color *get_background_color()
{
char *scolor;
free(key);
}
+bool config_is_appindicator_label_enabled(const char *sid)
+{
+ char *key;
+ gboolean b;
+
+ key = get_sensor_att_key(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
+ b = gconf_client_get_bool(client, key, NULL);
+ free(key);
+
+ return b;
+}
+
+void config_set_appindicator_label_enabled(const char *sid, bool enabled)
+{
+ char *key;
+
+ key = get_sensor_att_key(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
+ gconf_client_set_bool(client, key, enabled, NULL);
+ free(key);
+}
+
bool is_slog_enabled()
{
return gconf_client_get_bool(client, KEY_SLOG_ENABLED, NULL);
g_object_unref(client);
client = NULL;
}
+
+ if (user_dir) {
+ free(user_dir);
+ user_dir = NULL;
+ }
}
struct config *config_load()
c->temperature_unit,
NULL);
}
+
+const char *get_psensor_user_dir()
+{
+ const char *home;
+
+ log_fct_enter();
+
+ if (!user_dir) {
+ home = getenv("HOME");
+
+ if (!home)
+ return NULL;
+
+ user_dir = path_append(home, ".psensor");
+
+ if (mkdir(user_dir, 0700) == -1 && errno != EEXIST) {
+ log_err(_("Failed to create the directory %s: %s"),
+ user_dir,
+ strerror(errno));
+
+ free(user_dir);
+ user_dir = NULL;
+ }
+ }
+
+ log_fct_exit();
+
+ return user_dir;
+}