/*
- * Copyright (C) 2010-2013 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
* 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 "cfg.h"
-#include "log.h"
-
-static const char *KEY_SENSORS = "/apps/psensor/sensors";
-
-static const char *ATT_SENSOR_ALARM_ENABLED = "alarm/enabled";
-static const char *ATT_SENSOR_ALARM_HIGH_THRESHOLD = "alarm/high_threshold";
-static const char *ATT_SENSOR_ALARM_LOW_THRESHOLD = "alarm/low_threshold";
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <cfg.h>
+#include <graph.h>
+#include <pio.h>
+#include <plog.h>
+
+/* Properties of each sensor */
+static const char *ATT_SENSOR_ALARM_ENABLED = "alarm_enabled";
+static const char *ATT_SENSOR_ALARM_HIGH_THRESHOLD = "alarm_high_threshold";
+static const char *ATT_SENSOR_ALARM_LOW_THRESHOLD = "alarm_low_threshold";
static const char *ATT_SENSOR_COLOR = "color";
-static const char *ATT_SENSOR_ENABLED = "enabled";
+static const char *ATT_SENSOR_GRAPH_ENABLED = "graph_enabled";
static const char *ATT_SENSOR_NAME = "name";
-static const char *ATT_SENSOR_APPINDICATOR_DISABLED = "appindicator/disabled";
+static const char *ATT_SENSOR_APPINDICATOR_MENU_DISABLED
+= "appindicator_menu_disabled";
+static const char *ATT_SENSOR_APPINDICATOR_LABEL_ENABLED
+= "appindicator_label_enabled";
static const char *ATT_SENSOR_POSITION = "position";
+static const char *ATT_SENSOR_HIDE = "hide";
+/* Update interval of the measures of the sensors */
static const char *KEY_SENSOR_UPDATE_INTERVAL
-= "/apps/psensor/sensor/update_interval";
-
-static const char *KEY_GRAPH_UPDATE_INTERVAL
-= "/apps/psensor/graph/update_interval";
-
-static const char *KEY_GRAPH_MONITORING_DURATION
-= "/apps/psensor/graph/monitoring_duration";
-
-static const char *KEY_GRAPH_BACKGROUND_COLOR
-= "/apps/psensor/graph/background_color";
+= "sensor-update-interval";
+/* Graph settings */
+static const char *KEY_GRAPH_UPDATE_INTERVAL = "graph-update-interval";
+static const char *KEY_GRAPH_MONITORING_DURATION = "graph-monitoring-duration";
+static const char *KEY_GRAPH_BACKGROUND_COLOR = "graph-background-color";
static const char *DEFAULT_GRAPH_BACKGROUND_COLOR = "#e8f4e8f4a8f5";
-
-static const char *KEY_GRAPH_BACKGROUND_ALPHA
-= "/apps/psensor/graph/background_alpha";
-
+static const char *KEY_GRAPH_BACKGROUND_ALPHA = "graph-background-alpha";
static const char *KEY_GRAPH_FOREGROUND_COLOR
-= "/apps/psensor/graph/foreground_color";
+= "graph-foreground-color";
+static const char *KEY_GRAPH_SMOOTH_CURVES_ENABLED
+= "graph-smooth-curves-enabled";
+
static const char *DEFAULT_GRAPH_FOREGROUND_COLOR = "#000000000000";
-static const char *KEY_ALPHA_CHANNEL_ENABLED
-= "/apps/psensor/graph/alpha_channel_enabled";
+static const char *KEY_ALPHA_CHANNEL_ENABLED = "graph-alpha-channel-enabled";
+/* Inteface settings */
static const char *KEY_INTERFACE_SENSORLIST_POSITION
-= "/apps/psensor/interface/sensorlist_position";
+= "interface-sensorlist-position";
static const char *KEY_INTERFACE_WINDOW_DECORATION_DISABLED
-= "/apps/psensor/interface/window_decoration_disabled";
+= "interface-window-decoration-disabled";
static const char *KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED
-= "/apps/psensor/interface/window_keep_below_enabled";
+= "interface-window-keep-below-enabled";
static const char *KEY_INTERFACE_MENU_BAR_DISABLED
-= "/apps/psensor/interface/menu_bar_disabled";
+= "interface-menu-bar-disabled";
static const char *KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED
-= "/apps/psensor/interface/unity_launcher_count_disabled";
+= "interface-unity-launcher-count-disabled";
static const char *KEY_INTERFACE_HIDE_ON_STARTUP
-= "/apps/psensor/interface/hide_on_startup";
+= "interface-hide-on-startup";
static const char *KEY_INTERFACE_WINDOW_RESTORE_ENABLED
-= "/apps/psensor/interface/window_restore_enabled";
+= "interface-window-restore-enabled";
-static const char *KEY_INTERFACE_WINDOW_X = "/apps/psensor/interface/window_x";
-static const char *KEY_INTERFACE_WINDOW_Y = "/apps/psensor/interface/window_y";
-static const char *KEY_INTERFACE_WINDOW_W = "/apps/psensor/interface/window_w";
-static const char *KEY_INTERFACE_WINDOW_H = "/apps/psensor/interface/window_h";
+static const char *KEY_INTERFACE_WINDOW_X = "interface-window-x";
+static const char *KEY_INTERFACE_WINDOW_Y = "interface-window-y";
+static const char *KEY_INTERFACE_WINDOW_W = "interface-window-w";
+static const char *KEY_INTERFACE_WINDOW_H = "interface-window-h";
static const char *KEY_INTERFACE_WINDOW_DIVIDER_POS
-= "/apps/psensor/interface/window_divider_pos";
+= "interface-window-divider-pos";
static const char *KEY_INTERFACE_TEMPERATURE_UNIT
-= "/apps/psensor/interface/temperature_unit";
+= "interface-temperature-unit";
+
+/* Sensor logging settings */
+static const char *KEY_SLOG_ENABLED = "slog-enabled";
+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";
+
+/* Provider settings */
+static const char *KEY_PROVIDER_LMSENSORS_ENABLED
+= "provider-lmsensors-enabled";
+static const char *KEY_PROVIDER_ATIADLSDK_ENABLED
+= "provider-atiadlsdk-enabled";
+static const char *KEY_PROVIDER_GTOP2_ENABLED = "provider-gtop2-enabled";
+static const char *KEY_PROVIDER_HDDTEMP_ENABLED = "provider-hddtemp-enabled";
+static const char *KEY_PROVIDER_LIBATASMART_ENABLED
+= "provider-libatasmart-enabled";
+static const char *KEY_PROVIDER_NVCTRL_ENABLED = "provider-nvctrl-enabled";
+static const char *KEY_PROVIDER_UDISKS2_ENABLED = "provider-udisks2-enabled";
+
+static const char *KEY_DEFAULT_HIGH_THRESHOLD_TEMPERATURE
+= "default-high-threshold-temperature";
+static const char *KEY_DEFAULT_SENSOR_ALARM_ENABLED
+= "default-sensor-alarm-enabled";
+
+static GSettings *settings;
+
+static char *user_dir;
+
+static GKeyFile *key_file;
+
+static char *sensor_config_path;
-static const char *KEY_SLOG_ENABLED = "/apps/psensor/slog/enabled";
-static const char *KEY_SLOG_INTERVAL = "/apps/psensor/slog/interval";
+static void (*slog_enabled_cbk)(void *);
-static const char *KEY_NOTIFICATION_SCRIPT = "/apps/psensor/notif_script";
+static char *get_string(const char *key)
+{
+ return g_settings_get_string(settings, key);
+}
-static GConfClient *client;
+static void set_string(const char *key, const char *str)
+{
+ g_settings_set_string(settings, key, str);
+}
-static char *get_string(const char *key, const char *default_value)
+static void set_bool(const char *k, bool b)
{
- char *value;
+ g_settings_set_boolean(settings, k, b);
+}
- value = gconf_client_get_string(client, key, NULL);
+static bool get_bool(const char *k)
+{
+ return g_settings_get_boolean(settings, k);
+}
- if (!value) {
- value = strdup(default_value);
- gconf_client_set_string(client, key, default_value, NULL);
- }
+static void set_int(const char *k, int i)
+{
+ g_settings_set_int(settings, k, i);
+}
- return value;
+static double get_double(const char *k)
+{
+ return g_settings_get_double(settings, k);
+}
+
+static void set_double(const char *k, double d)
+{
+ g_settings_set_double(settings, k, d);
}
-char *config_get_notif_script()
+static int get_int(const char *k)
+{
+ return g_settings_get_int(settings, k);
+}
+
+char *config_get_notif_script(void)
{
char *str;
- str = gconf_client_get_string(client, KEY_NOTIFICATION_SCRIPT, NULL);
+ str = get_string(KEY_NOTIFICATION_SCRIPT);
if (str && !strlen(str)) {
free(str);
str = NULL;
void config_set_notif_script(const char *str)
{
if (str && strlen(str) > 0)
- gconf_client_set_string(client,
- KEY_NOTIFICATION_SCRIPT, str, NULL);
+ set_string(KEY_NOTIFICATION_SCRIPT, str);
else
- gconf_client_set_string(client,
- KEY_NOTIFICATION_SCRIPT, "", NULL);
+ set_string(KEY_NOTIFICATION_SCRIPT, "");
}
-static struct color *get_background_color()
+static struct color *get_background_color(void)
{
char *scolor;
struct color *c;
- scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR,
- DEFAULT_GRAPH_BACKGROUND_COLOR);
+ scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR);
c = str_to_color(scolor);
free(scolor);
if (!c)
- return color_new(0xffff, 0xffff, 0xffff);
+ return color_new(1, 1, 1);
return c;
}
-static struct color *get_foreground_color()
+static struct color *get_foreground_color(void)
{
char *scolor;
struct color *c;
- scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR,
- DEFAULT_GRAPH_FOREGROUND_COLOR);
+ scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR);
c = str_to_color(scolor);
free(scolor);
if (!c)
- return color_new(0x0000, 0x0000, 0x0000);
+ return color_new(0, 0, 0);
return c;
}
-static bool is_alpha_channel_enabled()
+static bool is_alpha_channel_enabled(void)
{
- return gconf_client_get_bool(client, KEY_ALPHA_CHANNEL_ENABLED, NULL);
+ return get_bool(KEY_ALPHA_CHANNEL_ENABLED);
}
-static enum sensorlist_position get_sensorlist_position()
+static void set_alpha_channeld_enabled(bool b)
{
- return gconf_client_get_int(client,
- KEY_INTERFACE_SENSORLIST_POSITION, NULL);
+ set_bool(KEY_ALPHA_CHANNEL_ENABLED, b);
}
-static void set_sensorlist_position(enum sensorlist_position pos)
+enum sensorlist_position config_get_sensorlist_position(void)
{
- gconf_client_set_int(client,
- KEY_INTERFACE_SENSORLIST_POSITION, pos, NULL);
+ return get_int(KEY_INTERFACE_SENSORLIST_POSITION);
}
-static double get_graph_background_alpha()
+void config_set_sensorlist_position(enum sensorlist_position pos)
{
- double a;
+ set_int(KEY_INTERFACE_SENSORLIST_POSITION, pos);
+}
- a = gconf_client_get_float(client, KEY_GRAPH_BACKGROUND_ALPHA, NULL);
- if (a == 0)
- gconf_client_set_float(client,
- KEY_GRAPH_BACKGROUND_ALPHA, 1.0, NULL);
- return a;
+static double get_graph_background_alpha(void)
+{
+ return get_double(KEY_GRAPH_BACKGROUND_ALPHA);
}
static void set_graph_background_alpha(double alpha)
{
- gconf_client_set_float(client, KEY_GRAPH_BACKGROUND_ALPHA, alpha, NULL);
+ set_double(KEY_GRAPH_BACKGROUND_ALPHA, alpha);
}
static void set_background_color(const struct color *color)
if (!scolor)
scolor = strdup(DEFAULT_GRAPH_BACKGROUND_COLOR);
- gconf_client_set_string(client,
- KEY_GRAPH_BACKGROUND_COLOR, scolor, NULL);
+ set_string(KEY_GRAPH_BACKGROUND_COLOR, scolor);
free(scolor);
}
if (!str)
str = strdup(DEFAULT_GRAPH_FOREGROUND_COLOR);
- gconf_client_set_string(client, KEY_GRAPH_FOREGROUND_COLOR, str, NULL);
+ set_string(KEY_GRAPH_FOREGROUND_COLOR, str);
free(str);
}
-static char *get_sensor_att_key(const char *sid, const char *att)
+bool is_slog_enabled(void)
+{
+ return get_bool(KEY_SLOG_ENABLED);
+}
+
+static void set_slog_enabled(bool enabled)
+{
+ set_bool(KEY_SLOG_ENABLED, enabled);
+}
+
+static void slog_enabled_changed_cbk(GSettings *settings,
+ gchar *key,
+ gpointer data)
+{
+ 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(void)
+{
+ return get_int(KEY_SLOG_INTERVAL);
+}
+
+static void set_slog_interval(int interval)
+{
+ if (interval <= 0)
+ interval = 300;
+
+ set_int(KEY_SLOG_INTERVAL, interval);
+}
+
+bool config_is_window_decoration_enabled(void)
+{
+ return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
+}
+
+bool config_is_window_keep_below_enabled(void)
+{
+ return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
+}
+
+void config_set_window_decoration_enabled(bool enabled)
+{
+ set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
+}
+
+void config_set_window_keep_below_enabled(bool enabled)
{
- char *esc_sid, *key;
+ set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
+}
- esc_sid = gconf_escape_key(sid, -1);
- /* [KEY_SENSORS]/[esc_sid]/[att] */
- key = malloc(strlen(KEY_SENSORS)
- + 1 + 2 * strlen(esc_sid)
- + 1 + strlen(att) + 1);
+bool config_is_smooth_curves_enabled(void)
+{
+ return get_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED);
+}
- sprintf(key, "%s/%s/%s", KEY_SENSORS, esc_sid, att);
+void config_set_smooth_curves_enabled(bool b)
+{
+ set_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED, b);
+}
- free(esc_sid);
+double config_get_default_high_threshold_temperature(void)
+{
+ return get_double(KEY_DEFAULT_HIGH_THRESHOLD_TEMPERATURE);
+}
- return key;
+static bool config_get_default_sensor_alarm_enabled(void)
+{
+ return get_bool(KEY_DEFAULT_SENSOR_ALARM_ENABLED);
}
-struct color *
-config_get_sensor_color(const char *sid, const struct color *dft)
+static void init(void)
{
- char *key, *scolor;
- struct color *color;
+ log_fct_enter();
- key = get_sensor_att_key(sid, ATT_SENSOR_COLOR);
+ if (!settings)
+ settings = g_settings_new("psensor");
- scolor = gconf_client_get_string(client, key, NULL);
+ log_fct_exit();
+}
- color = NULL;
+void config_cleanup(void)
+{
+ config_sync();
- if (scolor)
- color = str_to_color(scolor);
+ if (settings) {
+ g_settings_sync();
+ g_object_unref(settings);
+ settings = NULL;
+ }
- if (!scolor || !color) {
- color = color_new(dft->red, dft->green, dft->blue);
- scolor = color_to_str(color);
- gconf_client_set_string(client, key, scolor, NULL);
+ if (user_dir) {
+ free(user_dir);
+ user_dir = NULL;
}
- free(scolor);
- free(key);
+ if (key_file) {
+ g_key_file_free(key_file);
+ key_file = NULL;
+ }
- return color;
+ if (sensor_config_path) {
+ free(sensor_config_path);
+ sensor_config_path = NULL;
+ }
+
+ slog_enabled_cbk = NULL;
}
-void config_set_sensor_color(const char *sid, const struct color *color)
+struct config *config_load(void)
{
- char *key, *scolor;
+ struct config *c;
- key = get_sensor_att_key(sid, ATT_SENSOR_COLOR);
- scolor = color_to_str(color);
+ init();
- gconf_client_set_string(client, key, scolor, NULL);
+ c = malloc(sizeof(struct config));
- free(scolor);
- free(key);
+ c->graph_bgcolor = get_background_color();
+ c->graph_fgcolor = get_foreground_color();
+ c->graph_bg_alpha = get_graph_background_alpha();
+ c->alpha_channel_enabled = is_alpha_channel_enabled();
+ c->slog_enabled = is_slog_enabled();
+ c->slog_interval = config_get_slog_interval();
+
+ c->sensor_update_interval
+ = get_int(KEY_SENSOR_UPDATE_INTERVAL);
+ if (c->sensor_update_interval < 1)
+ c->sensor_update_interval = 1;
+
+ c->graph_update_interval = get_int(KEY_GRAPH_UPDATE_INTERVAL);
+ if (c->graph_update_interval < 1)
+ c->graph_update_interval = 1;
+
+ c->graph_monitoring_duration = get_int(KEY_GRAPH_MONITORING_DURATION);
+
+ if (c->graph_monitoring_duration < 1)
+ c->graph_monitoring_duration = 10;
+
+ c->window_restore_enabled
+ = get_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED);
+
+ c->window_x = get_int(KEY_INTERFACE_WINDOW_X);
+ c->window_y = get_int(KEY_INTERFACE_WINDOW_Y);
+ c->window_w = get_int(KEY_INTERFACE_WINDOW_W);
+ c->window_h = get_int(KEY_INTERFACE_WINDOW_H);
+
+ c->window_divider_pos = get_int(KEY_INTERFACE_WINDOW_DIVIDER_POS);
+
+ if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
+ c->window_w = 800;
+ c->window_h = 200;
+ }
+
+ c->sensor_values_max_length = compute_values_max_length(c);
+
+ return c;
}
-int config_get_sensor_alarm_high_threshold(const char *sid)
+void config_save(const struct config *c)
{
- int res;
- char *key;
+ set_alpha_channeld_enabled(c->alpha_channel_enabled);
+ set_background_color(c->graph_bgcolor);
+ set_foreground_color(c->graph_fgcolor);
+ set_graph_background_alpha(c->graph_bg_alpha);
+ set_slog_enabled(c->slog_enabled);
+ set_slog_interval(c->slog_interval);
+
+ set_int(KEY_GRAPH_UPDATE_INTERVAL, c->graph_update_interval);
+
+ set_int(KEY_GRAPH_MONITORING_DURATION, c->graph_monitoring_duration);
+
+ set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
+
+ set_bool(KEY_INTERFACE_HIDE_ON_STARTUP, c->hide_on_startup);
+
+ set_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
+ c->window_restore_enabled);
+
+ set_int(KEY_INTERFACE_WINDOW_X, c->window_x);
+ set_int(KEY_INTERFACE_WINDOW_Y, c->window_y);
+ set_int(KEY_INTERFACE_WINDOW_W, c->window_w);
+ set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
+
+ set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
+}
+
+const char *get_psensor_user_dir(void)
+{
+ 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));
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD);
- res = gconf_client_get_int(client, key, NULL);
- free(key);
+ free(user_dir);
+ user_dir = NULL;
+ }
+ }
+
+ log_fct_exit();
- return res;
+ return user_dir;
}
-void
-config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
+static const char *get_sensor_config_path(void)
{
- char *key;
+ const char *dir;
+
+ if (!sensor_config_path) {
+ dir = get_psensor_user_dir();
+
+ if (dir)
+ sensor_config_path = path_append(dir, "psensor.cfg");
+ }
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD);
- gconf_client_set_int(client, key, threshold, NULL);
- free(key);
+ return sensor_config_path;
}
-int config_get_sensor_alarm_low_threshold(const char *sid)
+static GKeyFile *get_sensor_key_file(void)
{
- int res;
- char *key;
+ int ret;
+ GError *err;
+ const char *path;
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD);
- res = gconf_client_get_int(client, key, NULL);
- free(key);
+ if (!key_file) {
+ path = get_sensor_config_path();
+
+ key_file = g_key_file_new();
+
+ err = NULL;
+ ret = g_key_file_load_from_file(key_file,
+ path,
+ G_KEY_FILE_KEEP_COMMENTS
+ | G_KEY_FILE_KEEP_TRANSLATIONS,
+ &err);
+
+ if (!ret) {
+ log_warn(_("Failed to load configuration file %s: %s"),
+ path,
+ err->message);
+ g_error_free(err);
+ }
+ }
- return res;
+ return key_file;
}
-void
-config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
+static void save_sensor_key_file(void)
{
- char *key;
+ GKeyFile *kfile;
+ const char *path;
+ char *data;
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD);
- gconf_client_set_int(client, key, threshold, NULL);
- free(key);
+ log_fct_enter();
+
+ kfile = get_sensor_key_file();
+
+ data = g_key_file_to_data(kfile, NULL, NULL);
+
+ path = get_sensor_config_path();
+
+ if (!g_file_set_contents(path, data, -1, NULL))
+ log_err(_("Failed to save configuration file %s."), path);
+
+ free(data);
+
+ log_fct_exit();
}
-bool config_get_sensor_alarm_enabled(const char *sid)
+void config_sync(void)
{
- gboolean b;
- char *key;
+ log_fct_enter();
+ if (settings)
+ g_settings_sync();
+ save_sensor_key_file();
+ log_fct_exit();
+}
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_ENABLED);
- b = gconf_client_get_bool(client, key, NULL);
- free(key);
+static void sensor_set_str(const char *sid, const char *att, const char *str)
+{
+ GKeyFile *kfile;
- return b;
+ kfile = get_sensor_key_file();
+ g_key_file_set_string(kfile, sid, att, str);
}
-void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
+static char *sensor_get_str(const char *sid, const char *att)
{
- char *key;
+ GKeyFile *kfile;
- key = get_sensor_att_key(sid, ATT_SENSOR_ALARM_ENABLED);
- gconf_client_set_bool(client, key, enabled, NULL);
- free(key);
+ kfile = get_sensor_key_file();
+ return g_key_file_get_string(kfile, sid, att, NULL);
}
-bool config_is_sensor_enabled(const char *sid)
+static bool sensor_get_double(const char *sid, const char *att, double *d)
{
- gboolean b;
- char *key;
+ GKeyFile *kfile;
+ GError *err;
+ double v;
+
+ kfile = get_sensor_key_file();
+
+ err = NULL;
+ v = g_key_file_get_double(kfile, sid, att, &err);
+
+ if (err) {
+ log_err(err->message);
- key = get_sensor_att_key(sid, ATT_SENSOR_ENABLED);
- b = gconf_client_get_bool(client, key, NULL);
- free(key);
+ g_error_free(err);
- return b;
+ return false;
+ }
+
+ *d = v;
+ return true;
}
-void config_set_sensor_enabled(const char *sid, bool enabled)
+static bool sensor_get_bool(const char *sid, const char *att, bool dft)
{
- char *key;
+ GKeyFile *kfile;
+ GError *err;
+ bool ret;
+
+ kfile = get_sensor_key_file();
- key = get_sensor_att_key(sid, ATT_SENSOR_ENABLED);
- gconf_client_set_bool(client, key, enabled, NULL);
- free(key);
+ err = NULL;
+ ret = g_key_file_get_boolean(kfile, sid, att, &err);
+
+ if (err) {
+ if (err->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND)
+ ret = dft;
+ else
+ log_err(err->message);
+
+ g_error_free(err);
+ }
+
+ return ret;
}
-char *config_get_sensor_name(const char *sid)
+static void sensor_set_bool(const char *sid, const char *att, bool enabled)
{
- char *name, *key;
+ GKeyFile *kfile;
- key = get_sensor_att_key(sid, ATT_SENSOR_NAME);
- name = gconf_client_get_string(client, key, NULL);
- free(key);
+ kfile = get_sensor_key_file();
- return name;
+ g_key_file_set_boolean(kfile, sid, att, enabled);
}
-void config_set_sensor_name(const char *sid, const char *name)
+static int sensor_get_int(const char *sid, const char *att)
{
- char *key;
+ GKeyFile *kfile;
- key = get_sensor_att_key(sid, ATT_SENSOR_NAME);
- gconf_client_set_string(client, key, name, NULL);
- free(key);
+ kfile = get_sensor_key_file();
+ return g_key_file_get_integer(kfile, sid, att, NULL);
}
-int config_get_sensor_position(const char *sid)
+static void sensor_set_int(const char *sid, const char *att, int i)
{
- char *key;
- int pos;
+ GKeyFile *kfile;
- key = get_sensor_att_key(sid, ATT_SENSOR_POSITION);
- pos = gconf_client_get_int(client, key, NULL);
- free(key);
+ kfile = get_sensor_key_file();
- return pos;
+ g_key_file_set_integer(kfile, sid, att, i);
}
-void config_set_sensor_position(const char *sid, int pos)
+char *config_get_sensor_name(const char *sid)
{
- char *key;
+ return sensor_get_str(sid, ATT_SENSOR_NAME);
+}
- key = get_sensor_att_key(sid, ATT_SENSOR_POSITION);
- gconf_client_set_int(client, key, pos, NULL);
- free(key);
+void config_set_sensor_name(const char *sid, const char *name)
+{
+ sensor_set_str(sid, ATT_SENSOR_NAME, name);
+}
+
+void config_set_sensor_color(const char *sid, const GdkRGBA *color)
+{
+ gchar *str;
+
+ str = gdk_rgba_to_string(color);
+
+ sensor_set_str(sid, ATT_SENSOR_COLOR, str);
+
+ g_free(str);
+}
+
+static const char *next_default_color(void)
+{
+ /* copied from the default colors of the gtk color color
+ * chooser.
+ */
+ const char *default_colors[27] = {
+ "#ef2929", /* Scarlet Red */
+ "#fcaf3e", /* Orange */
+ "#fce94f", /* Butter */
+ "#8ae234", /* Chameleon */
+ "#729fcf", /* Sky Blue */
+ "#ad7fa8", /* Plum */
+ "#e9b96e", /* Chocolate */
+ "#888a85", /* Aluminum 1 */
+ "#eeeeec", /* Aluminum 2 */
+ "#cc0000",
+ "#f57900",
+ "#edd400",
+ "#73d216",
+ "#3465a4",
+ "#75507b",
+ "#c17d11",
+ "#555753",
+ "#d3d7cf",
+ "#a40000",
+ "#ce5c00",
+ "#c4a000",
+ "#4e9a06",
+ "#204a87",
+ "#5c3566",
+ "#8f5902",
+ "#2e3436",
+ "#babdb6"
+ };
+ static int next_idx;
+ const char *c;
+
+ c = default_colors[next_idx % 27];
+
+ next_idx++;
+
+ return c;
}
-bool config_is_appindicator_enabled(const char *sid)
+GdkRGBA *config_get_sensor_color(const char *sid)
{
- char *key;
- gboolean b;
+ GdkRGBA rgba;
+ char *str;
+ gboolean ret;
+
+ str = sensor_get_str(sid, ATT_SENSOR_COLOR);
+
+ if (str) {
+ ret = gdk_rgba_parse(&rgba, str);
+ free(str);
+ }
- key = get_sensor_att_key(sid, ATT_SENSOR_APPINDICATOR_DISABLED);
- b = gconf_client_get_bool(client, key, NULL);
- free(key);
+ if (!str || !ret) {
+ gdk_rgba_parse(&rgba, next_default_color());
+ config_set_sensor_color(sid, &rgba);
+ }
- return !b;
+ return gdk_rgba_copy(&rgba);
}
-void config_set_appindicator_enabled(const char *sid, bool enabled)
+bool config_is_sensor_graph_enabled(const char *sid)
{
- char *key;
+ return sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED, false);
+}
- key = get_sensor_att_key(sid, ATT_SENSOR_APPINDICATOR_DISABLED);
- gconf_client_set_bool(client, key, !enabled, NULL);
- free(key);
+void config_set_sensor_graph_enabled(const char *sid, bool enabled)
+{
+ sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
}
-bool is_slog_enabled()
+bool config_get_sensor_alarm_high_threshold(const char *sid, double *v)
{
- return gconf_client_get_bool(client, KEY_SLOG_ENABLED, NULL);
+ return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v);
}
-static void set_slog_enabled(bool enabled)
+void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
{
- gconf_client_set_bool(client, KEY_SLOG_ENABLED, enabled, NULL);
+ sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
}
-void config_slog_enabled_notify_add(GConfClientNotifyFunc cbk, void *data)
+bool config_get_sensor_alarm_low_threshold(const char *sid, double *v)
{
- 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);
+ return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v);
}
-int config_get_slog_interval()
+void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
{
- int res;
+ sensor_set_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, threshold);
+}
- res = gconf_client_get_int(client, KEY_SLOG_INTERVAL, NULL);
+bool config_is_appindicator_enabled(const char *sid)
+{
+ return !sensor_get_bool(sid,
+ ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
+ false);
+}
- if (res <= 0)
- return 300;
- else
- return res;
+void config_set_appindicator_enabled(const char *sid, bool enabled)
+{
+ sensor_set_bool(sid,
+ ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
+ !enabled);
}
-static void set_slog_interval(int interval)
+int config_get_sensor_position(const char *sid)
{
- if (interval <= 0)
- interval = 300;
+ return sensor_get_int(sid, ATT_SENSOR_POSITION);
+}
- gconf_client_set_int(client, KEY_SLOG_INTERVAL, interval, NULL);
+void config_set_sensor_position(const char *sid, int pos)
+{
+ sensor_set_int(sid, ATT_SENSOR_POSITION, pos);
}
-static bool is_window_decoration_enabled()
+bool config_get_sensor_alarm_enabled(const char *sid)
{
- return !gconf_client_get_bool(client,
- KEY_INTERFACE_WINDOW_DECORATION_DISABLED,
- NULL);
+ return sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED, false);
}
-static bool is_window_keep_below_enabled()
+void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
{
- return gconf_client_get_bool(client,
- KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED,
- NULL);
+ sensor_set_bool(sid, ATT_SENSOR_ALARM_ENABLED, enabled);
}
-static void set_window_decoration_enabled(bool enabled)
+bool config_is_sensor_enabled(const char *sid)
{
- gconf_client_set_bool
- (client,
- KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled, NULL);
+ return !sensor_get_bool(sid,
+ ATT_SENSOR_HIDE,
+ config_get_default_sensor_alarm_enabled());
}
-static void set_window_keep_below_enabled(bool enabled)
+void config_set_sensor_enabled(const char *sid, bool enabled)
{
- gconf_client_set_bool(client,
- KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED,
- enabled, NULL);
+ sensor_set_bool(sid, ATT_SENSOR_HIDE, !enabled);
}
-/*
- * Initializes the GConf client.
- */
-static void init()
+bool config_is_appindicator_label_enabled(const char *sid)
{
- if (!client)
- client = gconf_client_get_default();
+ return sensor_get_bool(sid,
+ ATT_SENSOR_APPINDICATOR_LABEL_ENABLED,
+ false);
}
-void config_cleanup()
+void config_set_appindicator_label_enabled(const char *sid, bool enabled)
{
- if (client) {
- g_object_unref(client);
- client = NULL;
- }
+ sensor_set_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED, enabled);
}
-struct config *config_load()
+GSettings *config_get_GSettings(void)
{
- struct config *c;
+ return settings;
+}
- init();
+bool config_is_lmsensor_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_LMSENSORS_ENABLED);
+}
- c = malloc(sizeof(struct config));
+bool config_is_gtop2_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_GTOP2_ENABLED);
+}
- c->graph_bgcolor = get_background_color();
- 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->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();
+bool config_is_udisks2_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_UDISKS2_ENABLED);
+}
- c->sensor_update_interval
- = gconf_client_get_int(client, KEY_SENSOR_UPDATE_INTERVAL, NULL);
- if (c->sensor_update_interval < 1)
- c->sensor_update_interval = 1;
+bool config_is_hddtemp_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_HDDTEMP_ENABLED);
+}
- c->graph_update_interval
- = gconf_client_get_int(client, KEY_GRAPH_UPDATE_INTERVAL, NULL);
- if (c->graph_update_interval < 1)
- c->graph_update_interval = 1;
+bool config_is_libatasmart_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_LIBATASMART_ENABLED);
+}
- c->graph_monitoring_duration
- = gconf_client_get_int(client, KEY_GRAPH_MONITORING_DURATION, NULL);
+bool config_is_nvctrl_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_NVCTRL_ENABLED);
+}
- if (c->graph_monitoring_duration < 1)
- c->graph_monitoring_duration = 10;
+bool config_is_atiadlsdk_enabled(void)
+{
+ return get_bool(KEY_PROVIDER_ATIADLSDK_ENABLED);
+}
- c->sensor_values_max_length
- =
- (c->graph_monitoring_duration * 60) / c->sensor_update_interval;
- if (c->sensor_values_max_length < 3)
- c->sensor_values_max_length = 3;
+void config_set_lmsensor_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_LMSENSORS_ENABLED, b);
+}
- c->menu_bar_disabled
- = gconf_client_get_bool(client,
- KEY_INTERFACE_MENU_BAR_DISABLED,
- NULL);
+void config_set_nvctrl_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_NVCTRL_ENABLED, b);
+}
- c->unity_launcher_count_disabled
- = gconf_client_get_bool
- (client,
- KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
- NULL);
+void config_set_atiadlsdk_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_ATIADLSDK_ENABLED, b);
+}
- c->hide_on_startup
- = gconf_client_get_bool(client,
- KEY_INTERFACE_HIDE_ON_STARTUP,
- NULL);
+void config_set_gtop2_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_GTOP2_ENABLED, b);
+}
- c->window_restore_enabled
- = gconf_client_get_bool(client,
- KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
- NULL);
-
- c->window_x = gconf_client_get_int(client,
- KEY_INTERFACE_WINDOW_X,
- NULL);
- c->window_y = gconf_client_get_int(client,
- KEY_INTERFACE_WINDOW_Y,
- NULL);
- c->window_w = gconf_client_get_int(client,
- KEY_INTERFACE_WINDOW_W,
- NULL);
- c->window_h = gconf_client_get_int(client,
- KEY_INTERFACE_WINDOW_H,
- NULL);
- c->window_divider_pos
- = gconf_client_get_int(client,
- KEY_INTERFACE_WINDOW_DIVIDER_POS,
- NULL);
+void config_set_hddtemp_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_HDDTEMP_ENABLED, b);
+}
- if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
- c->window_w = 800;
- c->window_h = 200;
- }
+void config_set_libatasmart_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_LIBATASMART_ENABLED, b);
+}
- c->temperature_unit = gconf_client_get_int
- (client, KEY_INTERFACE_TEMPERATURE_UNIT, NULL);
+void config_set_udisks2_enable(bool b)
+{
+ set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
+}
- return c;
+enum temperature_unit config_get_temperature_unit(void)
+{
+ return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
}
-void config_save(const struct config *c)
+void config_set_temperature_unit(enum temperature_unit u)
{
- 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_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);
+ set_int(KEY_INTERFACE_TEMPERATURE_UNIT, u);
+}
- gconf_client_set_int(client,
- KEY_GRAPH_UPDATE_INTERVAL,
- c->graph_update_interval, NULL);
-
- gconf_client_set_int(client,
- KEY_GRAPH_MONITORING_DURATION,
- c->graph_monitoring_duration, NULL);
-
- gconf_client_set_int(client,
- KEY_SENSOR_UPDATE_INTERVAL,
- 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);
-
- gconf_client_set_int(client, KEY_INTERFACE_WINDOW_X, c->window_x, NULL);
- gconf_client_set_int(client, KEY_INTERFACE_WINDOW_Y, c->window_y, NULL);
- gconf_client_set_int(client, KEY_INTERFACE_WINDOW_W, c->window_w, NULL);
- gconf_client_set_int(client, KEY_INTERFACE_WINDOW_H, c->window_h, NULL);
-
- gconf_client_set_int(client,
- KEY_INTERFACE_WINDOW_DIVIDER_POS,
- c->window_divider_pos,
- NULL);
-
- gconf_client_set_int(client,
- KEY_INTERFACE_TEMPERATURE_UNIT,
- c->temperature_unit,
- NULL);
+bool config_is_menu_bar_enabled(void)
+{
+ return !get_bool(KEY_INTERFACE_MENU_BAR_DISABLED);
+}
+
+void config_set_menu_bar_enabled(bool enabled)
+{
+ set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, !enabled);
+}
+
+bool config_is_count_visible(void)
+{
+ return !get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
+}
+
+void config_set_count_visible(bool visible)
+{
+ set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED, !visible);
}