7fb64462f779a3fb520713c0e26110629f309498
[psensor.git] / src / cfg.c
1 /*
2  * Copyright (C) 2010-2014 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27
28 #include <locale.h>
29 #include <libintl.h>
30 #define _(str) gettext(str)
31
32 #include <cfg.h>
33 #include <graph.h>
34 #include <pio.h>
35 #include <plog.h>
36
37 /* Properties of each sensor */
38 static const char *ATT_SENSOR_ALARM_ENABLED = "alarm_enabled";
39 static const char *ATT_SENSOR_ALARM_HIGH_THRESHOLD = "alarm_high_threshold";
40 static const char *ATT_SENSOR_ALARM_LOW_THRESHOLD = "alarm_low_threshold";
41 static const char *ATT_SENSOR_COLOR = "color";
42 static const char *ATT_SENSOR_GRAPH_ENABLED = "graph_enabled";
43 static const char *ATT_SENSOR_NAME = "name";
44 static const char *ATT_SENSOR_APPINDICATOR_MENU_DISABLED
45 = "appindicator_menu_disabled";
46 static const char *ATT_SENSOR_APPINDICATOR_LABEL_ENABLED
47 = "appindicator_label_enabled";
48 static const char *ATT_SENSOR_POSITION = "position";
49 static const char *ATT_SENSOR_HIDE = "hide";
50
51 /* Update interval of the measures of the sensors */
52 static const char *KEY_SENSOR_UPDATE_INTERVAL
53 = "sensor-update-interval";
54
55 /* Graph settings */
56 static const char *KEY_GRAPH_UPDATE_INTERVAL = "graph-update-interval";
57 static const char *KEY_GRAPH_MONITORING_DURATION = "graph-monitoring-duration";
58 static const char *KEY_GRAPH_BACKGROUND_COLOR = "graph-background-color";
59 static const char *DEFAULT_GRAPH_BACKGROUND_COLOR = "#e8f4e8f4a8f5";
60 static const char *KEY_GRAPH_BACKGROUND_ALPHA = "graph-background-alpha";
61 static const char *KEY_GRAPH_FOREGROUND_COLOR
62 = "graph-foreground-color";
63 static const char *KEY_GRAPH_SMOOTH_CURVES_ENABLED
64 = "graph-smooth-curves-enabled";
65
66 static const char *DEFAULT_GRAPH_FOREGROUND_COLOR = "#000000000000";
67
68 static const char *KEY_ALPHA_CHANNEL_ENABLED = "graph-alpha-channel-enabled";
69
70 /* Inteface settings */
71 static const char *KEY_INTERFACE_SENSORLIST_POSITION
72 = "interface-sensorlist-position";
73
74 static const char *KEY_INTERFACE_WINDOW_DECORATION_DISABLED
75 = "interface-window-decoration-disabled";
76
77 static const char *KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED
78 = "interface-window-keep-below-enabled";
79
80 static const char *KEY_INTERFACE_MENU_BAR_DISABLED
81 = "interface-menu-bar-disabled";
82
83 static const char *KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED
84 = "interface-unity-launcher-count-disabled";
85
86 static const char *KEY_INTERFACE_HIDE_ON_STARTUP
87 = "interface-hide-on-startup";
88
89 static const char *KEY_INTERFACE_WINDOW_RESTORE_ENABLED
90 = "interface-window-restore-enabled";
91
92 static const char *KEY_INTERFACE_WINDOW_X = "interface-window-x";
93 static const char *KEY_INTERFACE_WINDOW_Y = "interface-window-y";
94 static const char *KEY_INTERFACE_WINDOW_W = "interface-window-w";
95 static const char *KEY_INTERFACE_WINDOW_H = "interface-window-h";
96
97 static const char *KEY_INTERFACE_WINDOW_DIVIDER_POS
98 = "interface-window-divider-pos";
99
100 static const char *KEY_INTERFACE_TEMPERATURE_UNIT
101 = "interface-temperature-unit";
102
103 /* Sensor logging settings */
104 static const char *KEY_SLOG_ENABLED = "slog-enabled";
105 static const char *KEY_SLOG_INTERVAL = "slog-interval";
106
107 /* Path to the script called when a notification is raised */
108 static const char *KEY_NOTIFICATION_SCRIPT = "notif-script";
109
110 /* Provider settings */
111 static const char *KEY_PROVIDER_LMSENSORS_ENABLED
112 = "provider-lmsensors-enabled";
113 static const char *KEY_PROVIDER_ATIADLSDK_ENABLED
114 = "provider-atiadlsdk-enabled";
115 static const char *KEY_PROVIDER_GTOP2_ENABLED = "provider-gtop2-enabled";
116 static const char *KEY_PROVIDER_HDDTEMP_ENABLED = "provider-hddtemp-enabled";
117 static const char *KEY_PROVIDER_LIBATASMART_ENABLED
118 = "provider-libatasmart-enabled";
119 static const char *KEY_PROVIDER_NVCTRL_ENABLED = "provider-nvctrl-enabled";
120 static const char *KEY_PROVIDER_UDISKS2_ENABLED = "provider-udisks2-enabled";
121
122 static const char *KEY_DEFAULT_HIGH_THRESHOLD_TEMPERATURE
123 = "default-high-threshold-temperature";
124
125 static GSettings *settings;
126
127 static char *user_dir;
128
129 static GKeyFile *key_file;
130
131 static char *sensor_config_path;
132
133 static void (*slog_enabled_cbk)(void *);
134
135 static char *get_string(const char *key)
136 {
137         return g_settings_get_string(settings, key);
138 }
139
140 static void set_string(const char *key, const char *str)
141 {
142         g_settings_set_string(settings, key, str);
143 }
144
145 static void set_bool(const char *k, bool b)
146 {
147         g_settings_set_boolean(settings, k, b);
148 }
149
150 static bool get_bool(const char *k)
151 {
152         return g_settings_get_boolean(settings, k);
153 }
154
155 static void set_int(const char *k, int i)
156 {
157         g_settings_set_int(settings, k, i);
158 }
159
160 static double get_double(const char *k)
161 {
162         return g_settings_get_double(settings, k);
163 }
164
165 static void set_double(const char *k, double d)
166 {
167         g_settings_set_double(settings, k, d);
168 }
169
170 static int get_int(const char *k)
171 {
172         return g_settings_get_int(settings, k);
173 }
174
175 char *config_get_notif_script(void)
176 {
177         char *str;
178
179         str =  get_string(KEY_NOTIFICATION_SCRIPT);
180         if (str && !strlen(str)) {
181                 free(str);
182                 str = NULL;
183         }
184
185         return str;
186 }
187
188 void config_set_notif_script(const char *str)
189 {
190         if (str && strlen(str) > 0)
191                 set_string(KEY_NOTIFICATION_SCRIPT, str);
192         else
193                 set_string(KEY_NOTIFICATION_SCRIPT, "");
194 }
195
196 static struct color *get_background_color(void)
197 {
198         char *scolor;
199         struct color *c;
200
201         scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR);
202
203         c = str_to_color(scolor);
204         free(scolor);
205
206         if (!c)
207                 return color_new(1, 1, 1);
208
209         return c;
210 }
211
212 static struct color *get_foreground_color(void)
213 {
214         char *scolor;
215         struct color *c;
216
217         scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR);
218
219         c = str_to_color(scolor);
220         free(scolor);
221
222         if (!c)
223                 return color_new(0, 0, 0);
224
225         return c;
226 }
227
228 static bool is_alpha_channel_enabled(void)
229 {
230         return get_bool(KEY_ALPHA_CHANNEL_ENABLED);
231 }
232
233 static void set_alpha_channeld_enabled(bool b)
234 {
235         set_bool(KEY_ALPHA_CHANNEL_ENABLED, b);
236 }
237
238 static enum sensorlist_position get_sensorlist_position(void)
239 {
240         return get_int(KEY_INTERFACE_SENSORLIST_POSITION);
241 }
242
243 static void set_sensorlist_position(enum sensorlist_position pos)
244 {
245         set_int(KEY_INTERFACE_SENSORLIST_POSITION, pos);
246 }
247
248 static double get_graph_background_alpha(void)
249 {
250         return get_double(KEY_GRAPH_BACKGROUND_ALPHA);
251 }
252
253 static void set_graph_background_alpha(double alpha)
254 {
255         set_double(KEY_GRAPH_BACKGROUND_ALPHA, alpha);
256 }
257
258 static void set_background_color(const struct color *color)
259 {
260         char *scolor;
261
262         scolor = color_to_str(color);
263         if (!scolor)
264                 scolor = strdup(DEFAULT_GRAPH_BACKGROUND_COLOR);
265
266         set_string(KEY_GRAPH_BACKGROUND_COLOR, scolor);
267
268         free(scolor);
269 }
270
271 static void set_foreground_color(const struct color *color)
272 {
273         char *str;
274
275         str = color_to_str(color);
276         if (!str)
277                 str = strdup(DEFAULT_GRAPH_FOREGROUND_COLOR);
278
279         set_string(KEY_GRAPH_FOREGROUND_COLOR, str);
280
281         free(str);
282 }
283
284 bool is_slog_enabled(void)
285 {
286         return get_bool(KEY_SLOG_ENABLED);
287 }
288
289 static void set_slog_enabled(bool enabled)
290 {
291         set_bool(KEY_SLOG_ENABLED, enabled);
292 }
293
294 static void slog_enabled_changed_cbk(GSettings *settings,
295                                      gchar *key,
296                                      gpointer data)
297 {
298         if (slog_enabled_cbk)
299                 slog_enabled_cbk(data);
300 }
301
302 void config_set_slog_enabled_changed_cbk(void (*cbk)(void *), void *data)
303 {
304         log_fct_enter();
305
306         slog_enabled_cbk = cbk;
307
308         g_signal_connect_after(settings,
309                                "changed::slog-enabled",
310                                G_CALLBACK(slog_enabled_changed_cbk),
311                                data);
312
313         log_fct_exit();
314 }
315
316 int config_get_slog_interval(void)
317 {
318         return get_int(KEY_SLOG_INTERVAL);
319 }
320
321 static void set_slog_interval(int interval)
322 {
323         if (interval <= 0)
324                 interval = 300;
325
326         set_int(KEY_SLOG_INTERVAL, interval);
327 }
328
329 static bool is_window_decoration_enabled(void)
330 {
331         return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
332 }
333
334 static bool is_window_keep_below_enabled(void)
335 {
336         return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
337 }
338
339 static void set_window_decoration_enabled(bool enabled)
340 {
341         set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
342 }
343
344 static void set_window_keep_below_enabled(bool enabled)
345 {
346         set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
347 }
348
349 bool config_is_smooth_curves_enabled(void)
350 {
351         return get_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED);
352 }
353
354 void config_set_smooth_curves_enabled(bool b)
355 {
356         set_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED, b);
357 }
358
359 double config_get_default_high_threshold_temperature(void)
360 {
361         return get_double(KEY_DEFAULT_HIGH_THRESHOLD_TEMPERATURE);
362 }
363
364 static void init(void)
365 {
366         log_fct_enter();
367
368         if (!settings)
369                 settings = g_settings_new("psensor");
370
371         log_fct_exit();
372 }
373
374 void config_cleanup(void)
375 {
376         config_sync();
377
378         if (settings) {
379                 g_settings_sync();
380                 g_object_unref(settings);
381                 settings = NULL;
382         }
383
384         if (user_dir) {
385                 free(user_dir);
386                 user_dir = NULL;
387         }
388
389         if (key_file) {
390                 g_key_file_free(key_file);
391                 key_file = NULL;
392         }
393
394         if (sensor_config_path) {
395                 free(sensor_config_path);
396                 sensor_config_path = NULL;
397         }
398
399         slog_enabled_cbk = NULL;
400 }
401
402 struct config *config_load(void)
403 {
404         struct config *c;
405
406         init();
407
408         c = malloc(sizeof(struct config));
409
410         c->graph_bgcolor = get_background_color();
411         c->graph_fgcolor = get_foreground_color();
412         c->graph_bg_alpha = get_graph_background_alpha();
413         c->alpha_channel_enabled = is_alpha_channel_enabled();
414         c->sensorlist_position = get_sensorlist_position();
415         c->window_decoration_enabled = is_window_decoration_enabled();
416         c->window_keep_below_enabled = is_window_keep_below_enabled();
417         c->slog_enabled = is_slog_enabled();
418         c->slog_interval = config_get_slog_interval();
419
420         c->sensor_update_interval
421             = get_int(KEY_SENSOR_UPDATE_INTERVAL);
422         if (c->sensor_update_interval < 1)
423                 c->sensor_update_interval = 1;
424
425         c->graph_update_interval = get_int(KEY_GRAPH_UPDATE_INTERVAL);
426         if (c->graph_update_interval < 1)
427                 c->graph_update_interval = 1;
428
429         c->graph_monitoring_duration = get_int(KEY_GRAPH_MONITORING_DURATION);
430
431         if (c->graph_monitoring_duration < 1)
432                 c->graph_monitoring_duration = 10;
433
434         c->menu_bar_disabled = get_bool(KEY_INTERFACE_MENU_BAR_DISABLED);
435
436         c->unity_launcher_count_disabled
437                 = get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
438
439         c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
440
441         c->window_restore_enabled
442                 = get_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED);
443
444         c->window_x = get_int(KEY_INTERFACE_WINDOW_X);
445         c->window_y = get_int(KEY_INTERFACE_WINDOW_Y);
446         c->window_w = get_int(KEY_INTERFACE_WINDOW_W);
447         c->window_h = get_int(KEY_INTERFACE_WINDOW_H);
448
449         c->window_divider_pos = get_int(KEY_INTERFACE_WINDOW_DIVIDER_POS);
450
451         if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
452                 c->window_w = 800;
453                 c->window_h = 200;
454         }
455
456         c->temperature_unit = get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
457
458         c->sensor_values_max_length = compute_values_max_length(c);
459
460         return c;
461 }
462
463 void config_save(const struct config *c)
464 {
465         set_alpha_channeld_enabled(c->alpha_channel_enabled);
466         set_background_color(c->graph_bgcolor);
467         set_foreground_color(c->graph_fgcolor);
468         set_graph_background_alpha(c->graph_bg_alpha);
469         set_sensorlist_position(c->sensorlist_position);
470         set_window_decoration_enabled(c->window_decoration_enabled);
471         set_window_keep_below_enabled(c->window_keep_below_enabled);
472         set_slog_enabled(c->slog_enabled);
473         set_slog_interval(c->slog_interval);
474
475         set_int(KEY_GRAPH_UPDATE_INTERVAL, c->graph_update_interval);
476
477         set_int(KEY_GRAPH_MONITORING_DURATION, c->graph_monitoring_duration);
478
479         set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
480
481         set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, c->menu_bar_disabled);
482
483         set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
484                  c->unity_launcher_count_disabled);
485
486         set_bool(KEY_INTERFACE_HIDE_ON_STARTUP, c->hide_on_startup);
487
488         set_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
489                  c->window_restore_enabled);
490
491         set_int(KEY_INTERFACE_WINDOW_X, c->window_x);
492         set_int(KEY_INTERFACE_WINDOW_Y, c->window_y);
493         set_int(KEY_INTERFACE_WINDOW_W, c->window_w);
494         set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
495
496         set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
497
498         set_int(KEY_INTERFACE_TEMPERATURE_UNIT, c->temperature_unit);
499 }
500
501 const char *get_psensor_user_dir(void)
502 {
503         const char *home;
504
505         log_fct_enter();
506
507         if (!user_dir) {
508                 home = getenv("HOME");
509
510                 if (!home)
511                         return NULL;
512
513                 user_dir = path_append(home, ".psensor");
514
515                 if (mkdir(user_dir, 0700) == -1 && errno != EEXIST) {
516                         log_err(_("Failed to create the directory %s: %s"),
517                                 user_dir,
518                                 strerror(errno));
519
520                         free(user_dir);
521                         user_dir = NULL;
522                 }
523         }
524
525         log_fct_exit();
526
527         return user_dir;
528 }
529
530 static const char *get_sensor_config_path(void)
531 {
532         const char *dir;
533
534         if (!sensor_config_path) {
535                 dir = get_psensor_user_dir();
536
537                 if (dir)
538                         sensor_config_path = path_append(dir, "psensor.cfg");
539         }
540
541         return sensor_config_path;
542 }
543
544 static GKeyFile *get_sensor_key_file(void)
545 {
546         int ret;
547         GError *err;
548         const char *path;
549
550         if (!key_file) {
551                 path = get_sensor_config_path();
552
553                 key_file = g_key_file_new();
554
555                 err = NULL;
556                 ret = g_key_file_load_from_file(key_file,
557                                                 path,
558                                                 G_KEY_FILE_KEEP_COMMENTS
559                                                 | G_KEY_FILE_KEEP_TRANSLATIONS,
560                                                 &err);
561
562                 if (!ret)
563                         log_warn(_("Failed to load configuration file %s: %s"),
564                                  path,
565                                  err->message);
566         }
567
568         return key_file;
569 }
570
571 static void save_sensor_key_file(void)
572 {
573         GKeyFile *kfile;
574         const char *path;
575         char *data;
576
577         log_fct_enter();
578
579         kfile = get_sensor_key_file();
580
581         data = g_key_file_to_data(kfile, NULL, NULL);
582
583         path = get_sensor_config_path();
584
585         if (!g_file_set_contents(path, data, -1, NULL))
586                 log_err(_("Failed to save configuration file %s."), path);
587
588         free(data);
589
590         log_fct_exit();
591 }
592
593 void config_sync(void)
594 {
595         log_fct_enter();
596         if (settings)
597                 g_settings_sync();
598         save_sensor_key_file();
599         log_fct_exit();
600 }
601
602 static void sensor_set_str(const char *sid, const char *att, const char *str)
603 {
604         GKeyFile *kfile;
605
606         kfile = get_sensor_key_file();
607         g_key_file_set_string(kfile, sid, att, str);
608 }
609
610 static char *sensor_get_str(const char *sid, const char *att)
611 {
612         GKeyFile *kfile;
613
614         kfile = get_sensor_key_file();
615         return g_key_file_get_string(kfile, sid, att, NULL);
616 }
617
618 static bool sensor_get_double(const char *sid, const char *att, double *d)
619 {
620         GKeyFile *kfile;
621         GError *err;
622         double v;
623
624         kfile = get_sensor_key_file();
625
626         err = NULL;
627         v = g_key_file_get_double(kfile, sid, att, &err);
628
629         if (err)
630                 return false;
631
632         *d = v;
633         return true;
634 }
635
636 static bool sensor_get_bool(const char *sid, const char *att)
637 {
638         GKeyFile *kfile;
639
640         kfile = get_sensor_key_file();
641         return g_key_file_get_boolean(kfile, sid, att, NULL);
642 }
643
644 static void sensor_set_bool(const char *sid, const char *att, bool enabled)
645 {
646         GKeyFile *kfile;
647
648         kfile = get_sensor_key_file();
649
650         g_key_file_set_boolean(kfile, sid, att, enabled);
651 }
652
653 static int sensor_get_int(const char *sid, const char *att)
654 {
655         GKeyFile *kfile;
656
657         kfile = get_sensor_key_file();
658         return g_key_file_get_integer(kfile, sid, att, NULL);
659 }
660
661 static void sensor_set_int(const char *sid, const char *att, int i)
662 {
663         GKeyFile *kfile;
664
665         kfile = get_sensor_key_file();
666
667         g_key_file_set_integer(kfile, sid, att, i);
668 }
669
670 char *config_get_sensor_name(const char *sid)
671 {
672         return sensor_get_str(sid, ATT_SENSOR_NAME);
673 }
674
675 void config_set_sensor_name(const char *sid, const char *name)
676 {
677         sensor_set_str(sid, ATT_SENSOR_NAME, name);
678 }
679
680 void config_set_sensor_color(const char *sid, const GdkRGBA *color)
681 {
682         gchar *str;
683
684         str = gdk_rgba_to_string(color);
685
686         sensor_set_str(sid, ATT_SENSOR_COLOR, str);
687
688         g_free(str);
689 }
690
691 static const char *next_default_color(void)
692 {
693         /* copied from the default colors of the gtk color color
694          * chooser. */
695         const char *default_colors[27] = {
696                 "#ef2929",  /* Scarlet Red */
697                 "#fcaf3e",  /* Orange */
698                 "#fce94f",  /* Butter */
699                 "#8ae234",  /* Chameleon */
700                 "#729fcf",  /* Sky Blue */
701                 "#ad7fa8",  /* Plum */
702                 "#e9b96e",  /* Chocolate */
703                 "#888a85",  /* Aluminum 1 */
704                 "#eeeeec",  /* Aluminum 2 */
705                 "#cc0000",
706                 "#f57900",
707                 "#edd400",
708                 "#73d216",
709                 "#3465a4",
710                 "#75507b",
711                 "#c17d11",
712                 "#555753",
713                 "#d3d7cf",
714                 "#a40000",
715                 "#ce5c00",
716                 "#c4a000",
717                 "#4e9a06",
718                 "#204a87",
719                 "#5c3566",
720                 "#8f5902",
721                 "#2e3436",
722                 "#babdb6"
723         };
724         static int next_idx;
725         const char *c;
726
727         c = default_colors[next_idx % 27];
728
729         next_idx++;
730
731         return c;
732 }
733
734 GdkRGBA *config_get_sensor_color(const char *sid)
735 {
736         GdkRGBA rgba;
737         char *str;
738         gboolean ret;
739
740         str = sensor_get_str(sid, ATT_SENSOR_COLOR);
741
742         if (str) {
743                 ret = gdk_rgba_parse(&rgba, str);
744                 free(str);
745         }
746
747         if (!str || !ret) {
748                 gdk_rgba_parse(&rgba, next_default_color());
749                 config_set_sensor_color(sid, &rgba);
750         }
751
752         return gdk_rgba_copy(&rgba);
753 }
754
755 bool config_is_sensor_graph_enabled(const char *sid)
756 {
757         return sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED);
758 }
759
760 void config_set_sensor_graph_enabled(const char *sid, bool enabled)
761 {
762         sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
763 }
764
765 bool config_get_sensor_alarm_high_threshold(const char *sid, double *v)
766 {
767         return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v);
768 }
769
770 void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
771 {
772         sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
773 }
774
775 bool config_get_sensor_alarm_low_threshold(const char *sid, double *v)
776 {
777         return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v);
778 }
779
780 void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
781 {
782         sensor_set_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, threshold);
783 }
784
785 bool config_is_appindicator_enabled(const char *sid)
786 {
787         return !sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_MENU_DISABLED);
788 }
789
790 void config_set_appindicator_enabled(const char *sid, bool enabled)
791 {
792         sensor_set_bool(sid,
793                         ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
794                         !enabled);
795 }
796
797 int config_get_sensor_position(const char *sid)
798 {
799         return sensor_get_int(sid, ATT_SENSOR_POSITION);
800 }
801
802 void config_set_sensor_position(const char *sid, int pos)
803 {
804         sensor_set_int(sid, ATT_SENSOR_POSITION, pos);
805 }
806
807 bool config_get_sensor_alarm_enabled(const char *sid)
808 {
809         return sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED);
810 }
811
812 void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
813 {
814         sensor_set_bool(sid, ATT_SENSOR_ALARM_ENABLED, enabled);
815 }
816
817 bool config_is_sensor_enabled(const char *sid)
818 {
819         return !sensor_get_bool(sid, ATT_SENSOR_HIDE);
820 }
821
822 void config_set_sensor_enabled(const char *sid, bool enabled)
823 {
824         sensor_set_bool(sid, ATT_SENSOR_HIDE, !enabled);
825 }
826
827 bool config_is_appindicator_label_enabled(const char *sid)
828 {
829         return sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
830 }
831
832 void config_set_appindicator_label_enabled(const char *sid, bool enabled)
833 {
834         sensor_set_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED, enabled);
835 }
836
837 GSettings *config_get_GSettings(void)
838 {
839         return settings;
840 }
841
842 bool config_is_lmsensor_enabled(void)
843 {
844         return get_bool(KEY_PROVIDER_LMSENSORS_ENABLED);
845 }
846
847 bool config_is_gtop2_enabled(void)
848 {
849         return get_bool(KEY_PROVIDER_GTOP2_ENABLED);
850 }
851
852 bool config_is_udisks2_enabled(void)
853 {
854         return get_bool(KEY_PROVIDER_UDISKS2_ENABLED);
855 }
856
857 bool config_is_hddtemp_enabled(void)
858 {
859         return get_bool(KEY_PROVIDER_HDDTEMP_ENABLED);
860 }
861
862 bool config_is_libatasmart_enabled(void)
863 {
864         return get_bool(KEY_PROVIDER_LIBATASMART_ENABLED);
865 }
866
867 bool config_is_nvctrl_enabled(void)
868 {
869         return get_bool(KEY_PROVIDER_NVCTRL_ENABLED);
870 }
871
872 bool config_is_atiadlsdk_enabled(void)
873 {
874         return get_bool(KEY_PROVIDER_ATIADLSDK_ENABLED);
875 }
876
877 void config_set_lmsensor_enable(bool b)
878 {
879         set_bool(KEY_PROVIDER_LMSENSORS_ENABLED, b);
880 }
881
882 void config_set_nvctrl_enable(bool b)
883 {
884         set_bool(KEY_PROVIDER_NVCTRL_ENABLED, b);
885 }
886
887 void config_set_atiadlsdk_enable(bool b)
888 {
889         set_bool(KEY_PROVIDER_ATIADLSDK_ENABLED, b);
890 }
891
892 void config_set_gtop2_enable(bool b)
893 {
894         set_bool(KEY_PROVIDER_GTOP2_ENABLED, b);
895 }
896
897 void config_set_hddtemp_enable(bool b)
898 {
899         set_bool(KEY_PROVIDER_HDDTEMP_ENABLED, b);
900 }
901
902 void config_set_libatasmart_enable(bool b)
903 {
904         set_bool(KEY_PROVIDER_LIBATASMART_ENABLED, b);
905 }
906
907 void config_set_udisks2_enable(bool b)
908 {
909         set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
910 }
911
912 int config_get_sensor_unit(void)
913 {
914         return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
915 }