Mercurial > audlegacy
annotate libaudacious/configdb_gconf.c @ 2203:60bd49189fde trunk
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
- removed duplicate code from vis.c
author | marvin |
---|---|
date | Fri, 22 Dec 2006 20:10:22 -0800 |
parents | c525c2b6a3d8 |
children |
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 | |
1759
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
197 if (value == NULL) { |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
198 bmp_cfg_db_unset_key(db, section, key); |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
199 } else { |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
200 cval = gconf_value_new(GCONF_VALUE_STRING); |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
201 gconf_value_set_string(cval, value); |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
202 bmp_cfg_db_set_value(db, section, key, cval); |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
203 gconf_value_free(cval); |
c525c2b6a3d8
[svn] Interpret set_string for a NULL value as a key unset action, as gconf will not store NULL values.
chainsaw
parents:
1757
diff
changeset
|
204 } |
0 | 205 } |
206 | |
207 void | |
208 bmp_cfg_db_set_int(ConfigDb * db, | |
209 const gchar * section, | |
210 const gchar * key, | |
211 gint value) | |
212 { | |
213 GConfValue *cval; | |
214 | |
215 cval = gconf_value_new(GCONF_VALUE_INT); | |
216 gconf_value_set_int(cval, value); | |
217 bmp_cfg_db_set_value(db, section, key, cval); | |
218 gconf_value_free(cval); | |
219 } | |
220 | |
221 void | |
222 bmp_cfg_db_set_bool(ConfigDb * db, | |
223 const gchar * section, | |
224 const gchar * key, | |
225 gboolean value) | |
226 { | |
227 GConfValue *cval; | |
228 | |
229 cval = gconf_value_new(GCONF_VALUE_BOOL); | |
230 gconf_value_set_bool(cval, value); | |
231 bmp_cfg_db_set_value(db, section, key, cval); | |
232 gconf_value_free(cval); | |
233 } | |
234 | |
235 void | |
236 bmp_cfg_db_set_float(ConfigDb * db, | |
237 const gchar * section, | |
238 const gchar * key, | |
239 gfloat value) | |
240 { | |
241 GConfValue *cval; | |
242 | |
243 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
244 gconf_value_set_float(cval, value); | |
245 bmp_cfg_db_set_value(db, section, key, cval); | |
246 gconf_value_free(cval); | |
247 } | |
248 | |
249 void | |
250 bmp_cfg_db_set_double(ConfigDb * db, | |
251 const gchar * section, | |
252 const gchar * key, | |
253 gdouble value) | |
254 { | |
255 GConfValue *cval; | |
256 | |
257 cval = gconf_value_new(GCONF_VALUE_FLOAT); | |
258 gconf_value_set_float(cval, value); | |
259 bmp_cfg_db_set_value(db, section, key, cval); | |
260 gconf_value_free(cval); | |
261 } | |
262 | |
263 void | |
264 bmp_cfg_db_unset_key(ConfigDb * db, | |
265 const gchar * section, | |
266 const gchar * key) | |
267 { | |
268 gchar *path; | |
269 | |
270 g_return_if_fail(db != NULL); | |
271 g_return_if_fail(key != NULL); | |
272 | |
273 path = build_keypath(section, key); | |
274 gconf_client_unset(db->client, path, NULL); | |
275 g_free(path); | |
276 } |