Mercurial > pidgin
annotate src/prefs.c @ 9478:0efa260e384f
[gaim-migrate @ 10303]
" This patch adds the following features for zephyr, in order
of usefulness :-)
Protocol action (Retrieve subscriptions from server) to
list user's subscriptions (chats) in a popup window.
Typing notification - (both sending and receiving --
using zephyrs with opcode ping).
Correct interpretation of %host% and %canon% entries in
.zephyr.subs . These are often used to subscribe to
system messages concerning a specific machine (by
hostname and canonical hostname, respectively).
An updated .todo list." --Arun A Tharuvai
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 07 Jul 2004 21:56:57 +0000 |
parents | 45d2ad4ac1c1 |
children | 15d09e546cee |
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/idle_only", FALSE); |
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 |
8235 | 132 void |
133 gaim_prefs_uninit() | |
134 { | |
135 if (prefs_save_timer != 0) { | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
136 gaim_timeout_remove(prefs_save_timer); |
8235 | 137 prefs_save_timer = 0; |
138 gaim_prefs_sync(); | |
139 } | |
140 } | |
141 | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
142 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
143 get_path_dirname(const char *name) |
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 char *c, *str; |
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 str = g_strdup(name); |
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 if ((c = strrchr(str, '/')) != NULL) { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
150 *c = '\0'; |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
151 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
152 if (*str == '\0') { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
153 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
154 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
155 str = g_strdup("/"); |
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 } |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
158 else { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
159 g_free(str); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
160 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
161 str = g_strdup("."); |
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 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
164 return str; |
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 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
167 static char * |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
168 get_path_basename(const char *name) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
169 { |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
170 const char *c; |
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 if ((c = strrchr(name, '/')) != NULL) |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
173 return g_strdup(c + 1); |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
174 |
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
175 return g_strdup(name); |
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 |
5440 | 178 static char *pref_full_name(struct gaim_pref *pref) { |
179 GString *name; | |
180 struct gaim_pref *parent; | |
6693 | 181 char *ret; |
182 | |
5440 | 183 if(!pref) |
184 return NULL; | |
185 | |
186 if(pref == &prefs) | |
187 return g_strdup("/"); | |
188 | |
189 name = g_string_new(pref->name); | |
190 parent = pref->parent; | |
3366 | 191 |
5440 | 192 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { |
193 name = g_string_prepend_c(name, '/'); | |
194 name = g_string_prepend(name, parent->name); | |
195 } | |
6693 | 196 ret = name->str; |
5440 | 197 g_string_free(name, FALSE); |
6693 | 198 return ret; |
5440 | 199 } |
200 | |
201 static struct gaim_pref *find_pref(const char *name) | |
202 { | |
203 if(!name || name[0] != '/') { | |
204 return NULL; | |
205 } else if(name[1] == '\0') { | |
206 return &prefs; | |
207 } else { | |
208 return g_hash_table_lookup(prefs_hash, name); | |
209 } | |
210 } | |
211 | |
212 static struct gaim_pref *find_pref_parent(const char *name) | |
213 { | |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
214 char *parent_name = get_path_dirname(name); |
5440 | 215 struct gaim_pref *ret = &prefs; |
216 | |
217 if(strcmp(parent_name, "/")) { | |
218 ret = find_pref(parent_name); | |
219 } | |
1026 | 220 |
5440 | 221 g_free(parent_name); |
222 return ret; | |
223 } | |
224 | |
225 static void free_pref_value(struct gaim_pref *pref) { | |
226 switch(pref->type) { | |
227 case GAIM_PREF_BOOLEAN: | |
228 pref->value.boolean = FALSE; | |
7317 | 229 break; |
5440 | 230 case GAIM_PREF_INT: |
231 pref->value.integer = 0; | |
232 break; | |
233 case GAIM_PREF_STRING: | |
234 g_free(pref->value.string); | |
235 pref->value.string = NULL; | |
236 break; | |
5561 | 237 case GAIM_PREF_STRING_LIST: |
238 { | |
239 GList *tmp; | |
240 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
241 g_free(tmp->data); | |
242 | |
243 g_list_free(pref->value.stringlist); | |
244 } break; | |
5440 | 245 case GAIM_PREF_NONE: |
246 break; | |
247 } | |
248 } | |
249 | |
250 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) { | |
251 struct gaim_pref *parent; | |
252 struct gaim_pref *me; | |
253 struct gaim_pref *sibling; | |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
254 char *my_name; |
5440 | 255 |
256 parent = find_pref_parent(name); | |
257 | |
258 if(!parent) | |
259 return NULL; | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
260 |
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
261 my_name = get_path_basename(name); |
5458
156e65ca910f
[gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
262 |
5440 | 263 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) { |
264 if(!strcmp(sibling->name, my_name)) { | |
265 g_free(my_name); | |
266 return NULL; | |
267 } | |
268 } | |
269 | |
270 me = g_new0(struct gaim_pref, 1); | |
271 me->type = type; | |
272 me->name = my_name; | |
273 | |
274 me->parent = parent; | |
275 if(parent->first_child) { | |
276 /* blatant abuse of a for loop */ | |
277 for(sibling = parent->first_child; sibling->sibling; | |
278 sibling = sibling->sibling); | |
279 sibling->sibling = me; | |
280 } else { | |
281 parent->first_child = me; | |
282 } | |
283 | |
284 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me); | |
285 | |
286 return me; | |
287 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
288 |
5440 | 289 void gaim_prefs_add_none(const char *name) { |
290 add_pref(GAIM_PREF_NONE, name); | |
291 } | |
292 | |
293 void gaim_prefs_add_bool(const char *name, gboolean value) { | |
294 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name); | |
295 | |
296 if(!pref) | |
297 return; | |
298 | |
299 pref->value.boolean = value; | |
300 } | |
3630 | 301 |
5440 | 302 void gaim_prefs_add_int(const char *name, int value) { |
303 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name); | |
304 | |
305 if(!pref) | |
306 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
307 |
5440 | 308 pref->value.integer = value; |
309 } | |
310 | |
311 void gaim_prefs_add_string(const char *name, const char *value) { | |
312 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name); | |
313 | |
314 if(!pref) | |
315 return; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
316 |
5440 | 317 pref->value.string = g_strdup(value); |
318 } | |
319 | |
5561 | 320 void gaim_prefs_add_string_list(const char *name, GList *value) { |
321 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); | |
322 GList *tmp; | |
323 | |
324 if(!pref) | |
325 return; | |
326 | |
327 for(tmp = value; tmp; tmp = tmp->next) | |
328 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
329 g_strdup(tmp->data)); | |
330 } | |
331 | |
5440 | 332 void remove_pref(struct gaim_pref *pref) { |
333 char *name; | |
334 | |
335 if(!pref || pref == &prefs) | |
336 return; | |
337 | |
6693 | 338 while(pref->first_child) |
339 remove_pref(pref->first_child); | |
340 | |
5440 | 341 if(pref->parent->first_child == pref) { |
342 pref->parent->first_child = pref->sibling; | |
343 } else { | |
344 struct gaim_pref *sib = pref->parent->first_child; | |
345 while(sib->sibling != pref) | |
346 sib = sib->sibling; | |
347 sib->sibling = pref->sibling; | |
348 } | |
349 | |
350 name = pref_full_name(pref); | |
351 | |
7785 | 352 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref /%s\n", name); |
6693 | 353 |
5440 | 354 g_hash_table_remove(prefs_hash, name); |
355 g_free(name); | |
356 | |
357 free_pref_value(pref); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
358 |
5440 | 359 g_slist_free(pref->callbacks); |
360 g_free(pref->name); | |
361 g_free(pref); | |
362 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
363 |
5440 | 364 void gaim_prefs_remove(const char *name) { |
365 struct gaim_pref *pref = find_pref(name); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
366 |
5440 | 367 if(!pref) |
368 return; | |
369 | |
370 remove_pref(pref); | |
371 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
372 |
5440 | 373 void gaim_prefs_destroy() { |
374 gaim_prefs_remove("/"); | |
375 } | |
376 | |
377 static void do_callbacks(const char* name, struct gaim_pref *pref) { | |
378 GSList *cbs; | |
379 struct gaim_pref *cb_pref; | |
380 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { | |
381 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { | |
382 struct pref_cb *cb = cbs->data; | |
383 cb->func(name, pref->type, pref->value.generic, cb->data); | |
4215 | 384 } |
385 } | |
1525
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
386 } |
ba8e6e211af5
[gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1455
diff
changeset
|
387 |
5684 | 388 void gaim_prefs_trigger_callback(const char *name) { |
389 struct gaim_pref *pref = find_pref(name); | |
390 | |
5814 | 391 if(!pref) { |
392 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
393 "gaim_prefs_trigger_callback: Unknown pref %s\n", name); | |
394 return; | |
395 } | |
396 | |
5684 | 397 do_callbacks(name, pref); |
398 } | |
399 | |
5440 | 400 void gaim_prefs_set_generic(const char *name, gpointer value) { |
401 struct gaim_pref *pref = find_pref(name); | |
3366 | 402 |
5814 | 403 if(!pref) { |
404 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
405 "gaim_prefs_set_generic: Unknown pref %s\n", name); | |
406 return; | |
407 } | |
3500 | 408 |
5440 | 409 pref->value.generic = value; |
410 do_callbacks(name, pref); | |
3366 | 411 } |
412 | |
5440 | 413 void gaim_prefs_set_bool(const char *name, gboolean value) { |
414 struct gaim_pref *pref = find_pref(name); | |
4288 | 415 |
5533 | 416 if(pref) { |
5814 | 417 if(pref->type != GAIM_PREF_BOOLEAN) { |
418 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
419 "gaim_prefs_set_bool: %s not a boolean pref\n", name); | |
420 return; | |
421 } | |
4325 | 422 |
5533 | 423 if(pref->value.boolean != value) { |
424 pref->value.boolean = value; | |
425 do_callbacks(name, pref); | |
426 } | |
427 } else { | |
428 gaim_prefs_add_bool(name, value); | |
4288 | 429 } |
4324 | 430 } |
4325 | 431 |
5440 | 432 void gaim_prefs_set_int(const char *name, int value) { |
433 struct gaim_pref *pref = find_pref(name); | |
4325 | 434 |
5533 | 435 if(pref) { |
5814 | 436 if(pref->type != GAIM_PREF_INT) { |
437 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
438 "gaim_prefs_set_int: %s not an integer pref\n", name); | |
439 return; | |
440 } | |
4325 | 441 |
5533 | 442 if(pref->value.integer != value) { |
443 pref->value.integer = value; | |
444 do_callbacks(name, pref); | |
445 } | |
446 } else { | |
447 gaim_prefs_add_int(name, value); | |
5440 | 448 } |
4326 | 449 } |
450 | |
5451 | 451 void gaim_prefs_set_string(const char *name, const char *value) { |
5440 | 452 struct gaim_pref *pref = find_pref(name); |
4325 | 453 |
5533 | 454 if(pref) { |
5814 | 455 if(pref->type != GAIM_PREF_STRING) { |
456 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
457 "gaim_prefs_set_string: %s not a string pref\n", name); | |
458 return; | |
459 } | |
4325 | 460 |
6295 | 461 if((value && !pref->value.string) || |
462 (!value && pref->value.string) || | |
463 strcmp(pref->value.string, value)) { | |
5533 | 464 g_free(pref->value.string); |
465 pref->value.string = g_strdup(value); | |
466 do_callbacks(name, pref); | |
467 } | |
468 } else { | |
469 gaim_prefs_add_string(name, value); | |
4325 | 470 } |
471 } | |
472 | |
5561 | 473 void gaim_prefs_set_string_list(const char *name, GList *value) { |
474 struct gaim_pref *pref = find_pref(name); | |
475 if(pref) { | |
476 GList *tmp; | |
5814 | 477 |
478 if(pref->type != GAIM_PREF_STRING_LIST) { | |
479 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
480 "gaim_prefs_set_string_list: %s not a string list pref\n", | |
481 name); | |
482 return; | |
483 } | |
484 | |
5561 | 485 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) |
486 g_free(tmp->data); | |
487 | |
488 g_list_free(pref->value.stringlist); | |
489 pref->value.stringlist = NULL; | |
490 | |
491 for(tmp = value; tmp; tmp = tmp->next) | |
492 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
493 g_strdup(tmp->data)); | |
494 | |
5986
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
495 do_callbacks(name, pref); |
96e0ac28d933
[gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
496 |
5561 | 497 } else { |
498 gaim_prefs_add_string_list(name, value); | |
499 } | |
500 } | |
501 | |
5440 | 502 gpointer gaim_prefs_get_generic(const char *name) { |
503 struct gaim_pref *pref = find_pref(name); | |
4325 | 504 |
5814 | 505 if(!pref) { |
506 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
507 "gaim_prefs_get_generic: Unknown pref %s\n", name); | |
508 return NULL; | |
509 } | |
4288 | 510 |
5440 | 511 return pref->value.generic; |
4288 | 512 } |
513 | |
6538 | 514 GaimPrefType gaim_prefs_get_type(const char *name) { |
515 struct gaim_pref *pref = find_pref(name); | |
516 | |
517 if (pref == NULL) | |
518 return GAIM_PREF_NONE; | |
519 | |
520 return (pref->type); | |
521 } | |
522 | |
5440 | 523 gboolean gaim_prefs_get_bool(const char *name) { |
524 struct gaim_pref *pref = find_pref(name); | |
3427 | 525 |
5814 | 526 if(!pref) { |
527 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
528 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
529 return FALSE; | |
530 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
531 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
532 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
533 return FALSE; | |
534 } | |
3472 | 535 |
5440 | 536 return pref->value.boolean; |
3366 | 537 } |
538 | |
5440 | 539 int gaim_prefs_get_int(const char *name) { |
540 struct gaim_pref *pref = find_pref(name); | |
3500 | 541 |
5814 | 542 if(!pref) { |
543 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
544 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
545 return 0; | |
546 } else if(pref->type != GAIM_PREF_INT) { | |
547 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
548 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
549 return 0; | |
550 } | |
3366 | 551 |
5440 | 552 return pref->value.integer; |
3366 | 553 } |
554 | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
555 const char *gaim_prefs_get_string(const char *name) { |
5440 | 556 struct gaim_pref *pref = find_pref(name); |
3366 | 557 |
5814 | 558 if(!pref) { |
559 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
560 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
561 return NULL; | |
562 } else if(pref->type != GAIM_PREF_STRING) { | |
563 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
564 "gaim_prefs_get_string: %s not a string pref\n", name); | |
565 return NULL; | |
566 } | |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
567 |
5440 | 568 return pref->value.string; |
4469
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
569 } |
d76095396a0e
[gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents:
4461
diff
changeset
|
570 |
5561 | 571 GList *gaim_prefs_get_string_list(const char *name) { |
572 struct gaim_pref *pref = find_pref(name); | |
573 GList *ret = NULL, *tmp; | |
574 | |
5814 | 575 if(!pref) { |
576 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
577 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
578 return NULL; | |
579 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
580 gaim_debug(GAIM_DEBUG_ERROR, "prefs", | |
581 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
582 return NULL; | |
583 } | |
5561 | 584 |
585 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
586 ret = g_list_append(ret, g_strdup(tmp->data)); | |
587 | |
588 return ret; | |
589 } | |
590 | |
6693 | 591 void gaim_prefs_rename(const char *oldname, const char *newname) { |
592 struct gaim_pref *oldpref, *newpref; | |
593 | |
594 oldpref = find_pref(oldname); | |
595 newpref = find_pref(newname); | |
596 | |
597 /* it's already been renamed, call off the dogs */ | |
598 if(!oldpref) | |
599 return; | |
600 | |
9031 | 601 gaim_debug_info("prefs", "Renaming %s to %s\n", oldname, newname); |
602 | |
603 g_return_if_fail(newpref != NULL); /* the new one needs to be created first */ | |
6693 | 604 g_return_if_fail(oldpref->type == newpref->type); |
605 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
606 | |
607 switch(oldpref->type) { | |
608 case GAIM_PREF_NONE: | |
609 break; | |
610 case GAIM_PREF_BOOLEAN: | |
611 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
612 break; | |
613 case GAIM_PREF_INT: | |
614 gaim_prefs_set_int(newname, oldpref->value.integer); | |
615 break; | |
616 case GAIM_PREF_STRING: | |
617 gaim_prefs_set_string(newname, oldpref->value.string); | |
618 break; | |
619 case GAIM_PREF_STRING_LIST: | |
620 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
621 break; | |
622 } | |
623 | |
624 remove_pref(oldpref); | |
625 } | |
626 | |
8705 | 627 void gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname) { |
628 struct gaim_pref *oldpref, *newpref; | |
629 | |
630 gaim_debug_info("prefs", "Attempting to rename and toggle %s to %s\n", oldname, newname); | |
631 | |
632 oldpref = find_pref(oldname); | |
633 newpref = find_pref(newname); | |
634 | |
635 /* it's already been renamed, call off the cats */ | |
636 if(!oldpref) | |
637 return; | |
638 | |
639 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
640 g_return_if_fail(oldpref->type == newpref->type); | |
641 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN); | |
642 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
643 | |
644 gaim_prefs_set_bool(newname, !(oldpref->value.boolean)); | |
645 | |
646 remove_pref(oldpref); | |
647 | |
6693 | 648 } |
649 | |
5440 | 650 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
651 { | |
9156 | 652 struct gaim_pref *pref; |
5440 | 653 struct pref_cb *cb; |
654 static guint cb_id = 0; | |
3366 | 655 |
9156 | 656 pref = find_pref(name); |
657 if (pref == NULL) | |
5440 | 658 return 0; |
3366 | 659 |
5440 | 660 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
661 |
5440 | 662 cb->func = func; |
663 cb->data = data; | |
664 cb->id = ++cb_id; | |
4991 | 665 |
5440 | 666 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 667 |
5440 | 668 return cb->id; |
3366 | 669 } |
670 | |
5440 | 671 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
672 GSList *cbs; | |
673 struct gaim_pref *child; | |
2254 | 674 |
5440 | 675 if(!pref) |
676 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
677 |
5440 | 678 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
679 struct pref_cb *cb = cbs->data; | |
680 if(cb->id == callback_id) { | |
681 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
682 g_free(cb); | |
683 return TRUE; | |
4428 | 684 } |
685 } | |
686 | |
5440 | 687 for(child = pref->first_child; child; child = child->sibling) { |
688 if(disco_callback_helper(child, callback_id)) | |
689 return TRUE; | |
4428 | 690 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
691 |
5440 | 692 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
693 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
694 |
5440 | 695 void gaim_prefs_disconnect_callback(guint callback_id) { |
696 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
697 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
698 |
5440 | 699 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
700 struct gaim_pref *tmp; | |
701 char *esc; | |
702 int i; | |
3500 | 703 |
5440 | 704 if(!pref) { |
705 pref = &prefs; | |
3551 | 706 |
5440 | 707 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
708 fprintf(f, "<pref name='/'"); | |
709 } else { | |
710 for(i=0; i<depth; i++) | |
711 fprintf(f, "\t"); | |
712 esc = g_markup_escape_text(pref->name, -1); | |
713 fprintf(f, "<pref name='%s'", esc); | |
714 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
715 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
716 |
5440 | 717 switch(pref->type) { |
718 case GAIM_PREF_NONE: | |
719 break; | |
720 case GAIM_PREF_BOOLEAN: | |
721 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
722 break; | |
723 case GAIM_PREF_INT: | |
724 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
725 break; | |
726 case GAIM_PREF_STRING: | |
727 esc = g_markup_escape_text(pref->value.string, -1); | |
728 fprintf(f, " type='string' value='%s'", esc); | |
729 g_free(esc); | |
730 break; | |
5561 | 731 case GAIM_PREF_STRING_LIST: |
732 fprintf(f, " type='stringlist'"); | |
733 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
734 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
735 |
5561 | 736 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 737 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
738 |
5440 | 739 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
740 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 741 |
742 if(pref->type == GAIM_PREF_STRING_LIST) { | |
743 GList *tmp2; | |
744 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
745 for(i=0; i<depth+1; i++) | |
746 fprintf(f, "\t"); | |
747 esc = g_markup_escape_text(tmp2->data, -1); | |
748 fprintf(f, "<item value='%s' />\n", esc); | |
749 g_free(esc); | |
750 } | |
751 } | |
752 | |
5440 | 753 for(i=0; i<depth; i++) |
754 fprintf(f, "\t"); | |
755 fprintf(f, "</pref>\n"); | |
756 } else { | |
757 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
758 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
759 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
760 |
5440 | 761 void gaim_prefs_sync() { |
762 FILE *file; | |
763 const char *user_dir = gaim_user_dir(); | |
764 char *filename; | |
765 char *filename_real; | |
3551 | 766 |
5534 | 767 if(!prefs_is_loaded) { |
768 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
769 schedule_prefs_save(); /* schedule a save for after we read in */ | |
770 return; | |
771 } | |
772 | |
5440 | 773 if(!user_dir) |
774 return; | |
3551 | 775 |
5534 | 776 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
777 | |
5440 | 778 file = fopen(user_dir, "r"); |
779 if(!file) | |
780 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
781 else | |
782 fclose(file); | |
3551 | 783 |
5440 | 784 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 785 |
5440 | 786 if((file = fopen(filename, "w"))) { |
787 gaim_prefs_write(file, NULL, 0); | |
788 fclose(file); | |
789 chmod(filename, S_IRUSR | S_IWUSR); | |
790 } else { | |
791 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
792 filename); | |
8549 | 793 g_free(filename); |
794 return; | |
5440 | 795 } |
3551 | 796 |
5440 | 797 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
798 if(rename(filename, filename_real) < 0) | |
799 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
800 filename, filename_real); | |
3551 | 801 |
5440 | 802 g_free(filename); |
803 g_free(filename_real); | |
3551 | 804 } |
805 | |
5440 | 806 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
807 |
5440 | 808 static void prefs_start_element_handler (GMarkupParseContext *context, |
809 const gchar *element_name, | |
810 const gchar **attribute_names, | |
811 const gchar **attribute_values, | |
812 gpointer user_data, | |
813 GError **error) { | |
814 GaimPrefType pref_type = GAIM_PREF_NONE; | |
815 int i; | |
816 const char *pref_name = NULL, *pref_value = NULL; | |
817 GString *pref_name_full; | |
818 GList *tmp; | |
3366 | 819 |
5561 | 820 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 821 return; |
3500 | 822 |
5440 | 823 for(i = 0; attribute_names[i]; i++) { |
824 if(!strcmp(attribute_names[i], "name")) { | |
825 pref_name = attribute_values[i]; | |
826 } else if(!strcmp(attribute_names[i], "type")) { | |
827 if(!strcmp(attribute_values[i], "bool")) | |
828 pref_type = GAIM_PREF_BOOLEAN; | |
829 else if(!strcmp(attribute_values[i], "int")) | |
830 pref_type = GAIM_PREF_INT; | |
831 else if(!strcmp(attribute_values[i], "string")) | |
832 pref_type = GAIM_PREF_STRING; | |
5561 | 833 else if(!strcmp(attribute_values[i], "stringlist")) |
834 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 835 else |
836 return; | |
837 } else if(!strcmp(attribute_names[i], "value")) { | |
838 pref_value = attribute_values[i]; | |
839 } | |
840 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
841 |
5561 | 842 if(!strcmp(element_name, "item")) { |
5838 | 843 struct gaim_pref *pref; |
844 | |
845 pref_name_full = g_string_new(""); | |
846 | |
847 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
848 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
849 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
850 } | |
851 | |
852 pref = find_pref(pref_name_full->str); | |
853 | |
5561 | 854 if(pref) { |
855 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
856 g_strdup(pref_value)); | |
857 } | |
5838 | 858 } else { |
859 if(!pref_name || !strcmp(pref_name, "/")) | |
860 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
861 |
5838 | 862 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
863 |
5838 | 864 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
865 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
866 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
867 } | |
868 | |
5440 | 869 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
870 |
5838 | 871 switch(pref_type) { |
872 case GAIM_PREF_NONE: | |
7785 | 873 gaim_prefs_add_none(pref_name_full->str); |
5838 | 874 break; |
875 case GAIM_PREF_BOOLEAN: | |
876 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
877 break; | |
878 case GAIM_PREF_INT: | |
879 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
880 break; | |
881 case GAIM_PREF_STRING: | |
882 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
883 break; | |
884 case GAIM_PREF_STRING_LIST: | |
885 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
886 break; | |
887 } | |
888 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
889 g_string_free(pref_name_full, TRUE); | |
5440 | 890 } |
1170 | 891 } |
892 | |
5440 | 893 static void prefs_end_element_handler(GMarkupParseContext *context, |
894 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 895 if(prefs_stack && !strcmp(element_name, "pref")) { |
896 g_free(prefs_stack->data); | |
5440 | 897 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
898 } | |
1170 | 899 } |
900 | |
5440 | 901 static GMarkupParser prefs_parser = { |
902 prefs_start_element_handler, | |
903 prefs_end_element_handler, | |
904 NULL, | |
905 NULL, | |
906 NULL | |
907 }; | |
1170 | 908 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
909 gboolean gaim_prefs_load() { |
5440 | 910 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
911 gchar *contents = NULL; | |
912 gsize length; | |
913 GMarkupParseContext *context; | |
914 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
915 |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
916 if (!filename) { |
5534 | 917 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
918 return FALSE; |
5534 | 919 } |
5440 | 920 |
921 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
922 |
5440 | 923 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
924 #ifndef _WIN32 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
925 g_free(filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
926 g_error_free(error); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
927 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
928 error = NULL; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
929 |
8702 | 930 filename = g_build_filename(SYSCONFDIR, "gaim", "prefs.xml", NULL); |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
931 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
932 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
933 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
934 if (!g_file_get_contents(filename, &contents, &length, &error)) { |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
935 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
936 error->message); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
937 g_error_free(error); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
938 g_free(filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
939 prefs_is_loaded = TRUE; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
940 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
941 return FALSE; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
942 } |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
943 #else /* _WIN32 */ |
5440 | 944 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", |
945 error->message); | |
946 g_error_free(error); | |
6040 | 947 g_free(filename); |
5534 | 948 prefs_is_loaded = TRUE; |
6040 | 949 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
950 return FALSE; |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
951 #endif /* _WIN32 */ |
1170 | 952 } |
953 | |
5440 | 954 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
955 | |
956 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
957 g_markup_parse_context_free(context); | |
958 g_free(contents); | |
6040 | 959 g_free(filename); |
5534 | 960 prefs_is_loaded = TRUE; |
6040 | 961 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
962 return FALSE; |
5440 | 963 } |
964 | |
965 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
966 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
967 g_markup_parse_context_free(context); | |
968 g_free(contents); | |
6040 | 969 g_free(filename); |
5534 | 970 prefs_is_loaded = TRUE; |
6040 | 971 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
972 return FALSE; |
5440 | 973 } |
974 | |
6040 | 975 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); |
5440 | 976 g_markup_parse_context_free(context); |
977 g_free(contents); | |
978 g_free(filename); | |
5534 | 979 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
980 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
981 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
982 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
983 |
8900 | 984 void gaim_prefs_update_old() { |
985 /* Remove some no-longer-used prefs */ | |
8948 | 986 gaim_prefs_remove("/core/away/auto_response/in_active_conv"); |
987 gaim_prefs_remove("/core/away/auto_response/sec_before_resend"); | |
8942 | 988 gaim_prefs_remove("/core/conversations/away_back_on_send"); |
8900 | 989 gaim_prefs_remove("/core/conversations/send_urls_as_links"); |
8942 | 990 gaim_prefs_remove("/core/conversations/im/show_login"); |
8998 | 991 gaim_prefs_remove("/core/conversations/chat/show_join"); |
992 gaim_prefs_remove("/core/conversations/chat/show_leave"); | |
9251 | 993 gaim_prefs_remove("/core/conversations/combine_chat_im"); |
8900 | 994 } |