annotate src/prefs.c @ 12780:c886fc7e3f24

[gaim-migrate @ 15127] Some more whitespace. I promise I'll get to real commits sooner or later. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Mon, 09 Jan 2006 06:45:16 +0000
parents 40584fbf8c6e
children cecc9706c11f
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 }
12759
019d0e4d8d65 [gaim-migrate @ 15106]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12615
diff changeset
468 name = g_string_prepend_c(name, '/');
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
469 ret = name->str;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
470 g_string_free(name, FALSE);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
471 return ret;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
474 static struct gaim_pref *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
475 find_pref_parent(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
476 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
477 char *parent_name = get_path_dirname(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
478 struct gaim_pref *ret = &prefs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
479
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
480 if(strcmp(parent_name, "/")) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
481 ret = find_pref(parent_name);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
484 g_free(parent_name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
485 return ret;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
488 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
489 free_pref_value(struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
490 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
491 switch(pref->type) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
492 case GAIM_PREF_BOOLEAN:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
493 pref->value.boolean = FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
494 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
495 case GAIM_PREF_INT:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
496 pref->value.integer = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
497 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
498 case GAIM_PREF_STRING:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
499 g_free(pref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
500 pref->value.string = NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
501 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
502 case GAIM_PREF_STRING_LIST:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
503 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
504 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
505 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
506 g_free(tmp->data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
507
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
508 g_list_free(pref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
509 } break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
510 case GAIM_PREF_NONE:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
511 break;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
515 static struct gaim_pref *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
516 add_pref(GaimPrefType type, const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
517 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
518 struct gaim_pref *parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
519 struct gaim_pref *me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
520 struct gaim_pref *sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
521 char *my_name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
522
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
523 parent = find_pref_parent(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
524
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
525 if(!parent)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
526 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
527
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
528 my_name = get_path_basename(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
529
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
530 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
531 if(!strcmp(sibling->name, my_name)) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
532 g_free(my_name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
533 return NULL;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
537 me = g_new0(struct gaim_pref, 1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
538 me->type = type;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
539 me->name = my_name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
540
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
541 me->parent = parent;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
542 if(parent->first_child) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
543 /* blatant abuse of a for loop */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
544 for(sibling = parent->first_child; sibling->sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
545 sibling = sibling->sibling);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
546 sibling->sibling = me;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
547 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
548 parent->first_child = me;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
551 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
552
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
553 return me;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
556 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
557 gaim_prefs_add_none(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
558 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
559 add_pref(GAIM_PREF_NONE, name);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
562 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
563 gaim_prefs_add_bool(const char *name, gboolean value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
564 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
565 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
566
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
567 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
568 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
569
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
570 pref->value.boolean = value;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
573 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
574 gaim_prefs_add_int(const char *name, int value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
575 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
576 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
577
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
578 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
579 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
580
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
581 pref->value.integer = value;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
584 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
585 gaim_prefs_add_string(const char *name, const char *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
586 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
587 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
588
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
589 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
590 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
591
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
592 pref->value.string = g_strdup(value);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
595 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
596 gaim_prefs_add_string_list(const char *name, GList *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
597 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
598 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
599 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
600
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
601 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
602 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
603
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
604 for(tmp = value; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
605 pref->value.stringlist = g_list_append(pref->value.stringlist,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
606 g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
607 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
608
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10850
diff changeset
609 static void
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
610 remove_pref(struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
611 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
612 char *name;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
613
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
614 if(!pref || pref == &prefs)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
615 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
616
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
617 while(pref->first_child)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
618 remove_pref(pref->first_child);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
619
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
620 if(pref->parent->first_child == pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
621 pref->parent->first_child = pref->sibling;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
622 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
623 struct gaim_pref *sib = pref->parent->first_child;
12599
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
624 while(sib && sib->sibling != pref)
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
625 sib = sib->sibling;
12599
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
626 if(sib)
e94c33909aa6 [gaim-migrate @ 14929]
Nathan Walp <nwalp@pidgin.im>
parents: 12573
diff changeset
627 sib->sibling = pref->sibling;
10443
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
630 name = pref_full_name(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
631
12762
40584fbf8c6e [gaim-migrate @ 15109]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12759
diff changeset
632 gaim_debug_info("prefs", "removing pref %s\n", name);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
633
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
634 g_hash_table_remove(prefs_hash, name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
635 g_free(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
636
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
637 free_pref_value(pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
638
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
639 g_slist_free(pref->callbacks);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
640 g_free(pref->name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
641 g_free(pref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
644 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
645 gaim_prefs_remove(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
646 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
647 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
648
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
649 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
650 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
651
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
652 remove_pref(pref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
655 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
656 gaim_prefs_destroy()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
657 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
658 gaim_prefs_remove("/");
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
661 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
662 do_callbacks(const char* name, struct gaim_pref *pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
663 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
664 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
665 struct gaim_pref *cb_pref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
666 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
667 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
668 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
669 cb->func(name, pref->type, pref->value.generic, cb->data);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
674 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
675 gaim_prefs_trigger_callback(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
676 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
677 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
678
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
679 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
680 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
681 "gaim_prefs_trigger_callback: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
682 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
685 do_callbacks(name, pref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
688 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
689 gaim_prefs_set_generic(const char *name, gpointer value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
690 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
691 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
692
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
693 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
694 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
695 "gaim_prefs_set_generic: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
696 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
699 pref->value.generic = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
700 do_callbacks(name, pref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
703 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
704 gaim_prefs_set_bool(const char *name, gboolean value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
705 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
706 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
707
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
708 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
709 if(pref->type != GAIM_PREF_BOOLEAN) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
710 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
711 "gaim_prefs_set_bool: %s not a boolean pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
712 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
715 if(pref->value.boolean != value) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
716 pref->value.boolean = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
717 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
718 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
719 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
720 gaim_prefs_add_bool(name, value);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
724 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
725 gaim_prefs_set_int(const char *name, int value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
726 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
727 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
728
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
729 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
730 if(pref->type != GAIM_PREF_INT) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
731 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
732 "gaim_prefs_set_int: %s not an integer pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
733 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
736 if(pref->value.integer != value) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
737 pref->value.integer = value;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
738 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
739 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
740 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
741 gaim_prefs_add_int(name, value);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
745 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
746 gaim_prefs_set_string(const char *name, const char *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
747 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
748 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
749
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
750 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
751 if(pref->type != GAIM_PREF_STRING) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
752 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
753 "gaim_prefs_set_string: %s not a string pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
754 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
757 if((value && !pref->value.string) ||
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
758 (!value && pref->value.string) ||
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
759 strcmp(pref->value.string, value)) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
760 g_free(pref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
761 pref->value.string = g_strdup(value);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
762 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
763 }
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
764 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
765 gaim_prefs_add_string(name, value);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
769 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
770 gaim_prefs_set_string_list(const char *name, GList *value)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
771 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
772 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
773 if(pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
774 GList *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
775
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
776 if(pref->type != GAIM_PREF_STRING_LIST) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
777 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
778 "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
779 name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
780 return;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
783 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
784 g_free(tmp->data);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
785
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
786 g_list_free(pref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
787 pref->value.stringlist = NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
788
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
789 for(tmp = value; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
790 pref->value.stringlist = g_list_append(pref->value.stringlist,
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
791 g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
792
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
793 do_callbacks(name, pref);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
794
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
795 } else {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
796 gaim_prefs_add_string_list(name, value);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
800 gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
801 gaim_prefs_exists(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
802 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
803 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
804
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
805 if (pref != NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
806 return TRUE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
807
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
808 return FALSE;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
811 GaimPrefType
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
812 gaim_prefs_get_type(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
813 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
814 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
815
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
816 if (pref == NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
817 return GAIM_PREF_NONE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
818
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
819 return (pref->type);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
822 gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
823 gaim_prefs_get_bool(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
824 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
825 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
826
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
827 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
828 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
829 "gaim_prefs_get_bool: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
830 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
831 } else if(pref->type != GAIM_PREF_BOOLEAN) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
832 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
833 "gaim_prefs_get_bool: %s not a boolean pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
834 return FALSE;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
837 return pref->value.boolean;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
840 int
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
841 gaim_prefs_get_int(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
842 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
843 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
844
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
845 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
846 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
847 "gaim_prefs_get_int: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
848 return 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
849 } else if(pref->type != GAIM_PREF_INT) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
850 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
851 "gaim_prefs_get_int: %s not an integer pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
852 return 0;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
855 return pref->value.integer;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
858 const char *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
859 gaim_prefs_get_string(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
860 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
861 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
862
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
863 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
864 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
865 "gaim_prefs_get_string: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
866 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
867 } else if(pref->type != GAIM_PREF_STRING) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
868 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
869 "gaim_prefs_get_string: %s not a string pref\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
870 return NULL;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
873 return pref->value.string;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
876 GList *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
877 gaim_prefs_get_string_list(const char *name)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
878 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
879 struct gaim_pref *pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
880 GList *ret = NULL, *tmp;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
881
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
882 if(!pref) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
883 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
884 "gaim_prefs_get_string_list: Unknown pref %s\n", name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
885 return NULL;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
886 } else if(pref->type != GAIM_PREF_STRING_LIST) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
887 gaim_debug_error("prefs",
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
888 "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
889 return NULL;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
892 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
893 ret = g_list_append(ret, g_strdup(tmp->data));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
894
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
895 return ret;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
898 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
899 gaim_prefs_rename(const char *oldname, const char *newname)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
900 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
901 struct gaim_pref *oldpref, *newpref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
902
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
903 oldpref = find_pref(oldname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
904 newpref = find_pref(newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
905
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
906 /* it's already been renamed, call off the dogs */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
907 if(!oldpref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
908 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
909
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
910 gaim_debug_info("prefs", "Renaming %s to %s\n", oldname, newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
911
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
912 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
913 g_return_if_fail(oldpref->type == newpref->type);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
914 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
915
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
916 switch(oldpref->type) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
917 case GAIM_PREF_NONE:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
918 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
919 case GAIM_PREF_BOOLEAN:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
920 gaim_prefs_set_bool(newname, oldpref->value.boolean);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
921 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
922 case GAIM_PREF_INT:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
923 gaim_prefs_set_int(newname, oldpref->value.integer);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
924 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
925 case GAIM_PREF_STRING:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
926 gaim_prefs_set_string(newname, oldpref->value.string);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
927 break;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
928 case GAIM_PREF_STRING_LIST:
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
929 gaim_prefs_set_string_list(newname, oldpref->value.stringlist);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
930 break;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
933 remove_pref(oldpref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
936 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
937 gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
938 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
939 struct gaim_pref *oldpref, *newpref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
940
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
941 oldpref = find_pref(oldname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
942 newpref = find_pref(newname);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
943
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
944 /* it's already been renamed, call off the cats */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
945 if(!oldpref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
946 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
947
11736
a14d72b6ca41 [gaim-migrate @ 14027]
Mark Doliner <mark@kingant.net>
parents: 11719
diff changeset
948 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
949
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
950 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
951 g_return_if_fail(oldpref->type == newpref->type);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
952 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
953 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
954
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
955 gaim_prefs_set_bool(newname, !(oldpref->value.boolean));
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
956
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
957 remove_pref(oldpref);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
961 guint
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
962 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
963 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
964 struct gaim_pref *pref;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
965 struct pref_cb *cb;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
966 static guint cb_id = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
967
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
968 pref = find_pref(name);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
969 if (pref == NULL)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
970 return 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
971
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
972 cb = g_new0(struct pref_cb, 1);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
973
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
974 cb->func = func;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
975 cb->data = data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
976 cb->id = ++cb_id;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
977 cb->handle = handle;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
978
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
979 pref->callbacks = g_slist_append(pref->callbacks, cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
980
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
981 return cb->id;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
984 static gboolean
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
985 disco_callback_helper(struct gaim_pref *pref, guint callback_id)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
986 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
987 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
988 struct gaim_pref *child;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
989
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
990 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
991 return FALSE;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
992
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
993 for(cbs = pref->callbacks; cbs; cbs = cbs->next) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
994 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
995 if(cb->id == callback_id) {
11719
109ee3bfeac5 [gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
996 pref->callbacks = g_slist_delete_link(pref->callbacks, cbs);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
997 g_free(cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
998 return TRUE;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1002 for(child = pref->first_child; child; child = child->sibling) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1003 if(disco_callback_helper(child, callback_id))
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1004 return TRUE;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1007 return FALSE;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1010 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1011 gaim_prefs_disconnect_callback(guint callback_id)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1012 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1013 disco_callback_helper(&prefs, callback_id);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1016 static void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1017 disco_callback_helper_handle(struct gaim_pref *pref, void *handle)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1018 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1019 GSList *cbs;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1020 struct gaim_pref *child;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1021
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1022 if(!pref)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1023 return;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1024
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1025 cbs = pref->callbacks;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1026 while (cbs != NULL) {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1027 struct pref_cb *cb = cbs->data;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1028 if(cb->handle == handle) {
11719
109ee3bfeac5 [gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
1029 pref->callbacks = g_slist_delete_link(pref->callbacks, cbs);
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1030 g_free(cb);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1031 cbs = pref->callbacks;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1032 } else
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1033 cbs = cbs->next;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1036 for(child = pref->first_child; child; child = child->sibling)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1037 disco_callback_helper_handle(child, handle);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1040 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1041 gaim_prefs_disconnect_by_handle(void *handle)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1042 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1043 g_return_if_fail(handle != NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1044
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1045 disco_callback_helper_handle(&prefs, handle);
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1048 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1049 gaim_prefs_update_old()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1050 {
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1051 /* Remove some no-longer-used prefs */
9594
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1052 gaim_prefs_remove("/core/away/auto_response/enabled");
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1053 gaim_prefs_remove("/core/away/auto_response/idle_only");
8948
175cbf710a47 [gaim-migrate @ 9720]
Mark Doliner <mark@kingant.net>
parents: 8942
diff changeset
1054 gaim_prefs_remove("/core/away/auto_response/in_active_conv");
175cbf710a47 [gaim-migrate @ 9720]
Mark Doliner <mark@kingant.net>
parents: 8942
diff changeset
1055 gaim_prefs_remove("/core/away/auto_response/sec_before_resend");
9594
15d09e546cee [gaim-migrate @ 10437]
Mark Doliner <mark@kingant.net>
parents: 9251
diff changeset
1056 gaim_prefs_remove("/core/away/auto_response");
11654
bf6ba37db13b [gaim-migrate @ 13938]
Mark Doliner <mark@kingant.net>
parents: 11256
diff changeset
1057 gaim_prefs_remove("/core/away/default_message");
10353
fc7168f9ecb0 [gaim-migrate @ 11570]
Mark Doliner <mark@kingant.net>
parents: 10349
diff changeset
1058 gaim_prefs_remove("/core/buddies/use_server_alias");
8942
06f47021ddd3 [gaim-migrate @ 9712]
Mark Doliner <mark@kingant.net>
parents: 8905
diff changeset
1059 gaim_prefs_remove("/core/conversations/away_back_on_send");
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1060 gaim_prefs_remove("/core/conversations/send_urls_as_links");
8942
06f47021ddd3 [gaim-migrate @ 9712]
Mark Doliner <mark@kingant.net>
parents: 8905
diff changeset
1061 gaim_prefs_remove("/core/conversations/im/show_login");
8998
3738d1eac0ad [gaim-migrate @ 9773]
Luke Schierer <lschiere@pidgin.im>
parents: 8948
diff changeset
1062 gaim_prefs_remove("/core/conversations/chat/show_join");
3738d1eac0ad [gaim-migrate @ 9773]
Luke Schierer <lschiere@pidgin.im>
parents: 8948
diff changeset
1063 gaim_prefs_remove("/core/conversations/chat/show_leave");
9251
45d2ad4ac1c1 [gaim-migrate @ 10050]
Ethan Blanton <elb@pidgin.im>
parents: 9156
diff changeset
1064 gaim_prefs_remove("/core/conversations/combine_chat_im");
10389
c432b927b0b1 [gaim-migrate @ 11616]
Sean Egan <seanegan@gmail.com>
parents: 10387
diff changeset
1065 gaim_prefs_remove("/core/conversations/use_alias_for_title");
11698
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1066 gaim_prefs_remove("/core/logging/log_signon_signoff");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1067 gaim_prefs_remove("/core/logging/log_idle_state");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1068 gaim_prefs_remove("/core/logging/log_away_state");
a647f92e1d57 [gaim-migrate @ 13989]
Mark Doliner <mark@kingant.net>
parents: 11654
diff changeset
1069 gaim_prefs_remove("/core/logging/log_own_states");
11959
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1070 gaim_prefs_remove("/plugins/core/autorecon/hide_connected_error");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1071 gaim_prefs_remove("/plugins/core/autorecon/hide_connecting_error");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1072 gaim_prefs_remove("/plugins/core/autorecon/hide_reconnecting_dialog");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1073 gaim_prefs_remove("/plugins/core/autorecon/restore_state");
6f8869d95c09 [gaim-migrate @ 14250]
Mark Doliner <mark@kingant.net>
parents: 11736
diff changeset
1074 gaim_prefs_remove("/plugins/core/autorecon");
8900
7a67c459ab8f [gaim-migrate @ 9669]
Mark Doliner <mark@kingant.net>
parents: 8705
diff changeset
1075 }
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1076
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1077 void *
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1078 gaim_prefs_get_handle(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1079 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1080 static int handle;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1081
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1082 return &handle;
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1085 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1086 gaim_prefs_init(void)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1087 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1088 void *handle = gaim_prefs_get_handle();
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1089
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1090 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
1091
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1092 gaim_prefs_connect_callback(handle, "/", prefs_save_cb, NULL);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1093
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1094 gaim_prefs_add_none("/core");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1095 gaim_prefs_add_none("/plugins");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1096 gaim_prefs_add_none("/plugins/core");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1097 gaim_prefs_add_none("/plugins/lopl");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1098 gaim_prefs_add_none("/plugins/prpl");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1099
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1100 /* Away */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1101 gaim_prefs_add_none("/core/away");
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12272
diff changeset
1102 gaim_prefs_add_string("/core/away/idle_reporting", "system");
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1103 gaim_prefs_add_bool("/core/away/away_when_idle", TRUE);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1104 gaim_prefs_add_int("/core/away/mins_before_away", 5);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1105
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1106 /* Away -> Auto-Reply */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1107 if (!gaim_prefs_exists("/core/away/auto_response/enabled") ||
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1108 !gaim_prefs_exists("/core/away/auto_response/idle_only"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1109 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1110 gaim_prefs_add_string("/core/away/auto_reply", "awayidle");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1111 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1112 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1113 {
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1114 if (!gaim_prefs_get_bool("/core/away/auto_response/enabled"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1115 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1116 gaim_prefs_add_string("/core/away/auto_reply", "never");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1117 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1118 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1119 {
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1120 if (gaim_prefs_get_bool("/core/away/auto_response/idle_only"))
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1121 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1122 gaim_prefs_add_string("/core/away/auto_reply", "awayidle");
12615
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1123 }
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1124 else
e3ca84a8b551 [gaim-migrate @ 14951]
Richard Laager <rlaager@wiktel.com>
parents: 12599
diff changeset
1125 {
10443
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1126 gaim_prefs_add_string("/core/away/auto_reply", "away");
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1131 /* Buddies */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1132 gaim_prefs_add_none("/core/buddies");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1133
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1134 /* Contact Priority Settings */
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1135 gaim_prefs_add_none("/core/contact");
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1136 gaim_prefs_add_bool("/core/contact/last_match", FALSE);
12164
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1137 gaim_prefs_remove("/core/contact/offline_score");
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1138 gaim_prefs_remove("/core/contact/away_score");
281ab2ecc08c [gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents: 11959
diff changeset
1139 gaim_prefs_remove("/core/contact/idle_score");
10443
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1142 void
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1143 gaim_prefs_uninit()
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1144 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1145 if (save_timer != 0)
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1146 {
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1147 gaim_timeout_remove(save_timer);
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1148 save_timer = 0;
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1149 sync_prefs();
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
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1152 gaim_prefs_disconnect_by_handle(gaim_prefs_get_handle());
b6ca0e1b19d0 [gaim-migrate @ 11703]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
1153 }