projects
/
psensor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
made the setting temperature unit dynamic
[psensor.git]
/
src
/
cfg.c
diff --git
a/src/cfg.c
b/src/cfg.c
index
3bd02f4
..
96baa27
100644
(file)
--- a/
src/cfg.c
+++ b/
src/cfg.c
@@
-119,6
+119,11
@@
static const char *KEY_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_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 GSettings *settings;
static char *user_dir;
@@
-323,22
+328,22
@@
static void set_slog_interval(int interval)
set_int(KEY_SLOG_INTERVAL, interval);
}
set_int(KEY_SLOG_INTERVAL, interval);
}
-
static bool
is_window_decoration_enabled(void)
+
bool config_
is_window_decoration_enabled(void)
{
return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
}
{
return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
}
-
static bool
is_window_keep_below_enabled(void)
+
bool config_
is_window_keep_below_enabled(void)
{
return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
}
{
return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
}
-
static void
set_window_decoration_enabled(bool enabled)
+
void config_
set_window_decoration_enabled(bool enabled)
{
set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
}
{
set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
}
-
static void
set_window_keep_below_enabled(bool enabled)
+
void config_
set_window_keep_below_enabled(bool enabled)
{
set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
}
{
set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
}
@@
-353,6
+358,15
@@
void config_set_smooth_curves_enabled(bool b)
set_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED, b);
}
set_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED, b);
}
+double config_get_default_high_threshold_temperature(void)
+{
+ return get_double(KEY_DEFAULT_HIGH_THRESHOLD_TEMPERATURE);
+}
+
+static bool config_get_default_sensor_alarm_enabled(void)
+{
+ return get_bool(KEY_DEFAULT_SENSOR_ALARM_ENABLED);
+}
static void init(void)
{
static void init(void)
{
@@
-405,8
+419,6
@@
struct config *config_load(void)
c->graph_bg_alpha = get_graph_background_alpha();
c->alpha_channel_enabled = is_alpha_channel_enabled();
c->sensorlist_position = get_sensorlist_position();
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();
c->slog_enabled = is_slog_enabled();
c->slog_interval = config_get_slog_interval();
@@
-446,8
+458,6
@@
struct config *config_load(void)
c->window_h = 200;
}
c->window_h = 200;
}
- c->temperature_unit = get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
-
c->sensor_values_max_length = compute_values_max_length(c);
return c;
c->sensor_values_max_length = compute_values_max_length(c);
return c;
@@
-460,8
+470,6
@@
void config_save(const struct config *c)
set_foreground_color(c->graph_fgcolor);
set_graph_background_alpha(c->graph_bg_alpha);
set_sensorlist_position(c->sensorlist_position);
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_slog_enabled(c->slog_enabled);
set_slog_interval(c->slog_interval);
@@
-487,8
+495,6
@@
void config_save(const struct config *c)
set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
-
- set_int(KEY_INTERFACE_TEMPERATURE_UNIT, c->temperature_unit);
}
const char *get_psensor_user_dir(void)
}
const char *get_psensor_user_dir(void)
@@
-552,10
+558,12
@@
static GKeyFile *get_sensor_key_file(void)
| G_KEY_FILE_KEEP_TRANSLATIONS,
&err);
| G_KEY_FILE_KEEP_TRANSLATIONS,
&err);
- if (!ret)
+ if (!ret)
{
log_warn(_("Failed to load configuration file %s: %s"),
path,
err->message);
log_warn(_("Failed to load configuration file %s: %s"),
path,
err->message);
+ g_error_free(err);
+ }
}
return key_file;
}
return key_file;
@@
-619,19
+627,39
@@
static bool sensor_get_double(const char *sid, const char *att, double *d)
err = NULL;
v = g_key_file_get_double(kfile, sid, att, &err);
err = NULL;
v = g_key_file_get_double(kfile, sid, att, &err);
- if (err)
+ if (err) {
+ log_err(err->message);
+
+ g_error_free(err);
+
return false;
return false;
+ }
*d = v;
return true;
}
*d = v;
return true;
}
-static bool sensor_get_bool(const char *sid, const char *att)
+static bool sensor_get_bool(const char *sid, const char *att
, bool dft
)
{
GKeyFile *kfile;
{
GKeyFile *kfile;
+ GError *err;
+ bool ret;
kfile = get_sensor_key_file();
kfile = get_sensor_key_file();
- return g_key_file_get_boolean(kfile, sid, att, NULL);
+
+ 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;
}
static void sensor_set_bool(const char *sid, const char *att, bool enabled)
}
static void sensor_set_bool(const char *sid, const char *att, bool enabled)
@@
-747,7
+775,7
@@
GdkRGBA *config_get_sensor_color(const char *sid)
bool config_is_sensor_graph_enabled(const char *sid)
{
bool config_is_sensor_graph_enabled(const char *sid)
{
- return sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED);
+ return sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED
, false
);
}
void config_set_sensor_graph_enabled(const char *sid, bool enabled)
}
void config_set_sensor_graph_enabled(const char *sid, bool enabled)
@@
-777,7
+805,9
@@
void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
bool config_is_appindicator_enabled(const char *sid)
{
bool config_is_appindicator_enabled(const char *sid)
{
- return !sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_MENU_DISABLED);
+ return !sensor_get_bool(sid,
+ ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
+ false);
}
void config_set_appindicator_enabled(const char *sid, bool enabled)
}
void config_set_appindicator_enabled(const char *sid, bool enabled)
@@
-799,7
+829,7
@@
void config_set_sensor_position(const char *sid, int pos)
bool config_get_sensor_alarm_enabled(const char *sid)
{
bool config_get_sensor_alarm_enabled(const char *sid)
{
- return sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED);
+ return sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED
, false
);
}
void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
}
void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
@@
-809,7
+839,9
@@
void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
bool config_is_sensor_enabled(const char *sid)
{
bool config_is_sensor_enabled(const char *sid)
{
- return !sensor_get_bool(sid, ATT_SENSOR_HIDE);
+ return !sensor_get_bool(sid,
+ ATT_SENSOR_HIDE,
+ config_get_default_sensor_alarm_enabled());
}
void config_set_sensor_enabled(const char *sid, bool enabled)
}
void config_set_sensor_enabled(const char *sid, bool enabled)
@@
-819,7
+851,9
@@
void config_set_sensor_enabled(const char *sid, bool enabled)
bool config_is_appindicator_label_enabled(const char *sid)
{
bool config_is_appindicator_label_enabled(const char *sid)
{
- return sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
+ return sensor_get_bool(sid,
+ ATT_SENSOR_APPINDICATOR_LABEL_ENABLED,
+ false);
}
void config_set_appindicator_label_enabled(const char *sid, bool enabled)
}
void config_set_appindicator_label_enabled(const char *sid, bool enabled)
@@
-902,7
+936,12
@@
void config_set_udisks2_enable(bool b)
set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
}
set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
}
-
int config_get_sensor
_unit(void)
+
enum temperature_unit config_get_temperature
_unit(void)
{
return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
}
{
return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
}
+
+void config_set_temperature_unit(enum temperature_unit u)
+{
+ set_int(KEY_INTERFACE_TEMPERATURE_UNIT, u);
+}