annotate src/prefs.c @ 12651:a74cb5952db4

[gaim-migrate @ 14992] Activate a GtkSpell on the status box. If your message contains a word that GtkSpell doesn't recognize then it will have red squiggles underneath it FOREVER. Is that going to annoy people? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 25 Dec 2005 01:36:31 +0000
parents e3ca84a8b551
children 019d0e4d8d65
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;
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9594
diff changeset
47 void *handle;
5440
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
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
50 /* TODO: This should use GaimValues? */
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
51 struct gaim_pref {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
52 GaimPrefType type;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
53 char *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
54 union {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
55 gpointer generic;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
56 gboolean boolean;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
57 int integer;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
58 char *string;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
59 GList *stringlist;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
60 } value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
61 GSList *callbacks;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
62 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
63 struct gaim_pref *sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
64 struct gaim_pref *first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
65 };
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
66
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
67
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
68 static struct gaim_pref prefs = {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
69 GAIM_PREF_NONE,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
70 NULL,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
71 { NULL },
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
72 NULL,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
73 NULL,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
74 NULL,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
75 NULL
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
76 };
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
77
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
78 static GHashTable *prefs_hash = NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
79 static guint save_timer = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
80 static gboolean prefs_loaded = FALSE;
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
81
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
82
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
83 /*********************************************************************
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
84 * Private utility functions *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
85 *********************************************************************/
8235
63c7a16a2c09 [gaim-migrate @ 8958]
Mark Doliner <mark@kingant.net>
parents: 8046
diff changeset
86
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
87 static struct
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
88 gaim_pref *find_pref(const char *name)
5787
2adc29c88a45 [gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents: 5684
diff changeset
89 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
90 if (!name || name[0] != '/')
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
91 return NULL;
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
92 else if (name[1] == '\0')
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
93 return &prefs;
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
94 else
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
95 return g_hash_table_lookup(prefs_hash, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
96 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
97
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
98
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
99 /*********************************************************************
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
100 * Writing to disk *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
101 *********************************************************************/
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
102
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
103 /*
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
104 * This function recursively creates the xmlnode tree from the prefs
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
105 * tree structure. Yay recursion!
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
106 */
10850
fa06fda62868 [gaim-migrate @ 12522]
Mark Doliner <mark@kingant.net>
parents: 10443
diff changeset
107 static void
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
108 pref_to_xmlnode(xmlnode *parent, struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
109 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
110 xmlnode *node, *childnode;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
111 struct gaim_pref *child;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
112 char buf[20];
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
113 GList *cur;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
114
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
115 /* Create a new node */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
116 node = xmlnode_new_child(parent, "pref");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
117 xmlnode_set_attrib(node, "name", pref->name);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
118
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
119 /* Set the type of this node (if type == GAIM_PREF_NONE then do nothing) */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
120 if (pref->type == GAIM_PREF_INT) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
121 xmlnode_set_attrib(node, "type", "int");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
122 snprintf(buf, sizeof(buf), "%d", pref->value.integer);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
123 xmlnode_set_attrib(node, "value", buf);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
124 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
125 else if (pref->type == GAIM_PREF_STRING) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
126 xmlnode_set_attrib(node, "type", "string");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
127 xmlnode_set_attrib(node, "value", pref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
128 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
129 else if (pref->type == GAIM_PREF_STRING_LIST) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
130 xmlnode_set_attrib(node, "type", "stringlist");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
131 for (cur = pref->value.stringlist; cur != NULL; cur = cur->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
132 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
133 childnode = xmlnode_new_child(node, "item");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
134 xmlnode_set_attrib(childnode, "value", cur->data);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
135 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
136 }
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
137 else if (pref->type == GAIM_PREF_BOOLEAN) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
138 xmlnode_set_attrib(node, "type", "bool");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
139 snprintf(buf, sizeof(buf), "%d", pref->value.boolean);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
140 xmlnode_set_attrib(node, "value", buf);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
141 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
142
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
143 /* All My Children */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
144 for (child = pref->first_child; child != NULL; child = child->sibling)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
145 pref_to_xmlnode(node, child);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
146 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
147
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
148 static xmlnode *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
149 prefs_to_xmlnode(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
150 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
151 xmlnode *node;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
152 struct gaim_pref *pref, *child;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
153
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
154 pref = &prefs;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
155
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
156 /* Create the root preference node */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
157 node = xmlnode_new("pref");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
158 xmlnode_set_attrib(node, "version", "1");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
159 xmlnode_set_attrib(node, "name", "/");
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
160
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
161 /* All My Children */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
162 for (child = pref->first_child; child != NULL; child = child->sibling)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
163 pref_to_xmlnode(node, child);
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
164
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
165 return node;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
166 }
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
167
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
168 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
169 sync_prefs(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
170 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
171 xmlnode *node;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
172 char *data;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
173
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
174 if (!prefs_loaded)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
175 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
176 /*
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
177 * TODO: Call schedule_prefs_save()? Ideally we wouldn't need to.
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
178 * (prefs.xml should be loaded when gaim_prefs_init is called)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
179 */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
180 gaim_debug_error("prefs", "Attempted to save prefs before "
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
181 "they were read!\n");
5814
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
182 return;
fb9209877f37 [gaim-migrate @ 6244]
Nathan Walp <nwalp@pidgin.im>
parents: 5787
diff changeset
183 }
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
184
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
185 node = prefs_to_xmlnode();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
186 data = xmlnode_to_formatted_str(node, NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
187 gaim_util_write_data_to_file("prefs.xml", data, -1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
188 g_free(data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
189 xmlnode_free(node);
4326
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
190 }
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
191
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
192 static gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
193 save_cb(gpointer data)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
194 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
195 sync_prefs();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
196 save_timer = 0;
9594
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
197 return FALSE;
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
198 }
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
199
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
200 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
201 schedule_prefs_save(void)
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
202 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
203 if (save_timer == 0)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
204 save_timer = gaim_timeout_add(5000, save_cb, NULL);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
205 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
206
2254
c0ac78ffe77f [gaim-migrate @ 2264]
Rob Flynn <gaim@robflynn.com>
parents: 2199
diff changeset
207
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
208 /*********************************************************************
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
209 * Reading from disk *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
210 *********************************************************************/
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
211
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
212 static GList *prefs_stack = NULL;
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
213
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
214 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
215 prefs_start_element_handler (GMarkupParseContext *context,
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
216 const gchar *element_name,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
217 const gchar **attribute_names,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
218 const gchar **attribute_values,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
219 gpointer user_data,
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
220 GError **error)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
221 {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
222 GaimPrefType pref_type = GAIM_PREF_NONE;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
223 int i;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
224 const char *pref_name = NULL, *pref_value = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
225 GString *pref_name_full;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
226 GList *tmp;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
227
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
228 if(strcmp(element_name, "pref") && strcmp(element_name, "item"))
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
229 return;
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
230
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
231 for(i = 0; attribute_names[i]; i++) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
232 if(!strcmp(attribute_names[i], "name")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
233 pref_name = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
234 } else if(!strcmp(attribute_names[i], "type")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
235 if(!strcmp(attribute_values[i], "bool"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
236 pref_type = GAIM_PREF_BOOLEAN;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
237 else if(!strcmp(attribute_values[i], "int"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
238 pref_type = GAIM_PREF_INT;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
239 else if(!strcmp(attribute_values[i], "string"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
240 pref_type = GAIM_PREF_STRING;
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
241 else if(!strcmp(attribute_values[i], "stringlist"))
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
242 pref_type = GAIM_PREF_STRING_LIST;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
243 else
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
244 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
245 } else if(!strcmp(attribute_names[i], "value")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
246 pref_value = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
247 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
248 }
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
249
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
250 if(!strcmp(element_name, "item")) {
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
251 struct gaim_pref *pref;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
252
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
253 pref_name_full = g_string_new("");
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
254
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
255 for(tmp = prefs_stack; tmp; tmp = tmp->next) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
256 pref_name_full = g_string_prepend(pref_name_full, tmp->data);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
257 pref_name_full = g_string_prepend_c(pref_name_full, '/');
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
258 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
259
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
260 pref = find_pref(pref_name_full->str);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
261
5561
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
262 if(pref) {
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
263 pref->value.stringlist = g_list_append(pref->value.stringlist,
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
264 g_strdup(pref_value));
d67b5b4e1323 [gaim-migrate @ 5962]
Nathan Walp <nwalp@pidgin.im>
parents: 5551
diff changeset
265 }
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
266 } else {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
267 if(!pref_name || !strcmp(pref_name, "/"))
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
268 return;
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
269
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
270 pref_name_full = g_string_new(pref_name);
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
271
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
272 for(tmp = prefs_stack; tmp; tmp = tmp->next) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
273 pref_name_full = g_string_prepend_c(pref_name_full, '/');
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
274 pref_name_full = g_string_prepend(pref_name_full, tmp->data);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
275 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
276
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
277 pref_name_full = g_string_prepend_c(pref_name_full, '/');
1253
8342d3aab1f1 [gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
278
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
279 switch(pref_type) {
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
280 case GAIM_PREF_NONE:
7785
d5ee9c6da122 [gaim-migrate @ 8430]
Nathan Walp <nwalp@pidgin.im>
parents: 7689
diff changeset
281 gaim_prefs_add_none(pref_name_full->str);
5838
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
282 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
283 case GAIM_PREF_BOOLEAN:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
284 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
285 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
286 case GAIM_PREF_INT:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
287 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
288 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
289 case GAIM_PREF_STRING:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
290 gaim_prefs_set_string(pref_name_full->str, pref_value);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
291 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
292 case GAIM_PREF_STRING_LIST:
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
293 gaim_prefs_set_string_list(pref_name_full->str, NULL);
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
294 break;
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
295 }
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
296 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name));
6aa7651c7c15 [gaim-migrate @ 6269]
Nathan Walp <nwalp@pidgin.im>
parents: 5814
diff changeset
297 g_string_free(pref_name_full, TRUE);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
298 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
299 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
300
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
301 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
302 prefs_end_element_handler(GMarkupParseContext *context,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
303 const gchar *element_name,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
304 gpointer user_data, GError **error)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
305 {
5940
94ad4d45346a [gaim-migrate @ 6380]
Nathan Walp <nwalp@pidgin.im>
parents: 5858
diff changeset
306 if(prefs_stack && !strcmp(element_name, "pref")) {
94ad4d45346a [gaim-migrate @ 6380]
Nathan Walp <nwalp@pidgin.im>
parents: 5858
diff changeset
307 g_free(prefs_stack->data);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
308 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
309 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
310 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
311
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
312 static GMarkupParser prefs_parser = {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
313 prefs_start_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
314 prefs_end_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
315 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
316 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
317 NULL
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
318 };
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
319
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
320 gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
321 gaim_prefs_load()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
322 {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
323 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
324 gchar *contents = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
325 gsize length;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
326 GMarkupParseContext *context;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
327 GError *error = NULL;
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
328
7561
cdfdbabd3266 [gaim-migrate @ 8175]
Christian Hammond <chipx86@chipx86.com>
parents: 7555
diff changeset
329 if (!filename) {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
330 prefs_loaded = TRUE;
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
331 return FALSE;
5534
0aa4d089125c [gaim-migrate @ 5934]
Nathan Walp <nwalp@pidgin.im>
parents: 5533
diff changeset
332 }
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
333
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
334 gaim_debug_info("prefs", "Reading %s\n", filename);
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
335
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
336 if(!g_file_get_contents(filename, &contents, &length, &error)) {
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
337 #ifndef _WIN32
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
338 g_free(filename);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
339 g_error_free(error);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
340
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
341 error = NULL;
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
342
8702
68d8280c5e13 [gaim-migrate @ 9455]
Luke Schierer <lschiere@pidgin.im>
parents: 8671
diff changeset
343 filename = g_build_filename(SYSCONFDIR, "gaim", "prefs.xml", NULL);
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
344
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
345 gaim_debug_info("prefs", "Reading %s\n", filename);
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
346
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
347 if (!g_file_get_contents(filename, &contents, &length, &error)) {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
348 gaim_debug_error("prefs", "Error reading prefs: %s\n",
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
349 error->message);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
350 g_error_free(error);
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
351 g_free(filename);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
352 prefs_loaded = TRUE;
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
353
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
354 return FALSE;
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
355 }
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
356 #else /* _WIN32 */
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
357 gaim_debug_error("prefs", "Error reading prefs: %s\n",
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
358 error->message);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
359 g_error_free(error);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
360 g_free(filename);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
361 prefs_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
362
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
363 return FALSE;
8671
d99d2572d1a9 [gaim-migrate @ 9423]
Christian Hammond <chipx86@chipx86.com>
parents: 8549
diff changeset
364 #endif /* _WIN32 */
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
365 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
366
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
367 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
368
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
369 if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
370 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
371 g_free(contents);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
372 g_free(filename);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
373 prefs_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
374
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
375 return FALSE;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
376 }
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 if(!g_markup_parse_context_end_parse(context, NULL)) {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
379 gaim_debug_error("prefs", "Error parsing %s\n", filename);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
380 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
381 g_free(contents);
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
382 g_free(filename);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
383 prefs_loaded = TRUE;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 5986
diff changeset
384
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
385 return FALSE;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
386 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
387
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
388 gaim_debug_info("prefs", "Finished reading %s\n", filename);
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
389 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
390 g_free(contents);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
391 g_free(filename);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
392 prefs_loaded = TRUE;
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
393
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5539
diff changeset
394 return TRUE;
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
395 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
396
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
397
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
398
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
399 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
400 prefs_save_cb(const char *name, GaimPrefType type, gpointer val,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
401 gpointer user_data)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
402 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
403
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
404 if(!prefs_loaded)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
405 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
406
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
407 gaim_debug_misc("prefs", "%s changed, scheduling save.\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
408
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
409 schedule_prefs_save();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
410 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
411
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
412 static char *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
413 get_path_dirname(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
414 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
415 char *c, *str;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
416
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
417 str = g_strdup(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
418
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
419 if ((c = strrchr(str, '/')) != NULL) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
420 *c = '\0';
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
421
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
422 if (*str == '\0') {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
423 g_free(str);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
424
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
425 str = g_strdup("/");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
426 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
427 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
428 else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
429 g_free(str);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
430
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
431 str = g_strdup(".");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
432 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
433
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
434 return str;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
435 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
436
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
437 static char *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
438 get_path_basename(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
439 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
440 const char *c;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
441
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
442 if ((c = strrchr(name, '/')) != NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
443 return g_strdup(c + 1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
444
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
445 return g_strdup(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
446 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
447
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
448 static char *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
449 pref_full_name(struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
450 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
451 GString *name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
452 struct gaim_pref *parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
453 char *ret;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
454
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
455 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
456 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
457
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
458 if(pref == &prefs)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
459 return g_strdup("/");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
460
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
461 name = g_string_new(pref->name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
462 parent = pref->parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
463
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
464 for(parent = pref->parent; parent && parent->name; parent = parent->parent) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
465 name = g_string_prepend_c(name, '/');
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
466 name = g_string_prepend(name, parent->name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
467 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
468 ret = name->str;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
469 g_string_free(name, FALSE);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
470 return ret;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
471 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
472
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
473 static struct gaim_pref *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
474 find_pref_parent(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
475 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
476 char *parent_name = get_path_dirname(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
477 struct gaim_pref *ret = &prefs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
478
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
479 if(strcmp(parent_name, "/")) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
480 ret = find_pref(parent_name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
481 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
482
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
483 g_free(parent_name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
484 return ret;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
485 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
486
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
487 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
488 free_pref_value(struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
489 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
490 switch(pref->type) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
491 case GAIM_PREF_BOOLEAN:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
492 pref->value.boolean = FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
493 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
494 case GAIM_PREF_INT:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
495 pref->value.integer = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
496 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
497 case GAIM_PREF_STRING:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
498 g_free(pref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
499 pref->value.string = NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
500 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
501 case GAIM_PREF_STRING_LIST:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
502 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
503 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
504 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
505 g_free(tmp->data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
506
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
507 g_list_free(pref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
508 } break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
509 case GAIM_PREF_NONE:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
510 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
511 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
512 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
513
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
514 static struct gaim_pref *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
515 add_pref(GaimPrefType type, const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
516 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
517 struct gaim_pref *parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
518 struct gaim_pref *me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
519 struct gaim_pref *sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
520 char *my_name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
521
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
522 parent = find_pref_parent(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
523
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
524 if(!parent)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
525 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
526
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
527 my_name = get_path_basename(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
528
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
529 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
530 if(!strcmp(sibling->name, my_name)) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
531 g_free(my_name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
532 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
533 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
534 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
535
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
536 me = g_new0(struct gaim_pref, 1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
537 me->type = type;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
538 me->name = my_name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
539
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
540 me->parent = parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
541 if(parent->first_child) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
542 /* blatant abuse of a for loop */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
543 for(sibling = parent->first_child; sibling->sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
544 sibling = sibling->sibling);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
545 sibling->sibling = me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
546 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
547 parent->first_child = me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
548 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
549
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
550 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
551
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
552 return me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
553 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
554
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
555 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
556 gaim_prefs_add_none(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
557 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
558 add_pref(GAIM_PREF_NONE, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
559 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
560
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
561 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
562 gaim_prefs_add_bool(const char *name, gboolean value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
563 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
564 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
565
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
566 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
567 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
568
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
569 pref->value.boolean = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
570 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
571
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
572 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
573 gaim_prefs_add_int(const char *name, int value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
574 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
575 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
576
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
577 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
578 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
579
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
580 pref->value.integer = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
581 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
582
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
583 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
584 gaim_prefs_add_string(const char *name, const char *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
585 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
586 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
587
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
588 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
589 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
590
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
591 pref->value.string = g_strdup(value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
592 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
593
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
594 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
595 gaim_prefs_add_string_list(const char *name, GList *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
596 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
597 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
598 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
599
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
600 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
601 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
602
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
603 for(tmp = value; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
604 pref->value.stringlist = g_list_append(pref->value.stringlist,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
605 g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
606 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
607
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10850
diff changeset
608 static void
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
609 remove_pref(struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
610 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
611 char *name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
612
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
613 if(!pref || pref == &prefs)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
614 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
615
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
616 while(pref->first_child)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
617 remove_pref(pref->first_child);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
618
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
619 if(pref->parent->first_child == pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
620 pref->parent->first_child = pref->sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
621 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
622 struct gaim_pref *sib = pref->parent->first_child;
12599
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
623 while(sib && sib->sibling != pref)
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
624 sib = sib->sibling;
12599
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
625 if(sib)
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
626 sib->sibling = pref->sibling;
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
627 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
628
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
629 name = pref_full_name(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
630
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
631 gaim_debug_info("prefs", "removing pref /%s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
632
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
633 g_hash_table_remove(prefs_hash, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
634 g_free(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
635
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
636 free_pref_value(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
637
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
638 g_slist_free(pref->callbacks);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
639 g_free(pref->name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
640 g_free(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
641 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
642
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
643 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
644 gaim_prefs_remove(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
645 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
646 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
647
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
648 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
649 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
650
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
651 remove_pref(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
652 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
653
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
654 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
655 gaim_prefs_destroy()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
656 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
657 gaim_prefs_remove("/");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
658 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
659
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
660 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
661 do_callbacks(const char* name, struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
662 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
663 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
664 struct gaim_pref *cb_pref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
665 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
666 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
667 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
668 cb->func(name, pref->type, pref->value.generic, cb->data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
669 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
670 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
671 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
672
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
673 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
674 gaim_prefs_trigger_callback(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
675 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
676 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
677
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
678 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
679 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
680 "gaim_prefs_trigger_callback: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
681 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
682 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
683
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
684 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
685 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
686
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
687 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
688 gaim_prefs_set_generic(const char *name, gpointer value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
689 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
690 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
691
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
692 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
693 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
694 "gaim_prefs_set_generic: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
695 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
696 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
697
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
698 pref->value.generic = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
699 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
700 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
701
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
702 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
703 gaim_prefs_set_bool(const char *name, gboolean value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
704 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
705 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
706
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
707 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
708 if(pref->type != GAIM_PREF_BOOLEAN) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
709 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
710 "gaim_prefs_set_bool: %s not a boolean pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
711 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
712 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
713
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
714 if(pref->value.boolean != value) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
715 pref->value.boolean = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
716 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
717 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
718 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
719 gaim_prefs_add_bool(name, value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
720 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
721 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
722
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
723 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
724 gaim_prefs_set_int(const char *name, int value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
725 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
726 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
727
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
728 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
729 if(pref->type != GAIM_PREF_INT) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
730 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
731 "gaim_prefs_set_int: %s not an integer pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
732 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
733 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
734
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
735 if(pref->value.integer != value) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
736 pref->value.integer = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
737 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
738 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
739 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
740 gaim_prefs_add_int(name, value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
741 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
742 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
743
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
744 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
745 gaim_prefs_set_string(const char *name, const char *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
746 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
747 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
748
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
749 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
750 if(pref->type != GAIM_PREF_STRING) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
751 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
752 "gaim_prefs_set_string: %s not a string pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
753 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
754 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
755
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
756 if((value && !pref->value.string) ||
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
757 (!value && pref->value.string) ||
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
758 strcmp(pref->value.string, value)) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
759 g_free(pref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
760 pref->value.string = g_strdup(value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
761 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
762 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
763 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
764 gaim_prefs_add_string(name, value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
765 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
766 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
767
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
768 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
769 gaim_prefs_set_string_list(const char *name, GList *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
770 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
771 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
772 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
773 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
774
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
775 if(pref->type != GAIM_PREF_STRING_LIST) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
776 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
777 "gaim_prefs_set_string_list: %s not a string list pref\n",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
778 name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
779 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
780 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
781
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
782 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
783 g_free(tmp->data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
784
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
785 g_list_free(pref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
786 pref->value.stringlist = NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
787
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
788 for(tmp = value; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
789 pref->value.stringlist = g_list_append(pref->value.stringlist,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
790 g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
791
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
792 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
793
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
794 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
795 gaim_prefs_add_string_list(name, value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
796 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
797 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
798
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
799 gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
800 gaim_prefs_exists(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
801 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
802 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
803
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
804 if (pref != NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
805 return TRUE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
806
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
807 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
808 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
809
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
810 GaimPrefType
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
811 gaim_prefs_get_type(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
812 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
813 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
814
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
815 if (pref == NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
816 return GAIM_PREF_NONE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
817
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
818 return (pref->type);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
819 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
820
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
821 gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
822 gaim_prefs_get_bool(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
823 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
824 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
825
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
826 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
827 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
828 "gaim_prefs_get_bool: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
829 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
830 } else if(pref->type != GAIM_PREF_BOOLEAN) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
831 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
832 "gaim_prefs_get_bool: %s not a boolean pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
833 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
834 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
835
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
836 return pref->value.boolean;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
837 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
838
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
839 int
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
840 gaim_prefs_get_int(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
841 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
842 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
843
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
844 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
845 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
846 "gaim_prefs_get_int: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
847 return 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
848 } else if(pref->type != GAIM_PREF_INT) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
849 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
850 "gaim_prefs_get_int: %s not an integer pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
851 return 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
852 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
853
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
854 return pref->value.integer;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
855 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
856
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
857 const char *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
858 gaim_prefs_get_string(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
859 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
860 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
861
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
862 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
863 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
864 "gaim_prefs_get_string: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
865 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
866 } else if(pref->type != GAIM_PREF_STRING) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
867 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
868 "gaim_prefs_get_string: %s not a string pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
869 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
870 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
871
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
872 return pref->value.string;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
873 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
874
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
875 GList *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
876 gaim_prefs_get_string_list(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
877 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
878 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
879 GList *ret = NULL, *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
880
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
881 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
882 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
883 "gaim_prefs_get_string_list: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
884 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
885 } else if(pref->type != GAIM_PREF_STRING_LIST) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
886 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
887 "gaim_prefs_get_string_list: %s not a string list pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
888 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
889 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
890
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
891 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
892 ret = g_list_append(ret, g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
893
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
894 return ret;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
895 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
896
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
897 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
898 gaim_prefs_rename(const char *oldname, const char *newname)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
899 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
900 struct gaim_pref *oldpref, *newpref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
901
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
902 oldpref = find_pref(oldname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
903 newpref = find_pref(newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
904
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
905 /* it's already been renamed, call off the dogs */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
906 if(!oldpref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
907 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
908
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
909 gaim_debug_info("prefs", "Renaming %s to %s\n", oldname, newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
910
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
911 g_return_if_fail(newpref != NULL); /* the new one needs to be created first */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
912 g_return_if_fail(oldpref->type == newpref->type);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
913 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
914
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
915 switch(oldpref->type) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
916 case GAIM_PREF_NONE:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
917 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
918 case GAIM_PREF_BOOLEAN:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
919 gaim_prefs_set_bool(newname, oldpref->value.boolean);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
920 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
921 case GAIM_PREF_INT:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
922 gaim_prefs_set_int(newname, oldpref->value.integer);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
923 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
924 case GAIM_PREF_STRING:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
925 gaim_prefs_set_string(newname, oldpref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
926 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
927 case GAIM_PREF_STRING_LIST:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
928 gaim_prefs_set_string_list(newname, oldpref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
929 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
930 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
931
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
932 remove_pref(oldpref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
933 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
934
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
935 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
936 gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
937 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
938 struct gaim_pref *oldpref, *newpref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
939
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
940 oldpref = find_pref(oldname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
941 newpref = find_pref(newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
942
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
943 /* it's already been renamed, call off the cats */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
944 if(!oldpref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
945 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
946
11736
a14d72b6ca41 [gaim-migrate @ 14027]
Mark Doliner <mark@kingant.net>
parents: 11719
diff changeset
947 gaim_debug_info("prefs", "Renaming and toggling %s to %s\n", oldname, newname);
a14d72b6ca41 [gaim-migrate @ 14027]
Mark Doliner <mark@kingant.net>
parents: 11719
diff changeset
948
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
949 g_return_if_fail(newpref != NULL); /* the new one needs to be created */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
950 g_return_if_fail(oldpref->type == newpref->type);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
951 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
952 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
953
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
954 gaim_prefs_set_bool(newname, !(oldpref->value.boolean));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
955
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
956 remove_pref(oldpref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
957
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
958 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
959
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
960 guint
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
961 gaim_prefs_connect_callback(void *handle, const char *name, GaimPrefCallback func, gpointer data)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
962 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
963 struct gaim_pref *pref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
964 struct pref_cb *cb;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
965 static guint cb_id = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
966
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
967 pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
968 if (pref == NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
969 return 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
970
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
971 cb = g_new0(struct pref_cb, 1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
972
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
973 cb->func = func;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
974 cb->data = data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
975 cb->id = ++cb_id;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
976 cb->handle = handle;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
977
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
978 pref->callbacks = g_slist_append(pref->callbacks, cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
979
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
980 return cb->id;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
981 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
982
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
983 static gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
984 disco_callback_helper(struct gaim_pref *pref, guint callback_id)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
985 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
986 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
987 struct gaim_pref *child;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
988
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
989 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
990 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
991
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
992 for(cbs = pref->callbacks; cbs; cbs = cbs->next) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
993 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
994 if(cb->id == callback_id) {
11719
109ee3bfeac5 [gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
995 pref->callbacks = g_slist_delete_link(pref->callbacks, cbs);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
996 g_free(cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
997 return TRUE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
998 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
999 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1000
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1001 for(child = pref->first_child; child; child = child->sibling) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1002 if(disco_callback_helper(child, callback_id))
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1003 return TRUE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1004 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1005
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1006 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1007 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1008
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1009 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1010 gaim_prefs_disconnect_callback(guint callback_id)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1011 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1012 disco_callback_helper(&prefs, callback_id);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1013 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1014
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1015 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1016 disco_callback_helper_handle(struct gaim_pref *pref, void *handle)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1017 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1018 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1019 struct gaim_pref *child;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1020
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1021 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1022 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1023
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1024 cbs = pref->callbacks;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1025 while (cbs != NULL) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1026 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1027 if(cb->handle == handle) {
11719
109ee3bfeac5 [gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
1028 pref->callbacks = g_slist_delete_link(pref->callbacks, cbs);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1029 g_free(cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1030 cbs = pref->callbacks;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1031 } else
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1032 cbs = cbs->next;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1033 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1034
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1035 for(child = pref->first_child; child; child = child->sibling)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1036 disco_callback_helper_handle(child, handle);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1037 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1038
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1039 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1040 gaim_prefs_disconnect_by_handle(void *handle)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1041 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1042 g_return_if_fail(handle != NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1043
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1044 disco_callback_helper_handle(&prefs, handle);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1045 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1046
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1047 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1048 gaim_prefs_update_old()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1049 {
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1050 /* Remove some no-longer-used prefs */
9594
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1051 gaim_prefs_remove("/core/away/auto_response/enabled");
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1052 gaim_prefs_remove("/core/away/auto_response/idle_only");
8948
175cbf710a47 [gaim-migrate @ 9720]
Mark Doliner <mark@kingant.net>
parents: 8942
diff changeset
1053 gaim_prefs_remove("/core/away/auto_response/in_active_conv");
175cbf710a47 [gaim-migrate @ 9720]
Mark Doliner <mark@kingant.net>
parents: 8942
diff changeset
1054 gaim_prefs_remove("/core/away/auto_response/sec_before_resend");
9594
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1055 gaim_prefs_remove("/core/away/auto_response");
11654
bf6ba37db13b [gaim-migrate @ 13938]
Mark Doliner <mark@kingant.net>
parents: 11256
diff changeset
1056 gaim_prefs_remove("/core/away/default_message");
10353
fc7168f9ecb0 [gaim-migrate @ 11570]
Mark Doliner <mark@kingant.net>
parents: 10349
diff changeset
1057 gaim_prefs_remove("/core/buddies/use_server_alias");
8942
06f47021ddd3 [gaim-migrate @ 9712]
Mark Doliner <mark@kingant.net>
parents: 8905
diff changeset
1058 gaim_prefs_remove("/core/conversations/away_back_on_send");
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1059 gaim_prefs_remove("/core/conversations/send_urls_as_links");
8942
06f47021ddd3 [gaim-migrate @ 9712]
Mark Doliner <mark@kingant.net>
parents: 8905
diff changeset
1060 gaim_prefs_remove("/core/conversations/im/show_login");
8998
3738d1eac0ad [gaim-migrate @ 9773]
Luke Schierer <lschiere@pidgin.im>
parents: 8948
diff changeset
1061 gaim_prefs_remove("/core/conversations/chat/show_join");
3738d1eac0ad [gaim-migrate @ 9773]
Luke Schierer <lschiere@pidgin.im>
parents: 8948
diff changeset
1062 gaim_prefs_remove("/core/conversations/chat/show_leave");
9251
45d2ad4ac1c1 [gaim-migrate @ 10050]
Ethan Blanton <elb@pidgin.im>
parents: 9156
diff changeset
1063 gaim_prefs_remove("/core/conversations/combine_chat_im");
10389
c432b927b0b1 [gaim-migrate @ 11616]
Sean Egan <seanegan@gmail.com>
parents: 10387
diff changeset
1064 gaim_prefs_remove("/core/conversations/use_alias_for_title");
11698
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1065 gaim_prefs_remove("/core/logging/log_signon_signoff");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1066 gaim_prefs_remove("/core/logging/log_idle_state");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1067 gaim_prefs_remove("/core/logging/log_away_state");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1068 gaim_prefs_remove("/core/logging/log_own_states");
11959
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1069 gaim_prefs_remove("/plugins/core/autorecon/hide_connected_error");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1070 gaim_prefs_remove("/plugins/core/autorecon/hide_connecting_error");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1071 gaim_prefs_remove("/plugins/core/autorecon/hide_reconnecting_dialog");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1072 gaim_prefs_remove("/plugins/core/autorecon/restore_state");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1073 gaim_prefs_remove("/plugins/core/autorecon");
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1074 }
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1075
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1076 void *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1077 gaim_prefs_get_handle(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1078 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1079 static int handle;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1080
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1081 return &handle;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1082 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1083
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1084 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1085 gaim_prefs_init(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1086 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1087 void *handle = gaim_prefs_get_handle();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1088
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1089 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1090
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1091 gaim_prefs_connect_callback(handle, "/", prefs_save_cb, NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1092
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1093 gaim_prefs_add_none("/core");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1094 gaim_prefs_add_none("/plugins");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1095 gaim_prefs_add_none("/plugins/core");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1096 gaim_prefs_add_none("/plugins/lopl");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1097 gaim_prefs_add_none("/plugins/prpl");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1098
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1099 /* Away */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1100 gaim_prefs_add_none("/core/away");
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12272
diff changeset
1101 gaim_prefs_add_string("/core/away/idle_reporting", "system");
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1102 gaim_prefs_add_bool("/core/away/away_when_idle", TRUE);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1103 gaim_prefs_add_int("/core/away/mins_before_away", 5);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1104
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1105 /* Away -> Auto-Reply */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1106 if (!gaim_prefs_exists("/core/away/auto_response/enabled") ||
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1107 !gaim_prefs_exists("/core/away/auto_response/idle_only"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1108 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1109 gaim_prefs_add_string("/core/away/auto_reply", "awayidle");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1110 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1111 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1112 {
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1113 if (!gaim_prefs_get_bool("/core/away/auto_response/enabled"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1114 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1115 gaim_prefs_add_string("/core/away/auto_reply", "never");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1116 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1117 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1118 {
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1119 if (gaim_prefs_get_bool("/core/away/auto_response/idle_only"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1120 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1121 gaim_prefs_add_string("/core/away/auto_reply", "awayidle");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1122 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1123 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1124 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1125 gaim_prefs_add_string("/core/away/auto_reply", "away");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1126 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1127 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1128 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1129
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1130 /* Buddies */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1131 gaim_prefs_add_none("/core/buddies");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1132
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1133 /* Contact Priority Settings */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1134 gaim_prefs_add_none("/core/contact");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1135 gaim_prefs_add_bool("/core/contact/last_match", FALSE);
12164
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1136 gaim_prefs_remove("/core/contact/offline_score");
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1137 gaim_prefs_remove("/core/contact/away_score");
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1138 gaim_prefs_remove("/core/contact/idle_score");
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1139 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1140
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1141 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1142 gaim_prefs_uninit()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1143 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1144 if (save_timer != 0)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1145 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1146 gaim_timeout_remove(save_timer);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1147 save_timer = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1148 sync_prefs();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1149 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1150
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1151 gaim_prefs_disconnect_by_handle(gaim_prefs_get_handle());
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1152 }