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