annotate src/prefs.c @ 5496:b7c0be69c749

[gaim-migrate @ 5892] do_ask_dialog() will soon go the way of the something that goes away a lot. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 23 May 2003 00:48:20 +0000
parents 156e65ca910f
children e7747cae9710
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 *
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * 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
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 340
diff changeset
22 #ifdef HAVE_CONFIG_H
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2074
diff changeset
23 #include <config.h>
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 340
diff changeset
24 #endif
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
25
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #include <string.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <stdio.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <stdlib.h>
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
29 #include <sys/stat.h>
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
30 #include <sys/types.h>
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
31 #include <glib.h>
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
32 #include "prefs.h"
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
33 #include "debug.h"
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
34 #include "util.h"
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
35
4026
a997156437b6 [gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4010
diff changeset
36 #ifdef _WIN32
a997156437b6 [gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4010
diff changeset
37 #include "win32dep.h"
a997156437b6 [gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4010
diff changeset
38 #endif
a997156437b6 [gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4010
diff changeset
39
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
40 struct pref_cb {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
41 GaimPrefCallback func;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
42 gpointer data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
43 guint id;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
44 };
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
45
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
46 struct gaim_pref {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
47 GaimPrefType type;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
48 char *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
49 union {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
50 gpointer generic;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
51 gboolean boolean;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
52 int integer;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
53 char *string;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
54 } value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
55 GSList *callbacks;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
56 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
57 struct gaim_pref *sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
58 struct gaim_pref *first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
59 };
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
60
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
61 static GHashTable *prefs_hash = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
62
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
63 static struct gaim_pref prefs = { GAIM_PREF_NONE, NULL, {NULL}, NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
64 NULL, NULL, NULL };
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
65
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
66 void gaim_prefs_init() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
67 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
68
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
69 /* XXX: this is where you would want to put prefs declarations */
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
70 }
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
71
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
72 static char *pref_full_name(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
73 GString *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
74 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
75 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
76 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
77
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
78 if(pref == &prefs)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
79 return g_strdup("/");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
80
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
81 name = g_string_new(pref->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
82 parent = pref->parent;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
83
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
84 for(parent = pref->parent; parent && parent->name; parent = parent->parent) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
85 name = g_string_prepend_c(name, '/');
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
86 name = g_string_prepend(name, parent->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
87 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
88 g_string_free(name, FALSE);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
89 return name->str;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
90 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
91
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
92 static struct gaim_pref *find_pref(const char *name)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
93 {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
94 if(!name || name[0] != '/') {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
95 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
96 } else if(name[1] == '\0') {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
97 return &prefs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
98 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
99 return g_hash_table_lookup(prefs_hash, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
100 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
101 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
102
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
103 static struct gaim_pref *find_pref_parent(const char *name)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
104 {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
105 char *parent_name = g_path_get_dirname(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
106 struct gaim_pref *ret = &prefs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
107
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
108 if(strcmp(parent_name, "/")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
109 ret = find_pref(parent_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
110 }
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1006
diff changeset
111
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
112 g_free(parent_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
113 return ret;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
114 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
115
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
116 static void free_pref_value(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
117 switch(pref->type) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
118 case GAIM_PREF_BOOLEAN:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
119 pref->value.boolean = FALSE;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
120 case GAIM_PREF_INT:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
121 pref->value.integer = 0;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
122 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
123 case GAIM_PREF_STRING:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
124 g_free(pref->value.string);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
125 pref->value.string = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
126 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
127 case GAIM_PREF_NONE:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
128 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
129 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
130 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
131
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
132 static struct gaim_pref *add_pref(GaimPrefType type, const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
133 struct gaim_pref *parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
134 struct gaim_pref *me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
135 struct gaim_pref *sibling;
5458
156e65ca910f [gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents: 5451
diff changeset
136 char *my_name;
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
137
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
138 parent = find_pref_parent(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
139
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
140 if(!parent)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
141 return NULL;
1525
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
142
5458
156e65ca910f [gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents: 5451
diff changeset
143 my_name = g_path_get_basename(name);
156e65ca910f [gaim-migrate @ 5846]
Christian Hammond <chipx86@chipx86.com>
parents: 5451
diff changeset
144
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
145 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
146 if(!strcmp(sibling->name, my_name)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
147 g_free(my_name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
148 return NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
149 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
150 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
151
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
152 me = g_new0(struct gaim_pref, 1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
153 me->type = type;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
154 me->name = my_name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
155
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
156 me->parent = parent;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
157 if(parent->first_child) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
158 /* blatant abuse of a for loop */
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
159 for(sibling = parent->first_child; sibling->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
160 sibling = sibling->sibling);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
161 sibling->sibling = me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
162 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
163 parent->first_child = me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
164 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
165
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
166 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
167
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
168 return me;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
169 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
170
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
171 void gaim_prefs_add_none(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
172 add_pref(GAIM_PREF_NONE, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
173 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
174
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
175 void gaim_prefs_add_bool(const char *name, gboolean value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
176 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
177
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
178 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
179 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
180
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
181 pref->value.boolean = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
182 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3567
diff changeset
183
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
184 void gaim_prefs_add_int(const char *name, int value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
185 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
186
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
187 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
188 return;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
189
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
190 pref->value.integer = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
191 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
192
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
193 void gaim_prefs_add_string(const char *name, const char *value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
194 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
195
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
196 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
197 return;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
198
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
199 pref->value.string = g_strdup(value);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
200 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
201
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
202 void remove_pref(struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
203 char *name;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
204
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
205 if(!pref || pref == &prefs)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
206 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
207
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
208 if(pref->parent->first_child == pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
209 pref->parent->first_child = pref->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
210 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
211 struct gaim_pref *sib = pref->parent->first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
212 while(sib->sibling != pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
213 sib = sib->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
214 sib->sibling = pref->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
215 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
216
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
217 name = pref_full_name(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
218
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
219 g_hash_table_remove(prefs_hash, name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
220 g_free(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
221
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
222 free_pref_value(pref);
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
223
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
224 g_slist_free(pref->callbacks);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
225 g_free(pref->name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
226 g_free(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
227 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
228
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
229 void gaim_prefs_remove(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
230 struct gaim_pref *pref = find_pref(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
231 struct gaim_pref *child, *child2;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
232
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
233 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
234 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
235 child = pref->first_child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
236 while(child) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
237 child2 = child;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
238 child = child->sibling;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
239 remove_pref(child2);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
240 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
241
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
242 remove_pref(pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
243 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
244
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
245 void gaim_prefs_destroy() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
246 gaim_prefs_remove("/");
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
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
249 static void do_callbacks(const char* name, struct gaim_pref *pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
250 GSList *cbs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
251 struct gaim_pref *cb_pref;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
252 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
253 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
254 struct pref_cb *cb = cbs->data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
255 cb->func(name, pref->type, pref->value.generic, cb->data);
4215
e9e55f0a991c [gaim-migrate @ 4454]
Luke Schierer <lschiere@pidgin.im>
parents: 4201
diff changeset
256 }
e9e55f0a991c [gaim-migrate @ 4454]
Luke Schierer <lschiere@pidgin.im>
parents: 4201
diff changeset
257 }
1525
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
258 }
ba8e6e211af5 [gaim-migrate @ 1535]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1455
diff changeset
259
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
260 void gaim_prefs_set_generic(const char *name, gpointer value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
261 struct gaim_pref *pref = find_pref(name);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
262
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
263 g_return_if_fail(pref != NULL);
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
264
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
265 pref->value.generic = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
266 do_callbacks(name, pref);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
267 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
268
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
269 void gaim_prefs_set_bool(const char *name, gboolean value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
270 struct gaim_pref *pref = find_pref(name);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
271
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
272 g_return_if_fail(pref != NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
273 g_return_if_fail(pref->type == GAIM_PREF_BOOLEAN);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
274
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
275 if(pref->value.boolean != value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
276 pref->value.boolean = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
277 do_callbacks(name, pref);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
278 }
4324
561316116cd8 [gaim-migrate @ 4579]
Sean Egan <seanegan@gmail.com>
parents: 4323
diff changeset
279 }
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
280
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
281 void gaim_prefs_set_int(const char *name, int value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
282 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
283
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
284 g_return_if_fail(pref != NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
285 g_return_if_fail(pref->type == GAIM_PREF_INT);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
286
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
287 if(pref->value.integer != value) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
288 pref->value.integer = value;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
289 do_callbacks(name, pref);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
290 }
4326
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
291 }
eb63f9960d07 [gaim-migrate @ 4582]
Rob Flynn <gaim@robflynn.com>
parents: 4325
diff changeset
292
5451
e1cc0c67e123 [gaim-migrate @ 5839]
Nathan Walp <nwalp@pidgin.im>
parents: 5444
diff changeset
293 void gaim_prefs_set_string(const char *name, const char *value) {
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
294 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
295
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
296 g_return_if_fail(pref != NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
297 g_return_if_fail(pref->type == GAIM_PREF_STRING);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
298
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
299 if(strcmp(pref->value.string, value)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
300 g_free(pref->value.string);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
301 pref->value.string = g_strdup(value);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
302 do_callbacks(name, pref);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
303 }
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
304 }
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
305
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
306 gpointer gaim_prefs_get_generic(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
307 struct gaim_pref *pref = find_pref(name);
4325
7fd57453e6fc [gaim-migrate @ 4580]
Rob Flynn <gaim@robflynn.com>
parents: 4324
diff changeset
308
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
309 g_return_val_if_fail(pref != NULL, NULL);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
310
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
311 return pref->value.generic;
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
312 }
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4241
diff changeset
313
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
314 gboolean gaim_prefs_get_bool(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
315 struct gaim_pref *pref = find_pref(name);
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3404
diff changeset
316
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
317 g_return_val_if_fail(pref != NULL, FALSE);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
318 g_return_val_if_fail(pref->type == GAIM_PREF_BOOLEAN, FALSE);
3472
d33ec392a5e1 [gaim-migrate @ 3523]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
319
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
320 return pref->value.boolean;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
321 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
322
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
323 int gaim_prefs_get_int(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
324 struct gaim_pref *pref = find_pref(name);
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
325
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
326 g_return_val_if_fail(pref != NULL, 0);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
327 g_return_val_if_fail(pref->type == GAIM_PREF_INT, 0);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
328
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
329 return pref->value.integer;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
330 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
331
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
332 char *gaim_prefs_get_string(const char *name) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
333 struct gaim_pref *pref = find_pref(name);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
334
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
335 g_return_val_if_fail(pref != NULL, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
336 g_return_val_if_fail(pref->type == GAIM_PREF_STRING, NULL);
4469
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
337
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
338 return pref->value.string;
4469
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
339 }
d76095396a0e [gaim-migrate @ 4744]
Christian Hammond <chipx86@chipx86.com>
parents: 4461
diff changeset
340
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
341 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
342 {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
343 struct gaim_pref *pref = find_pref(name);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
344 struct pref_cb *cb;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
345 static guint cb_id = 0;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
346
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
347 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
348 return 0;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
349
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
350 cb = g_new0(struct pref_cb, 1);
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
351
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
352 cb->func = func;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
353 cb->data = data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
354 cb->id = ++cb_id;
4991
c54fc48e33b0 [gaim-migrate @ 5326]
Rob Flynn <gaim@robflynn.com>
parents: 4985
diff changeset
355
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
356 pref->callbacks = g_slist_append(pref->callbacks, cb);
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
357
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
358 return cb->id;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
359 }
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
360
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
361 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
362 GSList *cbs;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
363 struct gaim_pref *child;
2254
c0ac78ffe77f [gaim-migrate @ 2264]
Rob Flynn <gaim@robflynn.com>
parents: 2199
diff changeset
364
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
365 if(!pref)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
366 return FALSE;
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
367
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
368 for(cbs = pref->callbacks; cbs; cbs = cbs->next) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
369 struct pref_cb *cb = cbs->data;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
370 if(cb->id == callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
371 pref->callbacks = g_slist_remove(pref->callbacks, cb);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
372 g_free(cb);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
373 return TRUE;
4428
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
374 }
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
375 }
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
376
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
377 for(child = pref->first_child; child; child = child->sibling) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
378 if(disco_callback_helper(child, callback_id))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
379 return TRUE;
4428
b5669740e34c [gaim-migrate @ 4703]
Sean Egan <seanegan@gmail.com>
parents: 4421
diff changeset
380 }
4451
ce5b64fac95d [gaim-migrate @ 4726]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4449
diff changeset
381
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
382 return FALSE;
1757
3dfe4aefd366 [gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1755
diff changeset
383 }
3dfe4aefd366 [gaim-migrate @ 1767]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1755
diff changeset
384
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
385 void gaim_prefs_disconnect_callback(guint callback_id) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
386 disco_callback_helper(&prefs, callback_id);
2262
9c8f353331e7 [gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2254
diff changeset
387 }
9c8f353331e7 [gaim-migrate @ 2272]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2254
diff changeset
388
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
389 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
390 struct gaim_pref *tmp;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
391 char *esc;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
392 int i;
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
393
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
394 if(!pref) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
395 pref = &prefs;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
396
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
397 fprintf(f, "<?xml version='1.0' encoding='UTF-8' ?>\n");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
398 fprintf(f, "<pref name='/'");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
399 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
400 for(i=0; i<depth; i++)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
401 fprintf(f, "\t");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
402 esc = g_markup_escape_text(pref->name, -1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
403 fprintf(f, "<pref name='%s'", esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
404 g_free(esc);
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
405 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
406
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
407 switch(pref->type) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
408 case GAIM_PREF_NONE:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
409 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
410 case GAIM_PREF_BOOLEAN:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
411 fprintf(f, " type='bool' value='%d'", pref->value.boolean);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
412 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
413 case GAIM_PREF_INT:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
414 fprintf(f, " type='int' value='%d'", pref->value.integer);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
415 break;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
416 case GAIM_PREF_STRING:
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
417 esc = g_markup_escape_text(pref->value.string, -1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
418 fprintf(f, " type='string' value='%s'", esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
419 g_free(esc);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
420 break;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
421 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
422
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
423 if(pref->first_child) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
424 fprintf(f, ">\n");
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
425
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
426 for(tmp = pref->first_child; tmp; tmp = tmp->sibling)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
427 gaim_prefs_write(f, tmp, depth+1);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
428 for(i=0; i<depth; i++)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
429 fprintf(f, "\t");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
430 fprintf(f, "</pref>\n");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
431 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
432 fprintf(f, " />\n");
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
433 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
434 }
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
435
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
436 void gaim_prefs_save() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
437 /* FIXME: do this with timers so we don't save so damn often */
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
438 gaim_prefs_sync();
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
439 }
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 5105
diff changeset
440
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
441 void gaim_prefs_sync() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
442 FILE *file;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
443 const char *user_dir = gaim_user_dir();
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
444 char *filename;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
445 char *filename_real;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
446
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
447 if(!user_dir)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
448 return;
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
449
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
450 file = fopen(user_dir, "r");
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
451 if(!file)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
452 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
453 else
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
454 fclose(file);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
455
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
456 filename = g_build_filename(user_dir, "prefs.xml.save", NULL);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
457
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
458 if((file = fopen(filename, "w"))) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
459 gaim_prefs_write(file, NULL, 0);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
460 fclose(file);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
461 chmod(filename, S_IRUSR | S_IWUSR);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
462 } else {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
463 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Unable to write %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
464 filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
465 }
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
466
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
467 filename_real = g_build_filename(user_dir, "prefs.xml", NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
468 if(rename(filename, filename_real) < 0)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
469 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error renaming %s to %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
470 filename, filename_real);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
471
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
472 g_free(filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
473 g_free(filename_real);
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
474 }
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3526
diff changeset
475
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
476 static GList *prefs_stack = NULL;
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
477
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
478 static void prefs_start_element_handler (GMarkupParseContext *context,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
479 const gchar *element_name,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
480 const gchar **attribute_names,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
481 const gchar **attribute_values,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
482 gpointer user_data,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
483 GError **error) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
484 GaimPrefType pref_type = GAIM_PREF_NONE;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
485 int i;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
486 const char *pref_name = NULL, *pref_value = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
487 GString *pref_name_full;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
488 GList *tmp;
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
489
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
490 if(strcmp(element_name, "pref"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
491 return;
3500
b79894c97bed [gaim-migrate @ 3563]
Luke Schierer <lschiere@pidgin.im>
parents: 3485
diff changeset
492
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
493 for(i = 0; attribute_names[i]; i++) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
494 if(!strcmp(attribute_names[i], "name")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
495 pref_name = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
496 } else if(!strcmp(attribute_names[i], "type")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
497 if(!strcmp(attribute_values[i], "bool"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
498 pref_type = GAIM_PREF_BOOLEAN;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
499 else if(!strcmp(attribute_values[i], "int"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
500 pref_type = GAIM_PREF_INT;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
501 else if(!strcmp(attribute_values[i], "string"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
502 pref_type = GAIM_PREF_STRING;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
503 else
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
504 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
505 } else if(!strcmp(attribute_names[i], "value")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
506 pref_value = attribute_values[i];
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
507 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
508 }
873
789df4b47508 [gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 864
diff changeset
509
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
510 if(!pref_name || !strcmp(pref_name, "/"))
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
511 return;
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
512
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
513 pref_name_full = g_string_new(pref_name);
652
4d3285caa191 [gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 619
diff changeset
514
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
515 for(tmp = prefs_stack; tmp; tmp = tmp->prev) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
516 pref_name_full = g_string_prepend_c(pref_name_full, '/');
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
517 pref_name_full = g_string_prepend(pref_name_full, tmp->data);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
518 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
519
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
520 pref_name_full = g_string_prepend_c(pref_name_full, '/');
1253
8342d3aab1f1 [gaim-migrate @ 1263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
521
5444
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
522 if(find_pref(pref_name_full->str)) {
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
523 switch(pref_type) {
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
524 case GAIM_PREF_NONE:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
525 gaim_prefs_add_none(pref_name_full->str);
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
526 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
527 case GAIM_PREF_BOOLEAN:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
528 gaim_prefs_add_bool(pref_name_full->str, atoi(pref_value));
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
529 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
530 case GAIM_PREF_INT:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
531 gaim_prefs_add_int(pref_name_full->str, atoi(pref_value));
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
532 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
533 case GAIM_PREF_STRING:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
534 gaim_prefs_add_string(pref_name_full->str, pref_value);
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
535 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
536 }
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
537 } else {
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
538 switch(pref_type) {
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
539 case GAIM_PREF_NONE:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
540 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
541 case GAIM_PREF_BOOLEAN:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
542 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value));
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
543 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
544 case GAIM_PREF_INT:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
545 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value));
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
546 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
547 case GAIM_PREF_STRING:
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
548 gaim_prefs_set_string(pref_name_full->str, pref_value);
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
549 break;
dec7e222a68b [gaim-migrate @ 5826]
Nathan Walp <nwalp@pidgin.im>
parents: 5440
diff changeset
550 }
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
551 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
552
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
553 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name));
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
554 g_string_free(pref_name_full, TRUE);
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
555 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
556
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
557 static void prefs_end_element_handler(GMarkupParseContext *context,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
558 const gchar *element_name, gpointer user_data, GError **error) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
559 if(!strcmp(element_name, "pref")) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
560 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
561 }
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
562 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
563
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
564 static GMarkupParser prefs_parser = {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
565 prefs_start_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
566 prefs_end_element_handler,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
567 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
568 NULL,
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
569 NULL
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
570 };
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
571
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
572 void gaim_prefs_load() {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
573 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
574 gchar *contents = NULL;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
575 gsize length;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
576 GMarkupParseContext *context;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
577 GError *error = NULL;
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
578
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
579 if(!filename)
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
580 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
581
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
582 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Reading %s\n", filename);
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5297
diff changeset
583
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
584 if(!g_file_get_contents(filename, &contents, &length, &error)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
585 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error reading prefs: %s\n",
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
586 error->message);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
587 g_error_free(error);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
588 return;
1170
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
589 }
16d748023b2b [gaim-migrate @ 1180]
Rob Flynn <gaim@robflynn.com>
parents: 1147
diff changeset
590
5440
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
591 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
592
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
593 if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
594 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
595 g_free(contents);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
596 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
597 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
598
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
599 if(!g_markup_parse_context_end_parse(context, NULL)) {
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
600 gaim_debug(GAIM_DEBUG_ERROR, "prefs", "Error parsing %s\n", filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
601 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
602 g_free(contents);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
603 return;
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
604 }
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
605
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
606 g_markup_parse_context_free(context);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
607 g_free(contents);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
608
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
609 gaim_debug(GAIM_DEBUG_INFO, "prefs", "Finished reading %s\n", filename);
7e8524b5ff98 [gaim-migrate @ 5822]
Nathan Walp <nwalp@pidgin.im>
parents: 5436
diff changeset
610 g_free(filename);
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
611 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1002
diff changeset
612
3366
120e08ea5aee [gaim-migrate @ 3385]
Sean Egan <seanegan@gmail.com>
parents: 3326
diff changeset
613