3bd02f4532c0a4848dbf6615a49706234af1eb66
[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 GSettings *settings;
123
124 static char *user_dir;
125
126 static GKeyFile *key_file;
127
128 static char *sensor_config_path;
129
130 static void (*slog_enabled_cbk)(void *);
131
132 static char *get_string(const char *key)
133 {
134         return g_settings_get_string(settings, key);
135 }
136
137 static void set_string(const char *key, const char *str)
138 {
139         g_settings_set_string(settings, key, str);
140 }
141
142 static void set_bool(const char *k, bool b)
143 {
144         g_settings_set_boolean(settings, k, b);
145 }
146
147 static bool get_bool(const char *k)
148 {
149         return g_settings_get_boolean(settings, k);
150 }
151
152 static void set_int(const char *k, int i)
153 {
154         g_settings_set_int(settings, k, i);
155 }
156
157 static double get_double(const char *k)
158 {
159         return g_settings_get_double(settings, k);
160 }
161
162 static void set_double(const char *k, double d)
163 {
164         g_settings_set_double(settings, k, d);
165 }
166
167 static int get_int(const char *k)
168 {
169         return g_settings_get_int(settings, k);
170 }
171
172 char *config_get_notif_script(void)
173 {
174         char *str;
175
176         str =  get_string(KEY_NOTIFICATION_SCRIPT);
177         if (str && !strlen(str)) {
178                 free(str);
179                 str = NULL;
180         }
181
182         return str;
183 }
184
185 void config_set_notif_script(const char *str)
186 {
187         if (str && strlen(str) > 0)
188                 set_string(KEY_NOTIFICATION_SCRIPT, str);
189         else
190                 set_string(KEY_NOTIFICATION_SCRIPT, "");
191 }
192
193 static struct color *get_background_color(void)
194 {
195         char *scolor;
196         struct color *c;
197
198         scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR);
199
200         c = str_to_color(scolor);
201         free(scolor);
202
203         if (!c)
204                 return color_new(1, 1, 1);
205
206         return c;
207 }
208
209 static struct color *get_foreground_color(void)
210 {
211         char *scolor;
212         struct color *c;
213
214         scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR);
215
216         c = str_to_color(scolor);
217         free(scolor);
218
219         if (!c)
220                 return color_new(0, 0, 0);
221
222         return c;
223 }
224
225 static bool is_alpha_channel_enabled(void)
226 {
227         return get_bool(KEY_ALPHA_CHANNEL_ENABLED);
228 }
229
230 static void set_alpha_channeld_enabled(bool b)
231 {
232         set_bool(KEY_ALPHA_CHANNEL_ENABLED, b);
233 }
234
235 static enum sensorlist_position get_sensorlist_position(void)
236 {
237         return get_int(KEY_INTERFACE_SENSORLIST_POSITION);
238 }
239
240 static void set_sensorlist_position(enum sensorlist_position pos)
241 {
242         set_int(KEY_INTERFACE_SENSORLIST_POSITION, pos);
243 }
244
245 static double get_graph_background_alpha(void)
246 {
247         return get_double(KEY_GRAPH_BACKGROUND_ALPHA);
248 }
249
250 static void set_graph_background_alpha(double alpha)
251 {
252         set_double(KEY_GRAPH_BACKGROUND_ALPHA, alpha);
253 }
254
255 static void set_background_color(const struct color *color)
256 {
257         char *scolor;
258
259         scolor = color_to_str(color);
260         if (!scolor)
261                 scolor = strdup(DEFAULT_GRAPH_BACKGROUND_COLOR);
262
263         set_string(KEY_GRAPH_BACKGROUND_COLOR, scolor);
264
265         free(scolor);
266 }
267
268 static void set_foreground_color(const struct color *color)
269 {
270         char *str;
271
272         str = color_to_str(color);
273         if (!str)
274                 str = strdup(DEFAULT_GRAPH_FOREGROUND_COLOR);
275
276         set_string(KEY_GRAPH_FOREGROUND_COLOR, str);
277
278         free(str);
279 }
280
281 bool is_slog_enabled(void)
282 {
283         return get_bool(KEY_SLOG_ENABLED);
284 }
285
286 static void set_slog_enabled(bool enabled)
287 {
288         set_bool(KEY_SLOG_ENABLED, enabled);
289 }
290
291 static void slog_enabled_changed_cbk(GSettings *settings,
292                                      gchar *key,
293                                      gpointer data)
294 {
295         if (slog_enabled_cbk)
296                 slog_enabled_cbk(data);
297 }
298
299 void config_set_slog_enabled_changed_cbk(void (*cbk)(void *), void *data)
300 {
301         log_fct_enter();
302
303         slog_enabled_cbk = cbk;
304
305         g_signal_connect_after(settings,
306                                "changed::slog-enabled",
307                                G_CALLBACK(slog_enabled_changed_cbk),
308                                data);
309
310         log_fct_exit();
311 }
312
313 int config_get_slog_interval(void)
314 {
315         return get_int(KEY_SLOG_INTERVAL);
316 }
317
318 static void set_slog_interval(int interval)
319 {
320         if (interval <= 0)
321                 interval = 300;
322
323         set_int(KEY_SLOG_INTERVAL, interval);
324 }
325
326 static bool is_window_decoration_enabled(void)
327 {
328         return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
329 }
330
331 static bool is_window_keep_below_enabled(void)
332 {
333         return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
334 }
335
336 static void set_window_decoration_enabled(bool enabled)
337 {
338         set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
339 }
340
341 static void set_window_keep_below_enabled(bool enabled)
342 {
343         set_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED, enabled);
344 }
345
346 bool config_is_smooth_curves_enabled(void)
347 {
348         return get_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED);
349 }
350
351 void config_set_smooth_curves_enabled(bool b)
352 {
353         set_bool(KEY_GRAPH_SMOOTH_CURVES_ENABLED, b);
354 }
355
356
357 static void init(void)
358 {
359         log_fct_enter();
360
361         if (!settings)
362                 settings = g_settings_new("psensor");
363
364         log_fct_exit();
365 }
366
367 void config_cleanup(void)
368 {
369         config_sync();
370
371         if (settings) {
372                 g_settings_sync();
373                 g_object_unref(settings);
374                 settings = NULL;
375         }
376
377         if (user_dir) {
378                 free(user_dir);
379                 user_dir = NULL;
380         }
381
382         if (key_file) {
383                 g_key_file_free(key_file);
384                 key_file = NULL;
385         }
386
387         if (sensor_config_path) {
388                 free(sensor_config_path);
389                 sensor_config_path = NULL;
390         }
391
392         slog_enabled_cbk = NULL;
393 }
394
395 struct config *config_load(void)
396 {
397         struct config *c;
398
399         init();
400
401         c = malloc(sizeof(struct config));
402
403         c->graph_bgcolor = get_background_color();
404         c->graph_fgcolor = get_foreground_color();
405         c->graph_bg_alpha = get_graph_background_alpha();
406         c->alpha_channel_enabled = is_alpha_channel_enabled();
407         c->sensorlist_position = get_sensorlist_position();
408         c->window_decoration_enabled = is_window_decoration_enabled();
409         c->window_keep_below_enabled = is_window_keep_below_enabled();
410         c->slog_enabled = is_slog_enabled();
411         c->slog_interval = config_get_slog_interval();
412
413         c->sensor_update_interval
414             = get_int(KEY_SENSOR_UPDATE_INTERVAL);
415         if (c->sensor_update_interval < 1)
416                 c->sensor_update_interval = 1;
417
418         c->graph_update_interval = get_int(KEY_GRAPH_UPDATE_INTERVAL);
419         if (c->graph_update_interval < 1)
420                 c->graph_update_interval = 1;
421
422         c->graph_monitoring_duration = get_int(KEY_GRAPH_MONITORING_DURATION);
423
424         if (c->graph_monitoring_duration < 1)
425                 c->graph_monitoring_duration = 10;
426
427         c->menu_bar_disabled = get_bool(KEY_INTERFACE_MENU_BAR_DISABLED);
428
429         c->unity_launcher_count_disabled
430                 = get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
431
432         c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
433
434         c->window_restore_enabled
435                 = get_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED);
436
437         c->window_x = get_int(KEY_INTERFACE_WINDOW_X);
438         c->window_y = get_int(KEY_INTERFACE_WINDOW_Y);
439         c->window_w = get_int(KEY_INTERFACE_WINDOW_W);
440         c->window_h = get_int(KEY_INTERFACE_WINDOW_H);
441
442         c->window_divider_pos = get_int(KEY_INTERFACE_WINDOW_DIVIDER_POS);
443
444         if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
445                 c->window_w = 800;
446                 c->window_h = 200;
447         }
448
449         c->temperature_unit = get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
450
451         c->sensor_values_max_length = compute_values_max_length(c);
452
453         return c;
454 }
455
456 void config_save(const struct config *c)
457 {
458         set_alpha_channeld_enabled(c->alpha_channel_enabled);
459         set_background_color(c->graph_bgcolor);
460         set_foreground_color(c->graph_fgcolor);
461         set_graph_background_alpha(c->graph_bg_alpha);
462         set_sensorlist_position(c->sensorlist_position);
463         set_window_decoration_enabled(c->window_decoration_enabled);
464         set_window_keep_below_enabled(c->window_keep_below_enabled);
465         set_slog_enabled(c->slog_enabled);
466         set_slog_interval(c->slog_interval);
467
468         set_int(KEY_GRAPH_UPDATE_INTERVAL, c->graph_update_interval);
469
470         set_int(KEY_GRAPH_MONITORING_DURATION, c->graph_monitoring_duration);
471
472         set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
473
474         set_bool(KEY_INTERFACE_MENU_BAR_DISABLED, c->menu_bar_disabled);
475
476         set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
477                  c->unity_launcher_count_disabled);
478
479         set_bool(KEY_INTERFACE_HIDE_ON_STARTUP, c->hide_on_startup);
480
481         set_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
482                  c->window_restore_enabled);
483
484         set_int(KEY_INTERFACE_WINDOW_X, c->window_x);
485         set_int(KEY_INTERFACE_WINDOW_Y, c->window_y);
486         set_int(KEY_INTERFACE_WINDOW_W, c->window_w);
487         set_int(KEY_INTERFACE_WINDOW_H, c->window_h);
488
489         set_int(KEY_INTERFACE_WINDOW_DIVIDER_POS, c->window_divider_pos);
490
491         set_int(KEY_INTERFACE_TEMPERATURE_UNIT, c->temperature_unit);
492 }
493
494 const char *get_psensor_user_dir(void)
495 {
496         const char *home;
497
498         log_fct_enter();
499
500         if (!user_dir) {
501                 home = getenv("HOME");
502
503                 if (!home)
504                         return NULL;
505
506                 user_dir = path_append(home, ".psensor");
507
508                 if (mkdir(user_dir, 0700) == -1 && errno != EEXIST) {
509                         log_err(_("Failed to create the directory %s: %s"),
510                                 user_dir,
511                                 strerror(errno));
512
513                         free(user_dir);
514                         user_dir = NULL;
515                 }
516         }
517
518         log_fct_exit();
519
520         return user_dir;
521 }
522
523 static const char *get_sensor_config_path(void)
524 {
525         const char *dir;
526
527         if (!sensor_config_path) {
528                 dir = get_psensor_user_dir();
529
530                 if (dir)
531                         sensor_config_path = path_append(dir, "psensor.cfg");
532         }
533
534         return sensor_config_path;
535 }
536
537 static GKeyFile *get_sensor_key_file(void)
538 {
539         int ret;
540         GError *err;
541         const char *path;
542
543         if (!key_file) {
544                 path = get_sensor_config_path();
545
546                 key_file = g_key_file_new();
547
548                 err = NULL;
549                 ret = g_key_file_load_from_file(key_file,
550                                                 path,
551                                                 G_KEY_FILE_KEEP_COMMENTS
552                                                 | G_KEY_FILE_KEEP_TRANSLATIONS,
553                                                 &err);
554
555                 if (!ret)
556                         log_warn(_("Failed to load configuration file %s: %s"),
557                                  path,
558                                  err->message);
559         }
560
561         return key_file;
562 }
563
564 static void save_sensor_key_file(void)
565 {
566         GKeyFile *kfile;
567         const char *path;
568         char *data;
569
570         log_fct_enter();
571
572         kfile = get_sensor_key_file();
573
574         data = g_key_file_to_data(kfile, NULL, NULL);
575
576         path = get_sensor_config_path();
577
578         if (!g_file_set_contents(path, data, -1, NULL))
579                 log_err(_("Failed to save configuration file %s."), path);
580
581         free(data);
582
583         log_fct_exit();
584 }
585
586 void config_sync(void)
587 {
588         log_fct_enter();
589         if (settings)
590                 g_settings_sync();
591         save_sensor_key_file();
592         log_fct_exit();
593 }
594
595 static void sensor_set_str(const char *sid, const char *att, const char *str)
596 {
597         GKeyFile *kfile;
598
599         kfile = get_sensor_key_file();
600         g_key_file_set_string(kfile, sid, att, str);
601 }
602
603 static char *sensor_get_str(const char *sid, const char *att)
604 {
605         GKeyFile *kfile;
606
607         kfile = get_sensor_key_file();
608         return g_key_file_get_string(kfile, sid, att, NULL);
609 }
610
611 static bool sensor_get_double(const char *sid, const char *att, double *d)
612 {
613         GKeyFile *kfile;
614         GError *err;
615         double v;
616
617         kfile = get_sensor_key_file();
618
619         err = NULL;
620         v = g_key_file_get_double(kfile, sid, att, &err);
621
622         if (err)
623                 return false;
624
625         *d = v;
626         return true;
627 }
628
629 static bool sensor_get_bool(const char *sid, const char *att)
630 {
631         GKeyFile *kfile;
632
633         kfile = get_sensor_key_file();
634         return g_key_file_get_boolean(kfile, sid, att, NULL);
635 }
636
637 static void sensor_set_bool(const char *sid, const char *att, bool enabled)
638 {
639         GKeyFile *kfile;
640
641         kfile = get_sensor_key_file();
642
643         g_key_file_set_boolean(kfile, sid, att, enabled);
644 }
645
646 static int sensor_get_int(const char *sid, const char *att)
647 {
648         GKeyFile *kfile;
649
650         kfile = get_sensor_key_file();
651         return g_key_file_get_integer(kfile, sid, att, NULL);
652 }
653
654 static void sensor_set_int(const char *sid, const char *att, int i)
655 {
656         GKeyFile *kfile;
657
658         kfile = get_sensor_key_file();
659
660         g_key_file_set_integer(kfile, sid, att, i);
661 }
662
663 char *config_get_sensor_name(const char *sid)
664 {
665         return sensor_get_str(sid, ATT_SENSOR_NAME);
666 }
667
668 void config_set_sensor_name(const char *sid, const char *name)
669 {
670         sensor_set_str(sid, ATT_SENSOR_NAME, name);
671 }
672
673 void config_set_sensor_color(const char *sid, const GdkRGBA *color)
674 {
675         gchar *str;
676
677         str = gdk_rgba_to_string(color);
678
679         sensor_set_str(sid, ATT_SENSOR_COLOR, str);
680
681         g_free(str);
682 }
683
684 static const char *next_default_color(void)
685 {
686         /* copied from the default colors of the gtk color color
687          * chooser. */
688         const char *default_colors[27] = {
689                 "#ef2929",  /* Scarlet Red */
690                 "#fcaf3e",  /* Orange */
691                 "#fce94f",  /* Butter */
692                 "#8ae234",  /* Chameleon */
693                 "#729fcf",  /* Sky Blue */
694                 "#ad7fa8",  /* Plum */
695                 "#e9b96e",  /* Chocolate */
696                 "#888a85",  /* Aluminum 1 */
697                 "#eeeeec",  /* Aluminum 2 */
698                 "#cc0000",
699                 "#f57900",
700                 "#edd400",
701                 "#73d216",
702                 "#3465a4",
703                 "#75507b",
704                 "#c17d11",
705                 "#555753",
706                 "#d3d7cf",
707                 "#a40000",
708                 "#ce5c00",
709                 "#c4a000",
710                 "#4e9a06",
711                 "#204a87",
712                 "#5c3566",
713                 "#8f5902",
714                 "#2e3436",
715                 "#babdb6"
716         };
717         static int next_idx;
718         const char *c;
719
720         c = default_colors[next_idx % 27];
721
722         next_idx++;
723
724         return c;
725 }
726
727 GdkRGBA *config_get_sensor_color(const char *sid)
728 {
729         GdkRGBA rgba;
730         char *str;
731         gboolean ret;
732
733         str = sensor_get_str(sid, ATT_SENSOR_COLOR);
734
735         if (str) {
736                 ret = gdk_rgba_parse(&rgba, str);
737                 free(str);
738         }
739
740         if (!str || !ret) {
741                 gdk_rgba_parse(&rgba, next_default_color());
742                 config_set_sensor_color(sid, &rgba);
743         }
744
745         return gdk_rgba_copy(&rgba);
746 }
747
748 bool config_is_sensor_graph_enabled(const char *sid)
749 {
750         return sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED);
751 }
752
753 void config_set_sensor_graph_enabled(const char *sid, bool enabled)
754 {
755         sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
756 }
757
758 bool config_get_sensor_alarm_high_threshold(const char *sid, double *v)
759 {
760         return sensor_get_double(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, v);
761 }
762
763 void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
764 {
765         sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
766 }
767
768 bool config_get_sensor_alarm_low_threshold(const char *sid, double *v)
769 {
770         return sensor_get_double(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, v);
771 }
772
773 void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
774 {
775         sensor_set_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, threshold);
776 }
777
778 bool config_is_appindicator_enabled(const char *sid)
779 {
780         return !sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_MENU_DISABLED);
781 }
782
783 void config_set_appindicator_enabled(const char *sid, bool enabled)
784 {
785         sensor_set_bool(sid,
786                         ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
787                         !enabled);
788 }
789
790 int config_get_sensor_position(const char *sid)
791 {
792         return sensor_get_int(sid, ATT_SENSOR_POSITION);
793 }
794
795 void config_set_sensor_position(const char *sid, int pos)
796 {
797         sensor_set_int(sid, ATT_SENSOR_POSITION, pos);
798 }
799
800 bool config_get_sensor_alarm_enabled(const char *sid)
801 {
802         return sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED);
803 }
804
805 void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
806 {
807         sensor_set_bool(sid, ATT_SENSOR_ALARM_ENABLED, enabled);
808 }
809
810 bool config_is_sensor_enabled(const char *sid)
811 {
812         return !sensor_get_bool(sid, ATT_SENSOR_HIDE);
813 }
814
815 void config_set_sensor_enabled(const char *sid, bool enabled)
816 {
817         sensor_set_bool(sid, ATT_SENSOR_HIDE, !enabled);
818 }
819
820 bool config_is_appindicator_label_enabled(const char *sid)
821 {
822         return sensor_get_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
823 }
824
825 void config_set_appindicator_label_enabled(const char *sid, bool enabled)
826 {
827         sensor_set_bool(sid, ATT_SENSOR_APPINDICATOR_LABEL_ENABLED, enabled);
828 }
829
830 GSettings *config_get_GSettings(void)
831 {
832         return settings;
833 }
834
835 bool config_is_lmsensor_enabled(void)
836 {
837         return get_bool(KEY_PROVIDER_LMSENSORS_ENABLED);
838 }
839
840 bool config_is_gtop2_enabled(void)
841 {
842         return get_bool(KEY_PROVIDER_GTOP2_ENABLED);
843 }
844
845 bool config_is_udisks2_enabled(void)
846 {
847         return get_bool(KEY_PROVIDER_UDISKS2_ENABLED);
848 }
849
850 bool config_is_hddtemp_enabled(void)
851 {
852         return get_bool(KEY_PROVIDER_HDDTEMP_ENABLED);
853 }
854
855 bool config_is_libatasmart_enabled(void)
856 {
857         return get_bool(KEY_PROVIDER_LIBATASMART_ENABLED);
858 }
859
860 bool config_is_nvctrl_enabled(void)
861 {
862         return get_bool(KEY_PROVIDER_NVCTRL_ENABLED);
863 }
864
865 bool config_is_atiadlsdk_enabled(void)
866 {
867         return get_bool(KEY_PROVIDER_ATIADLSDK_ENABLED);
868 }
869
870 void config_set_lmsensor_enable(bool b)
871 {
872         set_bool(KEY_PROVIDER_LMSENSORS_ENABLED, b);
873 }
874
875 void config_set_nvctrl_enable(bool b)
876 {
877         set_bool(KEY_PROVIDER_NVCTRL_ENABLED, b);
878 }
879
880 void config_set_atiadlsdk_enable(bool b)
881 {
882         set_bool(KEY_PROVIDER_ATIADLSDK_ENABLED, b);
883 }
884
885 void config_set_gtop2_enable(bool b)
886 {
887         set_bool(KEY_PROVIDER_GTOP2_ENABLED, b);
888 }
889
890 void config_set_hddtemp_enable(bool b)
891 {
892         set_bool(KEY_PROVIDER_HDDTEMP_ENABLED, b);
893 }
894
895 void config_set_libatasmart_enable(bool b)
896 {
897         set_bool(KEY_PROVIDER_LIBATASMART_ENABLED, b);
898 }
899
900 void config_set_udisks2_enable(bool b)
901 {
902         set_bool(KEY_PROVIDER_UDISKS2_ENABLED, b);
903 }
904
905 int config_get_sensor_unit(void)
906 {
907         return get_int(KEY_INTERFACE_TEMPERATURE_UNIT);
908 }