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