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