Mercurial > pidgin
annotate src/prefs.c @ 7623:5381f96fc185
[gaim-migrate @ 8247]
more logging tweaks. this should let the last </body></html> get written
to all the open logs when you quit gaim.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 24 Nov 2003 07:00:39 +0000 |
parents | cdfdbabd3266 |
children | 950ee542eea0 |
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); |
5550
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
108 gaim_prefs_add_int("/core/away/mins_before_away", 1); |
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 | |
6693 | 342 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref %s\n", name); |
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 | |
584 oldpref = find_pref(oldname); | |
585 newpref = find_pref(newname); | |
586 | |
587 /* it's already been renamed, call off the dogs */ | |
588 if(!oldpref) | |
589 return; | |
590 | |
591 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
592 g_return_if_fail(oldpref->type == newpref->type); | |
593 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
594 | |
595 switch(oldpref->type) { | |
596 case GAIM_PREF_NONE: | |
597 break; | |
598 case GAIM_PREF_BOOLEAN: | |
599 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
600 break; | |
601 case GAIM_PREF_INT: | |
602 gaim_prefs_set_int(newname, oldpref->value.integer); | |
603 break; | |
604 case GAIM_PREF_STRING: | |
605 gaim_prefs_set_string(newname, oldpref->value.string); | |
606 break; | |
607 case GAIM_PREF_STRING_LIST: | |
608 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
609 break; | |
610 } | |
611 | |
612 remove_pref(oldpref); | |
613 } | |
614 | |
615 void gaim_prefs_rename_old() { | |
7555 | 616 gaim_prefs_rename("/gaim/gtk/logging/log_ims", "/core/logging/log_ims"); |
617 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
|
618 gaim_prefs_rename("/core/conversations/placement", |
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
619 "/gaim/gtk/conversations/placement"); |
6693 | 620 } |
621 | |
5440 | 622 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
623 { | |
624 struct gaim_pref *pref = find_pref(name); | |
625 struct pref_cb *cb; | |
626 static guint cb_id = 0; | |
3366 | 627 |
5440 | 628 if(!pref) |
629 return 0; | |
3366 | 630 |
5440 | 631 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
632 |
5440 | 633 cb->func = func; |
634 cb->data = data; | |
635 cb->id = ++cb_id; | |
4991 | 636 |
5440 | 637 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 638 |
5440 | 639 return cb->id; |
3366 | 640 } |
641 | |
5440 | 642 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
643 GSList *cbs; | |
644 struct gaim_pref *child; | |
2254 | 645 |
5440 | 646 if(!pref) |
647 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
648 |
5440 | 649 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
650 struct pref_cb *cb = cbs->data; | |
651 if(cb->id == callback_id) { | |
652 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
653 g_free(cb); | |
654 return TRUE; | |
4428 | 655 } |
656 } | |
657 | |
5440 | 658 for(child = pref->first_child; child; child = child->sibling) { |
659 if(disco_callback_helper(child, callback_id)) | |
660 return TRUE; | |
4428 | 661 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
662 |
5440 | 663 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
664 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
665 |
5440 | 666 void gaim_prefs_disconnect_callback(guint callback_id) { |
667 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
668 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
669 |
5440 | 670 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
671 struct gaim_pref *tmp; | |
672 char *esc; | |
673 int i; | |
3500 | 674 |
5440 | 675 if(!pref) { |
676 pref = &prefs; | |
3551 | 677 |
5440 | 678 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
679 fprintf(f, "<pref name='/'"); | |
680 } else { | |
681 for(i=0; i<depth; i++) | |
682 fprintf(f, "\t"); | |
683 esc = g_markup_escape_text(pref->name, -1); | |
684 fprintf(f, "<pref name='%s'", esc); | |
685 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
686 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
687 |
5440 | 688 switch(pref->type) { |
689 case GAIM_PREF_NONE: | |
690 break; | |
691 case GAIM_PREF_BOOLEAN: | |
692 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
693 break; | |
694 case GAIM_PREF_INT: | |
695 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
696 break; | |
697 case GAIM_PREF_STRING: | |
698 esc = g_markup_escape_text(pref->value.string, -1); | |
699 fprintf(f, " type='string' value='%s'", esc); | |
700 g_free(esc); | |
701 break; | |
5561 | 702 case GAIM_PREF_STRING_LIST: |
703 fprintf(f, " type='stringlist'"); | |
704 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
705 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
706 |
5561 | 707 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 708 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
709 |
5440 | 710 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
711 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 712 |
713 if(pref->type == GAIM_PREF_STRING_LIST) { | |
714 GList *tmp2; | |
715 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
716 for(i=0; i<depth+1; i++) | |
717 fprintf(f, "\t"); | |
718 esc = g_markup_escape_text(tmp2->data, -1); | |
719 fprintf(f, "<item value='%s' />\n", esc); | |
720 g_free(esc); | |
721 } | |
722 } | |
723 | |
5440 | 724 for(i=0; i<depth; i++) |
725 fprintf(f, "\t"); | |
726 fprintf(f, "</pref>\n"); | |
727 } else { | |
728 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
729 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
730 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
731 |
5440 | 732 void gaim_prefs_sync() { |
733 FILE *file; | |
734 const char *user_dir = gaim_user_dir(); | |
735 char *filename; | |
736 char *filename_real; | |
3551 | 737 |
5534 | 738 if(!prefs_is_loaded) { |
739 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
740 schedule_prefs_save(); /* schedule a save for after we read in */ | |
741 return; | |
742 } | |
743 | |
5440 | 744 if(!user_dir) |
745 return; | |
3551 | 746 |
5534 | 747 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
748 | |
5440 | 749 file = fopen(user_dir, "r"); |
750 if(!file) | |
751 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
752 else | |
753 fclose(file); | |
3551 | 754 |
5440 | 755 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 756 |
5440 | 757 if((file = fopen(filename, "w"))) { |
758 gaim_prefs_write(file, NULL, 0); | |
759 fclose(file); | |
760 chmod(filename, S_IRUSR | S_IWUSR); | |
761 } else { | |
762 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
763 filename); | |
764 } | |
3551 | 765 |
5440 | 766 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
767 if(rename(filename, filename_real) < 0) | |
768 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
769 filename, filename_real); | |
3551 | 770 |
5440 | 771 g_free(filename); |
772 g_free(filename_real); | |
3551 | 773 } |
774 | |
5440 | 775 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
776 |
5440 | 777 static void prefs_start_element_handler (GMarkupParseContext *context, |
778 const gchar *element_name, | |
779 const gchar **attribute_names, | |
780 const gchar **attribute_values, | |
781 gpointer user_data, | |
782 GError **error) { | |
783 GaimPrefType pref_type = GAIM_PREF_NONE; | |
784 int i; | |
785 const char *pref_name = NULL, *pref_value = NULL; | |
786 GString *pref_name_full; | |
787 GList *tmp; | |
3366 | 788 |
5561 | 789 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 790 return; |
3500 | 791 |
5440 | 792 for(i = 0; attribute_names[i]; i++) { |
793 if(!strcmp(attribute_names[i], "name")) { | |
794 pref_name = attribute_values[i]; | |
795 } else if(!strcmp(attribute_names[i], "type")) { | |
796 if(!strcmp(attribute_values[i], "bool")) | |
797 pref_type = GAIM_PREF_BOOLEAN; | |
798 else if(!strcmp(attribute_values[i], "int")) | |
799 pref_type = GAIM_PREF_INT; | |
800 else if(!strcmp(attribute_values[i], "string")) | |
801 pref_type = GAIM_PREF_STRING; | |
5561 | 802 else if(!strcmp(attribute_values[i], "stringlist")) |
803 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 804 else |
805 return; | |
806 } else if(!strcmp(attribute_names[i], "value")) { | |
807 pref_value = attribute_values[i]; | |
808 } | |
809 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
810 |
5561 | 811 if(!strcmp(element_name, "item")) { |
5838 | 812 struct gaim_pref *pref; |
813 | |
814 pref_name_full = g_string_new(""); | |
815 | |
816 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
817 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
818 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
819 } | |
820 | |
821 pref = find_pref(pref_name_full->str); | |
822 | |
5561 | 823 if(pref) { |
824 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
825 g_strdup(pref_value)); | |
826 } | |
5838 | 827 } else { |
828 if(!pref_name || !strcmp(pref_name, "/")) | |
829 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
830 |
5838 | 831 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
832 |
5838 | 833 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
834 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
835 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
836 } | |
837 | |
5440 | 838 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
839 |
5838 | 840 switch(pref_type) { |
841 case GAIM_PREF_NONE: | |
842 break; | |
843 case GAIM_PREF_BOOLEAN: | |
844 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
845 break; | |
846 case GAIM_PREF_INT: | |
847 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
848 break; | |
849 case GAIM_PREF_STRING: | |
850 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
851 break; | |
852 case GAIM_PREF_STRING_LIST: | |
853 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
854 break; | |
855 } | |
856 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
857 g_string_free(pref_name_full, TRUE); | |
5440 | 858 } |
1170 | 859 } |
860 | |
5440 | 861 static void prefs_end_element_handler(GMarkupParseContext *context, |
862 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 863 if(prefs_stack && !strcmp(element_name, "pref")) { |
864 g_free(prefs_stack->data); | |
5440 | 865 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
866 } | |
1170 | 867 } |
868 | |
5440 | 869 static GMarkupParser prefs_parser = { |
870 prefs_start_element_handler, | |
871 prefs_end_element_handler, | |
872 NULL, | |
873 NULL, | |
874 NULL | |
875 }; | |
1170 | 876 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
877 gboolean gaim_prefs_load() { |
5440 | 878 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
879 gchar *contents = NULL; | |
880 gsize length; | |
881 GMarkupParseContext *context; | |
882 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
883 |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
884 if (!filename) { |
5534 | 885 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
886 return FALSE; |
5534 | 887 } |
5440 | 888 |
889 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
890 |
5440 | 891 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
892 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", | |
893 error->message); | |
894 g_error_free(error); | |
6040 | 895 g_free(filename); |
5534 | 896 prefs_is_loaded = TRUE; |
6040 | 897 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
898 return FALSE; |
1170 | 899 } |
900 | |
5440 | 901 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
902 | |
903 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
904 g_markup_parse_context_free(context); | |
905 g_free(contents); | |
6040 | 906 g_free(filename); |
5534 | 907 prefs_is_loaded = TRUE; |
6040 | 908 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
909 return FALSE; |
5440 | 910 } |
911 | |
912 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
913 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
914 g_markup_parse_context_free(context); | |
915 g_free(contents); | |
6040 | 916 g_free(filename); |
5534 | 917 prefs_is_loaded = TRUE; |
6040 | 918 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
919 return FALSE; |
5440 | 920 } |
921 | |
6040 | 922 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); |
5440 | 923 g_markup_parse_context_free(context); |
924 g_free(contents); | |
925 g_free(filename); | |
5534 | 926 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
927 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
928 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
929 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
930 |