added gsettings schema
[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 <pio.h>
34 #include <plog.h>
35
36 static const char *ATT_SENSOR_ALARM_ENABLED = "alarm_enabled";
37 static const char *ATT_SENSOR_ALARM_HIGH_THRESHOLD = "alarm_high_threshold";
38 static const char *ATT_SENSOR_ALARM_LOW_THRESHOLD = "alarm_low_threshold";
39 static const char *ATT_SENSOR_COLOR = "color";
40 static const char *ATT_SENSOR_GRAPH_ENABLED = "graph_enabled";
41 static const char *ATT_SENSOR_NAME = "name";
42 static const char *ATT_SENSOR_APPINDICATOR_MENU_DISABLED
43 = "appindicator_menu_disabled";
44 static const char *ATT_SENSOR_APPINDICATOR_LABEL_ENABLED
45 = "appindicator_label_enabled";
46 static const char *ATT_SENSOR_POSITION = "position";
47
48 static const char *KEY_SENSOR_UPDATE_INTERVAL
49 = "/apps/psensor/sensor/update_interval";
50
51 static const char *KEY_GRAPH_UPDATE_INTERVAL
52 = "/apps/psensor/graph/update_interval";
53
54 static const char *KEY_GRAPH_MONITORING_DURATION
55 = "/apps/psensor/graph/monitoring_duration";
56
57 static const char *KEY_GRAPH_BACKGROUND_COLOR
58 = "/apps/psensor/graph/background_color";
59
60 static const char *DEFAULT_GRAPH_BACKGROUND_COLOR = "#e8f4e8f4a8f5";
61
62 static const char *KEY_GRAPH_BACKGROUND_ALPHA
63 = "/apps/psensor/graph/background_alpha";
64
65 static const char *KEY_GRAPH_FOREGROUND_COLOR
66 = "/apps/psensor/graph/foreground_color";
67 static const char *DEFAULT_GRAPH_FOREGROUND_COLOR = "#000000000000";
68
69 static const char *KEY_ALPHA_CHANNEL_ENABLED
70 = "/apps/psensor/graph/alpha_channel_enabled";
71
72 static const char *KEY_INTERFACE_SENSORLIST_POSITION
73 = "/apps/psensor/interface/sensorlist_position";
74
75 static const char *KEY_INTERFACE_WINDOW_DECORATION_DISABLED
76 = "/apps/psensor/interface/window_decoration_disabled";
77
78 static const char *KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED
79 = "/apps/psensor/interface/window_keep_below_enabled";
80
81 static const char *KEY_INTERFACE_MENU_BAR_DISABLED
82 = "/apps/psensor/interface/menu_bar_disabled";
83
84 static const char *KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED
85 = "/apps/psensor/interface/unity_launcher_count_disabled";
86
87 static const char *KEY_INTERFACE_HIDE_ON_STARTUP
88 = "/apps/psensor/interface/hide_on_startup";
89
90 static const char *KEY_INTERFACE_WINDOW_RESTORE_ENABLED
91 = "/apps/psensor/interface/window_restore_enabled";
92
93 static const char *KEY_INTERFACE_WINDOW_X = "/apps/psensor/interface/window_x";
94 static const char *KEY_INTERFACE_WINDOW_Y = "/apps/psensor/interface/window_y";
95 static const char *KEY_INTERFACE_WINDOW_W = "/apps/psensor/interface/window_w";
96 static const char *KEY_INTERFACE_WINDOW_H = "/apps/psensor/interface/window_h";
97
98 static const char *KEY_INTERFACE_WINDOW_DIVIDER_POS
99 = "/apps/psensor/interface/window_divider_pos";
100
101 static const char *KEY_INTERFACE_TEMPERATURE_UNIT
102 = "/apps/psensor/interface/temperature_unit";
103
104 static const char *KEY_SLOG_ENABLED = "/apps/psensor/slog/enabled";
105 static const char *KEY_SLOG_INTERVAL = "/apps/psensor/slog/interval";
106
107 static const char *KEY_NOTIFICATION_SCRIPT = "/apps/psensor/notif_script";
108
109 static GConfClient *client;
110
111 static char *user_dir;
112
113 static GKeyFile *key_file;
114
115 static char *sensor_config_path;
116
117 static char *get_string(const char *key, const char *default_value)
118 {
119         char *value;
120
121         value = gconf_client_get_string(client, key, NULL);
122
123         if (!value) {
124                 value = strdup(default_value);
125                 gconf_client_set_string(client, key, default_value, NULL);
126         }
127
128         return value;
129 }
130
131 char *config_get_notif_script()
132 {
133         char *str;
134
135         str =  gconf_client_get_string(client, KEY_NOTIFICATION_SCRIPT, NULL);
136         if (str && !strlen(str)) {
137                 free(str);
138                 str = NULL;
139         }
140
141         return str;
142 }
143
144 void config_set_notif_script(const char *str)
145 {
146         if (str && strlen(str) > 0)
147                 gconf_client_set_string(client,
148                                         KEY_NOTIFICATION_SCRIPT, str, NULL);
149         else
150                 gconf_client_set_string(client,
151                                         KEY_NOTIFICATION_SCRIPT, "", NULL);
152 }
153
154 static struct color *get_background_color()
155 {
156         char *scolor;
157         struct color *c;
158
159         scolor = get_string(KEY_GRAPH_BACKGROUND_COLOR,
160                             DEFAULT_GRAPH_BACKGROUND_COLOR);
161
162         c = str_to_color(scolor);
163         free(scolor);
164
165         if (!c)
166                 return color_new(0xffff, 0xffff, 0xffff);
167
168         return c;
169 }
170
171 static struct color *get_foreground_color()
172 {
173         char *scolor;
174         struct color *c;
175
176         scolor = get_string(KEY_GRAPH_FOREGROUND_COLOR,
177                             DEFAULT_GRAPH_FOREGROUND_COLOR);
178
179         c = str_to_color(scolor);
180         free(scolor);
181
182         if (!c)
183                 return color_new(0x0000, 0x0000, 0x0000);
184
185         return c;
186 }
187
188 static bool is_alpha_channel_enabled()
189 {
190         return gconf_client_get_bool(client, KEY_ALPHA_CHANNEL_ENABLED, NULL);
191 }
192
193 static enum sensorlist_position get_sensorlist_position()
194 {
195         return gconf_client_get_int(client,
196                                     KEY_INTERFACE_SENSORLIST_POSITION, NULL);
197 }
198
199 static void set_sensorlist_position(enum sensorlist_position pos)
200 {
201         gconf_client_set_int(client,
202                              KEY_INTERFACE_SENSORLIST_POSITION, pos, NULL);
203 }
204
205 static double get_graph_background_alpha()
206 {
207         double a;
208
209         a = gconf_client_get_float(client, KEY_GRAPH_BACKGROUND_ALPHA, NULL);
210         if (a == 0)
211                 gconf_client_set_float(client,
212                                        KEY_GRAPH_BACKGROUND_ALPHA, 1.0, NULL);
213         return a;
214 }
215
216 static void set_graph_background_alpha(double alpha)
217 {
218         gconf_client_set_float(client, KEY_GRAPH_BACKGROUND_ALPHA, alpha, NULL);
219 }
220
221 static void set_background_color(const struct color *color)
222 {
223         char *scolor;
224
225         scolor = color_to_str(color);
226         if (!scolor)
227                 scolor = strdup(DEFAULT_GRAPH_BACKGROUND_COLOR);
228
229         gconf_client_set_string(client,
230                                 KEY_GRAPH_BACKGROUND_COLOR, scolor, NULL);
231
232         free(scolor);
233 }
234
235 static void set_foreground_color(const struct color *color)
236 {
237         char *str;
238
239         str = color_to_str(color);
240         if (!str)
241                 str = strdup(DEFAULT_GRAPH_FOREGROUND_COLOR);
242
243         gconf_client_set_string(client, KEY_GRAPH_FOREGROUND_COLOR, str, NULL);
244
245         free(str);
246 }
247
248 bool is_slog_enabled()
249 {
250         return gconf_client_get_bool(client, KEY_SLOG_ENABLED, NULL);
251 }
252
253 static void set_slog_enabled(bool enabled)
254 {
255         gconf_client_set_bool(client, KEY_SLOG_ENABLED, enabled, NULL);
256 }
257
258 void config_slog_enabled_notify_add(GConfClientNotifyFunc cbk, void *data)
259 {
260         log_debug("config_slog_enabled_notify_add");
261         gconf_client_add_dir(client,
262                              KEY_SLOG_ENABLED,
263                              GCONF_CLIENT_PRELOAD_NONE,
264                              NULL);
265         gconf_client_notify_add(client,
266                                 KEY_SLOG_ENABLED,
267                                 cbk,
268                                 data,
269                                 NULL,
270                                 NULL);
271 }
272
273 int config_get_slog_interval()
274 {
275         int res;
276
277         res = gconf_client_get_int(client, KEY_SLOG_INTERVAL, NULL);
278
279         if (res <= 0)
280                 return 300;
281         else
282                 return res;
283 }
284
285 static void set_slog_interval(int interval)
286 {
287         if (interval <= 0)
288                 interval = 300;
289
290         gconf_client_set_int(client, KEY_SLOG_INTERVAL, interval, NULL);
291 }
292
293 static bool is_window_decoration_enabled()
294 {
295         return !gconf_client_get_bool(client,
296                                       KEY_INTERFACE_WINDOW_DECORATION_DISABLED,
297                                       NULL);
298 }
299
300 static bool is_window_keep_below_enabled()
301 {
302         return gconf_client_get_bool(client,
303                                      KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED,
304                                      NULL);
305 }
306
307 static void set_window_decoration_enabled(bool enabled)
308 {
309         gconf_client_set_bool
310                 (client,
311                  KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled, NULL);
312 }
313
314 static void set_window_keep_below_enabled(bool enabled)
315 {
316         gconf_client_set_bool(client,
317                               KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED,
318                               enabled, NULL);
319 }
320
321 /*
322  * Initializes the GConf client.
323  */
324 static void init()
325 {
326         if (!client)
327                 client = gconf_client_get_default();
328 }
329
330 void config_cleanup()
331 {
332         if (client) {
333                 g_object_unref(client);
334                 client = NULL;
335         }
336
337         config_sync();
338
339         if (user_dir) {
340                 free(user_dir);
341                 user_dir = NULL;
342         }
343
344         if (key_file) {
345                 g_key_file_free(key_file);
346                 key_file = NULL;
347         }
348
349         if (sensor_config_path) {
350                 free(sensor_config_path);
351                 sensor_config_path = NULL;
352         }
353 }
354
355 struct config *config_load()
356 {
357         struct config *c;
358
359         init();
360
361         c = malloc(sizeof(struct config));
362
363         c->graph_bgcolor = get_background_color();
364         c->graph_fgcolor = get_foreground_color();
365         c->graph_bg_alpha = get_graph_background_alpha();
366         c->alpha_channel_enabled = is_alpha_channel_enabled();
367         c->sensorlist_position = get_sensorlist_position();
368         c->window_decoration_enabled = is_window_decoration_enabled();
369         c->window_keep_below_enabled = is_window_keep_below_enabled();
370         c->slog_enabled = is_slog_enabled();
371         c->slog_interval = config_get_slog_interval();
372
373         c->sensor_update_interval
374             = gconf_client_get_int(client, KEY_SENSOR_UPDATE_INTERVAL, NULL);
375         if (c->sensor_update_interval < 1)
376                 c->sensor_update_interval = 1;
377
378         c->graph_update_interval
379             = gconf_client_get_int(client, KEY_GRAPH_UPDATE_INTERVAL, NULL);
380         if (c->graph_update_interval < 1)
381                 c->graph_update_interval = 1;
382
383         c->graph_monitoring_duration
384             = gconf_client_get_int(client, KEY_GRAPH_MONITORING_DURATION, NULL);
385
386         if (c->graph_monitoring_duration < 1)
387                 c->graph_monitoring_duration = 10;
388
389         c->sensor_values_max_length
390             =
391             (c->graph_monitoring_duration * 60) / c->sensor_update_interval;
392         if (c->sensor_values_max_length < 3)
393                 c->sensor_values_max_length = 3;
394
395         c->menu_bar_disabled
396                 = gconf_client_get_bool(client,
397                                         KEY_INTERFACE_MENU_BAR_DISABLED,
398                                         NULL);
399
400         c->unity_launcher_count_disabled
401                 = gconf_client_get_bool
402                 (client,
403                  KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
404                  NULL);
405
406         c->hide_on_startup
407                 = gconf_client_get_bool(client,
408                                         KEY_INTERFACE_HIDE_ON_STARTUP,
409                                         NULL);
410
411         c->window_restore_enabled
412                 = gconf_client_get_bool(client,
413                                         KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
414                                         NULL);
415
416         c->window_x = gconf_client_get_int(client,
417                                            KEY_INTERFACE_WINDOW_X,
418                                            NULL);
419         c->window_y = gconf_client_get_int(client,
420                                            KEY_INTERFACE_WINDOW_Y,
421                                            NULL);
422         c->window_w = gconf_client_get_int(client,
423                                            KEY_INTERFACE_WINDOW_W,
424                                            NULL);
425         c->window_h = gconf_client_get_int(client,
426                                            KEY_INTERFACE_WINDOW_H,
427                                            NULL);
428         c->window_divider_pos
429                 = gconf_client_get_int(client,
430                                        KEY_INTERFACE_WINDOW_DIVIDER_POS,
431                                        NULL);
432
433         if (!c->window_restore_enabled || !c->window_w || !c->window_h) {
434                 c->window_w = 800;
435                 c->window_h = 200;
436         }
437
438         c->temperature_unit = gconf_client_get_int
439                 (client, KEY_INTERFACE_TEMPERATURE_UNIT, NULL);
440
441         return c;
442 }
443
444 void config_save(const struct config *c)
445 {
446         set_background_color(c->graph_bgcolor);
447         set_foreground_color(c->graph_fgcolor);
448         set_graph_background_alpha(c->graph_bg_alpha);
449         set_sensorlist_position(c->sensorlist_position);
450         set_window_decoration_enabled(c->window_decoration_enabled);
451         set_window_keep_below_enabled(c->window_keep_below_enabled);
452         set_slog_enabled(c->slog_enabled);
453         set_slog_interval(c->slog_interval);
454
455         gconf_client_set_int(client,
456                              KEY_GRAPH_UPDATE_INTERVAL,
457                              c->graph_update_interval, NULL);
458
459         gconf_client_set_int(client,
460                              KEY_GRAPH_MONITORING_DURATION,
461                              c->graph_monitoring_duration, NULL);
462
463         gconf_client_set_int(client,
464                              KEY_SENSOR_UPDATE_INTERVAL,
465                              c->sensor_update_interval, NULL);
466
467         gconf_client_set_bool(client,
468                               KEY_INTERFACE_MENU_BAR_DISABLED,
469                               c->menu_bar_disabled, NULL);
470
471         gconf_client_set_bool(client,
472                               KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
473                               c->unity_launcher_count_disabled, NULL);
474
475         gconf_client_set_bool(client,
476                               KEY_INTERFACE_HIDE_ON_STARTUP,
477                               c->hide_on_startup, NULL);
478
479         gconf_client_set_bool(client,
480                               KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
481                               c->window_restore_enabled,
482                               NULL);
483
484         gconf_client_set_int(client, KEY_INTERFACE_WINDOW_X, c->window_x, NULL);
485         gconf_client_set_int(client, KEY_INTERFACE_WINDOW_Y, c->window_y, NULL);
486         gconf_client_set_int(client, KEY_INTERFACE_WINDOW_W, c->window_w, NULL);
487         gconf_client_set_int(client, KEY_INTERFACE_WINDOW_H, c->window_h, NULL);
488
489         gconf_client_set_int(client,
490                              KEY_INTERFACE_WINDOW_DIVIDER_POS,
491                              c->window_divider_pos,
492                              NULL);
493
494         gconf_client_set_int(client,
495                              KEY_INTERFACE_TEMPERATURE_UNIT,
496                              c->temperature_unit,
497                              NULL);
498 }
499
500 const char *get_psensor_user_dir()
501 {
502         const char *home;
503
504         log_fct_enter();
505
506         if (!user_dir) {
507                 home = getenv("HOME");
508
509                 if (!home)
510                         return NULL;
511
512                 user_dir = path_append(home, ".psensor");
513
514                 if (mkdir(user_dir, 0700) == -1 && errno != EEXIST) {
515                         log_err(_("Failed to create the directory %s: %s"),
516                                 user_dir,
517                                 strerror(errno));
518
519                         free(user_dir);
520                         user_dir = NULL;
521                 }
522         }
523
524         log_fct_exit();
525
526         return user_dir;
527 }
528
529 static const char *get_sensor_config_path()
530 {
531         const char *dir;
532
533         if (!sensor_config_path) {
534                 dir = get_psensor_user_dir();
535
536                 if (dir)
537                         sensor_config_path = path_append(dir, "psensor.cfg");
538         }
539
540         return sensor_config_path;
541 }
542
543 static GKeyFile *get_sensor_key_file()
544 {
545         int ret;
546         GError *err;
547         const char *path;
548
549         if (!key_file) {
550                 path = get_sensor_config_path();
551
552                 key_file = g_key_file_new();
553
554                 err = NULL;
555                 ret = g_key_file_load_from_file(key_file,
556                                                 path,
557                                                 G_KEY_FILE_KEEP_COMMENTS
558                                                 | G_KEY_FILE_KEEP_TRANSLATIONS,
559                                                 &err);
560
561                 if (!ret) {
562                         if (err->code == G_KEY_FILE_ERROR_NOT_FOUND) {
563                                 log_fct(_("The configuration file "
564                                           "does not exist."));
565                         } else {
566                                 log_err(_("Failed to parse configuration "
567                                           "file: %s"),
568                                         path);
569                         }
570                 }
571         }
572
573         return key_file;
574 }
575
576 static void save_sensor_key_file()
577 {
578         GKeyFile *kfile;
579         const char *path;
580         char *data;
581
582         log_fct_enter();
583
584         kfile = get_sensor_key_file();
585
586         data = g_key_file_to_data(kfile, NULL, NULL);
587
588         path = get_sensor_config_path();
589
590         if (!g_file_set_contents(path, data, -1, NULL))
591                 log_err(_("Failed to save configuration file %s."), path);
592
593         free(data);
594
595         log_fct_exit();
596 }
597
598 void config_sync()
599 {
600         log_fct_enter();
601         save_sensor_key_file();
602         log_fct_exit();
603 }
604
605 static void
606 config_sensor_set_string(const char *sid, const char *att, const char *str)
607 {
608         GKeyFile *kfile;
609
610         kfile = get_sensor_key_file();
611         g_key_file_set_string(kfile, sid, att, str);
612 }
613
614 static char *config_sensor_get_string(const char *sid, const char *att)
615 {
616         GKeyFile *kfile;
617
618         kfile = get_sensor_key_file();
619         return g_key_file_get_string(kfile, sid, att, NULL);
620 }
621
622 static bool config_sensor_get_bool(const char *sid, const char *att)
623 {
624
625         GKeyFile *kfile;
626
627         kfile = get_sensor_key_file();
628         return g_key_file_get_boolean(kfile, sid, att, NULL);
629 }
630
631 static void
632 config_sensor_set_bool(const char *sid, const char *att, bool enabled)
633 {
634         GKeyFile *kfile;
635
636         kfile = get_sensor_key_file();
637
638         g_key_file_set_boolean(kfile, sid, att, enabled);
639 }
640
641 static int config_sensor_get_int(const char *sid, const char *att)
642 {
643
644         GKeyFile *kfile;
645
646         kfile = get_sensor_key_file();
647         return g_key_file_get_integer(kfile, sid, att, NULL);
648 }
649
650 static void
651 config_sensor_set_int(const char *sid, const char *att, int i)
652 {
653         GKeyFile *kfile;
654
655         kfile = get_sensor_key_file();
656
657         g_key_file_set_integer(kfile, sid, att, i);
658 }
659
660 char *config_get_sensor_name(const char *sid)
661 {
662         return config_sensor_get_string(sid, ATT_SENSOR_NAME);
663 }
664
665 void config_set_sensor_name(const char *sid, const char *name)
666 {
667         config_sensor_set_string(sid, ATT_SENSOR_NAME, name);
668 }
669
670 void config_set_sensor_color(const char *sid, const struct color *color)
671 {
672         char *scolor;
673
674         scolor = color_to_str(color);
675
676         config_sensor_set_string(sid, ATT_SENSOR_COLOR, scolor);
677
678         free(scolor);
679 }
680
681 struct color *
682 config_get_sensor_color(const char *sid, const struct color *dft)
683 {
684         char *scolor;
685         struct color *color;
686
687         scolor = config_sensor_get_string(sid, ATT_SENSOR_COLOR);
688
689         if (scolor)
690                 color = str_to_color(scolor);
691         else
692                 color = NULL;
693
694         if (!color) {
695                 color = color_new(dft->red, dft->green, dft->blue);
696                 config_set_sensor_color(sid, color);
697         }
698
699         free(scolor);
700
701         return color;
702 }
703
704 bool config_is_sensor_enabled(const char *sid)
705 {
706         return config_sensor_get_bool(sid, ATT_SENSOR_GRAPH_ENABLED);
707 }
708
709 void config_set_sensor_enabled(const char *sid, bool enabled)
710 {
711         config_sensor_set_bool(sid, ATT_SENSOR_GRAPH_ENABLED, enabled);
712 }
713
714 int config_get_sensor_alarm_high_threshold(const char *sid)
715 {
716         return config_sensor_get_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD);
717 }
718
719 void config_set_sensor_alarm_high_threshold(const char *sid, int threshold)
720 {
721         config_sensor_set_int(sid, ATT_SENSOR_ALARM_HIGH_THRESHOLD, threshold);
722 }
723
724 int config_get_sensor_alarm_low_threshold(const char *sid)
725 {
726         return config_sensor_get_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD);
727 }
728
729 void config_set_sensor_alarm_low_threshold(const char *sid, int threshold)
730 {
731         config_sensor_set_int(sid, ATT_SENSOR_ALARM_LOW_THRESHOLD, threshold);
732 }
733
734 bool config_is_appindicator_enabled(const char *sid)
735 {
736         return !config_sensor_get_bool(sid,
737                                        ATT_SENSOR_APPINDICATOR_MENU_DISABLED);
738 }
739
740 void config_set_appindicator_enabled(const char *sid, bool enabled)
741 {
742         return config_sensor_set_bool(sid,
743                                       ATT_SENSOR_APPINDICATOR_MENU_DISABLED,
744                                       !enabled);
745 }
746
747 int config_get_sensor_position(const char *sid)
748 {
749         return config_sensor_get_int(sid, ATT_SENSOR_POSITION);
750 }
751
752 void config_set_sensor_position(const char *sid, int pos)
753 {
754         return config_sensor_set_int(sid, ATT_SENSOR_POSITION, pos);
755 }
756
757 bool config_get_sensor_alarm_enabled(const char *sid)
758 {
759         return config_sensor_get_bool(sid, ATT_SENSOR_ALARM_ENABLED);
760 }
761
762 void config_set_sensor_alarm_enabled(const char *sid, bool enabled)
763 {
764         config_sensor_set_bool(sid, ATT_SENSOR_ALARM_ENABLED, enabled);
765 }
766
767 bool config_is_appindicator_label_enabled(const char *sid)
768 {
769         return config_sensor_get_bool(sid,
770                                       ATT_SENSOR_APPINDICATOR_LABEL_ENABLED);
771 }
772
773 void config_set_appindicator_label_enabled(const char *sid, bool enabled)
774 {
775         config_sensor_set_bool(sid,
776                                ATT_SENSOR_APPINDICATOR_LABEL_ENABLED,
777                                enabled);
778 }