+ 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->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->unity_launcher_count_disabled
+ = get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
+
+ c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
+
+ 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;
+}
+
+void config_save(const struct config *c)
+{
+ 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_sensorlist_position(c->sensorlist_position);
+ 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_UNITY_LAUNCHER_COUNT_DISABLED,
+ c->unity_launcher_count_disabled);
+
+ 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));
+
+ free(user_dir);
+ user_dir = NULL;
+ }
+ }
+
+ log_fct_exit();
+
+ return user_dir;