Mercurial > pidgin.yaz
annotate src/prefs.c @ 8481:6d0869404696
[gaim-migrate @ 9214]
" this fixes and should close 9, 10, and 12 on simguys
list... those are...
9 Buttons that are pushed in when text is sent, stay
pushed in. They should reset to the default for the
line based on the B/I/U preferences.
10 Buttons are not properly pushed in if B/I/U are set
in the prefs when the conversation window appears.
12 Buttons don't push in and out when the cursor
enters regions that are differently formatted. For
example, if you move the cursor to a place where the
text is bold, the B button should probably be pushed in.
While working on these i uncovered another bug which
i'll start working on shortly, but thats no reason to
hold this back when someone may find something I missed..." --Gary Kramlich
as per his note, this does not fix moving the cursor with the mouse, but
that doesn't work without this patch either.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 21 Mar 2004 18:38:30 +0000 |
parents | ef881489396e |
children | 1a016d979ce0 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
1 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2074
diff
changeset
|
25 #include <config.h> |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
26 #endif |
5440 | 27 |
1 | 28 #include <string.h> |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
5440 | 31 #include <sys/stat.h> |
32 #include <sys/types.h> | |
33 #include <glib.h> | |
6216 | 34 #include "internal.h" |
5440 | 35 #include "prefs.h" |
36 #include "debug.h" | |
37 #include "util.h" | |
3366 | 38 |
4026
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
39 #ifdef _WIN32 |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
40 #include "win32dep.h" |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
41 #endif |
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
42 |
5440 | 43 struct pref_cb { |
44 GaimPrefCallback func; | |
45 gpointer data; | |
46 guint id; | |
47 }; | |
48 | |
49 struct gaim_pref { | |
50 GaimPrefType type; | |
51 char *name; | |
52 union { | |
53 gpointer generic; | |
54 gboolean boolean; | |
55 int integer; | |
56 char *string; | |
5561 | 57 GList *stringlist; |
5440 | 58 } value; |
59 GSList *callbacks; | |
60 struct gaim_pref *parent; | |
61 struct gaim_pref *sibling; | |
62 struct gaim_pref *first_child; | |
63 }; | |
3366 | 64 |
5440 | 65 static GHashTable *prefs_hash = NULL; |
66 | |
67 static struct gaim_pref prefs = { GAIM_PREF_NONE, NULL, {NULL}, NULL, | |
68 NULL, NULL, NULL }; | |
69 | |
5534 | 70 static guint prefs_save_timer = 0; |
71 static gboolean prefs_is_loaded = FALSE; | |
72 | |
73 | |
74 static gboolean prefs_save_callback(gpointer who_cares) { | |
75 gaim_prefs_sync(); | |
76 prefs_save_timer = 0; | |
77 return FALSE; | |
78 } | |
79 | |
80 static void schedule_prefs_save() { | |
81 if(!prefs_save_timer) | |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8235
diff
changeset
|
82 prefs_save_timer = gaim_timeout_add(5000, prefs_save_callback, NULL); |
5534 | 83 } |
84 | |
85 static void prefs_save_cb(const char *name, GaimPrefType type, gpointer val, | |
86 gpointer user_data) { | |
87 | |
88 if(!prefs_is_loaded) | |
89 return; | |
90 | |
91 gaim_debug(GAIM_DEBUG_MISC, "prefs", "%s changed, scheduling save.\n", name); | |
92 | |
93 schedule_prefs_save(); | |
94 } | |
95 | |
5440 | 96 void gaim_prefs_init() { |
97 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
98 | |
5534 | 99 gaim_prefs_connect_callback("/", prefs_save_cb, NULL); |
100 | |
5529
e7747cae9710
[gaim-migrate @ 5929]
Christian Hammond <chipx86@chipx86.com>
parents:
5458
diff
changeset
|
101 gaim_prefs_add_none("/core"); |
5550
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
102 gaim_prefs_add_none("/plugins"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
103 gaim_prefs_add_none("/plugins/core"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
104 gaim_prefs_add_none("/plugins/lopl"); |
b18c2a37cc96
[gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents:
5547
diff
changeset
|
105 gaim_prefs_add_none("/plugins/prpl"); |
5529
e7747cae9710
[gaim-migrate @ 5929]
Christian Hammond <chipx86@chipx86.com>
parents:
5458
diff
changeset
|
106 |
5545
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); |
7689 | 110 gaim_prefs_add_int("/core/away/mins_before_away", 5); |
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); |
7420 | 125 |
126 /* Contact Priority Settings */ | |
127 gaim_prefs_add_none("/core/contact"); | |
128 gaim_prefs_add_bool("/core/contact/last_match", FALSE); | |
129 gaim_prefs_add_int("/core/contact/offline_score", 4); | |
130 gaim_prefs_add_int("/core/contact/away_score", 2); | |
131 gaim_prefs_add_int("/core/contact/idle_score", 1); | |
5440 | 132 } |
3366 | 133 |
8235 | 134 void |
135 gaim_prefs_uninit() | |
136 { | |
137 if (prefs_save_timer != 0) { | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
138 gaim_timeout_remove(prefs_save_timer); |
8235 | 139 prefs_save_timer = 0; |
140 gaim_prefs_sync(); | |
141 } | |
142 } | |
143 | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
144 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
145 get_path_dirname(const char *name) |
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 char *c, *str; |
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 str = g_strdup(name); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
150 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
151 if ((c = strrchr(str, '/')) != NULL) { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
152 *c = '\0'; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
153 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
154 if (*str == '\0') { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
155 g_free(str); |
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 str = g_strdup("/"); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
158 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
159 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
160 else { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
161 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
162 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
163 str = g_strdup("."); |
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 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
166 return str; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
167 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
168 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
169 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
170 get_path_basename(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
171 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
172 const char *c; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
173 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
174 if ((c = strrchr(name, '/')) != NULL) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
175 return g_strdup(c + 1); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
176 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
177 return g_strdup(name); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
178 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
179 |
5440 | 180 static char *pref_full_name(struct gaim_pref *pref) { |
181 GString *name; | |
182 struct gaim_pref *parent; | |
6693 | 183 char *ret; |
184 | |
5440 | 185 if(!pref) |
186 return NULL; | |
187 | |
188 if(pref == &prefs) | |
189 return g_strdup("/"); | |
190 | |
191 name = g_string_new(pref->name); | |
192 parent = pref->parent; | |
3366 | 193 |
5440 | 194 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { |
195 name = g_string_prepend_c(name, '/'); | |
196 name = g_string_prepend(name, parent->name); | |
197 } | |
6693 | 198 ret = name->str; |
5440 | 199 g_string_free(name, FALSE); |
6693 | 200 return ret; |
5440 | 201 } |
202 | |
203 static struct gaim_pref *find_pref(const char *name) | |
204 { | |
205 if(!name || name[0] != '/') { | |
206 return NULL; | |
207 } else if(name[1] == '\0') { | |
208 return &prefs; | |
209 } else { | |
210 return g_hash_table_lookup(prefs_hash, name); | |
211 } | |
212 } | |
213 | |
214 static struct gaim_pref *find_pref_parent(const char *name) | |
215 { | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
216 char *parent_name = get_path_dirname(name); |
5440 | 217 struct gaim_pref *ret = &prefs; |
218 | |
219 if(strcmp(parent_name, "/")) { | |
220 ret = find_pref(parent_name); | |
221 } | |
1026 | 222 |
5440 | 223 g_free(parent_name); |
224 return ret; | |
225 } | |
226 | |
227 static void free_pref_value(struct gaim_pref *pref) { | |
228 switch(pref->type) { | |
229 case GAIM_PREF_BOOLEAN: | |
230 pref->value.boolean = FALSE; | |
7317 | 231 break; |
5440 | 232 case GAIM_PREF_INT: |
233 pref->value.integer = 0; | |
234 break; | |
235 case GAIM_PREF_STRING: | |
236 g_free(pref->value.string); | |
237 pref->value.string = NULL; | |
238 break; | |
5561 | 239 case GAIM_PREF_STRING_LIST: |
240 { | |
241 GList *tmp; | |
242 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
243 g_free(tmp->data); | |
244 | |
245 g_list_free(pref->value.stringlist); | |
246 } break; | |
5440 | 247 case GAIM_PREF_NONE: |
248 break; | |
249 } | |
250 } | |
251 | |
252 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) { | |
253 struct gaim_pref *parent; | |
254 struct gaim_pref *me; | |
255 struct gaim_pref *sibling; | |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
256 char *my_name; |
5440 | 257 |
258 parent = find_pref_parent(name); | |
259 | |
260 if(!parent) | |
261 return NULL; | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
262 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
263 my_name = get_path_basename(name); |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
264 |
5440 | 265 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) { |
266 if(!strcmp(sibling->name, my_name)) { | |
267 g_free(my_name); | |
268 return NULL; | |
269 } | |
270 } | |
271 | |
272 me = g_new0(struct gaim_pref, 1); | |
273 me->type = type; | |
274 me->name = my_name; | |
275 | |
276 me->parent = parent; | |
277 if(parent->first_child) { | |
278 /* blatant abuse of a for loop */ | |
279 for(sibling = parent->first_child; sibling->sibling; | |
280 sibling = sibling->sibling); | |
281 sibling->sibling = me; | |
282 } else { | |
283 parent->first_child = me; | |
284 } | |
285 | |
286 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me); | |
287 | |
288 return me; | |
289 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
290 |
5440 | 291 void gaim_prefs_add_none(const char *name) { |
292 add_pref(GAIM_PREF_NONE, name); | |
293 } | |
294 | |
295 void gaim_prefs_add_bool(const char *name, gboolean value) { | |
296 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name); | |
297 | |
298 if(!pref) | |
299 return; | |
300 | |
301 pref->value.boolean = value; | |
302 } | |
3630 | 303 |
5440 | 304 void gaim_prefs_add_int(const char *name, int value) { |
305 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name); | |
306 | |
307 if(!pref) | |
308 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
309 |
5440 | 310 pref->value.integer = value; |
311 } | |
312 | |
313 void gaim_prefs_add_string(const char *name, const char *value) { | |
314 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name); | |
315 | |
316 if(!pref) | |
317 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
318 |
5440 | 319 pref->value.string = g_strdup(value); |
320 } | |
321 | |
5561 | 322 void gaim_prefs_add_string_list(const char *name, GList *value) { |
323 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); | |
324 GList *tmp; | |
325 | |
326 if(!pref) | |
327 return; | |
328 | |
329 for(tmp = value; tmp; tmp = tmp->next) | |
330 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
331 g_strdup(tmp->data)); | |
332 } | |
333 | |
5440 | 334 void remove_pref(struct gaim_pref *pref) { |
335 char *name; | |
336 | |
337 if(!pref || pref == &prefs) | |
338 return; | |
339 | |
6693 | 340 while(pref->first_child) |
341 remove_pref(pref->first_child); | |
342 | |
5440 | 343 if(pref->parent->first_child == pref) { |
344 pref->parent->first_child = pref->sibling; | |
345 } else { | |
346 struct gaim_pref *sib = pref->parent->first_child; | |
347 while(sib->sibling != pref) | |
348 sib = sib->sibling; | |
349 sib->sibling = pref->sibling; | |
350 } | |
351 | |
352 name = pref_full_name(pref); | |
353 | |
7785 | 354 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref /%s\n", name); |
6693 | 355 |
5440 | 356 g_hash_table_remove(prefs_hash, name); |
357 g_free(name); | |
358 | |
359 free_pref_value(pref); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
360 |
5440 | 361 g_slist_free(pref->callbacks); |
362 g_free(pref->name); | |
363 g_free(pref); | |
364 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
365 |
5440 | 366 void gaim_prefs_remove(const char *name) { |
367 struct gaim_pref *pref = find_pref(name); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
368 |
5440 | 369 if(!pref) |
370 return; | |
371 | |
372 remove_pref(pref); | |
373 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
374 |
5440 | 375 void gaim_prefs_destroy() { |
376 gaim_prefs_remove("/"); | |
377 } | |
378 | |
379 static void do_callbacks(const char* name, struct gaim_pref *pref) { | |
380 GSList *cbs; | |
381 struct gaim_pref *cb_pref; | |
382 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { | |
383 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { | |
384 struct pref_cb *cb = cbs->data; | |
385 cb->func(name, pref->type, pref->value.generic, cb->data); | |
4215 | 386 } |
387 } | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
388 } |
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
389 |
5684 | 390 void gaim_prefs_trigger_callback(const char *name) { |
391 struct gaim_pref *pref = find_pref(name); | |
392 | |
5814 | 393 if(!pref) { |
394 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
395 "gaim_prefs_trigger_callback: Unknown pref %s\n", name); | |
396 return; | |
397 } | |
398 | |
5684 | 399 do_callbacks(name, pref); |
400 } | |
401 | |
5440 | 402 void gaim_prefs_set_generic(const char *name, gpointer value) { |
403 struct gaim_pref *pref = find_pref(name); | |
3366 | 404 |
5814 | 405 if(!pref) { |
406 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
407 "gaim_prefs_set_generic: Unknown pref %s\n", name); | |
408 return; | |
409 } | |
3500 | 410 |
5440 | 411 pref->value.generic = value; |
412 do_callbacks(name, pref); | |
3366 | 413 } |
414 | |
5440 | 415 void gaim_prefs_set_bool(const char *name, gboolean value) { |
416 struct gaim_pref *pref = find_pref(name); | |
4288 | 417 |
5533 | 418 if(pref) { |
5814 | 419 if(pref->type != GAIM_PREF_BOOLEAN) { |
420 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
421 "gaim_prefs_set_bool: %s not a boolean pref\n", name); | |
422 return; | |
423 } | |
4325 | 424 |
5533 | 425 if(pref->value.boolean != value) { |
426 pref->value.boolean = value; | |
427 do_callbacks(name, pref); | |
428 } | |
429 } else { | |
430 gaim_prefs_add_bool(name, value); | |
4288 | 431 } |
4324 | 432 } |
4325 | 433 |
5440 | 434 void gaim_prefs_set_int(const char *name, int value) { |
435 struct gaim_pref *pref = find_pref(name); | |
4325 | 436 |
5533 | 437 if(pref) { |
5814 | 438 if(pref->type != GAIM_PREF_INT) { |
439 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
440 "gaim_prefs_set_int: %s not an integer pref\n", name); | |
441 return; | |
442 } | |
4325 | 443 |
5533 | 444 if(pref->value.integer != value) { |
445 pref->value.integer = value; | |
446 do_callbacks(name, pref); | |
447 } | |
448 } else { | |
449 gaim_prefs_add_int(name, value); | |
5440 | 450 } |
4326 | 451 } |
452 | |
5451 | 453 void gaim_prefs_set_string(const char *name, const char *value) { |
5440 | 454 struct gaim_pref *pref = find_pref(name); |
4325 | 455 |
5533 | 456 if(pref) { |
5814 | 457 if(pref->type != GAIM_PREF_STRING) { |
458 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
459 "gaim_prefs_set_string: %s not a string pref\n", name); | |
460 return; | |
461 } | |
4325 | 462 |
6295 | 463 if((value && !pref->value.string) || |
464 (!value && pref->value.string) || | |
465 strcmp(pref->value.string, value)) { | |
5533 | 466 g_free(pref->value.string); |
467 pref->value.string = g_strdup(value); | |
468 do_callbacks(name, pref); | |
469 } | |
470 } else { | |
471 gaim_prefs_add_string(name, value); | |
4325 | 472 } |
473 } | |
474 | |
5561 | 475 void gaim_prefs_set_string_list(const char *name, GList *value) { |
476 struct gaim_pref *pref = find_pref(name); | |
477 if(pref) { | |
478 GList *tmp; | |
5814 | 479 |
480 if(pref->type != GAIM_PREF_STRING_LIST) { | |
481 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
482 "gaim_prefs_set_string_list: %s not a string list pref\n", | |
483 name); | |
484 return; | |
485 } | |
486 | |
5561 | 487 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) |
488 g_free(tmp->data); | |
489 | |
490 g_list_free(pref->value.stringlist); | |
491 pref->value.stringlist = NULL; | |
492 | |
493 for(tmp = value; tmp; tmp = tmp->next) | |
494 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
495 g_strdup(tmp->data)); | |
496 | |
5986
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
497 do_callbacks(name, pref); |
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
498 |
5561 | 499 } else { |
500 gaim_prefs_add_string_list(name, value); | |
501 } | |
502 } | |
503 | |
5440 | 504 gpointer gaim_prefs_get_generic(const char *name) { |
505 struct gaim_pref *pref = find_pref(name); | |
4325 | 506 |
5814 | 507 if(!pref) { |
508 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
509 "gaim_prefs_get_generic: Unknown pref %s\n", name); | |
510 return NULL; | |
511 } | |
4288 | 512 |
5440 | 513 return pref->value.generic; |
4288 | 514 } |
515 | |
6538 | 516 GaimPrefType gaim_prefs_get_type(const char *name) { |
517 struct gaim_pref *pref = find_pref(name); | |
518 | |
519 if (pref == NULL) | |
520 return GAIM_PREF_NONE; | |
521 | |
522 return (pref->type); | |
523 } | |
524 | |
5440 | 525 gboolean gaim_prefs_get_bool(const char *name) { |
526 struct gaim_pref *pref = find_pref(name); | |
3427 | 527 |
5814 | 528 if(!pref) { |
529 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
530 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
531 return FALSE; | |
532 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
533 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
534 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
535 return FALSE; | |
536 } | |
3472 | 537 |
5440 | 538 return pref->value.boolean; |
3366 | 539 } |
540 | |
5440 | 541 int gaim_prefs_get_int(const char *name) { |
542 struct gaim_pref *pref = find_pref(name); | |
3500 | 543 |
5814 | 544 if(!pref) { |
545 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
546 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
547 return 0; | |
548 } else if(pref->type != GAIM_PREF_INT) { | |
549 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
550 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
551 return 0; | |
552 } | |
3366 | 553 |
5440 | 554 return pref->value.integer; |
3366 | 555 } |
556 | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
557 const char *gaim_prefs_get_string(const char *name) { |
5440 | 558 struct gaim_pref *pref = find_pref(name); |
3366 | 559 |
5814 | 560 if(!pref) { |
561 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
562 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
563 return NULL; | |
564 } else if(pref->type != GAIM_PREF_STRING) { | |
565 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
566 "gaim_prefs_get_string: %s not a string pref\n", name); | |
567 return NULL; | |
568 } | |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
569 |
5440 | 570 return pref->value.string; |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
571 } |
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
572 |
5561 | 573 GList *gaim_prefs_get_string_list(const char *name) { |
574 struct gaim_pref *pref = find_pref(name); | |
575 GList *ret = NULL, *tmp; | |
576 | |
5814 | 577 if(!pref) { |
578 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
579 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
580 return NULL; | |
581 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
582 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
583 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
584 return NULL; | |
585 } | |
5561 | 586 |
587 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
588 ret = g_list_append(ret, g_strdup(tmp->data)); | |
589 | |
590 return ret; | |
591 } | |
592 | |
6693 | 593 void gaim_prefs_rename(const char *oldname, const char *newname) { |
594 struct gaim_pref *oldpref, *newpref; | |
595 | |
7785 | 596 gaim_debug_info("prefs", "Attempting to rename %s to %s\n", oldname, newname); |
597 | |
6693 | 598 oldpref = find_pref(oldname); |
599 newpref = find_pref(newname); | |
600 | |
601 /* it's already been renamed, call off the dogs */ | |
602 if(!oldpref) | |
603 return; | |
604 | |
605 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
606 g_return_if_fail(oldpref->type == newpref->type); | |
607 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
608 | |
609 switch(oldpref->type) { | |
610 case GAIM_PREF_NONE: | |
611 break; | |
612 case GAIM_PREF_BOOLEAN: | |
613 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
614 break; | |
615 case GAIM_PREF_INT: | |
616 gaim_prefs_set_int(newname, oldpref->value.integer); | |
617 break; | |
618 case GAIM_PREF_STRING: | |
619 gaim_prefs_set_string(newname, oldpref->value.string); | |
620 break; | |
621 case GAIM_PREF_STRING_LIST: | |
622 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
623 break; | |
624 } | |
625 | |
626 remove_pref(oldpref); | |
627 } | |
628 | |
629 void gaim_prefs_rename_old() { | |
7555 | 630 gaim_prefs_rename("/gaim/gtk/logging/log_ims", "/core/logging/log_ims"); |
631 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
|
632 gaim_prefs_rename("/core/conversations/placement", |
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
633 "/gaim/gtk/conversations/placement"); |
6693 | 634 } |
635 | |
5440 | 636 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
637 { | |
638 struct gaim_pref *pref = find_pref(name); | |
639 struct pref_cb *cb; | |
640 static guint cb_id = 0; | |
3366 | 641 |
5440 | 642 if(!pref) |
643 return 0; | |
3366 | 644 |
5440 | 645 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
646 |
5440 | 647 cb->func = func; |
648 cb->data = data; | |
649 cb->id = ++cb_id; | |
4991 | 650 |
5440 | 651 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 652 |
5440 | 653 return cb->id; |
3366 | 654 } |
655 | |
5440 | 656 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
657 GSList *cbs; | |
658 struct gaim_pref *child; | |
2254 | 659 |
5440 | 660 if(!pref) |
661 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
662 |
5440 | 663 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
664 struct pref_cb *cb = cbs->data; | |
665 if(cb->id == callback_id) { | |
666 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
667 g_free(cb); | |
668 return TRUE; | |
4428 | 669 } |
670 } | |
671 | |
5440 | 672 for(child = pref->first_child; child; child = child->sibling) { |
673 if(disco_callback_helper(child, callback_id)) | |
674 return TRUE; | |
4428 | 675 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
676 |
5440 | 677 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
678 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
679 |
5440 | 680 void gaim_prefs_disconnect_callback(guint callback_id) { |
681 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
682 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
683 |
5440 | 684 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
685 struct gaim_pref *tmp; | |
686 char *esc; | |
687 int i; | |
3500 | 688 |
5440 | 689 if(!pref) { |
690 pref = &prefs; | |
3551 | 691 |
5440 | 692 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
693 fprintf(f, "<pref name='/'"); | |
694 } else { | |
695 for(i=0; i<depth; i++) | |
696 fprintf(f, "\t"); | |
697 esc = g_markup_escape_text(pref->name, -1); | |
698 fprintf(f, "<pref name='%s'", esc); | |
699 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
700 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
701 |
5440 | 702 switch(pref->type) { |
703 case GAIM_PREF_NONE: | |
704 break; | |
705 case GAIM_PREF_BOOLEAN: | |
706 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
707 break; | |
708 case GAIM_PREF_INT: | |
709 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
710 break; | |
711 case GAIM_PREF_STRING: | |
712 esc = g_markup_escape_text(pref->value.string, -1); | |
713 fprintf(f, " type='string' value='%s'", esc); | |
714 g_free(esc); | |
715 break; | |
5561 | 716 case GAIM_PREF_STRING_LIST: |
717 fprintf(f, " type='stringlist'"); | |
718 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
719 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
720 |
5561 | 721 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 722 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
723 |
5440 | 724 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
725 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 726 |
727 if(pref->type == GAIM_PREF_STRING_LIST) { | |
728 GList *tmp2; | |
729 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
730 for(i=0; i<depth+1; i++) | |
731 fprintf(f, "\t"); | |
732 esc = g_markup_escape_text(tmp2->data, -1); | |
733 fprintf(f, "<item value='%s' />\n", esc); | |
734 g_free(esc); | |
735 } | |
736 } | |
737 | |
5440 | 738 for(i=0; i<depth; i++) |
739 fprintf(f, "\t"); | |
740 fprintf(f, "</pref>\n"); | |
741 } else { | |
742 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
743 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
744 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
745 |
5440 | 746 void gaim_prefs_sync() { |
747 FILE *file; | |
748 const char *user_dir = gaim_user_dir(); | |
749 char *filename; | |
750 char *filename_real; | |
3551 | 751 |
5534 | 752 if(!prefs_is_loaded) { |
753 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
754 schedule_prefs_save(); /* schedule a save for after we read in */ | |
755 return; | |
756 } | |
757 | |
5440 | 758 if(!user_dir) |
759 return; | |
3551 | 760 |
5534 | 761 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
762 | |
5440 | 763 file = fopen(user_dir, "r"); |
764 if(!file) | |
765 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
766 else | |
767 fclose(file); | |
3551 | 768 |
5440 | 769 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 770 |
5440 | 771 if((file = fopen(filename, "w"))) { |
772 gaim_prefs_write(file, NULL, 0); | |
773 fclose(file); | |
774 chmod(filename, S_IRUSR | S_IWUSR); | |
775 } else { | |
776 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
777 filename); | |
778 } | |
3551 | 779 |
5440 | 780 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
781 if(rename(filename, filename_real) < 0) | |
782 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
783 filename, filename_real); | |
3551 | 784 |
5440 | 785 g_free(filename); |
786 g_free(filename_real); | |
3551 | 787 } |
788 | |
5440 | 789 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
790 |
5440 | 791 static void prefs_start_element_handler (GMarkupParseContext *context, |
792 const gchar *element_name, | |
793 const gchar **attribute_names, | |
794 const gchar **attribute_values, | |
795 gpointer user_data, | |
796 GError **error) { | |
797 GaimPrefType pref_type = GAIM_PREF_NONE; | |
798 int i; | |
799 const char *pref_name = NULL, *pref_value = NULL; | |
800 GString *pref_name_full; | |
801 GList *tmp; | |
3366 | 802 |
5561 | 803 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 804 return; |
3500 | 805 |
5440 | 806 for(i = 0; attribute_names[i]; i++) { |
807 if(!strcmp(attribute_names[i], "name")) { | |
808 pref_name = attribute_values[i]; | |
809 } else if(!strcmp(attribute_names[i], "type")) { | |
810 if(!strcmp(attribute_values[i], "bool")) | |
811 pref_type = GAIM_PREF_BOOLEAN; | |
812 else if(!strcmp(attribute_values[i], "int")) | |
813 pref_type = GAIM_PREF_INT; | |
814 else if(!strcmp(attribute_values[i], "string")) | |
815 pref_type = GAIM_PREF_STRING; | |
5561 | 816 else if(!strcmp(attribute_values[i], "stringlist")) |
817 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 818 else |
819 return; | |
820 } else if(!strcmp(attribute_names[i], "value")) { | |
821 pref_value = attribute_values[i]; | |
822 } | |
823 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
824 |
5561 | 825 if(!strcmp(element_name, "item")) { |
5838 | 826 struct gaim_pref *pref; |
827 | |
828 pref_name_full = g_string_new(""); | |
829 | |
830 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
831 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
832 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
833 } | |
834 | |
835 pref = find_pref(pref_name_full->str); | |
836 | |
5561 | 837 if(pref) { |
838 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
839 g_strdup(pref_value)); | |
840 } | |
5838 | 841 } else { |
842 if(!pref_name || !strcmp(pref_name, "/")) | |
843 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
844 |
5838 | 845 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
846 |
5838 | 847 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
848 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
849 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
850 } | |
851 | |
5440 | 852 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
853 |
5838 | 854 switch(pref_type) { |
855 case GAIM_PREF_NONE: | |
7785 | 856 gaim_prefs_add_none(pref_name_full->str); |
5838 | 857 break; |
858 case GAIM_PREF_BOOLEAN: | |
859 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
860 break; | |
861 case GAIM_PREF_INT: | |
862 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
863 break; | |
864 case GAIM_PREF_STRING: | |
865 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
866 break; | |
867 case GAIM_PREF_STRING_LIST: | |
868 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
869 break; | |
870 } | |
871 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
872 g_string_free(pref_name_full, TRUE); | |
5440 | 873 } |
1170 | 874 } |
875 | |
5440 | 876 static void prefs_end_element_handler(GMarkupParseContext *context, |
877 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 878 if(prefs_stack && !strcmp(element_name, "pref")) { |
879 g_free(prefs_stack->data); | |
5440 | 880 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
881 } | |
1170 | 882 } |
883 | |
5440 | 884 static GMarkupParser prefs_parser = { |
885 prefs_start_element_handler, | |
886 prefs_end_element_handler, | |
887 NULL, | |
888 NULL, | |
889 NULL | |
890 }; | |
1170 | 891 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
892 gboolean gaim_prefs_load() { |
5440 | 893 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
894 gchar *contents = NULL; | |
895 gsize length; | |
896 GMarkupParseContext *context; | |
897 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
898 |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
899 if (!filename) { |
5534 | 900 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
901 return FALSE; |
5534 | 902 } |
5440 | 903 |
904 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
905 |
5440 | 906 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
907 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", | |
908 error->message); | |
909 g_error_free(error); | |
6040 | 910 g_free(filename); |
5534 | 911 prefs_is_loaded = TRUE; |
6040 | 912 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
913 return FALSE; |
1170 | 914 } |
915 | |
5440 | 916 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
917 | |
918 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
919 g_markup_parse_context_free(context); | |
920 g_free(contents); | |
6040 | 921 g_free(filename); |
5534 | 922 prefs_is_loaded = TRUE; |
6040 | 923 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
924 return FALSE; |
5440 | 925 } |
926 | |
927 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
928 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
929 g_markup_parse_context_free(context); | |
930 g_free(contents); | |
6040 | 931 g_free(filename); |
5534 | 932 prefs_is_loaded = TRUE; |
6040 | 933 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
934 return FALSE; |
5440 | 935 } |
936 | |
6040 | 937 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); |
5440 | 938 g_markup_parse_context_free(context); |
939 g_free(contents); | |
940 g_free(filename); | |
5534 | 941 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
942 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
943 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
944 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
945 |