0
|
1 /* This program is free software; you can redistribute it and/or modify
|
|
2 * it under the terms of the GNU General Public License as published by
|
|
3 * the Free Software Foundation; either version 2 of the License, or
|
|
4 * (at your option) any later version.
|
|
5 *
|
|
6 * This program is distributed in the hope that it will be useful,
|
|
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9 * GNU General Public License for more details.
|
|
10 *
|
|
11 * You should have received a copy of the GNU General Public License
|
|
12 * along with this program; if not, write to the Free Software
|
|
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
14 */
|
|
15
|
|
16 #include "configdb.h"
|
|
17
|
|
18 #include <string.h>
|
|
19 #include <gconf/gconf-client.h>
|
|
20
|
|
21
|
|
22 #define BMP_CONFIG_BASE_PATH "/apps/audacious"
|
|
23
|
|
24
|
|
25 struct _ConfigDb {
|
|
26 GConfClient *client;
|
|
27 };
|
|
28
|
|
29
|
|
30 ConfigDb *
|
|
31 bmp_cfg_db_open()
|
|
32 {
|
|
33 ConfigDb *db;
|
|
34
|
|
35 db = g_new(ConfigDb, 1);
|
|
36
|
|
37 db->client = gconf_client_get_default();
|
|
38
|
|
39 return db;
|
|
40 }
|
|
41
|
|
42 void
|
|
43 bmp_cfg_db_close(ConfigDb * db)
|
|
44 {
|
|
45 g_object_unref(db->client);
|
|
46 }
|
|
47
|
|
48 static gchar *
|
|
49 build_keypath(const gchar * section,
|
|
50 const gchar * key)
|
|
51 {
|
|
52 if (section == NULL) {
|
|
53 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", key, NULL);
|
|
54 }
|
|
55 else {
|
|
56 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", section, "/",
|
|
57 key, NULL);
|
|
58 }
|
|
59 }
|
|
60
|
|
61 static gboolean
|
|
62 bmp_cfg_db_get_value(ConfigDb * db,
|
|
63 const gchar * section,
|
|
64 const gchar * key,
|
|
65 GConfValue ** value)
|
|
66 {
|
|
67 gchar *path;
|
|
68
|
|
69 g_return_val_if_fail(db != NULL, FALSE);
|
|
70 g_return_val_if_fail(key != NULL, FALSE);
|
|
71 g_return_val_if_fail(value != NULL, FALSE);
|
|
72
|
|
73 path = build_keypath(section, key);
|
|
74 *value = gconf_client_get(db->client, path, NULL);
|
|
75 g_free(path);
|
|
76
|
|
77 return (*value != NULL) ? TRUE : FALSE;
|
|
78 }
|
|
79
|
|
80 static void
|
|
81 bmp_cfg_db_set_value(ConfigDb * db,
|
|
82 const gchar * section,
|
|
83 const gchar * key,
|
|
84 GConfValue * value)
|
|
85 {
|
|
86 gchar *path;
|
|
87
|
|
88 g_return_if_fail(db != NULL);
|
|
89 g_return_if_fail(key != NULL);
|
|
90 g_return_if_fail(value != NULL);
|
|
91
|
|
92 path = build_keypath(section, key);
|
|
93 gconf_client_set(db->client, path, value, NULL);
|
|
94 g_free(path);
|
|
95 }
|
|
96
|
|
97 gboolean
|
|
98 bmp_cfg_db_get_string(ConfigDb * db,
|
|
99 const gchar * section,
|
|
100 const gchar * key,
|
|
101 gchar ** value)
|
|
102 {
|
|
103 GConfValue *cval;
|
|
104
|
|
105 if (!bmp_cfg_db_get_value(db, section, key, &cval))
|
|
106 return FALSE;
|
|
107 if (cval->type != GCONF_VALUE_STRING)
|
|
108 return FALSE;
|
|
109 *value = strdup(gconf_value_get_string(cval));
|
|
110 gconf_value_free(cval);
|
|
111
|
|
112 return TRUE;
|
|
113 }
|
|
114
|
|
115 gboolean
|
|
116 bmp_cfg_db_get_int(ConfigDb * db,
|
|
117 const gchar * section,
|
|
118 const gchar * key,
|
|
119 gint * value)
|
|
120 {
|
|
121 GConfValue *cval;
|
|
122
|
|
123 if (!bmp_cfg_db_get_value(db, section, key, &cval))
|
|
124 return FALSE;
|
|
125 if (cval->type != GCONF_VALUE_INT)
|
|
126 return FALSE;
|
|
127 *value = gconf_value_get_int(cval);
|
|
128 gconf_value_free(cval);
|
|
129
|
|
130 return TRUE;
|
|
131 }
|
|
132
|
|
133 gboolean
|
|
134 bmp_cfg_db_get_bool(ConfigDb * db,
|
|
135 const gchar * section,
|
|
136 const gchar * key,
|
|
137 gboolean * value)
|
|
138 {
|
|
139 GConfValue *cval;
|
|
140
|
|
141 if (!bmp_cfg_db_get_value(db, section, key, &cval))
|
|
142 return FALSE;
|
|
143 if (cval->type != GCONF_VALUE_BOOL)
|
|
144 return FALSE;
|
|
145 *value = gconf_value_get_bool(cval);
|
|
146 gconf_value_free(cval);
|
|
147
|
|
148 return TRUE;
|
|
149 }
|
|
150
|
|
151 gboolean
|
|
152 bmp_cfg_db_get_float(ConfigDb * db,
|
|
153 const gchar * section,
|
|
154 const gchar * key,
|
|
155 gfloat * value)
|
|
156 {
|
|
157 GConfValue *cval;
|
|
158
|
|
159 if (!bmp_cfg_db_get_value(db, section, key, &cval))
|
|
160 return FALSE;
|
|
161 if (cval->type != GCONF_VALUE_FLOAT)
|
|
162 return FALSE;
|
|
163 *value = gconf_value_get_float(cval);
|
|
164 gconf_value_free(cval);
|
|
165
|
|
166 return TRUE;
|
|
167 }
|
|
168
|
|
169 gboolean
|
|
170 bmp_cfg_db_get_double(ConfigDb * db,
|
|
171 const gchar * section,
|
|
172 const gchar * key,
|
|
173 gdouble * value)
|
|
174 {
|
|
175 GConfValue *cval;
|
|
176
|
|
177 if (!bmp_cfg_db_get_value(db, section, key, &cval))
|
|
178 return FALSE;
|
|
179 if (cval->type != GCONF_VALUE_FLOAT)
|
|
180 return FALSE;
|
|
181 *value = gconf_value_get_float(cval);
|
|
182 gconf_value_free(cval);
|
|
183
|
|
184 return TRUE;
|
|
185 }
|
|
186
|
|
187 void
|
|
188 bmp_cfg_db_set_string(ConfigDb * db,
|
|
189 const gchar * section,
|
|
190 const gchar * key,
|
|
191 gchar * value)
|
|
192 {
|
|
193 GConfValue *cval;
|
|
194
|
|
195 cval = gconf_value_new(GCONF_VALUE_STRING);
|
|
196 gconf_value_set_string(cval, value);
|
|
197 bmp_cfg_db_set_value(db, section, key, cval);
|
|
198 gconf_value_free(cval);
|
|
199 }
|
|
200
|
|
201 void
|
|
202 bmp_cfg_db_set_int(ConfigDb * db,
|
|
203 const gchar * section,
|
|
204 const gchar * key,
|
|
205 gint value)
|
|
206 {
|
|
207 GConfValue *cval;
|
|
208
|
|
209 cval = gconf_value_new(GCONF_VALUE_INT);
|
|
210 gconf_value_set_int(cval, value);
|
|
211 bmp_cfg_db_set_value(db, section, key, cval);
|
|
212 gconf_value_free(cval);
|
|
213 }
|
|
214
|
|
215 void
|
|
216 bmp_cfg_db_set_bool(ConfigDb * db,
|
|
217 const gchar * section,
|
|
218 const gchar * key,
|
|
219 gboolean value)
|
|
220 {
|
|
221 GConfValue *cval;
|
|
222
|
|
223 cval = gconf_value_new(GCONF_VALUE_BOOL);
|
|
224 gconf_value_set_bool(cval, value);
|
|
225 bmp_cfg_db_set_value(db, section, key, cval);
|
|
226 gconf_value_free(cval);
|
|
227 }
|
|
228
|
|
229 void
|
|
230 bmp_cfg_db_set_float(ConfigDb * db,
|
|
231 const gchar * section,
|
|
232 const gchar * key,
|
|
233 gfloat value)
|
|
234 {
|
|
235 GConfValue *cval;
|
|
236
|
|
237 cval = gconf_value_new(GCONF_VALUE_FLOAT);
|
|
238 gconf_value_set_float(cval, value);
|
|
239 bmp_cfg_db_set_value(db, section, key, cval);
|
|
240 gconf_value_free(cval);
|
|
241 }
|
|
242
|
|
243 void
|
|
244 bmp_cfg_db_set_double(ConfigDb * db,
|
|
245 const gchar * section,
|
|
246 const gchar * key,
|
|
247 gdouble value)
|
|
248 {
|
|
249 GConfValue *cval;
|
|
250
|
|
251 cval = gconf_value_new(GCONF_VALUE_FLOAT);
|
|
252 gconf_value_set_float(cval, value);
|
|
253 bmp_cfg_db_set_value(db, section, key, cval);
|
|
254 gconf_value_free(cval);
|
|
255 }
|
|
256
|
|
257 void
|
|
258 bmp_cfg_db_unset_key(ConfigDb * db,
|
|
259 const gchar * section,
|
|
260 const gchar * key)
|
|
261 {
|
|
262 gchar *path;
|
|
263
|
|
264 g_return_if_fail(db != NULL);
|
|
265 g_return_if_fail(key != NULL);
|
|
266
|
|
267 path = build_keypath(section, key);
|
|
268 gconf_client_unset(db->client, path, NULL);
|
|
269 g_free(path);
|
|
270 }
|