Mercurial > audlegacy
annotate libaudacious/configdb_gconf.c @ 1566:e513069caf71 trunk
[svn] - pls and m3u is now fully modular
author | nenolod |
---|---|
date | Thu, 10 Aug 2006 20:44:47 -0700 |
parents | 705d4c089fce |
children | dd78822cd1d8 |
rev | line source |
---|---|
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 | |
1459 | 13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 14 */ |
15 | |
16 #include "configdb.h" | |
17 | |
18 #include <string.h> | |
19 #include <gconf/gconf-client.h> | |
20 | |
21 #define BMP_CONFIG_BASE_PATH "/apps/audacious" | |
22 | |
23 struct _ConfigDb { | |
24 GConfClient *client; | |
25 }; | |
26 | |
27 ConfigDb * | |
28 bmp_cfg_db_open() | |
29 { | |
30 ConfigDb *db; | |
31 | |
1449
a69db3a15bf2
[svn] - experimental change to bmp_cfg_db_open() to ensure that g_type_init()
nenolod
parents:
1446
diff
changeset
|
32 g_type_init(); |
a69db3a15bf2
[svn] - experimental change to bmp_cfg_db_open() to ensure that g_type_init()
nenolod
parents:
1446
diff
changeset
|
33 |
0 | 34 db = g_new(ConfigDb, 1); |
35 | |
36 db->client = gconf_client_get_default(); | |
37 | |
38 return db; | |
39 } | |
40 | |
41 void | |
42 bmp_cfg_db_close(ConfigDb * db) | |
43 { | |
1446 | 44 g_return_if_fail(db != NULL); |
45 | |
0 | 46 g_object_unref(db->client); |
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
0
diff
changeset
|
47 g_free(db); |
0 | 48 } |
49 | |
50 static gchar * | |
51 build_keypath(const gchar * section, | |
52 const gchar * key) | |
53 { | |
54 if (section == NULL) { | |
55 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", key, NULL); | |
56 } | |
57 else { | |
58 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", section, "/", | |
59 key, NULL); | |
60 } | |
61 } | |
62 | |
63 static gboolean | |
64 bmp_cfg_db_get_value(ConfigDb * db, | |
65 const gchar * section, | |
66 const gchar * key, | |
67 GConfValue ** value) | |
68 { | |
69 gchar *path; | |
70 | |
71 g_return_val_if_fail(db != NULL, FALSE); | |
72 g_return_val_if_fail(key != NULL, FALSE); | |
73 g_return_val_if_fail(value != NULL, FALSE); | |
74 | |
75 path = build_keypath(section, key); | |
76 *value = gconf_client_get(db->client, path, NULL); | |
77 g_free(path); | |
78 | |
79 return (*value != NULL) ? TRUE : FALSE; | |
80 } | |
81 | |
82 static void | |
83 bmp_cfg_db_set_value(ConfigDb * db, | |
84 const gchar * section, | |
85 const gchar * key, | |
86 GConfValue * value) | |
87 { | |
88 gchar *path; | |
89 | |
90 g_return_if_fail(db != NULL); | |
91 g_return_if_fail(key != NULL); | |
92 g_return_if_fail(value != NULL); | |
93 | |
94 path = build_keypath(section, key); | |
95 gconf_client_set(db->client, path, value, NULL); | |
96 g_free(path); | |
97 } | |
98 | |
99 gboolean | |
100 bmp_cfg_db_get_string(ConfigDb * db, | |
101 const gchar * section, | |
102 const gchar * key, | |
103 gchar ** value) | |
104 { | |
105 GConfValue *cval; | |
106 | |
107 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
108 return FALSE; | |
109 if (cval->type != GCONF_VALUE_STRING) | |
110 return FALSE; | |
111 *value = strdup(gconf_value_get_string(cval)); | |
112 gconf_value_free(cval); | |
113 | |
114 return TRUE; | |
115 } | |
116 | |
117 gboolean | |
118 bmp_cfg_db_get_int(ConfigDb * db, | |
119 const gchar * section, | |
120 const gchar * key, | |
121 gint * value) | |
122 { | |
123 GConfValue *cval; | |
124 | |
125 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
126 return FALSE; | |
127 if (cval->type != GCONF_VALUE_INT) | |
128 return FALSE; | |
129 *value = gconf_value_get_int(cval); | |
130 gconf_value_free(cval); | |
131 | |
132 return TRUE; | |
133 } | |
134 | |
135 gboolean | |
136 bmp_cfg_db_get_bool(ConfigDb * db, | |
137 const gchar * section, | |
138 const gchar * key, | |
139 gboolean * value) | |
140 { | |
141 GConfValue *cval; | |
142 | |
143 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
144 return FALSE; | |
145 if (cval->type != GCONF_VALUE_BOOL) | |
146 return FALSE; | |
147 *value = gconf_value_get_bool(cval); | |
148 gconf_value_free(cval); | |
149 | |
150 return TRUE; | |
151 } | |
152 | |
153 gboolean | |
154 bmp_cfg_db_get_float(ConfigDb * db, | |
155 const gchar * section, | |
156 const gchar * key, | |
157 gfloat * value) | |
158 { | |
159 GConfValue *cval; | |
160 | |
161 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
162 return FALSE; | |
163 if (cval->type != GCONF_VALUE_FLOAT) | |
164 return FALSE; | |
165 *value = gconf_value_get_float(cval); | |
166 gconf_value_free(cval); | |
167 | |
168 return TRUE; | |
169 } | |
170 | |
171 gboolean | |
172 bmp_cfg_db_get_double(ConfigDb * db, | |
173 const gchar * section, | |
174 const gchar * key, | |
175 gdouble * value) | |
176 { | |
177 GConfValue *cval; | |
178 | |
179 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
180 return FALSE; | |
181 if (cval->type != GCONF_VALUE_FLOAT) | |
182 return FALSE; | |
183 *value = gconf_value_get_float(cval); | |
184 gconf_value_free(cval); | |
185 | |
186 return TRUE; | |
187 } | |
188 | |
189 void | |
190 bmp_cfg_db_set_string(ConfigDb * db, | |
191 const gchar * section, | |
192 const gchar * key, | |
193 gchar * value) | |
194 { | |
195 GConfValue *cval; | |
196 | |
197 cval = gconf_value_new(GCONF_VALUE_STRING); | |
198 gconf_value_set_string(cval, value); | |
199 bmp_cfg_db_set_value(db, section, key, cval); | |
200 gconf_value_free(cval); | |
201 } | |
202 | |
203 void | |
204 bmp_cfg_db_set_int(ConfigDb * db, | |
205 const gchar * section, | |
206 const gchar * key, | |
207 gint value) | |
208 { | |
209 GConfValue *cval; | |
210 | |
211 cval = gconf_value_new(GCONF_VALUE_INT); | |
212 gconf_value_set_int(cval, value); | |
213 bmp_cfg_db_set_value(db, section, key, cval); | |
214 gconf_value_free(cval); | |
215 } | |
216 | |
217 void | |
218 bmp_cfg_db_set_bool(ConfigDb * db, | |
219 const gchar * section, | |
220 const gchar * key, | |
221 gboolean value) | |
222 { | |
223 GConfValue *cval; | |
224 | |
225 cval = gconf_value_new(GCONF_VALUE_BOOL); | |
226 gconf_value_set_bool(cval, value); | |
227 bmp_cfg_db_set_value(db, section, key, cval); | |
228 gconf_value_free(cval); | |
229 } | |
230 | |
231 void | |
232 bmp_cfg_db_set_float(ConfigDb * db, | |
233 const gchar * section, | |
234 const gchar * key, | |
235 gfloat value) | |
236 { | |
237 GConfValue *cval; | |
238 | |
239 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
240 gconf_value_set_float(cval, value); | |
241 bmp_cfg_db_set_value(db, section, key, cval); | |
242 gconf_value_free(cval); | |
243 } | |
244 | |
245 void | |
246 bmp_cfg_db_set_double(ConfigDb * db, | |
247 const gchar * section, | |
248 const gchar * key, | |
249 gdouble value) | |
250 { | |
251 GConfValue *cval; | |
252 | |
253 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
254 gconf_value_set_float(cval, value); | |
255 bmp_cfg_db_set_value(db, section, key, cval); | |
256 gconf_value_free(cval); | |
257 } | |
258 | |
259 void | |
260 bmp_cfg_db_unset_key(ConfigDb * db, | |
261 const gchar * section, | |
262 const gchar * key) | |
263 { | |
264 gchar *path; | |
265 | |
266 g_return_if_fail(db != NULL); | |
267 g_return_if_fail(key != NULL); | |
268 | |
269 path = build_keypath(section, key); | |
270 gconf_client_unset(db->client, path, NULL); | |
271 g_free(path); | |
272 } |