Mercurial > pidgin
annotate src/prefs.c @ 5979:49ae70ffcea5
[gaim-migrate @ 6426]
The check mail option now actually works. It turns out I was quite stupid
and cleared all settings almost immediately after setting that one. Doh.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 30 Jun 2003 04:45:52 +0000 |
parents | 90d0849abd3c |
children | 96e0ac28d933 |
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 | |
472 } else { | |
473 gaim_prefs_add_string_list(name, value); | |
474 } | |
475 } | |
476 | |
5440 | 477 gpointer gaim_prefs_get_generic(const char *name) { |
478 struct gaim_pref *pref = find_pref(name); | |
4325 | 479 |
5814 | 480 if(!pref) { |
481 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
482 "gaim_prefs_get_generic: Unknown pref %s\n", name); | |
483 return NULL; | |
484 } | |
4288 | 485 |
5440 | 486 return pref->value.generic; |
4288 | 487 } |
488 | |
5440 | 489 gboolean gaim_prefs_get_bool(const char *name) { |
490 struct gaim_pref *pref = find_pref(name); | |
3427 | 491 |
5814 | 492 if(!pref) { |
493 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
494 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
495 return FALSE; | |
496 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
497 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
498 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
499 return FALSE; | |
500 } | |
3472 | 501 |
5440 | 502 return pref->value.boolean; |
3366 | 503 } |
504 | |
5440 | 505 int gaim_prefs_get_int(const char *name) { |
506 struct gaim_pref *pref = find_pref(name); | |
3500 | 507 |
5814 | 508 if(!pref) { |
509 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
510 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
511 return 0; | |
512 } else if(pref->type != GAIM_PREF_INT) { | |
513 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
514 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
515 return 0; | |
516 } | |
3366 | 517 |
5440 | 518 return pref->value.integer; |
3366 | 519 } |
520 | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
521 const char *gaim_prefs_get_string(const char *name) { |
5440 | 522 struct gaim_pref *pref = find_pref(name); |
3366 | 523 |
5814 | 524 if(!pref) { |
525 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
526 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
527 return NULL; | |
528 } else if(pref->type != GAIM_PREF_STRING) { | |
529 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
530 "gaim_prefs_get_string: %s not a string pref\n", name); | |
531 return NULL; | |
532 } | |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
533 |
5440 | 534 return pref->value.string; |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
535 } |
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
536 |
5561 | 537 GList *gaim_prefs_get_string_list(const char *name) { |
538 struct gaim_pref *pref = find_pref(name); | |
539 GList *ret = NULL, *tmp; | |
540 | |
5814 | 541 if(!pref) { |
542 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
543 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
544 return NULL; | |
545 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
546 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
547 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
548 return NULL; | |
549 } | |
5561 | 550 |
551 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
552 ret = g_list_append(ret, g_strdup(tmp->data)); | |
553 | |
554 return ret; | |
555 } | |
556 | |
5440 | 557 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
558 { | |
559 struct gaim_pref *pref = find_pref(name); | |
560 struct pref_cb *cb; | |
561 static guint cb_id = 0; | |
3366 | 562 |
5440 | 563 if(!pref) |
564 return 0; | |
3366 | 565 |
5440 | 566 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
567 |
5440 | 568 cb->func = func; |
569 cb->data = data; | |
570 cb->id = ++cb_id; | |
4991 | 571 |
5440 | 572 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 573 |
5440 | 574 return cb->id; |
3366 | 575 } |
576 | |
5440 | 577 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
578 GSList *cbs; | |
579 struct gaim_pref *child; | |
2254 | 580 |
5440 | 581 if(!pref) |
582 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
583 |
5440 | 584 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
585 struct pref_cb *cb = cbs->data; | |
586 if(cb->id == callback_id) { | |
587 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
588 g_free(cb); | |
589 return TRUE; | |
4428 | 590 } |
591 } | |
592 | |
5440 | 593 for(child = pref->first_child; child; child = child->sibling) { |
594 if(disco_callback_helper(child, callback_id)) | |
595 return TRUE; | |
4428 | 596 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
597 |
5440 | 598 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
599 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
600 |
5440 | 601 void gaim_prefs_disconnect_callback(guint callback_id) { |
602 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
603 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
604 |
5440 | 605 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
606 struct gaim_pref *tmp; | |
607 char *esc; | |
608 int i; | |
3500 | 609 |
5440 | 610 if(!pref) { |
611 pref = &prefs; | |
3551 | 612 |
5440 | 613 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
614 fprintf(f, "<pref name='/'"); | |
615 } else { | |
616 for(i=0; i<depth; i++) | |
617 fprintf(f, "\t"); | |
618 esc = g_markup_escape_text(pref->name, -1); | |
619 fprintf(f, "<pref name='%s'", esc); | |
620 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
621 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
622 |
5440 | 623 switch(pref->type) { |
624 case GAIM_PREF_NONE: | |
625 break; | |
626 case GAIM_PREF_BOOLEAN: | |
627 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
628 break; | |
629 case GAIM_PREF_INT: | |
630 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
631 break; | |
632 case GAIM_PREF_STRING: | |
633 esc = g_markup_escape_text(pref->value.string, -1); | |
634 fprintf(f, " type='string' value='%s'", esc); | |
635 g_free(esc); | |
636 break; | |
5561 | 637 case GAIM_PREF_STRING_LIST: |
638 fprintf(f, " type='stringlist'"); | |
639 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
640 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
641 |
5561 | 642 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 643 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
644 |
5440 | 645 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
646 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 647 |
648 if(pref->type == GAIM_PREF_STRING_LIST) { | |
649 GList *tmp2; | |
650 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
651 for(i=0; i<depth+1; i++) | |
652 fprintf(f, "\t"); | |
653 esc = g_markup_escape_text(tmp2->data, -1); | |
654 fprintf(f, "<item value='%s' />\n", esc); | |
655 g_free(esc); | |
656 } | |
657 } | |
658 | |
5440 | 659 for(i=0; i<depth; i++) |
660 fprintf(f, "\t"); | |
661 fprintf(f, "</pref>\n"); | |
662 } else { | |
663 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
664 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
665 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
666 |
5440 | 667 void gaim_prefs_sync() { |
668 FILE *file; | |
669 const char *user_dir = gaim_user_dir(); | |
670 char *filename; | |
671 char *filename_real; | |
3551 | 672 |
5534 | 673 if(!prefs_is_loaded) { |
674 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
675 schedule_prefs_save(); /* schedule a save for after we read in */ | |
676 return; | |
677 } | |
678 | |
5440 | 679 if(!user_dir) |
680 return; | |
3551 | 681 |
5534 | 682 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
683 | |
5440 | 684 file = fopen(user_dir, "r"); |
685 if(!file) | |
686 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
687 else | |
688 fclose(file); | |
3551 | 689 |
5440 | 690 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 691 |
5440 | 692 if((file = fopen(filename, "w"))) { |
693 gaim_prefs_write(file, NULL, 0); | |
694 fclose(file); | |
695 chmod(filename, S_IRUSR | S_IWUSR); | |
696 } else { | |
697 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
698 filename); | |
699 } | |
3551 | 700 |
5440 | 701 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
702 if(rename(filename, filename_real) < 0) | |
703 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
704 filename, filename_real); | |
3551 | 705 |
5440 | 706 g_free(filename); |
707 g_free(filename_real); | |
3551 | 708 } |
709 | |
5440 | 710 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
711 |
5440 | 712 static void prefs_start_element_handler (GMarkupParseContext *context, |
713 const gchar *element_name, | |
714 const gchar **attribute_names, | |
715 const gchar **attribute_values, | |
716 gpointer user_data, | |
717 GError **error) { | |
718 GaimPrefType pref_type = GAIM_PREF_NONE; | |
719 int i; | |
720 const char *pref_name = NULL, *pref_value = NULL; | |
721 GString *pref_name_full; | |
722 GList *tmp; | |
3366 | 723 |
5561 | 724 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 725 return; |
3500 | 726 |
5440 | 727 for(i = 0; attribute_names[i]; i++) { |
728 if(!strcmp(attribute_names[i], "name")) { | |
729 pref_name = attribute_values[i]; | |
730 } else if(!strcmp(attribute_names[i], "type")) { | |
731 if(!strcmp(attribute_values[i], "bool")) | |
732 pref_type = GAIM_PREF_BOOLEAN; | |
733 else if(!strcmp(attribute_values[i], "int")) | |
734 pref_type = GAIM_PREF_INT; | |
735 else if(!strcmp(attribute_values[i], "string")) | |
736 pref_type = GAIM_PREF_STRING; | |
5561 | 737 else if(!strcmp(attribute_values[i], "stringlist")) |
738 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 739 else |
740 return; | |
741 } else if(!strcmp(attribute_names[i], "value")) { | |
742 pref_value = attribute_values[i]; | |
743 } | |
744 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
745 |
5561 | 746 if(!strcmp(element_name, "item")) { |
5838 | 747 struct gaim_pref *pref; |
748 | |
749 pref_name_full = g_string_new(""); | |
750 | |
751 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
752 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
753 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
754 } | |
755 | |
756 pref = find_pref(pref_name_full->str); | |
757 | |
5561 | 758 if(pref) { |
759 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
760 g_strdup(pref_value)); | |
761 } | |
5838 | 762 } else { |
763 if(!pref_name || !strcmp(pref_name, "/")) | |
764 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
765 |
5838 | 766 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
767 |
5838 | 768 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
769 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
770 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
771 } | |
772 | |
5440 | 773 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
774 |
5838 | 775 switch(pref_type) { |
776 case GAIM_PREF_NONE: | |
777 break; | |
778 case GAIM_PREF_BOOLEAN: | |
779 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
780 break; | |
781 case GAIM_PREF_INT: | |
782 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
783 break; | |
784 case GAIM_PREF_STRING: | |
785 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
786 break; | |
787 case GAIM_PREF_STRING_LIST: | |
788 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
789 break; | |
790 } | |
791 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
792 g_string_free(pref_name_full, TRUE); | |
5440 | 793 } |
1170 | 794 } |
795 | |
5440 | 796 static void prefs_end_element_handler(GMarkupParseContext *context, |
797 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 798 if(prefs_stack && !strcmp(element_name, "pref")) { |
799 g_free(prefs_stack->data); | |
5440 | 800 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
801 } | |
1170 | 802 } |
803 | |
5440 | 804 static GMarkupParser prefs_parser = { |
805 prefs_start_element_handler, | |
806 prefs_end_element_handler, | |
807 NULL, | |
808 NULL, | |
809 NULL | |
810 }; | |
1170 | 811 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
812 gboolean gaim_prefs_load() { |
5440 | 813 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
814 gchar *contents = NULL; | |
815 gsize length; | |
816 GMarkupParseContext *context; | |
817 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
818 |
5534 | 819 |
820 if(!filename) { | |
821 prefs_is_loaded = TRUE; | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
822 return FALSE; |
5534 | 823 } |
5440 | 824 |
825 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
826 |
5440 | 827 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
828 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", | |
829 error->message); | |
830 g_error_free(error); | |
5534 | 831 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
832 return FALSE; |
1170 | 833 } |
834 | |
5440 | 835 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
836 | |
837 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
838 g_markup_parse_context_free(context); | |
839 g_free(contents); | |
5534 | 840 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
841 return FALSE; |
5440 | 842 } |
843 | |
844 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
845 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
846 g_markup_parse_context_free(context); | |
847 g_free(contents); | |
5534 | 848 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
849 return FALSE; |
5440 | 850 } |
851 | |
852 g_markup_parse_context_free(context); | |
853 g_free(contents); | |
854 | |
855 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); | |
856 g_free(filename); | |
5534 | 857 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
858 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
859 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
860 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
861 |