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