static const char *KEY_PROVIDER_NVCTRL_ENABLED = "provider-nvctrl-enabled";
static const char *KEY_PROVIDER_UDISKS2_ENABLED = "provider-udisks2-enabled";
-
static GSettings *settings;
static char *user_dir;
return g_key_file_get_string(kfile, sid, att, NULL);
}
+static bool sensor_get_double(const char *sid, const char *att, double *d)
+{
+ 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)
+ return false;
+
+ *d = v;
+ return true;
+}
+
static bool sensor_get_bool(const char *sid, const char *att)
{
GKeyFile *kfile;
sensor_set_str(sid, ATT_SENSOR_NAME, name);
}
-void config_set_sensor_color(const char *sid, const struct color *color)
-{
- char *scolor;
-
- scolor = color_to_str(color);
-
- sensor_set_str(sid, ATT_SENSOR_COLOR, scolor);
+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++;
- free(scolor);
+ return c;
}
-struct color *
-config_get_sensor_color(const char *sid, const struct color *dft)
+GdkRGBA *config_get_sensor_color(const char *sid)
{
- char *scolor;
- struct color *color;
-
- scolor = sensor_get_str(sid, ATT_SENSOR_COLOR);
+ GdkRGBA rgba;
+ char *str;
+ gboolean ret;
- if (scolor)
- color = str_to_color(scolor);
- else
- color = NULL;
+ str = sensor_get_str(sid, ATT_SENSOR_COLOR);
- if (!color) {
- color = color_new(dft->red, dft->green, dft->blue);
- config_set_sensor_color(sid, color);
+ if (str) {
+ ret = gdk_rgba_parse(&rgba, str);
+ free(str);
}
- free(scolor);
+ if (!str || !ret) {
+ gdk_rgba_parse(&rgba, next_default_color());
+ config_set_sensor_color(sid, &rgba);
+ }
- return color;
+ return gdk_rgba_copy(&rgba);
}
bool config_is_sensor_graph_enabled(const char *sid)
sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
}
-int config_get_sensor_alarm_high_threshold(const char *sid)
+bool config_get_sensor_alarm_high_threshold(const char *sid, double *v)
{
- return sensor_get_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD);
+ return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v);
}
void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
}
-int config_get_sensor_alarm_low_threshold(const char *sid)
+bool config_get_sensor_alarm_low_threshold(const char *sid, double *v)
{
- return sensor_get_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD);
+ return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v);
}
void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
{
set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
}
+
+int config_get_sensor_unit(void)
+{
+ return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
+}