Mercurial > pidgin
annotate src/prefs.c @ 8966:cd1c9bbab491
[gaim-migrate @ 9740]
Bring back "raise window on events" for IMs and chats. We don't think
these were supposed to be removed. My precious.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 18 May 2004 02:33:12 +0000 |
parents | 175cbf710a47 |
children | 3738d1eac0ad |
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 | |
7785 | 594 gaim_debug_info("prefs", "Attempting to rename %s to %s\n", oldname, newname); |
595 | |
6693 | 596 oldpref = find_pref(oldname); |
597 newpref = find_pref(newname); | |
598 | |
599 /* it's already been renamed, call off the dogs */ | |
600 if(!oldpref) | |
601 return; | |
602 | |
603 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
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 { | |
652 struct gaim_pref *pref = find_pref(name); | |
653 struct pref_cb *cb; | |
654 static guint cb_id = 0; | |
3366 | 655 |
5440 | 656 if(!pref) |
657 return 0; | |
3366 | 658 |
5440 | 659 cb = g_new0(struct pref_cb, 1); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
660 |
5440 | 661 cb->func = func; |
662 cb->data = data; | |
663 cb->id = ++cb_id; | |
4991 | 664 |
5440 | 665 pref->callbacks = g_slist_append(pref->callbacks, cb); |
3366 | 666 |
5440 | 667 return cb->id; |
3366 | 668 } |
669 | |
5440 | 670 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { |
671 GSList *cbs; | |
672 struct gaim_pref *child; | |
2254 | 673 |
5440 | 674 if(!pref) |
675 return FALSE; | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
676 |
5440 | 677 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { |
678 struct pref_cb *cb = cbs->data; | |
679 if(cb->id == callback_id) { | |
680 pref->callbacks = g_slist_remove(pref->callbacks, cb); | |
681 g_free(cb); | |
682 return TRUE; | |
4428 | 683 } |
684 } | |
685 | |
5440 | 686 for(child = pref->first_child; child; child = child->sibling) { |
687 if(disco_callback_helper(child, callback_id)) | |
688 return TRUE; | |
4428 | 689 } |
4451
ce5b64fac95d
[gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4449
diff
changeset
|
690 |
5440 | 691 return FALSE; |
1757
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
692 } |
3dfe4aefd366
[gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1755
diff
changeset
|
693 |
5440 | 694 void gaim_prefs_disconnect_callback(guint callback_id) { |
695 disco_callback_helper(&prefs, callback_id); | |
2262
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
696 } |
9c8f353331e7
[gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2254
diff
changeset
|
697 |
5440 | 698 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { |
699 struct gaim_pref *tmp; | |
700 char *esc; | |
701 int i; | |
3500 | 702 |
5440 | 703 if(!pref) { |
704 pref = &prefs; | |
3551 | 705 |
5440 | 706 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
707 fprintf(f, "<pref name='/'"); | |
708 } else { | |
709 for(i=0; i<depth; i++) | |
710 fprintf(f, "\t"); | |
711 esc = g_markup_escape_text(pref->name, -1); | |
712 fprintf(f, "<pref name='%s'", esc); | |
713 g_free(esc); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
714 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
715 |
5440 | 716 switch(pref->type) { |
717 case GAIM_PREF_NONE: | |
718 break; | |
719 case GAIM_PREF_BOOLEAN: | |
720 fprintf(f, " type='bool' value='%d'", pref->value.boolean); | |
721 break; | |
722 case GAIM_PREF_INT: | |
723 fprintf(f, " type='int' value='%d'", pref->value.integer); | |
724 break; | |
725 case GAIM_PREF_STRING: | |
726 esc = g_markup_escape_text(pref->value.string, -1); | |
727 fprintf(f, " type='string' value='%s'", esc); | |
728 g_free(esc); | |
729 break; | |
5561 | 730 case GAIM_PREF_STRING_LIST: |
731 fprintf(f, " type='stringlist'"); | |
732 break; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
733 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
734 |
5561 | 735 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { |
5440 | 736 fprintf(f, ">\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
737 |
5440 | 738 for(tmp = pref->first_child; tmp; tmp = tmp->sibling) |
739 gaim_prefs_write(f, tmp, depth+1); | |
5561 | 740 |
741 if(pref->type == GAIM_PREF_STRING_LIST) { | |
742 GList *tmp2; | |
743 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { | |
744 for(i=0; i<depth+1; i++) | |
745 fprintf(f, "\t"); | |
746 esc = g_markup_escape_text(tmp2->data, -1); | |
747 fprintf(f, "<item value='%s' />\n", esc); | |
748 g_free(esc); | |
749 } | |
750 } | |
751 | |
5440 | 752 for(i=0; i<depth; i++) |
753 fprintf(f, "\t"); | |
754 fprintf(f, "</pref>\n"); | |
755 } else { | |
756 fprintf(f, " />\n"); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
757 } |
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 |
5440 | 760 void gaim_prefs_sync() { |
761 FILE *file; | |
762 const char *user_dir = gaim_user_dir(); | |
763 char *filename; | |
764 char *filename_real; | |
3551 | 765 |
5534 | 766 if(!prefs_is_loaded) { |
767 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n"); | |
768 schedule_prefs_save(); /* schedule a save for after we read in */ | |
769 return; | |
770 } | |
771 | |
5440 | 772 if(!user_dir) |
773 return; | |
3551 | 774 |
5534 | 775 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n"); |
776 | |
5440 | 777 file = fopen(user_dir, "r"); |
778 if(!file) | |
779 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
780 else | |
781 fclose(file); | |
3551 | 782 |
5440 | 783 filename = g_build_filename(user_dir, "prefs.xml.save", NULL); |
3551 | 784 |
5440 | 785 if((file = fopen(filename, "w"))) { |
786 gaim_prefs_write(file, NULL, 0); | |
787 fclose(file); | |
788 chmod(filename, S_IRUSR | S_IWUSR); | |
789 } else { | |
790 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n", | |
791 filename); | |
8549 | 792 g_free(filename); |
793 return; | |
5440 | 794 } |
3551 | 795 |
5440 | 796 filename_real = g_build_filename(user_dir, "prefs.xml", NULL); |
797 if(rename(filename, filename_real) < 0) | |
798 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n", | |
799 filename, filename_real); | |
3551 | 800 |
5440 | 801 g_free(filename); |
802 g_free(filename_real); | |
3551 | 803 } |
804 | |
5440 | 805 static GList *prefs_stack = NULL; |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
806 |
5440 | 807 static void prefs_start_element_handler (GMarkupParseContext *context, |
808 const gchar *element_name, | |
809 const gchar **attribute_names, | |
810 const gchar **attribute_values, | |
811 gpointer user_data, | |
812 GError **error) { | |
813 GaimPrefType pref_type = GAIM_PREF_NONE; | |
814 int i; | |
815 const char *pref_name = NULL, *pref_value = NULL; | |
816 GString *pref_name_full; | |
817 GList *tmp; | |
3366 | 818 |
5561 | 819 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
5440 | 820 return; |
3500 | 821 |
5440 | 822 for(i = 0; attribute_names[i]; i++) { |
823 if(!strcmp(attribute_names[i], "name")) { | |
824 pref_name = attribute_values[i]; | |
825 } else if(!strcmp(attribute_names[i], "type")) { | |
826 if(!strcmp(attribute_values[i], "bool")) | |
827 pref_type = GAIM_PREF_BOOLEAN; | |
828 else if(!strcmp(attribute_values[i], "int")) | |
829 pref_type = GAIM_PREF_INT; | |
830 else if(!strcmp(attribute_values[i], "string")) | |
831 pref_type = GAIM_PREF_STRING; | |
5561 | 832 else if(!strcmp(attribute_values[i], "stringlist")) |
833 pref_type = GAIM_PREF_STRING_LIST; | |
5440 | 834 else |
835 return; | |
836 } else if(!strcmp(attribute_names[i], "value")) { | |
837 pref_value = attribute_values[i]; | |
838 } | |
839 } | |
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
840 |
5561 | 841 if(!strcmp(element_name, "item")) { |
5838 | 842 struct gaim_pref *pref; |
843 | |
844 pref_name_full = g_string_new(""); | |
845 | |
846 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
847 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
848 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
849 } | |
850 | |
851 pref = find_pref(pref_name_full->str); | |
852 | |
5561 | 853 if(pref) { |
854 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
855 g_strdup(pref_value)); | |
856 } | |
5838 | 857 } else { |
858 if(!pref_name || !strcmp(pref_name, "/")) | |
859 return; | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
860 |
5838 | 861 pref_name_full = g_string_new(pref_name); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
862 |
5838 | 863 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
864 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
865 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
866 } | |
867 | |
5440 | 868 pref_name_full = g_string_prepend_c(pref_name_full, '/'); |
1253
8342d3aab1f1
[gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
869 |
5838 | 870 switch(pref_type) { |
871 case GAIM_PREF_NONE: | |
7785 | 872 gaim_prefs_add_none(pref_name_full->str); |
5838 | 873 break; |
874 case GAIM_PREF_BOOLEAN: | |
875 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
876 break; | |
877 case GAIM_PREF_INT: | |
878 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
879 break; | |
880 case GAIM_PREF_STRING: | |
881 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
882 break; | |
883 case GAIM_PREF_STRING_LIST: | |
884 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
885 break; | |
886 } | |
887 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
888 g_string_free(pref_name_full, TRUE); | |
5440 | 889 } |
1170 | 890 } |
891 | |
5440 | 892 static void prefs_end_element_handler(GMarkupParseContext *context, |
893 const gchar *element_name, gpointer user_data, GError **error) { | |
5940 | 894 if(prefs_stack && !strcmp(element_name, "pref")) { |
895 g_free(prefs_stack->data); | |
5440 | 896 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
897 } | |
1170 | 898 } |
899 | |
5440 | 900 static GMarkupParser prefs_parser = { |
901 prefs_start_element_handler, | |
902 prefs_end_element_handler, | |
903 NULL, | |
904 NULL, | |
905 NULL | |
906 }; | |
1170 | 907 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
908 gboolean gaim_prefs_load() { |
5440 | 909 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
910 gchar *contents = NULL; | |
911 gsize length; | |
912 GMarkupParseContext *context; | |
913 GError *error = NULL; | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
914 |
7561
cdfdbabd3266
[gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents:
7555
diff
changeset
|
915 if (!filename) { |
5534 | 916 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
917 return FALSE; |
5534 | 918 } |
5440 | 919 |
920 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5297
diff
changeset
|
921 |
5440 | 922 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
923 #ifndef _WIN32 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
924 g_free(filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
925 g_error_free(error); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
926 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
927 error = NULL; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
928 |
8702 | 929 filename = g_build_filename(SYSCONFDIR, "gaim", "prefs.xml", NULL); |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
930 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
931 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
932 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
933 if (!g_file_get_contents(filename, &contents, &length, &error)) { |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
934 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
935 error->message); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
936 g_error_free(error); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
937 g_free(filename); |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
938 prefs_is_loaded = TRUE; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
939 |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
940 return FALSE; |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
941 } |
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
942 #else /* _WIN32 */ |
5440 | 943 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n", |
944 error->message); | |
945 g_error_free(error); | |
6040 | 946 g_free(filename); |
5534 | 947 prefs_is_loaded = TRUE; |
6040 | 948 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
949 return FALSE; |
8671
d99d2572d1a9
[gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents:
8549
diff
changeset
|
950 #endif /* _WIN32 */ |
1170 | 951 } |
952 | |
5440 | 953 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
954 | |
955 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
956 g_markup_parse_context_free(context); | |
957 g_free(contents); | |
6040 | 958 g_free(filename); |
5534 | 959 prefs_is_loaded = TRUE; |
6040 | 960 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
961 return FALSE; |
5440 | 962 } |
963 | |
964 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
965 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename); | |
966 g_markup_parse_context_free(context); | |
967 g_free(contents); | |
6040 | 968 g_free(filename); |
5534 | 969 prefs_is_loaded = TRUE; |
6040 | 970 |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
971 return FALSE; |
5440 | 972 } |
973 | |
6040 | 974 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename); |
5440 | 975 g_markup_parse_context_free(context); |
976 g_free(contents); | |
977 g_free(filename); | |
5534 | 978 prefs_is_loaded = TRUE; |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
979 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
980 return TRUE; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
981 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
982 |
8900 | 983 void gaim_prefs_update_old() { |
984 /* Remove some no-longer-used prefs */ | |
8948 | 985 gaim_prefs_remove("/core/away/auto_response/in_active_conv"); |
986 gaim_prefs_remove("/core/away/auto_response/sec_before_resend"); | |
8942 | 987 gaim_prefs_remove("/core/conversations/away_back_on_send"); |
8900 | 988 gaim_prefs_remove("/core/conversations/send_urls_as_links"); |
8942 | 989 gaim_prefs_remove("/core/conversations/im/show_login"); |
8900 | 990 } |