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