Mercurial > pidgin
annotate src/prefs.c @ 5878:9e54bb2ee3b5
[gaim-migrate @ 6310]
Whether or not pounces save after activation is now saved and loaded in
pounces.xml.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 15 Jun 2003 03:22:55 +0000 |
parents | 96e5b32e75ad |
children | 94ad4d45346a |
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"); |
5838 | 103 gaim_prefs_add_string_list("/plugins/loaded", NULL); |
5529
e7747cae9710
[gaim-migrate @ 5929]
Christian Hammond <chipx86@chipx86.com>
parents:
5458
diff
changeset
|
104 |
5440 | 105 /* 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
|
106 |
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); |
5550
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
110 gaim_prefs_add_int("/core/away/mins_before_away", 1); |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
111 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
112 /* Away -> Auto Response */ |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
113 gaim_prefs_add_none("/core/away/auto_response"); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
114 gaim_prefs_add_bool("/core/away/auto_response/enabled", TRUE); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
119 /* Buddies */ |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
120 gaim_prefs_add_none("/core/buddies"); |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
121 gaim_prefs_add_bool("/core/buddies/use_server_alias", TRUE); |
5440 | 122 } |
3366 | 123 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
124 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
125 get_path_dirname(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
126 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
127 char *c, *str; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
128 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
129 str = g_strdup(name); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
130 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
131 if ((c = strrchr(str, '/')) != NULL) { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
132 *c = '\0'; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
133 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
134 if (*str == '\0') { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
135 g_free(str); |
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 str = g_strdup("/"); |
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 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
140 else { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
141 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
142 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
143 str = g_strdup("."); |
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 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
146 return str; |
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 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
149 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
150 get_path_basename(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
151 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
152 const char *c; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
153 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
154 if ((c = strrchr(name, '/')) != NULL) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
155 return g_strdup(c + 1); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
156 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
157 return g_strdup(name); |
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 |
5440 | 160 static char *pref_full_name(struct gaim_pref *pref) { |
161 GString *name; | |
162 struct gaim_pref *parent; | |
163 if(!pref) | |
164 return NULL; | |
165 | |
166 if(pref == &prefs) | |
167 return g_strdup("/"); | |
168 | |
169 name = g_string_new(pref->name); | |
170 parent = pref->parent; | |
3366 | 171 |
5440 | 172 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { |
173 name = g_string_prepend_c(name, '/'); | |
174 name = g_string_prepend(name, parent->name); | |
175 } | |
176 g_string_free(name, FALSE); | |
177 return name->str; | |
178 } | |
179 | |
180 static struct gaim_pref *find_pref(const char *name) | |
181 { | |
182 if(!name || name[0] != '/') { | |
183 return NULL; | |
184 } else if(name[1] == '\0') { | |
185 return &prefs; | |
186 } else { | |
187 return g_hash_table_lookup(prefs_hash, name); | |
188 } | |
189 } | |
190 | |
191 static struct gaim_pref *find_pref_parent(const char *name) | |
192 { | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
193 char *parent_name = get_path_dirname(name); |
5440 | 194 struct gaim_pref *ret = &prefs; |
195 | |
196 if(strcmp(parent_name, "/")) { | |
197 ret = find_pref(parent_name); | |
198 } | |
1026 | 199 |
5440 | 200 g_free(parent_name); |
201 return ret; | |
202 } | |
203 | |
204 static void free_pref_value(struct gaim_pref *pref) { | |
205 switch(pref->type) { | |
206 case GAIM_PREF_BOOLEAN: | |
207 pref->value.boolean = FALSE; | |
208 case GAIM_PREF_INT: | |
209 pref->value.integer = 0; | |
210 break; | |
211 case GAIM_PREF_STRING: | |
212 g_free(pref->value.string); | |
213 pref->value.string = NULL; | |
214 break; | |
5561 | 215 case GAIM_PREF_STRING_LIST: |
216 { | |
217 GList *tmp; | |
218 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
219 g_free(tmp->data); | |
220 | |
221 g_list_free(pref->value.stringlist); | |
222 } break; | |
5440 | 223 case GAIM_PREF_NONE: |
224 break; | |
225 } | |
226 } | |
227 | |
228 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) { | |
229 struct gaim_pref *parent; | |
230 struct gaim_pref *me; | |
231 struct gaim_pref *sibling; | |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
232 char *my_name; |
5440 | 233 |
234 parent = find_pref_parent(name); | |
235 | |
236 if(!parent) | |
237 return NULL; | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
238 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
239 my_name = get_path_basename(name); |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
240 |
5440 | 241 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) { |
242 if(!strcmp(sibling->name, my_name)) { | |
243 g_free(my_name); | |
244 return NULL; | |
245 } | |
246 } | |
247 | |
248 me = g_new0(struct gaim_pref, 1); | |
249 me->type = type; | |
250 me->name = my_name; | |
251 | |
252 me->parent = parent; | |
253 if(parent->first_child) { | |
254 /* blatant abuse of a for loop */ | |
255 for(sibling = parent->first_child; sibling->sibling; | |
256 sibling = sibling->sibling); | |
257 sibling->sibling = me; | |
258 } else { | |
259 parent->first_child = me; | |
260 } | |
261 | |
262 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me); | |
263 | |
264 return me; | |
265 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
266 |
5440 | 267 void gaim_prefs_add_none(const char *name) { |
268 add_pref(GAIM_PREF_NONE, name); | |
269 } | |
270 | |
271 void gaim_prefs_add_bool(const char *name, gboolean value) { | |
272 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name); | |
273 | |
274 if(!pref) | |
275 return; | |
276 | |
277 pref->value.boolean = value; | |
278 } | |
3630 | 279 |
5440 | 280 void gaim_prefs_add_int(const char *name, int value) { |
281 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name); | |
282 | |
283 if(!pref) | |
284 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
285 |
5440 | 286 pref->value.integer = value; |
287 } | |
288 | |
289 void gaim_prefs_add_string(const char *name, const char *value) { | |
290 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name); | |
291 | |
292 if(!pref) | |
293 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
294 |
5440 | 295 pref->value.string = g_strdup(value); |
296 } | |
297 | |
5561 | 298 void gaim_prefs_add_string_list(const char *name, GList *value) { |
299 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); | |
300 GList *tmp; | |
301 | |
302 if(!pref) | |
303 return; | |
304 | |
305 for(tmp = value; tmp; tmp = tmp->next) | |
306 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
307 g_strdup(tmp->data)); | |
308 } | |
309 | |
5440 | 310 void remove_pref(struct gaim_pref *pref) { |
311 char *name; | |
312 | |
313 if(!pref || pref == &prefs) | |
314 return; | |
315 | |
316 if(pref->parent->first_child == pref) { | |
317 pref->parent->first_child = pref->sibling; | |
318 } else { | |
319 struct gaim_pref *sib = pref->parent->first_child; | |
320 while(sib->sibling != pref) | |
321 sib = sib->sibling; | |
322 sib->sibling = pref->sibling; | |
323 } | |
324 | |
325 name = pref_full_name(pref); | |
326 | |
327 g_hash_table_remove(prefs_hash, name); | |
328 g_free(name); | |
329 | |
330 free_pref_value(pref); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
331 |
5440 | 332 g_slist_free(pref->callbacks); |
333 g_free(pref->name); | |
334 g_free(pref); | |
335 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
336 |
5440 | 337 void gaim_prefs_remove(const char *name) { |
338 struct gaim_pref *pref = find_pref(name); | |
339 struct gaim_pref *child, *child2; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
340 |
5440 | 341 if(!pref) |
342 return; | |
343 child = pref->first_child; | |
344 while(child) { | |
345 child2 = child; | |
346 child = child->sibling; | |
347 remove_pref(child2); | |
348 } | |
349 | |
350 remove_pref(pref); | |
351 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
352 |
5440 | 353 void gaim_prefs_destroy() { |
354 gaim_prefs_remove("/"); | |
355 } | |
356 | |
357 static void do_callbacks(const char* name, struct gaim_pref *pref) { | |
358 GSList *cbs; | |
359 struct gaim_pref *cb_pref; | |
360 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { | |
361 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { | |
362 struct pref_cb *cb = cbs->data; | |
363 cb->func(name, pref->type, pref->value.generic, cb->data); | |
4215 | 364 } |
365 } | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
366 } |
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
367 |
5684 | 368 void gaim_prefs_trigger_callback(const char *name) { |
369 struct gaim_pref *pref = find_pref(name); | |
370 | |
5814 | 371 if(!pref) { |
372 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
373 "gaim_prefs_trigger_callback: Unknown pref %s\n", name); | |
374 return; | |
375 } | |
376 | |
5684 | 377 do_callbacks(name, pref); |
378 } | |
379 | |
5440 | 380 void gaim_prefs_set_generic(const char *name, gpointer value) { |
381 struct gaim_pref *pref = find_pref(name); | |
3366 | 382 |
5814 | 383 if(!pref) { |
384 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
385 "gaim_prefs_set_generic: Unknown pref %s\n", name); | |
386 return; | |
387 } | |
3500 | 388 |
5440 | 389 pref->value.generic = value; |
390 do_callbacks(name, pref); | |
3366 | 391 } |
392 | |
5440 | 393 void gaim_prefs_set_bool(const char *name, gboolean value) { |
394 struct gaim_pref *pref = find_pref(name); | |
4288 | 395 |
5533 | 396 if(pref) { |
5814 | 397 if(pref->type != GAIM_PREF_BOOLEAN) { |
398 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
399 "gaim_prefs_set_bool: %s not a boolean pref\n", name); | |
400 return; | |
401 } | |
4325 | 402 |
5533 | 403 if(pref->value.boolean != value) { |
404 pref->value.boolean = value; | |
405 do_callbacks(name, pref); | |
406 } | |
407 } else { | |
408 gaim_prefs_add_bool(name, value); | |
4288 | 409 } |
4324 | 410 } |
4325 | 411 |
5440 | 412 void gaim_prefs_set_int(const char *name, int value) { |
413 struct gaim_pref *pref = find_pref(name); | |
4325 | 414 |
5533 | 415 if(pref) { |
5814 | 416 if(pref->type != GAIM_PREF_INT) { |
417 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
418 "gaim_prefs_set_int: %s not an integer pref\n", name); | |
419 return; | |
420 } | |
4325 | 421 |
5533 | 422 if(pref->value.integer != value) { |
423 pref->value.integer = value; | |
424 do_callbacks(name, pref); | |
425 } | |
426 } else { | |
427 gaim_prefs_add_int(name, value); | |
5440 | 428 } |
4326 | 429 } |
430 | |
5451 | 431 void gaim_prefs_set_string(const char *name, const char *value) { |
5440 | 432 struct gaim_pref *pref = find_pref(name); |
4325 | 433 |
5533 | 434 if(pref) { |
5814 | 435 if(pref->type != GAIM_PREF_STRING) { |
436 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
437 "gaim_prefs_set_string: %s not a string pref\n", name); | |
438 return; | |
439 } | |
4325 | 440 |
5533 | 441 if(strcmp(pref->value.string, value)) { |
442 g_free(pref->value.string); | |
443 pref->value.string = g_strdup(value); | |
444 do_callbacks(name, pref); | |
445 } | |
446 } else { | |
447 gaim_prefs_add_string(name, value); | |
4325 | 448 } |
449 } | |
450 | |
5561 | 451 void gaim_prefs_set_string_list(const char *name, GList *value) { |
452 struct gaim_pref *pref = find_pref(name); | |
453 if(pref) { | |
454 GList *tmp; | |
5814 | 455 |
456 if(pref->type != GAIM_PREF_STRING_LIST) { | |
457 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
458 "gaim_prefs_set_string_list: %s not a string list pref\n", | |
459 name); | |
460 return; | |
461 } | |
462 | |
5561 | 463 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) |
464 g_free(tmp->data); | |
465 | |
466 g_list_free(pref->value.stringlist); | |
467 pref->value.stringlist = NULL; | |
468 | |
469 for(tmp = value; tmp; tmp = tmp->next) | |
470 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
471 g_strdup(tmp->data)); | |
472 | |
473 } else { | |
474 gaim_prefs_add_string_list(name, value); | |
475 } | |
476 } | |
477 | |
5440 | 478 gpointer gaim_prefs_get_generic(const char *name) { |
479 struct gaim_pref *pref = find_pref(name); | |
4325 | 480 |
5814 | 481 if(!pref) { |
482 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
483 "gaim_prefs_get_generic: Unknown pref %s\n", name); | |
484 return NULL; | |
485 } | |
4288 | 486 |
5440 | 487 return pref->value.generic; |
4288 | 488 } |
489 | |
5440 | 490 gboolean gaim_prefs_get_bool(const char *name) { |
491 struct gaim_pref *pref = find_pref(name); | |
3427 | 492 |
5814 | 493 if(!pref) { |
494 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
495 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
496 return FALSE; | |
497 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
498 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
499 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
500 return FALSE; | |
501 } | |
3472 | 502 |
5440 | 503 return pref->value.boolean; |
3366 | 504 } |
505 | |
5440 | 506 int gaim_prefs_get_int(const char *name) { |
507 struct gaim_pref *pref = find_pref(name); | |
3500 | 508 |
5814 | 509 if(!pref) { |
510 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
511 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
512 return 0; | |
513 } else if(pref->type != GAIM_PREF_INT) { | |
514 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
515 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
516 return 0; | |
517 } | |
3366 | 518 |
5440 | 519 return pref->value.integer; |
3366 | 520 } |
521 | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
522 const char *gaim_prefs_get_string(const char *name) { |
5440 | 523 struct gaim_pref *pref = find_pref(name); |
3366 | 524 |
5814 | 525 if(!pref) { |
526 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
527 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
528 return NULL; | |
529 } else if(pref->type != GAIM_PREF_STRING) { | |
530 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
531 "gaim_prefs_get_string: %s not a string pref\n", name); | |
532 return NULL; | |
533 } | |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
534 |
5440 | 535 return pref->value.string; |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
536 } |
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
537 |
5561 | 538 GList *gaim_prefs_get_string_list(const char *name) { |
539 struct gaim_pref *pref = find_pref(name); | |
540 GList *ret = NULL, *tmp; | |
541 | |
5814 | 542 if(!pref) { |
543 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
544 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
545 return NULL; | |
546 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
547 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
548 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
549 return NULL; | |
550 } | |
5561 | 551 |
552 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
553 ret = g_list_append(ret, g_strdup(tmp->data)); | |
554 | |
555 return ret; | |
556 } | |
557 | |
5440 | 558 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
559 { | |
560 struct gaim_pref *pref = find_pref(name); | |
561 struct pref_cb *cb; | |
562 static guint cb_id = 0; | |
3366 | 563 |
5440 | 564 if(!pref) |
565 return 0; | |
3366 | 566 |
5440 | 567 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
568 |
5440 | 569 cb->func = func; |
570 cb->data = data; | |
571 cb->id = ++cb_id; | |
4991 | 572 |
5440 | 573 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 574 |
5440 | 575 return cb->id; |
3366 | 576 } |
577 | |
5440 | 578 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
579 GSList *cbs; | |
580 struct gaim_pref *child; | |
2254 | 581 |
5440 | 582 if(!pref) |
583 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
584 |
5440 | 585 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
586 struct pref_cb *cb = cbs->data; | |
587 if(cb->id == callback_id) { | |
588 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
589 g_free(cb); | |
590 return TRUE; | |
4428 | 591 } |
592 } | |
593 | |
5440 | 594 for(child = pref->first_child; child; child = child->sibling) { |
595 if(disco_callback_helper(child, callback_id)) | |
596 return TRUE; | |
4428 | 597 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
598 |
5440 | 599 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
600 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
601 |
5440 | 602 void gaim_prefs_disconnect_callback(guint callback_id) { |
603 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
604 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
605 |
5440 | 606 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
607 struct gaim_pref *tmp; | |
608 char *esc; | |
609 int i; | |
3500 | 610 |
5440 | 611 if(!pref) { |
612 pref = &prefs; | |
3551 | 613 |
5440 | 614 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
615 fprintf(f, "<pref name='/'"); | |
616 } else { | |
617 for(i=0; i<depth; i++) | |
618 fprintf(f, "\t"); | |
619 esc = g_markup_escape_text(pref->name, -1); | |
620 fprintf(f, "<pref name='%s'", esc); | |
621 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
622 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
623 |
5440 | 624 switch(pref->type) { |
625 case GAIM_PREF_NONE: | |
626 break; | |
627 case GAIM_PREF_BOOLEAN: | |
628 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
629 break; | |
630 case GAIM_PREF_INT: | |
631 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
632 break; | |
633 case GAIM_PREF_STRING: | |
634 esc = g_markup_escape_text(pref->value.string, -1); | |
635 fprintf(f, " type='string' value='%s'", esc); | |
636 g_free(esc); | |
637 break; | |
5561 | 638 case GAIM_PREF_STRING_LIST: |
639 fprintf(f, " type='stringlist'"); | |
640 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
641 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
642 |
5561 | 643 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 644 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
645 |
5440 | 646 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
647 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 648 |
649 if(pref->type == GAIM_PREF_STRING_LIST) { | |
650 GList *tmp2; | |
651 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
652 for(i=0; i<depth+1; i++) | |
653 fprintf(f, "\t"); | |
654 esc = g_markup_escape_text(tmp2->data, -1); | |
655 fprintf(f, "<item value='%s' />\n", esc); | |
656 g_free(esc); | |
657 } | |
658 } | |
659 | |
5440 | 660 for(i=0; i<depth; i++) |
661 fprintf(f, "\t"); | |
662 fprintf(f, "</pref>\n"); | |
663 } else { | |
664 fprintf(f, " />\n"); | |
5205
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 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
667 |
5440 | 668 void gaim_prefs_sync() { |
669 FILE *file; | |
670 const char *user_dir = gaim_user_dir(); | |
671 char *filename; | |
672 char *filename_real; | |
3551 | 673 |
5534 | 674 if(!prefs_is_loaded) { |
675 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
676 schedule_prefs_save(); /* schedule a save for after we read in */ | |
677 return; | |
678 } | |
679 | |
5440 | 680 if(!user_dir) |
681 return; | |
3551 | 682 |
5534 | 683 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
684 | |
5440 | 685 file = fopen(user_dir, "r"); |
686 if(!file) | |
687 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
688 else | |
689 fclose(file); | |
3551 | 690 |
5440 | 691 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 692 |
5440 | 693 if((file = fopen(filename, "w"))) { |
694 gaim_prefs_write(file, NULL, 0); | |
695 fclose(file); | |
696 chmod(filename, S_IRUSR | S_IWUSR); | |
697 } else { | |
698 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
699 filename); | |
700 } | |
3551 | 701 |
5440 | 702 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
703 if(rename(filename, filename_real) < 0) | |
704 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
705 filename, filename_real); | |
3551 | 706 |
5440 | 707 g_free(filename); |
708 g_free(filename_real); | |
3551 | 709 } |
710 | |
5440 | 711 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
712 |
5440 | 713 static void prefs_start_element_handler (GMarkupParseContext *context, |
714 const gchar *element_name, | |
715 const gchar **attribute_names, | |
716 const gchar **attribute_values, | |
717 gpointer user_data, | |
718 GError **error) { | |
719 GaimPrefType pref_type = GAIM_PREF_NONE; | |
720 int i; | |
721 const char *pref_name = NULL, *pref_value = NULL; | |
722 GString *pref_name_full; | |
723 GList *tmp; | |
3366 | 724 |
5561 | 725 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 726 return; |
3500 | 727 |
5440 | 728 for(i = 0; attribute_names[i]; i++) { |
729 if(!strcmp(attribute_names[i], "name")) { | |
730 pref_name = attribute_values[i]; | |
731 } else if(!strcmp(attribute_names[i], "type")) { | |
732 if(!strcmp(attribute_values[i], "bool")) | |
733 pref_type = GAIM_PREF_BOOLEAN; | |
734 else if(!strcmp(attribute_values[i], "int")) | |
735 pref_type = GAIM_PREF_INT; | |
736 else if(!strcmp(attribute_values[i], "string")) | |
737 pref_type = GAIM_PREF_STRING; | |
5561 | 738 else if(!strcmp(attribute_values[i], "stringlist")) |
739 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 740 else |
741 return; | |
742 } else if(!strcmp(attribute_names[i], "value")) { | |
743 pref_value = attribute_values[i]; | |
744 } | |
745 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
746 |
5561 | 747 if(!strcmp(element_name, "item")) { |
5838 | 748 struct gaim_pref *pref; |
749 | |
750 pref_name_full = g_string_new(""); | |
751 | |
752 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
753 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
754 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
755 } | |
756 | |
757 pref = find_pref(pref_name_full->str); | |
758 | |
5561 | 759 if(pref) { |
760 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
761 g_strdup(pref_value)); | |
762 } | |
5838 | 763 } else { |
764 if(!pref_name || !strcmp(pref_name, "/")) | |
765 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
766 |
5838 | 767 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
768 |
5838 | 769 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
770 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
771 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
772 } | |
773 | |
5440 | 774 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
775 |
5838 | 776 switch(pref_type) { |
777 case GAIM_PREF_NONE: | |
778 break; | |
779 case GAIM_PREF_BOOLEAN: | |
780 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
781 break; | |
782 case GAIM_PREF_INT: | |
783 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
784 break; | |
785 case GAIM_PREF_STRING: | |
786 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
787 break; | |
788 case GAIM_PREF_STRING_LIST: | |
789 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
790 break; | |
791 } | |
792 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
793 g_string_free(pref_name_full, TRUE); | |
5440 | 794 } |
1170 | 795 } |
796 | |
5440 | 797 static void prefs_end_element_handler(GMarkupParseContext *context, |
798 const gchar *element_name, gpointer user_data, GError **error) { | |
799 if(!strcmp(element_name, "pref")) { | |
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 |