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