GConf backend for settings
[tunertool] / src / settings.c
1 /* vim: set sts=2 sw=2 et: */
2 /* 
3  * Copyright (C) 2008 Jari Tenhunen <jari.tenhunen@iki.fi>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "settings.h"
26
27 static GConfClient * client = NULL;
28
29 static GConfClient *
30 get_client ()
31 {
32   if (!client)
33     client = gconf_client_get_default ();
34
35   return client;
36
37 }
38
39 gboolean
40 settings_get_display_keepalive (gboolean default_value)
41 {
42   GConfValue * value = NULL;
43   GError * err = NULL;
44   gboolean val = default_value;
45
46   value = gconf_client_get (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, &err);
47   if (err) {
48     g_error_free (err);
49   }
50
51   if (value) {
52     if (value->type == GCONF_VALUE_BOOL)
53       val = gconf_value_get_bool (value);
54
55     gconf_value_free (value);
56   }
57
58   return val;
59 }
60
61 gboolean
62 settings_set_disp_keepalive (gboolean val)
63 {
64   return gconf_client_set_bool (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, val, NULL);
65 }
66
67 gint
68 settings_get_algorithm (gint default_value)
69 {
70   GConfValue * value = NULL;
71   GError * err = NULL;
72   gint val = default_value;
73
74   value = gconf_client_get (get_client (), GCONF_KEY_ALGORITHM, &err);
75   if (err) {
76     g_error_free (err);
77   }
78
79   if (value) {
80     if (value->type == GCONF_VALUE_INT)
81       val = gconf_value_get_int (value);
82
83     gconf_value_free (value);
84   }
85
86   return val;
87 }
88
89 gboolean
90 settings_set_algorithm (gint val)
91 {
92   return gconf_client_set_int (get_client (), GCONF_KEY_ALGORITHM, val, NULL);
93 }
94
95 gint
96 settings_get_calibration (gint default_value)
97 {
98   GError * err = NULL;
99   gint val;
100
101   val = gconf_client_get_int (get_client (), GCONF_KEY_CALIBRATION, &err);
102   if (err) {
103     val = default_value;
104     g_error_free (err);
105   }
106   if (val == 0)
107     val = default_value;
108
109   return val;
110 }
111
112 gboolean
113 settings_set_calibration (gint value)
114 {
115   return gconf_client_set_int (get_client (), GCONF_KEY_CALIBRATION, value, NULL);
116 }
117
118 gboolean
119 settings_init (GConfClientNotifyFunc func, gpointer user_data)
120 {
121   gconf_client_add_dir (get_client (), GCONF_ROOT, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
122   gconf_client_notify_add (get_client (), GCONF_ROOT, func, user_data, NULL, NULL);
123
124   return TRUE;
125 }