annotate src/prefs.c @ 8685:2ac2f4cf1de5

[gaim-migrate @ 9438] Patch by Kevin Stange to fix some crashbugs. I believe this was supposed to go in with marv's patch. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 17 Apr 2004 18:50:46 +0000
parents d99d2572d1a9
children 68d8280c5e13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7785
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7785
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7785
diff changeset
6 * source distribution.
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
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
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
27
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <string.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <stdio.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <stdlib.h>
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
31 #include <sys/stat.h>
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
32 #include <sys/types.h>
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
33 #include <glib.h>
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6040
diff changeset
34 #include "internal.h"
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
35 #include "prefs.h"
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
36 #include "debug.h"
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
37 #include "util.h"
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
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
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
43 struct pref_cb {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
44 GaimPrefCallback func;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
45 gpointer data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
46 guint id;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
47 };
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
48
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
49 struct gaim_pref {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
50 GaimPrefType type;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
51 char *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
52 union {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
53 gpointer generic;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
54 gboolean boolean;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
55 int integer;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
56 char *string;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
57 GList *stringlist;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
58 } value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
59 GSList *callbacks;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
60 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
61 struct gaim_pref *sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
62 struct gaim_pref *first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
63 };
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
64
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
65 static GHashTable *prefs_hash = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
66
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
67 static struct gaim_pref prefs = { GAIM_PREF_NONE, NULL, {NULL}, NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
68 NULL, NULL, NULL };
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
69
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
70 static guint prefs_save_timer = 0;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
71 static gboolean prefs_is_loaded = FALSE;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
72
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
73
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
74 static gboolean prefs_save_callback(gpointer who_cares) {
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
75 gaim_prefs_sync();
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
76 prefs_save_timer = 0;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
77 return FALSE;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
78 }
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
79
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
80 static void schedule_prefs_save() {
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
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
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
83 }
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
84
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
85 static void prefs_save_cb(const char *name, GaimPrefType type, gpointer val,
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
86 gpointer user_data) {
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
87
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
88 if(!prefs_is_loaded)
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
89 return;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
90
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
91 gaim_debug(GAIM_DEBUG_MISC, "prefs", "%s changed, scheduling save.\n", name);
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
92
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
93 schedule_prefs_save();
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
94 }
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
95
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
96 void gaim_prefs_init() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
97 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
98
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
99 gaim_prefs_connect_callback("/", prefs_save_cb, NULL);
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
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
950ee542eea0 [gaim-migrate @ 8333]
Mark Doliner <mark@kingant.net>
parents: 7561
diff changeset
110 gaim_prefs_add_int("/core/away/mins_before_away", 5);
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6040
diff changeset
111 /* XXX: internationalized string in prefs...evil */
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6040
diff changeset
112 gaim_prefs_add_string("/core/away/default_message",
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6040
diff changeset
113 _("Slightly less boring default"));
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
114
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
115 /* Away -> Auto Response */
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
116 gaim_prefs_add_none("/core/away/auto_response");
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
117 gaim_prefs_add_bool("/core/away/auto_response/enabled", TRUE);
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
118 gaim_prefs_add_bool("/core/away/auto_response/in_active_conv", TRUE);
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
119 gaim_prefs_add_bool("/core/away/auto_response/idle_only", FALSE);
5550
b18c2a37cc96 [gaim-migrate @ 5951]
Christian Hammond <chipx86@chipx86.com>
parents: 5547
diff changeset
120 gaim_prefs_add_int("/core/away/auto_response/sec_before_resend", 60);
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
121
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
122 /* Buddies */
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
123 gaim_prefs_add_none("/core/buddies");
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
124 gaim_prefs_add_bool("/core/buddies/use_server_alias", TRUE);
7420
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
125
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
126 /* Contact Priority Settings */
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
127 gaim_prefs_add_none("/core/contact");
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
128 gaim_prefs_add_bool("/core/contact/last_match", FALSE);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
129 gaim_prefs_add_int("/core/contact/offline_score", 4);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
130 gaim_prefs_add_int("/core/contact/away_score", 2);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7317
diff changeset
131 gaim_prefs_add_int("/core/contact/idle_score", 1);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
132 }
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
133
8235
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
134 void
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
135 gaim_prefs_uninit()
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
136 {
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
137 if (prefs_save_timer != 0) {
8287
ef881489396e [gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents: 8273
diff changeset
138 gaim_timeout_remove(prefs_save_timer);
8235
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
139 prefs_save_timer = 0;
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
140 gaim_prefs_sync();
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
141 }
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
142 }
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
143
5787
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
144 static char *
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
145 get_path_dirname(const char *name)
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
146 {
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
147 char *c, *str;
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
148
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
149 str = g_strdup(name);
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
150
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
151 if ((c = strrchr(str, '/')) != NULL) {
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
152 *c = '\0';
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
153
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
154 if (*str == '\0') {
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
155 g_free(str);
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 str = g_strdup("/");
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 }
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
160 else {
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
161 g_free(str);
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 str = g_strdup(".");
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
164 }
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
165
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
166 return str;
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 static char *
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
170 get_path_basename(const char *name)
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 const char *c;
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 if ((c = strrchr(name, '/')) != NULL)
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
175 return g_strdup(c + 1);
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 return g_strdup(name);
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
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
180 static char *pref_full_name(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
181 GString *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
182 struct gaim_pref *parent;
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
183 char *ret;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
184
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
185 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
186 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
187
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
188 if(pref == &prefs)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
189 return g_strdup("/");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
190
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
191 name = g_string_new(pref->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
192 parent = pref->parent;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
193
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
194 for(parent = pref->parent; parent && parent->name; parent = parent->parent) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
195 name = g_string_prepend_c(name, '/');
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
196 name = g_string_prepend(name, parent->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
197 }
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
198 ret = name->str;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
199 g_string_free(name, FALSE);
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
200 return ret;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
201 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
202
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
203 static struct gaim_pref *find_pref(const char *name)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
204 {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
205 if(!name || name[0] != '/') {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
206 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
207 } else if(name[1] == '\0') {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
208 return &prefs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
209 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
210 return g_hash_table_lookup(prefs_hash, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
211 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
212 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
213
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
214 static struct gaim_pref *find_pref_parent(const char *name)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
215 {
5787
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
216 char *parent_name = get_path_dirname(name);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
217 struct gaim_pref *ret = &prefs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
218
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
219 if(strcmp(parent_name, "/")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
220 ret = find_pref(parent_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
221 }
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1006
diff changeset
222
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
223 g_free(parent_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
224 return ret;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
225 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
226
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
227 static void free_pref_value(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
228 switch(pref->type) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
229 case GAIM_PREF_BOOLEAN:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
230 pref->value.boolean = FALSE;
7317
9b303dd88cb2 [gaim-migrate @ 7901]
Nathan Walp <nwalp@pidgin.im>
parents: 6695
diff changeset
231 break;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
232 case GAIM_PREF_INT:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
233 pref->value.integer = 0;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
234 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
235 case GAIM_PREF_STRING:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
236 g_free(pref->value.string);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
237 pref->value.string = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
238 break;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
239 case GAIM_PREF_STRING_LIST:
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
240 {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
241 GList *tmp;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
242 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
243 g_free(tmp->data);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
244
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
245 g_list_free(pref->value.stringlist);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
246 } break;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
247 case GAIM_PREF_NONE:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
248 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
249 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
250 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
251
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
252 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
253 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
254 struct gaim_pref *me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
255 struct gaim_pref *sibling;
5458
156e65ca910f [gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents: 5451
diff changeset
256 char *my_name;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
257
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
258 parent = find_pref_parent(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
259
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
260 if(!parent)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
261 return NULL;
1525
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
262
5787
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
263 my_name = get_path_basename(name);
5458
156e65ca910f [gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents: 5451
diff changeset
264
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
265 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
266 if(!strcmp(sibling->name, my_name)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
267 g_free(my_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
268 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
269 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
270 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
271
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
272 me = g_new0(struct gaim_pref, 1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
273 me->type = type;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
274 me->name = my_name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
275
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
276 me->parent = parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
277 if(parent->first_child) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
278 /* blatant abuse of a for loop */
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
279 for(sibling = parent->first_child; sibling->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
280 sibling = sibling->sibling);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
281 sibling->sibling = me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
282 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
283 parent->first_child = me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
284 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
285
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
286 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
287
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
288 return me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
289 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
290
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
291 void gaim_prefs_add_none(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
292 add_pref(GAIM_PREF_NONE, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
293 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
294
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
295 void gaim_prefs_add_bool(const char *name, gboolean value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
296 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
297
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
298 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
299 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
300
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
301 pref->value.boolean = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
302 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3567
diff changeset
303
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
304 void gaim_prefs_add_int(const char *name, int value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
305 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
306
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
307 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
308 return;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
309
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
310 pref->value.integer = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
311 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
312
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
313 void gaim_prefs_add_string(const char *name, const char *value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
314 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
315
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
316 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
317 return;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
318
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
319 pref->value.string = g_strdup(value);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
320 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
321
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
322 void gaim_prefs_add_string_list(const char *name, GList *value) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
323 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
324 GList *tmp;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
325
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
326 if(!pref)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
327 return;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
328
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
329 for(tmp = value; tmp; tmp = tmp->next)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
330 pref->value.stringlist = g_list_append(pref->value.stringlist,
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
331 g_strdup(tmp->data));
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
332 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
333
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
334 void remove_pref(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
335 char *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
336
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
337 if(!pref || pref == &prefs)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
338 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
339
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
340 while(pref->first_child)
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
341 remove_pref(pref->first_child);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
342
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
343 if(pref->parent->first_child == pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
344 pref->parent->first_child = pref->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
345 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
346 struct gaim_pref *sib = pref->parent->first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
347 while(sib->sibling != pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
348 sib = sib->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
349 sib->sibling = pref->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
350 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
351
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
352 name = pref_full_name(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
353
7785
d5ee9c6da122 [gaim-migrate @ 8430]
Nathan Walp <nwalp@pidgin.im>
parents: 7689
diff changeset
354 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref /%s\n", name);
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
355
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
356 g_hash_table_remove(prefs_hash, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
357 g_free(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
358
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
359 free_pref_value(pref);
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
360
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
361 g_slist_free(pref->callbacks);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
362 g_free(pref->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
363 g_free(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
364 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
365
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
366 void gaim_prefs_remove(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
367 struct gaim_pref *pref = find_pref(name);
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
368
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
369 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
370 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
371
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
372 remove_pref(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
373 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
374
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
375 void gaim_prefs_destroy() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
376 gaim_prefs_remove("/");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
377 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
378
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
379 static void do_callbacks(const char* name, struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
380 GSList *cbs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
381 struct gaim_pref *cb_pref;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
382 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
383 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
384 struct pref_cb *cb = cbs->data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
385 cb->func(name, pref->type, pref->value.generic, cb->data);
4215
e9e55f0a991c [gaim-migrate @ 4454]
Luke Schierer <lschiere@pidgin.im>
parents: 4201
diff changeset
386 }
e9e55f0a991c [gaim-migrate @ 4454]
Luke Schierer <lschiere@pidgin.im>
parents: 4201
diff changeset
387 }
1525
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
388 }
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
389
5684
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
390 void gaim_prefs_trigger_callback(const char *name) {
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
391 struct gaim_pref *pref = find_pref(name);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
392
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
393 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
394 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
395 "gaim_prefs_trigger_callback: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
396 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
397 }
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
398
5684
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
399 do_callbacks(name, pref);
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
400 }
b61520e71679 [gaim-migrate @ 6104]
Nathan Walp <nwalp@pidgin.im>
parents: 5683
diff changeset
401
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
402 void gaim_prefs_set_generic(const char *name, gpointer value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
403 struct gaim_pref *pref = find_pref(name);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
404
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
405 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
406 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
407 "gaim_prefs_set_generic: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
408 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
409 }
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
410
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
411 pref->value.generic = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
412 do_callbacks(name, pref);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
413 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
414
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
415 void gaim_prefs_set_bool(const char *name, gboolean value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
416 struct gaim_pref *pref = find_pref(name);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
417
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
418 if(pref) {
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
419 if(pref->type != GAIM_PREF_BOOLEAN) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
420 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
421 "gaim_prefs_set_bool: %s not a boolean pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
422 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
423 }
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
424
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
425 if(pref->value.boolean != value) {
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
426 pref->value.boolean = value;
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
427 do_callbacks(name, pref);
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
428 }
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
429 } else {
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
430 gaim_prefs_add_bool(name, value);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
431 }
4324
561316116cd8 [gaim-migrate @ 4579]
Sean Egan <seanegan@gmail.com>
parents: 4323
diff changeset
432 }
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
433
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
434 void gaim_prefs_set_int(const char *name, int value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
435 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
436
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
437 if(pref) {
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
438 if(pref->type != GAIM_PREF_INT) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
439 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
440 "gaim_prefs_set_int: %s not an integer pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
441 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
442 }
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
443
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
444 if(pref->value.integer != value) {
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
445 pref->value.integer = value;
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
446 do_callbacks(name, pref);
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
447 }
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
448 } else {
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
449 gaim_prefs_add_int(name, value);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
450 }
4326
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
451 }
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
452
5451
e1cc0c67e123 [gaim-migrate @ 5839]
Nathan Walp <nwalp@pidgin.im>
parents: 5444
diff changeset
453 void gaim_prefs_set_string(const char *name, const char *value) {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
454 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
455
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
456 if(pref) {
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
457 if(pref->type != GAIM_PREF_STRING) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
458 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
459 "gaim_prefs_set_string: %s not a string pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
460 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
461 }
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
462
6295
44daf60ae44a [gaim-migrate @ 6794]
Nathan Walp <nwalp@pidgin.im>
parents: 6216
diff changeset
463 if((value && !pref->value.string) ||
44daf60ae44a [gaim-migrate @ 6794]
Nathan Walp <nwalp@pidgin.im>
parents: 6216
diff changeset
464 (!value && pref->value.string) ||
44daf60ae44a [gaim-migrate @ 6794]
Nathan Walp <nwalp@pidgin.im>
parents: 6216
diff changeset
465 strcmp(pref->value.string, value)) {
5533
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
466 g_free(pref->value.string);
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
467 pref->value.string = g_strdup(value);
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
468 do_callbacks(name, pref);
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
469 }
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
470 } else {
b4c32b9a797d [gaim-migrate @ 5933]
Nathan Walp <nwalp@pidgin.im>
parents: 5529
diff changeset
471 gaim_prefs_add_string(name, value);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
472 }
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
473 }
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
474
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
475 void gaim_prefs_set_string_list(const char *name, GList *value) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
476 struct gaim_pref *pref = find_pref(name);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
477 if(pref) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
478 GList *tmp;
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
479
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
480 if(pref->type != GAIM_PREF_STRING_LIST) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
481 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
482 "gaim_prefs_set_string_list: %s not a string list pref\n",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
483 name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
484 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
485 }
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
486
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
487 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
488 g_free(tmp->data);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
489
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
490 g_list_free(pref->value.stringlist);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
491 pref->value.stringlist = NULL;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
492
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
493 for(tmp = value; tmp; tmp = tmp->next)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
494 pref->value.stringlist = g_list_append(pref->value.stringlist,
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
495 g_strdup(tmp->data));
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
496
5986
96e0ac28d933 [gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents: 5949
diff changeset
497 do_callbacks(name, pref);
96e0ac28d933 [gaim-migrate @ 6434]
Christian Hammond <chipx86@chipx86.com>
parents: 5949
diff changeset
498
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
499 } else {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
500 gaim_prefs_add_string_list(name, value);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
501 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
502 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
503
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
504 gpointer gaim_prefs_get_generic(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
505 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
506
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
507 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
508 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
509 "gaim_prefs_get_generic: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
510 return NULL;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
511 }
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
512
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
513 return pref->value.generic;
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
514 }
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
515
6538
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
516 GaimPrefType gaim_prefs_get_type(const char *name) {
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
517 struct gaim_pref *pref = find_pref(name);
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
518
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
519 if (pref == NULL)
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
520 return GAIM_PREF_NONE;
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
521
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
522 return (pref->type);
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
523 }
4bc050b1af34 [gaim-migrate @ 7056]
Ethan Blanton <elb@pidgin.im>
parents: 6295
diff changeset
524
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
525 gboolean gaim_prefs_get_bool(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
526 struct gaim_pref *pref = find_pref(name);
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3404
diff changeset
527
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
528 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
529 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
530 "gaim_prefs_get_bool: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
531 return FALSE;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
532 } else if(pref->type != GAIM_PREF_BOOLEAN) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
533 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
534 "gaim_prefs_get_bool: %s not a boolean pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
535 return FALSE;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
536 }
3472
d33ec392a5e1 [gaim-migrate @ 3523]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
537
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
538 return pref->value.boolean;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
539 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
540
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
541 int gaim_prefs_get_int(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
542 struct gaim_pref *pref = find_pref(name);
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
543
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
544 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
545 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
546 "gaim_prefs_get_int: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
547 return 0;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
548 } else if(pref->type != GAIM_PREF_INT) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
549 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
550 "gaim_prefs_get_int: %s not an integer pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
551 return 0;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
552 }
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
553
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
554 return pref->value.integer;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
555 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
556
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
557 const char *gaim_prefs_get_string(const char *name) {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
558 struct gaim_pref *pref = find_pref(name);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
559
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
560 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
561 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
562 "gaim_prefs_get_string: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
563 return NULL;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
564 } else if(pref->type != GAIM_PREF_STRING) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
565 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
566 "gaim_prefs_get_string: %s not a string pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
567 return NULL;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
568 }
4469
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
569
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
570 return pref->value.string;
4469
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
571 }
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
572
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
573 GList *gaim_prefs_get_string_list(const char *name) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
574 struct gaim_pref *pref = find_pref(name);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
575 GList *ret = NULL, *tmp;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
576
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
577 if(!pref) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
578 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
579 "gaim_prefs_get_string_list: Unknown pref %s\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
580 return NULL;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
581 } else if(pref->type != GAIM_PREF_STRING_LIST) {
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
582 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
583 "gaim_prefs_get_string_list: %s not a string list pref\n", name);
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
584 return NULL;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
585 }
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
586
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
587 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
588 ret = g_list_append(ret, g_strdup(tmp->data));
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
589
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
590 return ret;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
591 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
592
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
593 void gaim_prefs_rename(const char *oldname, const char *newname) {
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
594 struct gaim_pref *oldpref, *newpref;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
595
7785
d5ee9c6da122 [gaim-migrate @ 8430]
Nathan Walp <nwalp@pidgin.im>
parents: 7689
diff changeset
596 gaim_debug_info("prefs", "Attempting to rename %s to %s\n", oldname, newname);
d5ee9c6da122 [gaim-migrate @ 8430]
Nathan Walp <nwalp@pidgin.im>
parents: 7689
diff changeset
597
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
598 oldpref = find_pref(oldname);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
599 newpref = find_pref(newname);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
600
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
601 /* it's already been renamed, call off the dogs */
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
602 if(!oldpref)
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
603 return;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
604
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
605 g_return_if_fail(newpref != NULL); /* the new one needs to be created */
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
606 g_return_if_fail(oldpref->type == newpref->type);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
607 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
608
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
609 switch(oldpref->type) {
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
610 case GAIM_PREF_NONE:
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
611 break;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
612 case GAIM_PREF_BOOLEAN:
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
613 gaim_prefs_set_bool(newname, oldpref->value.boolean);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
614 break;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
615 case GAIM_PREF_INT:
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
616 gaim_prefs_set_int(newname, oldpref->value.integer);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
617 break;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
618 case GAIM_PREF_STRING:
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
619 gaim_prefs_set_string(newname, oldpref->value.string);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
620 break;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
621 case GAIM_PREF_STRING_LIST:
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
622 gaim_prefs_set_string_list(newname, oldpref->value.stringlist);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
623 break;
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
624 }
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
625
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
626 remove_pref(oldpref);
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
627 }
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
628
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
629 void gaim_prefs_rename_old() {
7555
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7420
diff changeset
630 gaim_prefs_rename("/gaim/gtk/logging/log_ims", "/core/logging/log_ims");
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7420
diff changeset
631 gaim_prefs_rename("/gaim/gtk/logging/log_chats", "/core/logging/log_chats");
7561
cdfdbabd3266 [gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents: 7555
diff changeset
632 gaim_prefs_rename("/core/conversations/placement",
cdfdbabd3266 [gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents: 7555
diff changeset
633 "/gaim/gtk/conversations/placement");
6693
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
634 }
8c1b5dd87fbf [gaim-migrate @ 7219]
Nathan Walp <nwalp@pidgin.im>
parents: 6538
diff changeset
635
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
636 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
637 {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
638 struct gaim_pref *pref = find_pref(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
639 struct pref_cb *cb;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
640 static guint cb_id = 0;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
641
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
642 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
643 return 0;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
644
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
645 cb = g_new0(struct pref_cb, 1);
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
646
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
647 cb->func = func;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
648 cb->data = data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
649 cb->id = ++cb_id;
4991
c54fc48e33b0 [gaim-migrate @ 5326]
Rob Flynn <gaim@robflynn.com>
parents: 4985
diff changeset
650
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
651 pref->callbacks = g_slist_append(pref->callbacks, cb);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
652
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
653 return cb->id;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
654 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
655
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
656 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
657 GSList *cbs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
658 struct gaim_pref *child;
2254
c0ac78ffe77f [gaim-migrate @ 2264]
Rob Flynn <gaim@robflynn.com>
parents: 2199
diff changeset
659
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
660 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
661 return FALSE;
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
662
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
663 for(cbs = pref->callbacks; cbs; cbs = cbs->next) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
664 struct pref_cb *cb = cbs->data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
665 if(cb->id == callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
666 pref->callbacks = g_slist_remove(pref->callbacks, cb);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
667 g_free(cb);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
668 return TRUE;
4428
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
669 }
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
670 }
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
671
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
672 for(child = pref->first_child; child; child = child->sibling) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
673 if(disco_callback_helper(child, callback_id))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
674 return TRUE;
4428
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
675 }
4451
ce5b64fac95d [gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4449
diff changeset
676
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
677 return FALSE;
1757
3dfe4aefd366 [gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1755
diff changeset
678 }
3dfe4aefd366 [gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1755
diff changeset
679
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
680 void gaim_prefs_disconnect_callback(guint callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
681 disco_callback_helper(&prefs, callback_id);
2262
9c8f353331e7 [gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2254
diff changeset
682 }
9c8f353331e7 [gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2254
diff changeset
683
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
684 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
685 struct gaim_pref *tmp;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
686 char *esc;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
687 int i;
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
688
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
689 if(!pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
690 pref = &prefs;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
691
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
692 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
693 fprintf(f, "<pref name='/'");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
694 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
695 for(i=0; i<depth; i++)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
696 fprintf(f, "\t");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
697 esc = g_markup_escape_text(pref->name, -1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
698 fprintf(f, "<pref name='%s'", esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
699 g_free(esc);
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
700 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
701
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
702 switch(pref->type) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
703 case GAIM_PREF_NONE:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
704 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
705 case GAIM_PREF_BOOLEAN:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
706 fprintf(f, " type='bool' value='%d'", pref->value.boolean);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
707 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
708 case GAIM_PREF_INT:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
709 fprintf(f, " type='int' value='%d'", pref->value.integer);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
710 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
711 case GAIM_PREF_STRING:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
712 esc = g_markup_escape_text(pref->value.string, -1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
713 fprintf(f, " type='string' value='%s'", esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
714 g_free(esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
715 break;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
716 case GAIM_PREF_STRING_LIST:
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
717 fprintf(f, " type='stringlist'");
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
718 break;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
719 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
720
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
721 if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
722 fprintf(f, ">\n");
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
723
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
724 for(tmp = pref->first_child; tmp; tmp = tmp->sibling)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
725 gaim_prefs_write(f, tmp, depth+1);
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
726
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
727 if(pref->type == GAIM_PREF_STRING_LIST) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
728 GList *tmp2;
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
729 for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
730 for(i=0; i<depth+1; i++)
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
731 fprintf(f, "\t");
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
732 esc = g_markup_escape_text(tmp2->data, -1);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
733 fprintf(f, "<item value='%s' />\n", esc);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
734 g_free(esc);
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
735 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
736 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
737
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
738 for(i=0; i<depth; i++)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
739 fprintf(f, "\t");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
740 fprintf(f, "</pref>\n");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
741 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
742 fprintf(f, " />\n");
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
743 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
744 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
745
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
746 void gaim_prefs_sync() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
747 FILE *file;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
748 const char *user_dir = gaim_user_dir();
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
749 char *filename;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
750 char *filename_real;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
751
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
752 if(!prefs_is_loaded) {
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
753 gaim_debug(GAIM_DEBUG_WARNING, "prefs", "prefs saved before loading! scheduling save.\n");
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
754 schedule_prefs_save(); /* schedule a save for after we read in */
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
755 return;
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
756 }
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
757
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
758 if(!user_dir)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
759 return;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
760
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
761 gaim_debug(GAIM_DEBUG_INFO, "prefs", "writing prefs out to disk.\n");
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
762
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
763 file = fopen(user_dir, "r");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
764 if(!file)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
765 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
766 else
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
767 fclose(file);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
768
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
769 filename = g_build_filename(user_dir, "prefs.xml.save", NULL);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
770
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
771 if((file = fopen(filename, "w"))) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
772 gaim_prefs_write(file, NULL, 0);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
773 fclose(file);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
774 chmod(filename, S_IRUSR | S_IWUSR);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
775 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
776 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
777 filename);
8549
1a016d979ce0 [gaim-migrate @ 9291]
Nathan Walp <nwalp@pidgin.im>
parents: 8287
diff changeset
778 g_free(filename);
1a016d979ce0 [gaim-migrate @ 9291]
Nathan Walp <nwalp@pidgin.im>
parents: 8287
diff changeset
779 return;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
780 }
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
781
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
782 filename_real = g_build_filename(user_dir, "prefs.xml", NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
783 if(rename(filename, filename_real) < 0)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
784 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
785 filename, filename_real);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
786
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
787 g_free(filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
788 g_free(filename_real);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
789 }
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
790
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
791 static GList *prefs_stack = NULL;
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
792
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
793 static void prefs_start_element_handler (GMarkupParseContext *context,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
794 const gchar *element_name,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
795 const gchar **attribute_names,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
796 const gchar **attribute_values,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
797 gpointer user_data,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
798 GError **error) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
799 GaimPrefType pref_type = GAIM_PREF_NONE;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
800 int i;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
801 const char *pref_name = NULL, *pref_value = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
802 GString *pref_name_full;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
803 GList *tmp;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
804
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
805 if(strcmp(element_name, "pref") && strcmp(element_name, "item"))
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
806 return;
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
807
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
808 for(i = 0; attribute_names[i]; i++) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
809 if(!strcmp(attribute_names[i], "name")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
810 pref_name = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
811 } else if(!strcmp(attribute_names[i], "type")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
812 if(!strcmp(attribute_values[i], "bool"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
813 pref_type = GAIM_PREF_BOOLEAN;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
814 else if(!strcmp(attribute_values[i], "int"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
815 pref_type = GAIM_PREF_INT;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
816 else if(!strcmp(attribute_values[i], "string"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
817 pref_type = GAIM_PREF_STRING;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
818 else if(!strcmp(attribute_values[i], "stringlist"))
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
819 pref_type = GAIM_PREF_STRING_LIST;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
820 else
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
821 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
822 } else if(!strcmp(attribute_names[i], "value")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
823 pref_value = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
824 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
825 }
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
826
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
827 if(!strcmp(element_name, "item")) {
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
828 struct gaim_pref *pref;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
829
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
830 pref_name_full = g_string_new("");
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
831
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
832 for(tmp = prefs_stack; tmp; tmp = tmp->next) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
833 pref_name_full = g_string_prepend(pref_name_full, tmp->data);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
834 pref_name_full = g_string_prepend_c(pref_name_full, '/');
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
835 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
836
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
837 pref = find_pref(pref_name_full->str);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
838
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
839 if(pref) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
840 pref->value.stringlist = g_list_append(pref->value.stringlist,
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
841 g_strdup(pref_value));
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
842 }
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
843 } else {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
844 if(!pref_name || !strcmp(pref_name, "/"))
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
845 return;
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
846
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
847 pref_name_full = g_string_new(pref_name);
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
848
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
849 for(tmp = prefs_stack; tmp; tmp = tmp->next) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
850 pref_name_full = g_string_prepend_c(pref_name_full, '/');
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
851 pref_name_full = g_string_prepend(pref_name_full, tmp->data);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
852 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
853
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
854 pref_name_full = g_string_prepend_c(pref_name_full, '/');
1253
8342d3aab1f1 [gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
855
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
856 switch(pref_type) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
857 case GAIM_PREF_NONE:
7785
d5ee9c6da122 [gaim-migrate @ 8430]
Nathan Walp <nwalp@pidgin.im>
parents: 7689
diff changeset
858 gaim_prefs_add_none(pref_name_full->str);
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
859 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
860 case GAIM_PREF_BOOLEAN:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
861 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
862 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
863 case GAIM_PREF_INT:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
864 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
865 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
866 case GAIM_PREF_STRING:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
867 gaim_prefs_set_string(pref_name_full->str, pref_value);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
868 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
869 case GAIM_PREF_STRING_LIST:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
870 gaim_prefs_set_string_list(pref_name_full->str, NULL);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
871 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
872 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
873 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
874 g_string_free(pref_name_full, TRUE);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
875 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
876 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
877
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
878 static void prefs_end_element_handler(GMarkupParseContext *context,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
879 const gchar *element_name, gpointer user_data, GError **error) {
5940
94ad4d45346a [gaim-migrate @ 6380]
Nathan Walp <nwalp@pidgin.im>
parents: 5858
diff changeset
880 if(prefs_stack && !strcmp(element_name, "pref")) {
94ad4d45346a [gaim-migrate @ 6380]
Nathan Walp <nwalp@pidgin.im>
parents: 5858
diff changeset
881 g_free(prefs_stack->data);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
882 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
883 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
884 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
885
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
886 static GMarkupParser prefs_parser = {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
887 prefs_start_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
888 prefs_end_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
889 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
890 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
891 NULL
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
892 };
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
893
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
894 gboolean gaim_prefs_load() {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
895 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
896 gchar *contents = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
897 gsize length;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
898 GMarkupParseContext *context;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
899 GError *error = NULL;
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
900
7561
cdfdbabd3266 [gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents: 7555
diff changeset
901 if (!filename) {
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
902 prefs_is_loaded = TRUE;
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
903 return FALSE;
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
904 }
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
905
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
906 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename);
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
907
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
908 if(!g_file_get_contents(filename, &contents, &length, &error)) {
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
909 #ifndef _WIN32
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
910 g_free(filename);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
911 g_error_free(error);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
912
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
913 error = NULL;
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
914
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
915 /*
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
916 * We're hard-coding /etc here, which may not be great, but for
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
917 * now it works. This was requested by the Fedora guys for the
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
918 * upcoming FC2 release.
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
919 */
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
920 filename = g_build_filename("/etc", "gaim", "prefs.xml", NULL);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
921
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
922 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
923
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
924 if (!g_file_get_contents(filename, &contents, &length, &error)) {
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
925 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n",
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
926 error->message);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
927 g_error_free(error);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
928 g_free(filename);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
929 prefs_is_loaded = TRUE;
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
930
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
931 return FALSE;
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
932 }
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
933 #else /* _WIN32 */
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
934 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
935 error->message);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
936 g_error_free(error);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
937 g_free(filename);
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
938 prefs_is_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
939
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
940 return FALSE;
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
941 #endif /* _WIN32 */
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
942 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
943
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
944 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
945
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
946 if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
947 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
948 g_free(contents);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
949 g_free(filename);
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
950 prefs_is_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
951
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
952 return FALSE;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
953 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
954
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
955 if(!g_markup_parse_context_end_parse(context, NULL)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
956 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
957 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
958 g_free(contents);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
959 g_free(filename);
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
960 prefs_is_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
961
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
962 return FALSE;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
963 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
964
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
965 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
966 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
967 g_free(contents);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
968 g_free(filename);
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
969 prefs_is_loaded = TRUE;
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
970
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
971 return TRUE;
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
972 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
973