Mercurial > audlegacy
annotate libaudacious/configdb_gconf.c @ 1282:e80a7a0b1065 trunk
[svn] - update Makefile
author | nenolod |
---|---|
date | Sat, 17 Jun 2006 19:50:11 -0700 |
parents | c8cf439179b8 |
children | 7610ab1233a7 |
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 | |
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); | |
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
|
46 g_free(db); |
0 | 47 } |
48 | |
49 static gchar * | |
50 build_keypath(const gchar * section, | |
51 const gchar * key) | |
52 { | |
53 if (section == NULL) { | |
54 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", key, NULL); | |
55 } | |
56 else { | |
57 return g_strconcat(BMP_CONFIG_BASE_PATH, "/", section, "/", | |
58 key, NULL); | |
59 } | |
60 } | |
61 | |
62 static gboolean | |
63 bmp_cfg_db_get_value(ConfigDb * db, | |
64 const gchar * section, | |
65 const gchar * key, | |
66 GConfValue ** value) | |
67 { | |
68 gchar *path; | |
69 | |
70 g_return_val_if_fail(db != NULL, FALSE); | |
71 g_return_val_if_fail(key != NULL, FALSE); | |
72 g_return_val_if_fail(value != NULL, FALSE); | |
73 | |
74 path = build_keypath(section, key); | |
75 *value = gconf_client_get(db->client, path, NULL); | |
76 g_free(path); | |
77 | |
78 return (*value != NULL) ? TRUE : FALSE; | |
79 } | |
80 | |
81 static void | |
82 bmp_cfg_db_set_value(ConfigDb * db, | |
83 const gchar * section, | |
84 const gchar * key, | |
85 GConfValue * value) | |
86 { | |
87 gchar *path; | |
88 | |
89 g_return_if_fail(db != NULL); | |
90 g_return_if_fail(key != NULL); | |
91 g_return_if_fail(value != NULL); | |
92 | |
93 path = build_keypath(section, key); | |
94 gconf_client_set(db->client, path, value, NULL); | |
95 g_free(path); | |
96 } | |
97 | |
98 gboolean | |
99 bmp_cfg_db_get_string(ConfigDb * db, | |
100 const gchar * section, | |
101 const gchar * key, | |
102 gchar ** value) | |
103 { | |
104 GConfValue *cval; | |
105 | |
106 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
107 return FALSE; | |
108 if (cval->type != GCONF_VALUE_STRING) | |
109 return FALSE; | |
110 *value = strdup(gconf_value_get_string(cval)); | |
111 gconf_value_free(cval); | |
112 | |
113 return TRUE; | |
114 } | |
115 | |
116 gboolean | |
117 bmp_cfg_db_get_int(ConfigDb * db, | |
118 const gchar * section, | |
119 const gchar * key, | |
120 gint * value) | |
121 { | |
122 GConfValue *cval; | |
123 | |
124 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
125 return FALSE; | |
126 if (cval->type != GCONF_VALUE_INT) | |
127 return FALSE; | |
128 *value = gconf_value_get_int(cval); | |
129 gconf_value_free(cval); | |
130 | |
131 return TRUE; | |
132 } | |
133 | |
134 gboolean | |
135 bmp_cfg_db_get_bool(ConfigDb * db, | |
136 const gchar * section, | |
137 const gchar * key, | |
138 gboolean * value) | |
139 { | |
140 GConfValue *cval; | |
141 | |
142 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
143 return FALSE; | |
144 if (cval->type != GCONF_VALUE_BOOL) | |
145 return FALSE; | |
146 *value = gconf_value_get_bool(cval); | |
147 gconf_value_free(cval); | |
148 | |
149 return TRUE; | |
150 } | |
151 | |
152 gboolean | |
153 bmp_cfg_db_get_float(ConfigDb * db, | |
154 const gchar * section, | |
155 const gchar * key, | |
156 gfloat * value) | |
157 { | |
158 GConfValue *cval; | |
159 | |
160 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
161 return FALSE; | |
162 if (cval->type != GCONF_VALUE_FLOAT) | |
163 return FALSE; | |
164 *value = gconf_value_get_float(cval); | |
165 gconf_value_free(cval); | |
166 | |
167 return TRUE; | |
168 } | |
169 | |
170 gboolean | |
171 bmp_cfg_db_get_double(ConfigDb * db, | |
172 const gchar * section, | |
173 const gchar * key, | |
174 gdouble * value) | |
175 { | |
176 GConfValue *cval; | |
177 | |
178 if (!bmp_cfg_db_get_value(db, section, key, &cval)) | |
179 return FALSE; | |
180 if (cval->type != GCONF_VALUE_FLOAT) | |
181 return FALSE; | |
182 *value = gconf_value_get_float(cval); | |
183 gconf_value_free(cval); | |
184 | |
185 return TRUE; | |
186 } | |
187 | |
188 void | |
189 bmp_cfg_db_set_string(ConfigDb * db, | |
190 const gchar * section, | |
191 const gchar * key, | |
192 gchar * value) | |
193 { | |
194 GConfValue *cval; | |
195 | |
196 cval = gconf_value_new(GCONF_VALUE_STRING); | |
197 gconf_value_set_string(cval, value); | |
198 bmp_cfg_db_set_value(db, section, key, cval); | |
199 gconf_value_free(cval); | |
200 } | |
201 | |
202 void | |
203 bmp_cfg_db_set_int(ConfigDb * db, | |
204 const gchar * section, | |
205 const gchar * key, | |
206 gint value) | |
207 { | |
208 GConfValue *cval; | |
209 | |
210 cval = gconf_value_new(GCONF_VALUE_INT); | |
211 gconf_value_set_int(cval, value); | |
212 bmp_cfg_db_set_value(db, section, key, cval); | |
213 gconf_value_free(cval); | |
214 } | |
215 | |
216 void | |
217 bmp_cfg_db_set_bool(ConfigDb * db, | |
218 const gchar * section, | |
219 const gchar * key, | |
220 gboolean value) | |
221 { | |
222 GConfValue *cval; | |
223 | |
224 cval = gconf_value_new(GCONF_VALUE_BOOL); | |
225 gconf_value_set_bool(cval, value); | |
226 bmp_cfg_db_set_value(db, section, key, cval); | |
227 gconf_value_free(cval); | |
228 } | |
229 | |
230 void | |
231 bmp_cfg_db_set_float(ConfigDb * db, | |
232 const gchar * section, | |
233 const gchar * key, | |
234 gfloat value) | |
235 { | |
236 GConfValue *cval; | |
237 | |
238 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
239 gconf_value_set_float(cval, value); | |
240 bmp_cfg_db_set_value(db, section, key, cval); | |
241 gconf_value_free(cval); | |
242 } | |
243 | |
244 void | |
245 bmp_cfg_db_set_double(ConfigDb * db, | |
246 const gchar * section, | |
247 const gchar * key, | |
248 gdouble value) | |
249 { | |
250 GConfValue *cval; | |
251 | |
252 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
253 gconf_value_set_float(cval, value); | |
254 bmp_cfg_db_set_value(db, section, key, cval); | |
255 gconf_value_free(cval); | |
256 } | |
257 | |
258 void | |
259 bmp_cfg_db_unset_key(ConfigDb * db, | |
260 const gchar * section, | |
261 const gchar * key) | |
262 { | |
263 gchar *path; | |
264 | |
265 g_return_if_fail(db != NULL); | |
266 g_return_if_fail(key != NULL); | |
267 | |
268 path = build_keypath(section, key); | |
269 gconf_client_unset(db->client, path, NULL); | |
270 g_free(path); | |
271 } |