Mercurial > pidgin
annotate src/prefs.c @ 8121:edc9d9b4197a
[gaim-migrate @ 8825]
see, if win32 used automake, you wouldn't have to nag me
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 16 Jan 2004 01:14:59 +0000 |
parents | fa6395637e2c |
children | 63c7a16a2c09 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
1 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2074
diff
changeset
|
25 #include <config.h> |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
26 #endif |
5440 | 27 |
1 | 28 #include <string.h> |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
5440 | 31 #include <sys/stat.h> |
32 #include <sys/types.h> | |
33 #include <glib.h> | |
6216 | 34 #include "internal.h" |
5440 | 35 #include "prefs.h" |
36 #include "debug.h" | |
37 #include "util.h" | |
3366 | 38 |
4026
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
39 #ifdef _WIN32 |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
40 #include "win32dep.h" |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
41 #endif |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
42 |
5440 | 43 struct pref_cb { |
44 GaimPrefCallback func; | |
45 gpointer data; | |
46 guint id; | |
47 }; | |
48 | |
49 struct gaim_pref { | |
50 GaimPrefType type; | |
51 char *name; | |
52 union { | |
53 gpointer generic; | |
54 gboolean boolean; | |
55 int integer; | |
56 char *string; | |
5561 | 57 GList *stringlist; |
5440 | 58 } value; |
59 GSList *callbacks; | |
60 struct gaim_pref *parent; | |
61 struct gaim_pref *sibling; | |
62 struct gaim_pref *first_child; | |
63 }; | |
3366 | 64 |
5440 | 65 static GHashTable *prefs_hash = NULL; |
66 | |
67 static struct gaim_pref prefs = { GAIM_PREF_NONE, NULL, {NULL}, NULL, | |
68 NULL, NULL, NULL }; | |
69 | |
5534 | 70 static guint prefs_save_timer = 0; |
71 static gboolean prefs_is_loaded = FALSE; | |
72 | |
73 | |
74 static gboolean prefs_save_callback(gpointer who_cares) { | |
75 gaim_prefs_sync(); | |
76 prefs_save_timer = 0; | |
77 return FALSE; | |
78 } | |
79 | |
80 static void schedule_prefs_save() { | |
81 if(!prefs_save_timer) | |
82 prefs_save_timer = g_timeout_add(5000, prefs_save_callback, NULL); | |
83 } | |
84 | |
85 static void prefs_save_cb(const char *name, GaimPrefType type, gpointer val, | |
86 gpointer user_data) { | |
87 | |
88 if(!prefs_is_loaded) | |
89 return; | |
90 | |
91 gaim_debug(GAIM_DEBUG_MISC, "prefs", "%s changed, scheduling save.\n", name); | |
92 | |
93 schedule_prefs_save(); | |
94 } | |
95 | |
5440 | 96 void gaim_prefs_init() { |
97 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
98 | |
5534 | 99 gaim_prefs_connect_callback("/", prefs_save_cb, NULL); |
100 | |
5529
e7747cae9710
[gaim-migrate @ 5929]
Christian Hammond <chipx86@chipx86.com>
parents:
5458
diff
changeset
|
101 gaim_prefs_add_none("/core"); |
5550
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
102 gaim_prefs_add_none("/plugins"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
103 gaim_prefs_add_none("/plugins/core"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
104 gaim_prefs_add_none("/plugins/lopl"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
105 gaim_prefs_add_none("/plugins/prpl"); |
5529
e7747cae9710
[gaim-migrate @ 5929]
Christian Hammond <chipx86@chipx86.com>
parents:
5458
diff
changeset
|
106 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
107 /* Away */ |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
108 gaim_prefs_add_none("/core/away"); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
109 gaim_prefs_add_bool("/core/away/away_when_idle", TRUE); |
7689 | 110 gaim_prefs_add_int("/core/away/mins_before_away", 5); |
6216 | 111 /* XXX: internationalized string in prefs...evil */ |
112 gaim_prefs_add_string("/core/away/default_message", | |
113 _("Slightly less boring default")); | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
114 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
115 /* Away -> Auto Response */ |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
116 gaim_prefs_add_none("/core/away/auto_response"); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
117 gaim_prefs_add_bool("/core/away/auto_response/enabled", TRUE); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
118 gaim_prefs_add_bool("/core/away/auto_response/in_active_conv", TRUE); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
119 gaim_prefs_add_bool("/core/away/auto_response/idle_only", FALSE); |
5550
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
120 gaim_prefs_add_int("/core/away/auto_response/sec_before_resend", 60); |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
121 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
122 /* Buddies */ |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
123 gaim_prefs_add_none("/core/buddies"); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
124 gaim_prefs_add_bool("/core/buddies/use_server_alias", TRUE); |
7420 | 125 |
126 /* Contact Priority Settings */ | |
127 gaim_prefs_add_none("/core/contact"); | |
128 gaim_prefs_add_bool("/core/contact/last_match", FALSE); | |
129 gaim_prefs_add_int("/core/contact/offline_score", 4); | |
130 gaim_prefs_add_int("/core/contact/away_score", 2); | |
131 gaim_prefs_add_int("/core/contact/idle_score", 1); | |
5440 | 132 } |
3366 | 133 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
134 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
135 get_path_dirname(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
136 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
137 char *c, *str; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
138 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
139 str = g_strdup(name); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
140 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
141 if ((c = strrchr(str, '/')) != NULL) { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
142 *c = '\0'; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
143 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
144 if (*str == '\0') { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
145 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
146 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
147 str = g_strdup("/"); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
148 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
149 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
150 else { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
151 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
152 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
153 str = g_strdup("."); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
154 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
155 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
156 return str; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
157 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
158 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
159 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
160 get_path_basename(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
161 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
162 const char *c; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
163 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
164 if ((c = strrchr(name, '/')) != NULL) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
165 return g_strdup(c + 1); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
166 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
167 return g_strdup(name); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
168 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
169 |
5440 | 170 static char *pref_full_name(struct gaim_pref *pref) { |
171 GString *name; | |
172 struct gaim_pref *parent; | |
6693 | 173 char *ret; |
174 | |
5440 | 175 if(!pref) |
176 return NULL; | |
177 | |
178 if(pref == &prefs) | |
179 return g_strdup("/"); | |
180 | |
181 name = g_string_new(pref->name); | |
182 parent = pref->parent; | |
3366 | 183 |
5440 | 184 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { |
185 name = g_string_prepend_c(name, '/'); | |
186 name = g_string_prepend(name, parent->name); | |
187 } | |
6693 | 188 ret = name->str; |
5440 | 189 g_string_free(name, FALSE); |
6693 | 190 return ret; |
5440 | 191 } |
192 | |
193 static struct gaim_pref *find_pref(const char *name) | |
194 { | |
195 if(!name || name[0] != '/') { | |
196 return NULL; | |
197 } else if(name[1] == '\0') { | |
198 return &prefs; | |
199 } else { | |
200 return g_hash_table_lookup(prefs_hash, name); | |
201 } | |
202 } | |
203 | |
204 static struct gaim_pref *find_pref_parent(const char *name) | |
205 { | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
206 char *parent_name = get_path_dirname(name); |
5440 | 207 struct gaim_pref *ret = &prefs; |
208 | |
209 if(strcmp(parent_name, "/")) { | |
210 ret = find_pref(parent_name); | |
211 } | |
1026 | 212 |
5440 | 213 g_free(parent_name); |
214 return ret; | |
215 } | |
216 | |
217 static void free_pref_value(struct gaim_pref *pref) { | |
218 switch(pref->type) { | |
219 case GAIM_PREF_BOOLEAN: | |
220 pref->value.boolean = FALSE; | |
7317 | 221 break; |
5440 | 222 case GAIM_PREF_INT: |
223 pref->value.integer = 0; | |
224 break; | |
225 case GAIM_PREF_STRING: | |
226 g_free(pref->value.string); | |
227 pref->value.string = NULL; | |
228 break; | |
5561 | 229 case GAIM_PREF_STRING_LIST: |
230 { | |
231 GList *tmp; | |
232 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
233 g_free(tmp->data); | |
234 | |
235 g_list_free(pref->value.stringlist); | |
236 } break; | |
5440 | 237 case GAIM_PREF_NONE: |
238 break; | |
239 } | |
240 } | |
241 | |
242 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) { | |
243 struct gaim_pref *parent; | |
244 struct gaim_pref *me; | |
245 struct gaim_pref *sibling; | |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
246 char *my_name; |
5440 | 247 |
248 parent = find_pref_parent(name); | |
249 | |
250 if(!parent) | |
251 return NULL; | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
252 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
253 my_name = get_path_basename(name); |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
254 |
5440 | 255 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) { |
256 if(!strcmp(sibling->name, my_name)) { | |
257 g_free(my_name); | |
258 return NULL; | |
259 } | |
260 } | |
261 | |
262 me = g_new0(struct gaim_pref, 1); | |
263 me->type = type; | |
264 me->name = my_name; | |
265 | |
266 me->parent = parent; | |
267 if(parent->first_child) { | |
268 /* blatant abuse of a for loop */ | |
269 for(sibling = parent->first_child; sibling->sibling; | |
270 sibling = sibling->sibling); | |
271 sibling->sibling = me; | |
272 } else { | |
273 parent->first_child = me; | |
274 } | |
275 | |
276 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me); | |
277 | |
278 return me; | |
279 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
280 |
5440 | 281 void gaim_prefs_add_none(const char *name) { |
282 add_pref(GAIM_PREF_NONE, name); | |
283 } | |
284 | |
285 void gaim_prefs_add_bool(const char *name, gboolean value) { | |
286 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name); | |
287 | |
288 if(!pref) | |
289 return; | |
290 | |
291 pref->value.boolean = value; | |
292 } | |
3630 | 293 |
5440 | 294 void gaim_prefs_add_int(const char *name, int value) { |
295 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name); | |
296 | |
297 if(!pref) | |
298 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
299 |
5440 | 300 pref->value.integer = value; |
301 } | |
302 | |
303 void gaim_prefs_add_string(const char *name, const char *value) { | |
304 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name); | |
305 | |
306 if(!pref) | |
307 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
308 |
5440 | 309 pref->value.string = g_strdup(value); |
310 } | |
311 | |
5561 | 312 void gaim_prefs_add_string_list(const char *name, GList *value) { |
313 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); | |
314 GList *tmp; | |
315 | |
316 if(!pref) | |
317 return; | |
318 | |
319 for(tmp = value; tmp; tmp = tmp->next) | |
320 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
321 g_strdup(tmp->data)); | |
322 } | |
323 | |
5440 | 324 void remove_pref(struct gaim_pref *pref) { |
325 char *name; | |
326 | |
327 if(!pref || pref == &prefs) | |
328 return; | |
329 | |
6693 | 330 while(pref->first_child) |
331 remove_pref(pref->first_child); | |
332 | |
5440 | 333 if(pref->parent->first_child == pref) { |
334 pref->parent->first_child = pref->sibling; | |
335 } else { | |
336 struct gaim_pref *sib = pref->parent->first_child; | |
337 while(sib->sibling != pref) | |
338 sib = sib->sibling; | |
339 sib->sibling = pref->sibling; | |
340 } | |
341 | |
342 name = pref_full_name(pref); | |
343 | |
7785 | 344 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref /%s\n", name); |
6693 | 345 |
5440 | 346 g_hash_table_remove(prefs_hash, name); |
347 g_free(name); | |
348 | |
349 free_pref_value(pref); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
350 |
5440 | 351 g_slist_free(pref->callbacks); |
352 g_free(pref->name); | |
353 g_free(pref); | |
354 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
355 |
5440 | 356 void gaim_prefs_remove(const char *name) { |
357 struct gaim_pref *pref = find_pref(name); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
358 |
5440 | 359 if(!pref) |
360 return; | |
361 | |
362 remove_pref(pref); | |
363 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
364 |
5440 | 365 void gaim_prefs_destroy() { |
366 gaim_prefs_remove("/"); | |
367 } | |
368 | |
369 static void do_callbacks(const char* name, struct gaim_pref *pref) { | |
370 GSList *cbs; | |
371 struct gaim_pref *cb_pref; | |
372 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { | |
373 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { | |
374 struct pref_cb *cb = cbs->data; | |
375 cb->func(name, pref->type, pref->value.generic, cb->data); | |
4215 | 376 } |
377 } | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
378 } |
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
379 |
5684 | 380 void gaim_prefs_trigger_callback(const char *name) { |
381 struct gaim_pref *pref = find_pref(name); | |
382 | |
5814 | 383 if(!pref) { |
384 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
385 "gaim_prefs_trigger_callback: Unknown pref %s\n", name); | |
386 return; | |
387 } | |
388 | |
5684 | 389 do_callbacks(name, pref); |
390 } | |
391 | |
5440 | 392 void gaim_prefs_set_generic(const char *name, gpointer value) { |
393 struct gaim_pref *pref = find_pref(name); | |
3366 | 394 |
5814 | 395 if(!pref) { |
396 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
397 "gaim_prefs_set_generic: Unknown pref %s\n", name); | |
398 return; | |
399 } | |
3500 | 400 |
5440 | 401 pref->value.generic = value; |
402 do_callbacks(name, pref); | |
3366 | 403 } |
404 | |
5440 | 405 void gaim_prefs_set_bool(const char *name, gboolean value) { |
406 struct gaim_pref *pref = find_pref(name); | |
4288 | 407 |
5533 | 408 if(pref) { |
5814 | 409 if(pref->type != GAIM_PREF_BOOLEAN) { |
410 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
411 "gaim_prefs_set_bool: %s not a boolean pref\n", name); | |
412 return; | |
413 } | |
4325 | 414 |
5533 | 415 if(pref->value.boolean != value) { |
416 pref->value.boolean = value; | |
417 do_callbacks(name, pref); | |
418 } | |
419 } else { | |
420 gaim_prefs_add_bool(name, value); | |
4288 | 421 } |
4324 | 422 } |
4325 | 423 |
5440 | 424 void gaim_prefs_set_int(const char *name, int value) { |
425 struct gaim_pref *pref = find_pref(name); | |
4325 | 426 |
5533 | 427 if(pref) { |
5814 | 428 if(pref->type != GAIM_PREF_INT) { |
429 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
430 "gaim_prefs_set_int: %s not an integer pref\n", name); | |
431 return; | |
432 } | |
4325 | 433 |
5533 | 434 if(pref->value.integer != value) { |
435 pref->value.integer = value; | |
436 do_callbacks(name, pref); | |
437 } | |
438 } else { | |
439 gaim_prefs_add_int(name, value); | |
5440 | 440 } |
4326 | 441 } |
442 | |
5451 | 443 void gaim_prefs_set_string(const char *name, const char *value) { |
5440 | 444 struct gaim_pref *pref = find_pref(name); |
4325 | 445 |
5533 | 446 if(pref) { |
5814 | 447 if(pref->type != GAIM_PREF_STRING) { |
448 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
449 "gaim_prefs_set_string: %s not a string pref\n", name); | |
450 return; | |
451 } | |
4325 | 452 |
6295 | 453 if((value && !pref->value.string) || |
454 (!value && pref->value.string) || | |
455 strcmp(pref->value.string, value)) { | |
5533 | 456 g_free(pref->value.string); |
457 pref->value.string = g_strdup(value); | |
458 do_callbacks(name, pref); | |
459 } | |
460 } else { | |
461 gaim_prefs_add_string(name, value); | |
4325 | 462 } |
463 } | |
464 | |
5561 | 465 void gaim_prefs_set_string_list(const char *name, GList *value) { |
466 struct gaim_pref *pref = find_pref(name); | |
467 if(pref) { | |
468 GList *tmp; | |
5814 | 469 |
470 if(pref->type != GAIM_PREF_STRING_LIST) { | |
471 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
472 "gaim_prefs_set_string_list: %s not a string list pref\n", | |
473 name); | |
474 return; | |
475 } | |
476 | |
5561 | 477 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) |
478 g_free(tmp->data); | |
479 | |
480 g_list_free(pref->value.stringlist); | |
481 pref->value.stringlist = NULL; | |
482 | |
483 for(tmp = value; tmp; tmp = tmp->next) | |
484 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
485 g_strdup(tmp->data)); | |
486 | |
5986
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
487 do_callbacks(name, pref); |
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
488 |
5561 | 489 } else { |
490 gaim_prefs_add_string_list(name, value); | |
491 } | |
492 } | |
493 | |
5440 | 494 gpointer gaim_prefs_get_generic(const char *name) { |
495 struct gaim_pref *pref = find_pref(name); | |
4325 | 496 |
5814 | 497 if(!pref) { |
498 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
499 "gaim_prefs_get_generic: Unknown pref %s\n", name); | |
500 return NULL; | |
501 } | |
4288 | 502 |
5440 | 503 return pref->value.generic; |
4288 | 504 } |
505 | |
6538 | 506 GaimPrefType gaim_prefs_get_type(const char *name) { |
507 struct gaim_pref *pref = find_pref(name); | |
508 | |
509 if (pref == NULL) | |
510 return GAIM_PREF_NONE; | |
511 | |
512 return (pref->type); | |
513 } | |
514 | |
5440 | 515 gboolean gaim_prefs_get_bool(const char *name) { |
516 struct gaim_pref *pref = find_pref(name); | |
3427 | 517 |
5814 | 518 if(!pref) { |
519 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
520 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
521 return FALSE; | |
522 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
523 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
524 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
525 return FALSE; | |
526 } | |
3472 | 527 |
5440 | 528 return pref->value.boolean; |
3366 | 529 } |
530 | |
5440 | 531 int gaim_prefs_get_int(const char *name) { |
532 struct gaim_pref *pref = find_pref(name); | |
3500 | 533 |
5814 | 534 if(!pref) { |
535 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
536 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
537 return 0; | |
538 } else if(pref->type != GAIM_PREF_INT) { | |
539 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
540 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
541 return 0; | |
542 } | |
3366 | 543 |
5440 | 544 return pref->value.integer; |
3366 | 545 } |
546 | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
547 const char *gaim_prefs_get_string(const char *name) { |
5440 | 548 struct gaim_pref *pref = find_pref(name); |
3366 | 549 |
5814 | 550 if(!pref) { |
551 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
552 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
553 return NULL; | |
554 } else if(pref->type != GAIM_PREF_STRING) { | |
555 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
556 "gaim_prefs_get_string: %s not a string pref\n", name); | |
557 return NULL; | |
558 } | |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
559 |
5440 | 560 return pref->value.string; |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
561 } |
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
562 |
5561 | 563 GList *gaim_prefs_get_string_list(const char *name) { |
564 struct gaim_pref *pref = find_pref(name); | |
565 GList *ret = NULL, *tmp; | |
566 | |
5814 | 567 if(!pref) { |
568 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
569 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
570 return NULL; | |
571 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
572 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
573 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
574 return NULL; | |
575 } | |
5561 | 576 |
577 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
578 ret = g_list_append(ret, g_strdup(tmp->data)); | |
579 | |
580 return ret; | |
581 } | |
582 | |
6693 | 583 void gaim_prefs_rename(const char *oldname, const char *newname) { |
584 struct gaim_pref *oldpref, *newpref; | |
585 | |
7785 | 586 gaim_debug_info("prefs", "Attempting to rename %s to %s\n", oldname, newname); |
587 | |
6693 | 588 oldpref = find_pref(oldname); |
589 newpref = find_pref(newname); | |
590 | |
591 /* it's already been renamed, call off the dogs */ | |
592 if(!oldpref) | |
593 return; | |
594 | |
595 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
596 g_return_if_fail(oldpref->type == newpref->type); | |
597 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
598 | |
599 switch(oldpref->type) { | |
600 case GAIM_PREF_NONE: | |
601 break; | |
602 case GAIM_PREF_BOOLEAN: | |
603 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
604 break; | |
605 case GAIM_PREF_INT: | |
606 gaim_prefs_set_int(newname, oldpref->value.integer); | |
607 break; | |
608 case GAIM_PREF_STRING: | |
609 gaim_prefs_set_string(newname, oldpref->value.string); | |
610 break; | |
611 case GAIM_PREF_STRING_LIST: | |
612 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
613 break; | |
614 } | |
615 | |
616 remove_pref(oldpref); | |
617 } | |
618 | |
619 void gaim_prefs_rename_old() { | |
7555 | 620 gaim_prefs_rename("/gaim/gtk/logging/log_ims", "/core/logging/log_ims"); |
621 gaim_prefs_rename("/gaim/gtk/logging/log_chats", "/core/logging/log_chats"); | |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
622 gaim_prefs_rename("/core/conversations/placement", |
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
623 "/gaim/gtk/conversations/placement"); |
6693 | 624 } |
625 | |
5440 | 626 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
627 { | |
628 struct gaim_pref *pref = find_pref(name); | |
629 struct pref_cb *cb; | |
630 static guint cb_id = 0; | |
3366 | 631 |
5440 | 632 if(!pref) |
633 return 0; | |
3366 | 634 |
5440 | 635 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
636 |
5440 | 637 cb->func = func; |
638 cb->data = data; | |
639 cb->id = ++cb_id; | |
4991 | 640 |
5440 | 641 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 642 |
5440 | 643 return cb->id; |
3366 | 644 } |
645 | |
5440 | 646 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
647 GSList *cbs; | |
648 struct gaim_pref *child; | |
2254 | 649 |
5440 | 650 if(!pref) |
651 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
652 |
5440 | 653 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
654 struct pref_cb *cb = cbs->data; | |
655 if(cb->id == callback_id) { | |
656 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
657 g_free(cb); | |
658 return TRUE; | |
4428 | 659 } |
660 } | |
661 | |
5440 | 662 for(child = pref->first_child; child; child = child->sibling) { |
663 if(disco_callback_helper(child, callback_id)) | |
664 return TRUE; | |
4428 | 665 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
666 |
5440 | 667 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
668 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
669 |
5440 | 670 void gaim_prefs_disconnect_callback(guint callback_id) { |
671 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
672 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
673 |
5440 | 674 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
675 struct gaim_pref *tmp; | |
676 char *esc; | |
677 int i; | |
3500 | 678 |
5440 | 679 if(!pref) { |
680 pref = &prefs; | |
3551 | 681 |
5440 | 682 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
683 fprintf(f, "<pref name='/'"); | |
684 } else { | |
685 for(i=0; i<depth; i++) | |
686 fprintf(f, "\t"); | |
687 esc = g_markup_escape_text(pref->name, -1); | |
688 fprintf(f, "<pref name='%s'", esc); | |
689 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
690 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
691 |
5440 | 692 switch(pref->type) { |
693 case GAIM_PREF_NONE: | |
694 break; | |
695 case GAIM_PREF_BOOLEAN: | |
696 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
697 break; | |
698 case GAIM_PREF_INT: | |
699 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
700 break; | |
701 case GAIM_PREF_STRING: | |
702 esc = g_markup_escape_text(pref->value.string, -1); | |
703 fprintf(f, " type='string' value='%s'", esc); | |
704 g_free(esc); | |
705 break; | |
5561 | 706 case GAIM_PREF_STRING_LIST: |
707 fprintf(f, " type='stringlist'"); | |
708 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
709 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
710 |
5561 | 711 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 712 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
713 |
5440 | 714 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
715 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 716 |
717 if(pref->type == GAIM_PREF_STRING_LIST) { | |
718 GList *tmp2; | |
719 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
720 for(i=0; i<depth+1; i++) | |
721 fprintf(f, "\t"); | |
722 esc = g_markup_escape_text(tmp2->data, -1); | |
723 fprintf(f, "<item value='%s' />\n", esc); | |
724 g_free(esc); | |
725 } | |
726 } | |
727 | |
5440 | 728 for(i=0; i<depth; i++) |
729 fprintf(f, "\t"); | |
730 fprintf(f, "</pref>\n"); | |
731 } else { | |
732 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
733 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
734 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
735 |
5440 | 736 void gaim_prefs_sync() { |
737 FILE *file; | |
738 const char *user_dir = gaim_user_dir(); | |
739 char *filename; | |
740 char *filename_real; | |
3551 | 741 |
5534 | 742 if(!prefs_is_loaded) { |
743 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
744 schedule_prefs_save(); /* schedule a save for after we read in */ | |
745 return; | |
746 } | |
747 | |
5440 | 748 if(!user_dir) |
749 return; | |
3551 | 750 |
5534 | 751 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
752 | |
5440 | 753 file = fopen(user_dir, "r"); |
754 if(!file) | |
755 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
756 else | |
757 fclose(file); | |
3551 | 758 |
5440 | 759 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 760 |
5440 | 761 if((file = fopen(filename, "w"))) { |
762 gaim_prefs_write(file, NULL, 0); | |
763 fclose(file); | |
764 chmod(filename, S_IRUSR | S_IWUSR); | |
765 } else { | |
766 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
767 filename); | |
768 } | |
3551 | 769 |
5440 | 770 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
771 if(rename(filename, filename_real) < 0) | |
772 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
773 filename, filename_real); | |
3551 | 774 |
5440 | 775 g_free(filename); |
776 g_free(filename_real); | |
3551 | 777 } |
778 | |
5440 | 779 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
780 |
5440 | 781 static void prefs_start_element_handler (GMarkupParseContext *context, |
782 const gchar *element_name, | |
783 const gchar **attribute_names, | |
784 const gchar **attribute_values, | |
785 gpointer user_data, | |
786 GError **error) { | |
787 GaimPrefType pref_type = GAIM_PREF_NONE; | |
788 int i; | |
789 const char *pref_name = NULL, *pref_value = NULL; | |
790 GString *pref_name_full; | |
791 GList *tmp; | |
3366 | 792 |
5561 | 793 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 794 return; |
3500 | 795 |
5440 | 796 for(i = 0; attribute_names[i]; i++) { |
797 if(!strcmp(attribute_names[i], "name")) { | |
798 pref_name = attribute_values[i]; | |
799 } else if(!strcmp(attribute_names[i], "type")) { | |
800 if(!strcmp(attribute_values[i], "bool")) | |
801 pref_type = GAIM_PREF_BOOLEAN; | |
802 else if(!strcmp(attribute_values[i], "int")) | |
803 pref_type = GAIM_PREF_INT; | |
804 else if(!strcmp(attribute_values[i], "string")) | |
805 pref_type = GAIM_PREF_STRING; | |
5561 | 806 else if(!strcmp(attribute_values[i], "stringlist")) |
807 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 808 else |
809 return; | |
810 } else if(!strcmp(attribute_names[i], "value")) { | |
811 pref_value = attribute_values[i]; | |
812 } | |
813 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
814 |
5561 | 815 if(!strcmp(element_name, "item")) { |
5838 | 816 struct gaim_pref *pref; |
817 | |
818 pref_name_full = g_string_new(""); | |
819 | |
820 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
821 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
822 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
823 } | |
824 | |
825 pref = find_pref(pref_name_full->str); | |
826 | |
5561 | 827 if(pref) { |
828 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
829 g_strdup(pref_value)); | |
830 } | |
5838 | 831 } else { |
832 if(!pref_name || !strcmp(pref_name, "/")) | |
833 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
834 |
5838 | 835 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
836 |
5838 | 837 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
838 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
839 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
840 } | |
841 | |
5440 | 842 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
843 |
5838 | 844 switch(pref_type) { |
845 case GAIM_PREF_NONE: | |
7785 | 846 gaim_prefs_add_none(pref_name_full->str); |
5838 | 847 break; |
848 case GAIM_PREF_BOOLEAN: | |
849 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
850 break; | |
851 case GAIM_PREF_INT: | |
852 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
853 break; | |
854 case GAIM_PREF_STRING: | |
855 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
856 break; | |
857 case GAIM_PREF_STRING_LIST: | |
858 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
859 break; | |
860 } | |
861 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
862 g_string_free(pref_name_full, TRUE); | |
5440 | 863 } |
1170 | 864 } |
865 | |
5440 | 866 static void prefs_end_element_handler(GMarkupParseContext *context, |
867 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 868 if(prefs_stack && !strcmp(element_name, "pref")) { |
869 g_free(prefs_stack->data); | |
5440 | 870 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
871 } | |
1170 | 872 } |
873 | |
5440 | 874 static GMarkupParser prefs_parser = { |
875 prefs_start_element_handler, | |
876 prefs_end_element_handler, | |
877 NULL, | |
878 NULL, | |
879 NULL | |
880 }; | |
1170 | 881 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
882 gboolean gaim_prefs_load() { |
5440 | 883 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
884 gchar *contents = NULL; | |
885 gsize length; | |
886 GMarkupParseContext *context; | |
887 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
888 |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
889 if (!filename) { |
5534 | 890 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
891 return FALSE; |
5534 | 892 } |
5440 | 893 |
894 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
895 |
5440 | 896 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
897 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", | |
898 error->message); | |
899 g_error_free(error); | |
6040 | 900 g_free(filename); |
5534 | 901 prefs_is_loaded = TRUE; |
6040 | 902 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
903 return FALSE; |
1170 | 904 } |
905 | |
5440 | 906 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
907 | |
908 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
909 g_markup_parse_context_free(context); | |
910 g_free(contents); | |
6040 | 911 g_free(filename); |
5534 | 912 prefs_is_loaded = TRUE; |
6040 | 913 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
914 return FALSE; |
5440 | 915 } |
916 | |
917 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
918 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
919 g_markup_parse_context_free(context); | |
920 g_free(contents); | |
6040 | 921 g_free(filename); |
5534 | 922 prefs_is_loaded = TRUE; |
6040 | 923 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
924 return FALSE; |
5440 | 925 } |
926 | |
6040 | 927 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); |
5440 | 928 g_markup_parse_context_free(context); |
929 g_free(contents); | |
930 g_free(filename); | |
5534 | 931 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
932 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
933 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
934 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
935 |