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