Mercurial > pidgin
annotate src/prefs.c @ 12986:4e9935a539db
[gaim-migrate @ 15339]
We need to figure this out so that things don't break again. The new plugin
dependency unload code assumed that all plugins would have ids set, this was
true for most plugins, but both the perl and tcl loaders didn't set id for
perl and tcl plugins. And I didn't see any code in my quick looking which
actually verified (m)any parts of the struct.
committer: Tailor Script <tailor@pidgin.im>
| author | Etan Reisner <pidgin@unreliablesource.net> |
|---|---|
| date | Sun, 22 Jan 2006 07:09:06 +0000 |
| parents | cecc9706c11f |
| children | b705e30efe61 |
| rev | line source |
|---|---|
| 1 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 1 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 | |
|
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
|
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2074
diff
changeset
|
25 #include <config.h> |
|
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
26 #endif |
| 5440 | 27 |
| 1 | 28 #include <string.h> |
| 29 #include <stdio.h> | |
| 30 #include <stdlib.h> | |
| 5440 | 31 #include <sys/stat.h> |
| 32 #include <sys/types.h> | |
| 33 #include <glib.h> | |
| 6216 | 34 #include "internal.h" |
| 5440 | 35 #include "prefs.h" |
| 36 #include "debug.h" | |
| 37 #include "util.h" | |
| 3366 | 38 |
|
4026
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
39 #ifdef _WIN32 |
|
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
40 #include "win32dep.h" |
|
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
41 #endif |
|
a997156437b6
[gaim-migrate @ 4230]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4010
diff
changeset
|
42 |
| 5440 | 43 struct pref_cb { |
| 44 GaimPrefCallback func; | |
| 45 gpointer data; | |
| 46 guint id; | |
| 10087 | 47 void *handle; |
| 5440 | 48 }; |
| 49 | |
| 10443 | 50 /* TODO: This should use GaimValues? */ |
| 5440 | 51 struct gaim_pref { |
| 52 GaimPrefType type; | |
| 53 char *name; | |
| 54 union { | |
| 55 gpointer generic; | |
| 56 gboolean boolean; | |
| 57 int integer; | |
| 58 char *string; | |
| 5561 | 59 GList *stringlist; |
| 5440 | 60 } value; |
| 61 GSList *callbacks; | |
| 62 struct gaim_pref *parent; | |
| 63 struct gaim_pref *sibling; | |
| 64 struct gaim_pref *first_child; | |
| 65 }; | |
| 3366 | 66 |
| 5440 | 67 |
| 10443 | 68 static struct gaim_pref prefs = { |
| 69 GAIM_PREF_NONE, | |
| 70 NULL, | |
| 71 { NULL }, | |
| 72 NULL, | |
| 73 NULL, | |
| 74 NULL, | |
| 75 NULL | |
| 76 }; | |
| 5440 | 77 |
| 10443 | 78 static GHashTable *prefs_hash = NULL; |
| 79 static guint save_timer = 0; | |
| 80 static gboolean prefs_loaded = FALSE; | |
| 5534 | 81 |
| 82 | |
| 10443 | 83 /********************************************************************* |
| 84 * Private utility functions * | |
| 85 *********************************************************************/ | |
| 8235 | 86 |
| 10443 | 87 static struct |
| 88 gaim_pref *find_pref(const char *name) | |
|
5787
2adc29c88a45
[gaim-migrate @ 6212]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
89 { |
| 10443 | 90 if (!name || name[0] != '/') |
| 5440 | 91 return NULL; |
| 10443 | 92 else if (name[1] == '\0') |
| 5440 | 93 return &prefs; |
| 10443 | 94 else |
| 5440 | 95 return g_hash_table_lookup(prefs_hash, name); |
| 96 } | |
| 97 | |
| 10443 | 98 |
| 99 /********************************************************************* | |
| 100 * Writing to disk * | |
| 101 *********************************************************************/ | |
| 102 | |
| 103 /* | |
| 104 * This function recursively creates the xmlnode tree from the prefs | |
| 105 * tree structure. Yay recursion! | |
| 106 */ | |
| 10850 | 107 static void |
| 10443 | 108 pref_to_xmlnode(xmlnode *parent, struct gaim_pref *pref) |
| 109 { | |
| 110 xmlnode *node, *childnode; | |
| 111 struct gaim_pref *child; | |
| 112 char buf[20]; | |
| 113 GList *cur; | |
| 5561 | 114 |
| 10443 | 115 /* Create a new node */ |
| 116 node = xmlnode_new_child(parent, "pref"); | |
| 117 xmlnode_set_attrib(node, "name", pref->name); | |
| 5440 | 118 |
| 10443 | 119 /* Set the type of this node (if type == GAIM_PREF_NONE then do nothing) */ |
| 120 if (pref->type == GAIM_PREF_INT) { | |
| 121 xmlnode_set_attrib(node, "type", "int"); | |
| 122 snprintf(buf, sizeof(buf), "%d", pref->value.integer); | |
| 123 xmlnode_set_attrib(node, "value", buf); | |
| 124 } | |
| 125 else if (pref->type == GAIM_PREF_STRING) { | |
| 126 xmlnode_set_attrib(node, "type", "string"); | |
| 127 xmlnode_set_attrib(node, "value", pref->value.string); | |
| 128 } | |
| 129 else if (pref->type == GAIM_PREF_STRING_LIST) { | |
| 130 xmlnode_set_attrib(node, "type", "stringlist"); | |
| 131 for (cur = pref->value.stringlist; cur != NULL; cur = cur->next) | |
| 132 { | |
| 133 childnode = xmlnode_new_child(node, "item"); | |
| 134 xmlnode_set_attrib(childnode, "value", cur->data); | |
| 5440 | 135 } |
| 136 } | |
| 10443 | 137 else if (pref->type == GAIM_PREF_BOOLEAN) { |
| 138 xmlnode_set_attrib(node, "type", "bool"); | |
| 139 snprintf(buf, sizeof(buf), "%d", pref->value.boolean); | |
| 140 xmlnode_set_attrib(node, "value", buf); | |
| 5440 | 141 } |
| 142 | |
| 10443 | 143 /* All My Children */ |
| 144 for (child = pref->first_child; child != NULL; child = child->sibling) | |
| 145 pref_to_xmlnode(node, child); | |
| 5440 | 146 } |
| 147 | |
| 10443 | 148 static xmlnode * |
| 149 prefs_to_xmlnode(void) | |
| 150 { | |
| 151 xmlnode *node; | |
| 152 struct gaim_pref *pref, *child; | |
| 5440 | 153 |
| 10443 | 154 pref = &prefs; |
| 5440 | 155 |
| 10443 | 156 /* Create the root preference node */ |
| 157 node = xmlnode_new("pref"); | |
| 158 xmlnode_set_attrib(node, "version", "1"); | |
| 159 xmlnode_set_attrib(node, "name", "/"); | |
| 5561 | 160 |
| 10443 | 161 /* All My Children */ |
| 162 for (child = pref->first_child; child != NULL; child = child->sibling) | |
| 163 pref_to_xmlnode(node, child); | |
| 5561 | 164 |
| 10443 | 165 return node; |
| 5561 | 166 } |
| 167 | |
| 10443 | 168 static void |
| 169 sync_prefs(void) | |
| 170 { | |
| 171 xmlnode *node; | |
| 172 char *data; | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5105
diff
changeset
|
173 |
| 10443 | 174 if (!prefs_loaded) |
| 175 { | |
| 176 /* | |
| 177 * TODO: Call schedule_prefs_save()? Ideally we wouldn't need to. | |
| 178 * (prefs.xml should be loaded when gaim_prefs_init is called) | |
| 179 */ | |
| 180 gaim_debug_error("prefs", "Attempted to save prefs before " | |
| 181 "they were read!\n"); | |
| 5814 | 182 return; |
| 183 } | |
| 3500 | 184 |
| 10443 | 185 node = prefs_to_xmlnode(); |
| 186 data = xmlnode_to_formatted_str(node, NULL); | |
| 187 gaim_util_write_data_to_file("prefs.xml", data, -1); | |
| 188 g_free(data); | |
| 189 xmlnode_free(node); | |
| 4326 | 190 } |
| 191 | |
| 10443 | 192 static gboolean |
| 193 save_cb(gpointer data) | |
| 194 { | |
| 195 sync_prefs(); | |
| 196 save_timer = 0; | |
| 9594 | 197 return FALSE; |
| 4288 | 198 } |
| 199 | |
| 10443 | 200 static void |
| 201 schedule_prefs_save(void) | |
| 5440 | 202 { |
| 10443 | 203 if (save_timer == 0) |
| 204 save_timer = gaim_timeout_add(5000, save_cb, NULL); | |
| 3366 | 205 } |
| 206 | |
| 2254 | 207 |
| 10443 | 208 /********************************************************************* |
| 209 * Reading from disk * | |
| 210 *********************************************************************/ | |
| 3551 | 211 |
| 5440 | 212 static GList *prefs_stack = NULL; |
|
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
213 |
| 10443 | 214 static void |
| 215 prefs_start_element_handler (GMarkupParseContext *context, | |
| 5440 | 216 const gchar *element_name, |
| 217 const gchar **attribute_names, | |
| 218 const gchar **attribute_values, | |
| 219 gpointer user_data, | |
| 10443 | 220 GError **error) |
| 221 { | |
| 5440 | 222 GaimPrefType pref_type = GAIM_PREF_NONE; |
| 223 int i; | |
| 224 const char *pref_name = NULL, *pref_value = NULL; | |
| 225 GString *pref_name_full; | |
| 226 GList *tmp; | |
| 3366 | 227 |
| 5561 | 228 if(strcmp(element_name, "pref") && strcmp(element_name, "item")) |
| 5440 | 229 return; |
| 3500 | 230 |
| 5440 | 231 for(i = 0; attribute_names[i]; i++) { |
| 232 if(!strcmp(attribute_names[i], "name")) { | |
| 233 pref_name = attribute_values[i]; | |
| 234 } else if(!strcmp(attribute_names[i], "type")) { | |
| 235 if(!strcmp(attribute_values[i], "bool")) | |
| 236 pref_type = GAIM_PREF_BOOLEAN; | |
| 237 else if(!strcmp(attribute_values[i], "int")) | |
| 238 pref_type = GAIM_PREF_INT; | |
| 239 else if(!strcmp(attribute_values[i], "string")) | |
| 240 pref_type = GAIM_PREF_STRING; | |
| 5561 | 241 else if(!strcmp(attribute_values[i], "stringlist")) |
| 242 pref_type = GAIM_PREF_STRING_LIST; | |
| 5440 | 243 else |
| 244 return; | |
| 245 } else if(!strcmp(attribute_names[i], "value")) { | |
| 246 pref_value = attribute_values[i]; | |
| 247 } | |
| 248 } | |
|
873
789df4b47508
[gaim-migrate @ 883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
864
diff
changeset
|
249 |
| 5561 | 250 if(!strcmp(element_name, "item")) { |
| 5838 | 251 struct gaim_pref *pref; |
| 252 | |
| 253 pref_name_full = g_string_new(""); | |
| 254 | |
| 255 for(tmp = prefs_stack; tmp; tmp = tmp->next) { | |
| 256 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
| 257 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
| 258 } | |
| 259 | |
| 260 pref = find_pref(pref_name_full->str); | |
| 261 | |
| 5561 | 262 if(pref) { |
| 263 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
| 264 g_strdup(pref_value)); | |
| 265 } | |
| 5838 | 266 } else { |
| 267 if(!pref_name || !strcmp(pref_name, "/")) | |
| 268 return; | |
|
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
619
diff
changeset
|
269 |
| 5838 | 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 | 272 for(tmp = prefs_stack; tmp; tmp = tmp->next) { |
| 273 pref_name_full = g_string_prepend_c(pref_name_full, '/'); | |
| 274 pref_name_full = g_string_prepend(pref_name_full, tmp->data); | |
| 275 } | |
| 276 | |
| 5440 | 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 | 279 switch(pref_type) { |
| 280 case GAIM_PREF_NONE: | |
| 7785 | 281 gaim_prefs_add_none(pref_name_full->str); |
| 5838 | 282 break; |
| 283 case GAIM_PREF_BOOLEAN: | |
| 284 gaim_prefs_set_bool(pref_name_full->str, atoi(pref_value)); | |
| 285 break; | |
| 286 case GAIM_PREF_INT: | |
| 287 gaim_prefs_set_int(pref_name_full->str, atoi(pref_value)); | |
| 288 break; | |
| 289 case GAIM_PREF_STRING: | |
| 290 gaim_prefs_set_string(pref_name_full->str, pref_value); | |
| 291 break; | |
| 292 case GAIM_PREF_STRING_LIST: | |
| 293 gaim_prefs_set_string_list(pref_name_full->str, NULL); | |
| 294 break; | |
| 295 } | |
| 296 prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); | |
| 297 g_string_free(pref_name_full, TRUE); | |
| 5440 | 298 } |
| 1170 | 299 } |
| 300 | |
| 10443 | 301 static void |
| 302 prefs_end_element_handler(GMarkupParseContext *context, | |
| 303 const gchar *element_name, | |
| 304 gpointer user_data, GError **error) | |
| 305 { | |
| 5940 | 306 if(prefs_stack && !strcmp(element_name, "pref")) { |
| 307 g_free(prefs_stack->data); | |
| 5440 | 308 prefs_stack = g_list_delete_link(prefs_stack, prefs_stack); |
| 309 } | |
| 1170 | 310 } |
| 311 | |
| 5440 | 312 static GMarkupParser prefs_parser = { |
| 313 prefs_start_element_handler, | |
| 314 prefs_end_element_handler, | |
| 315 NULL, | |
| 316 NULL, | |
| 317 NULL | |
| 318 }; | |
| 1170 | 319 |
| 10443 | 320 gboolean |
| 321 gaim_prefs_load() | |
| 322 { | |
| 5440 | 323 gchar *filename = g_build_filename(gaim_user_dir(), "prefs.xml", NULL); |
| 324 gchar *contents = NULL; | |
| 325 gsize length; | |
| 326 GMarkupParseContext *context; | |
| 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 | 330 prefs_loaded = TRUE; |
|
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
331 return FALSE; |
| 5534 | 332 } |
| 5440 | 333 |
| 10443 | 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 | 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 | 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 | 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 | 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 | 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 | 357 gaim_debug_error("prefs", "Error reading prefs: %s\n", |
| 5440 | 358 error->message); |
| 359 g_error_free(error); | |
| 6040 | 360 g_free(filename); |
| 10443 | 361 prefs_loaded = TRUE; |
| 6040 | 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 | 365 } |
| 366 | |
| 5440 | 367 context = g_markup_parse_context_new(&prefs_parser, 0, NULL, NULL); |
| 368 | |
| 369 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 370 g_markup_parse_context_free(context); | |
| 371 g_free(contents); | |
| 6040 | 372 g_free(filename); |
| 10443 | 373 prefs_loaded = TRUE; |
| 6040 | 374 |
|
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
375 return FALSE; |
| 5440 | 376 } |
| 377 | |
| 378 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 10443 | 379 gaim_debug_error("prefs", "Error parsing %s\n", filename); |
| 5440 | 380 g_markup_parse_context_free(context); |
| 381 g_free(contents); | |
| 6040 | 382 g_free(filename); |
| 10443 | 383 prefs_loaded = TRUE; |
| 6040 | 384 |
|
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5539
diff
changeset
|
385 return FALSE; |
| 5440 | 386 } |
| 387 | |
| 10443 | 388 gaim_debug_info("prefs", "Finished reading %s\n", filename); |
| 5440 | 389 g_markup_parse_context_free(context); |
| 390 g_free(contents); | |
| 391 g_free(filename); | |
| 10443 | 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 | 397 |
| 398 | |
| 399 static void | |
|
12822
cecc9706c11f
[gaim-migrate @ 15170]
Richard Laager <rlaager@wiktel.com>
parents:
12762
diff
changeset
|
400 prefs_save_cb(const char *name, GaimPrefType type, gconstpointer val, |
| 10443 | 401 gpointer user_data) |
| 402 { | |
| 403 | |
| 404 if(!prefs_loaded) | |
| 405 return; | |
| 406 | |
| 407 gaim_debug_misc("prefs", "%s changed, scheduling save.\n", name); | |
| 408 | |
| 409 schedule_prefs_save(); | |
| 410 } | |
| 411 | |
| 412 static char * | |
| 413 get_path_dirname(const char *name) | |
| 414 { | |
| 415 char *c, *str; | |
| 416 | |
| 417 str = g_strdup(name); | |
| 418 | |
| 419 if ((c = strrchr(str, '/')) != NULL) { | |
| 420 *c = '\0'; | |
| 421 | |
| 422 if (*str == '\0') { | |
| 423 g_free(str); | |
| 424 | |
| 425 str = g_strdup("/"); | |
| 426 } | |
| 427 } | |
| 428 else { | |
| 429 g_free(str); | |
| 430 | |
| 431 str = g_strdup("."); | |
| 432 } | |
| 433 | |
| 434 return str; | |
| 435 } | |
| 436 | |
| 437 static char * | |
| 438 get_path_basename(const char *name) | |
| 439 { | |
| 440 const char *c; | |
| 441 | |
| 442 if ((c = strrchr(name, '/')) != NULL) | |
| 443 return g_strdup(c + 1); | |
| 444 | |
| 445 return g_strdup(name); | |
| 446 } | |
| 447 | |
| 448 static char * | |
| 449 pref_full_name(struct gaim_pref *pref) | |
| 450 { | |
| 451 GString *name; | |
| 452 struct gaim_pref *parent; | |
| 453 char *ret; | |
| 454 | |
| 455 if(!pref) | |
| 456 return NULL; | |
| 457 | |
| 458 if(pref == &prefs) | |
| 459 return g_strdup("/"); | |
| 460 | |
| 461 name = g_string_new(pref->name); | |
| 462 parent = pref->parent; | |
| 463 | |
| 464 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { | |
| 465 name = g_string_prepend_c(name, '/'); | |
| 466 name = g_string_prepend(name, parent->name); | |
| 467 } | |
|
12759
019d0e4d8d65
[gaim-migrate @ 15106]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12615
diff
changeset
|
468 name = g_string_prepend_c(name, '/'); |
| 10443 | 469 ret = name->str; |
| 470 g_string_free(name, FALSE); | |
| 471 return ret; | |
| 472 } | |
| 473 | |
| 474 static struct gaim_pref * | |
| 475 find_pref_parent(const char *name) | |
| 476 { | |
| 477 char *parent_name = get_path_dirname(name); | |
| 478 struct gaim_pref *ret = &prefs; | |
| 479 | |
| 480 if(strcmp(parent_name, "/")) { | |
| 481 ret = find_pref(parent_name); | |
| 482 } | |
| 483 | |
| 484 g_free(parent_name); | |
| 485 return ret; | |
| 486 } | |
| 487 | |
| 488 static void | |
| 489 free_pref_value(struct gaim_pref *pref) | |
| 490 { | |
| 491 switch(pref->type) { | |
| 492 case GAIM_PREF_BOOLEAN: | |
| 493 pref->value.boolean = FALSE; | |
| 494 break; | |
| 495 case GAIM_PREF_INT: | |
| 496 pref->value.integer = 0; | |
| 497 break; | |
| 498 case GAIM_PREF_STRING: | |
| 499 g_free(pref->value.string); | |
| 500 pref->value.string = NULL; | |
| 501 break; | |
| 502 case GAIM_PREF_STRING_LIST: | |
| 503 { | |
| 504 GList *tmp; | |
| 505 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
| 506 g_free(tmp->data); | |
| 507 | |
| 508 g_list_free(pref->value.stringlist); | |
| 509 } break; | |
| 510 case GAIM_PREF_NONE: | |
| 511 break; | |
| 512 } | |
| 513 } | |
| 514 | |
| 515 static struct gaim_pref * | |
| 516 add_pref(GaimPrefType type, const char *name) | |
| 517 { | |
| 518 struct gaim_pref *parent; | |
| 519 struct gaim_pref *me; | |
| 520 struct gaim_pref *sibling; | |
| 521 char *my_name; | |
| 522 | |
| 523 parent = find_pref_parent(name); | |
| 524 | |
| 525 if(!parent) | |
| 526 return NULL; | |
| 527 | |
| 528 my_name = get_path_basename(name); | |
| 529 | |
| 530 for(sibling = parent->first_child; sibling; sibling = sibling->sibling) { | |
| 531 if(!strcmp(sibling->name, my_name)) { | |
| 532 g_free(my_name); | |
| 533 return NULL; | |
| 534 } | |
| 535 } | |
| 536 | |
| 537 me = g_new0(struct gaim_pref, 1); | |
| 538 me->type = type; | |
| 539 me->name = my_name; | |
| 540 | |
| 541 me->parent = parent; | |
| 542 if(parent->first_child) { | |
| 543 /* blatant abuse of a for loop */ | |
| 544 for(sibling = parent->first_child; sibling->sibling; | |
| 545 sibling = sibling->sibling); | |
| 546 sibling->sibling = me; | |
| 547 } else { | |
| 548 parent->first_child = me; | |
| 549 } | |
| 550 | |
| 551 g_hash_table_insert(prefs_hash, g_strdup(name), (gpointer)me); | |
| 552 | |
| 553 return me; | |
| 554 } | |
| 555 | |
| 556 void | |
| 557 gaim_prefs_add_none(const char *name) | |
| 558 { | |
| 559 add_pref(GAIM_PREF_NONE, name); | |
| 560 } | |
| 561 | |
| 562 void | |
| 563 gaim_prefs_add_bool(const char *name, gboolean value) | |
| 564 { | |
| 565 struct gaim_pref *pref = add_pref(GAIM_PREF_BOOLEAN, name); | |
| 566 | |
| 567 if(!pref) | |
| 568 return; | |
| 569 | |
| 570 pref->value.boolean = value; | |
| 571 } | |
| 572 | |
| 573 void | |
| 574 gaim_prefs_add_int(const char *name, int value) | |
| 575 { | |
| 576 struct gaim_pref *pref = add_pref(GAIM_PREF_INT, name); | |
| 577 | |
| 578 if(!pref) | |
| 579 return; | |
| 580 | |
| 581 pref->value.integer = value; | |
| 582 } | |
| 583 | |
| 584 void | |
| 585 gaim_prefs_add_string(const char *name, const char *value) | |
| 586 { | |
| 587 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING, name); | |
| 588 | |
| 589 if(!pref) | |
| 590 return; | |
| 591 | |
| 592 pref->value.string = g_strdup(value); | |
| 593 } | |
| 594 | |
| 595 void | |
| 596 gaim_prefs_add_string_list(const char *name, GList *value) | |
| 597 { | |
| 598 struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); | |
| 599 GList *tmp; | |
| 600 | |
| 601 if(!pref) | |
| 602 return; | |
| 603 | |
| 604 for(tmp = value; tmp; tmp = tmp->next) | |
| 605 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
| 606 g_strdup(tmp->data)); | |
| 607 } | |
| 608 | |
| 10871 | 609 static void |
| 10443 | 610 remove_pref(struct gaim_pref *pref) |
| 611 { | |
| 612 char *name; | |
| 613 | |
| 614 if(!pref || pref == &prefs) | |
| 615 return; | |
| 616 | |
| 617 while(pref->first_child) | |
| 618 remove_pref(pref->first_child); | |
| 619 | |
| 620 if(pref->parent->first_child == pref) { | |
| 621 pref->parent->first_child = pref->sibling; | |
| 622 } else { | |
| 623 struct gaim_pref *sib = pref->parent->first_child; | |
| 12599 | 624 while(sib && sib->sibling != pref) |
| 10443 | 625 sib = sib->sibling; |
| 12599 | 626 if(sib) |
| 627 sib->sibling = pref->sibling; | |
| 10443 | 628 } |
| 629 | |
| 630 name = pref_full_name(pref); | |
| 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 | 633 |
| 634 g_hash_table_remove(prefs_hash, name); | |
| 635 g_free(name); | |
| 636 | |
| 637 free_pref_value(pref); | |
| 638 | |
| 639 g_slist_free(pref->callbacks); | |
| 640 g_free(pref->name); | |
| 641 g_free(pref); | |
| 642 } | |
| 643 | |
| 644 void | |
| 645 gaim_prefs_remove(const char *name) | |
| 646 { | |
| 647 struct gaim_pref *pref = find_pref(name); | |
| 648 | |
| 649 if(!pref) | |
| 650 return; | |
| 651 | |
| 652 remove_pref(pref); | |
| 653 } | |
| 654 | |
| 655 void | |
| 656 gaim_prefs_destroy() | |
| 657 { | |
| 658 gaim_prefs_remove("/"); | |
| 659 } | |
| 660 | |
| 661 static void | |
| 662 do_callbacks(const char* name, struct gaim_pref *pref) | |
| 663 { | |
| 664 GSList *cbs; | |
| 665 struct gaim_pref *cb_pref; | |
| 666 for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { | |
| 667 for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { | |
| 668 struct pref_cb *cb = cbs->data; | |
| 669 cb->func(name, pref->type, pref->value.generic, cb->data); | |
| 670 } | |
| 671 } | |
| 672 } | |
| 673 | |
| 674 void | |
| 675 gaim_prefs_trigger_callback(const char *name) | |
| 676 { | |
| 677 struct gaim_pref *pref = find_pref(name); | |
| 678 | |
| 679 if(!pref) { | |
| 680 gaim_debug_error("prefs", | |
| 681 "gaim_prefs_trigger_callback: Unknown pref %s\n", name); | |
| 682 return; | |
| 683 } | |
| 684 | |
| 685 do_callbacks(name, pref); | |
| 686 } | |
| 687 | |
| 688 void | |
| 689 gaim_prefs_set_generic(const char *name, gpointer value) | |
| 690 { | |
| 691 struct gaim_pref *pref = find_pref(name); | |
| 692 | |
| 693 if(!pref) { | |
| 694 gaim_debug_error("prefs", | |
| 695 "gaim_prefs_set_generic: Unknown pref %s\n", name); | |
| 696 return; | |
| 697 } | |
| 698 | |
| 699 pref->value.generic = value; | |
| 700 do_callbacks(name, pref); | |
| 701 } | |
| 702 | |
| 703 void | |
| 704 gaim_prefs_set_bool(const char *name, gboolean value) | |
| 705 { | |
| 706 struct gaim_pref *pref = find_pref(name); | |
| 707 | |
| 708 if(pref) { | |
| 709 if(pref->type != GAIM_PREF_BOOLEAN) { | |
| 710 gaim_debug_error("prefs", | |
| 711 "gaim_prefs_set_bool: %s not a boolean pref\n", name); | |
| 712 return; | |
| 713 } | |
| 714 | |
| 715 if(pref->value.boolean != value) { | |
| 716 pref->value.boolean = value; | |
| 717 do_callbacks(name, pref); | |
| 718 } | |
| 719 } else { | |
| 720 gaim_prefs_add_bool(name, value); | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 void | |
| 725 gaim_prefs_set_int(const char *name, int value) | |
| 726 { | |
| 727 struct gaim_pref *pref = find_pref(name); | |
| 728 | |
| 729 if(pref) { | |
| 730 if(pref->type != GAIM_PREF_INT) { | |
| 731 gaim_debug_error("prefs", | |
| 732 "gaim_prefs_set_int: %s not an integer pref\n", name); | |
| 733 return; | |
| 734 } | |
| 735 | |
| 736 if(pref->value.integer != value) { | |
| 737 pref->value.integer = value; | |
| 738 do_callbacks(name, pref); | |
| 739 } | |
| 740 } else { | |
| 741 gaim_prefs_add_int(name, value); | |
| 742 } | |
| 743 } | |
| 744 | |
| 745 void | |
| 746 gaim_prefs_set_string(const char *name, const char *value) | |
| 747 { | |
| 748 struct gaim_pref *pref = find_pref(name); | |
| 749 | |
| 750 if(pref) { | |
| 751 if(pref->type != GAIM_PREF_STRING) { | |
| 752 gaim_debug_error("prefs", | |
| 753 "gaim_prefs_set_string: %s not a string pref\n", name); | |
| 754 return; | |
| 755 } | |
| 756 | |
| 757 if((value && !pref->value.string) || | |
| 758 (!value && pref->value.string) || | |
| 759 strcmp(pref->value.string, value)) { | |
| 760 g_free(pref->value.string); | |
| 761 pref->value.string = g_strdup(value); | |
| 762 do_callbacks(name, pref); | |
| 763 } | |
| 764 } else { | |
| 765 gaim_prefs_add_string(name, value); | |
| 766 } | |
| 767 } | |
| 768 | |
| 769 void | |
| 770 gaim_prefs_set_string_list(const char *name, GList *value) | |
| 771 { | |
| 772 struct gaim_pref *pref = find_pref(name); | |
| 773 if(pref) { | |
| 774 GList *tmp; | |
| 775 | |
| 776 if(pref->type != GAIM_PREF_STRING_LIST) { | |
| 777 gaim_debug_error("prefs", | |
| 778 "gaim_prefs_set_string_list: %s not a string list pref\n", | |
| 779 name); | |
| 780 return; | |
| 781 } | |
| 782 | |
| 783 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
| 784 g_free(tmp->data); | |
| 785 | |
| 786 g_list_free(pref->value.stringlist); | |
| 787 pref->value.stringlist = NULL; | |
| 788 | |
| 789 for(tmp = value; tmp; tmp = tmp->next) | |
| 790 pref->value.stringlist = g_list_append(pref->value.stringlist, | |
| 791 g_strdup(tmp->data)); | |
| 792 | |
| 793 do_callbacks(name, pref); | |
| 794 | |
| 795 } else { | |
| 796 gaim_prefs_add_string_list(name, value); | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 gboolean | |
| 801 gaim_prefs_exists(const char *name) | |
| 802 { | |
| 803 struct gaim_pref *pref = find_pref(name); | |
| 804 | |
| 805 if (pref != NULL) | |
| 806 return TRUE; | |
| 807 | |
| 808 return FALSE; | |
| 809 } | |
| 810 | |
| 811 GaimPrefType | |
| 812 gaim_prefs_get_type(const char *name) | |
| 813 { | |
| 814 struct gaim_pref *pref = find_pref(name); | |
| 815 | |
| 816 if (pref == NULL) | |
| 817 return GAIM_PREF_NONE; | |
| 818 | |
| 819 return (pref->type); | |
| 820 } | |
| 821 | |
| 822 gboolean | |
| 823 gaim_prefs_get_bool(const char *name) | |
| 824 { | |
| 825 struct gaim_pref *pref = find_pref(name); | |
| 826 | |
| 827 if(!pref) { | |
| 828 gaim_debug_error("prefs", | |
| 829 "gaim_prefs_get_bool: Unknown pref %s\n", name); | |
| 830 return FALSE; | |
| 831 } else if(pref->type != GAIM_PREF_BOOLEAN) { | |
| 832 gaim_debug_error("prefs", | |
| 833 "gaim_prefs_get_bool: %s not a boolean pref\n", name); | |
| 834 return FALSE; | |
| 835 } | |
| 836 | |
| 837 return pref->value.boolean; | |
| 838 } | |
| 839 | |
| 840 int | |
| 841 gaim_prefs_get_int(const char *name) | |
| 842 { | |
| 843 struct gaim_pref *pref = find_pref(name); | |
| 844 | |
| 845 if(!pref) { | |
| 846 gaim_debug_error("prefs", | |
| 847 "gaim_prefs_get_int: Unknown pref %s\n", name); | |
| 848 return 0; | |
| 849 } else if(pref->type != GAIM_PREF_INT) { | |
| 850 gaim_debug_error("prefs", | |
| 851 "gaim_prefs_get_int: %s not an integer pref\n", name); | |
| 852 return 0; | |
| 853 } | |
| 854 | |
| 855 return pref->value.integer; | |
| 856 } | |
| 857 | |
| 858 const char * | |
| 859 gaim_prefs_get_string(const char *name) | |
| 860 { | |
| 861 struct gaim_pref *pref = find_pref(name); | |
| 862 | |
| 863 if(!pref) { | |
| 864 gaim_debug_error("prefs", | |
| 865 "gaim_prefs_get_string: Unknown pref %s\n", name); | |
| 866 return NULL; | |
| 867 } else if(pref->type != GAIM_PREF_STRING) { | |
| 868 gaim_debug_error("prefs", | |
| 869 "gaim_prefs_get_string: %s not a string pref\n", name); | |
| 870 return NULL; | |
| 871 } | |
| 872 | |
| 873 return pref->value.string; | |
| 874 } | |
| 875 | |
| 876 GList * | |
| 877 gaim_prefs_get_string_list(const char *name) | |
| 878 { | |
| 879 struct gaim_pref *pref = find_pref(name); | |
| 880 GList *ret = NULL, *tmp; | |
| 881 | |
| 882 if(!pref) { | |
| 883 gaim_debug_error("prefs", | |
| 884 "gaim_prefs_get_string_list: Unknown pref %s\n", name); | |
| 885 return NULL; | |
| 886 } else if(pref->type != GAIM_PREF_STRING_LIST) { | |
| 887 gaim_debug_error("prefs", | |
| 888 "gaim_prefs_get_string_list: %s not a string list pref\n", name); | |
| 889 return NULL; | |
| 890 } | |
| 891 | |
| 892 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | |
| 893 ret = g_list_append(ret, g_strdup(tmp->data)); | |
| 894 | |
| 895 return ret; | |
| 896 } | |
| 897 | |
| 898 void | |
| 899 gaim_prefs_rename(const char *oldname, const char *newname) | |
| 900 { | |
| 901 struct gaim_pref *oldpref, *newpref; | |
| 902 | |
| 903 oldpref = find_pref(oldname); | |
| 904 newpref = find_pref(newname); | |
| 905 | |
| 906 /* it's already been renamed, call off the dogs */ | |
| 907 if(!oldpref) | |
| 908 return; | |
| 909 | |
| 910 gaim_debug_info("prefs", "Renaming %s to %s\n", oldname, newname); | |
| 911 | |
| 912 g_return_if_fail(newpref != NULL); /* the new one needs to be created first */ | |
| 913 g_return_if_fail(oldpref->type == newpref->type); | |
| 914 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
| 915 | |
| 916 switch(oldpref->type) { | |
| 917 case GAIM_PREF_NONE: | |
| 918 break; | |
| 919 case GAIM_PREF_BOOLEAN: | |
| 920 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
| 921 break; | |
| 922 case GAIM_PREF_INT: | |
| 923 gaim_prefs_set_int(newname, oldpref->value.integer); | |
| 924 break; | |
| 925 case GAIM_PREF_STRING: | |
| 926 gaim_prefs_set_string(newname, oldpref->value.string); | |
| 927 break; | |
| 928 case GAIM_PREF_STRING_LIST: | |
| 929 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
| 930 break; | |
| 931 } | |
| 932 | |
| 933 remove_pref(oldpref); | |
| 934 } | |
| 935 | |
| 936 void | |
| 937 gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname) | |
| 938 { | |
| 939 struct gaim_pref *oldpref, *newpref; | |
| 940 | |
| 941 oldpref = find_pref(oldname); | |
| 942 newpref = find_pref(newname); | |
| 943 | |
| 944 /* it's already been renamed, call off the cats */ | |
| 945 if(!oldpref) | |
| 946 return; | |
| 947 | |
| 11736 | 948 gaim_debug_info("prefs", "Renaming and toggling %s to %s\n", oldname, newname); |
| 949 | |
| 10443 | 950 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ |
| 951 g_return_if_fail(oldpref->type == newpref->type); | |
| 952 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN); | |
| 953 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
| 954 | |
| 955 gaim_prefs_set_bool(newname, !(oldpref->value.boolean)); | |
| 956 | |
| 957 remove_pref(oldpref); | |
| 958 | |
| 959 } | |
| 960 | |
| 961 guint | |
| 962 gaim_prefs_connect_callback(void *handle, const char *name, GaimPrefCallback func, gpointer data) | |
| 963 { | |
| 964 struct gaim_pref *pref; | |
| 965 struct pref_cb *cb; | |
| 966 static guint cb_id = 0; | |
| 967 | |
| 968 pref = find_pref(name); | |
| 969 if (pref == NULL) | |
| 970 return 0; | |
| 971 | |
| 972 cb = g_new0(struct pref_cb, 1); | |
| 973 | |
| 974 cb->func = func; | |
| 975 cb->data = data; | |
| 976 cb->id = ++cb_id; | |
| 977 cb->handle = handle; | |
| 978 | |
| 979 pref->callbacks = g_slist_append(pref->callbacks, cb); | |
| 980 | |
| 981 return cb->id; | |
| 982 } | |
| 983 | |
| 984 static gboolean | |
| 985 disco_callback_helper(struct gaim_pref *pref, guint callback_id) | |
| 986 { | |
| 987 GSList *cbs; | |
| 988 struct gaim_pref *child; | |
| 989 | |
| 990 if(!pref) | |
| 991 return FALSE; | |
| 992 | |
| 993 for(cbs = pref->callbacks; cbs; cbs = cbs->next) { | |
| 994 struct pref_cb *cb = cbs->data; | |
| 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 | 997 g_free(cb); |
| 998 return TRUE; | |
| 999 } | |
| 1000 } | |
| 1001 | |
| 1002 for(child = pref->first_child; child; child = child->sibling) { | |
| 1003 if(disco_callback_helper(child, callback_id)) | |
| 1004 return TRUE; | |
| 1005 } | |
| 1006 | |
| 1007 return FALSE; | |
| 1008 } | |
| 1009 | |
| 1010 void | |
| 1011 gaim_prefs_disconnect_callback(guint callback_id) | |
| 1012 { | |
| 1013 disco_callback_helper(&prefs, callback_id); | |
| 1014 } | |
| 1015 | |
| 1016 static void | |
| 1017 disco_callback_helper_handle(struct gaim_pref *pref, void *handle) | |
| 1018 { | |
| 1019 GSList *cbs; | |
| 1020 struct gaim_pref *child; | |
| 1021 | |
| 1022 if(!pref) | |
| 1023 return; | |
| 1024 | |
| 1025 cbs = pref->callbacks; | |
| 1026 while (cbs != NULL) { | |
| 1027 struct pref_cb *cb = cbs->data; | |
| 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 | 1030 g_free(cb); |
| 1031 cbs = pref->callbacks; | |
| 1032 } else | |
| 1033 cbs = cbs->next; | |
| 1034 } | |
| 1035 | |
| 1036 for(child = pref->first_child; child; child = child->sibling) | |
| 1037 disco_callback_helper_handle(child, handle); | |
| 1038 } | |
| 1039 | |
| 1040 void | |
| 1041 gaim_prefs_disconnect_by_handle(void *handle) | |
| 1042 { | |
| 1043 g_return_if_fail(handle != NULL); | |
| 1044 | |
| 1045 disco_callback_helper_handle(&prefs, handle); | |
| 1046 } | |
| 1047 | |
| 1048 void | |
| 1049 gaim_prefs_update_old() | |
| 1050 { | |
| 8900 | 1051 /* Remove some no-longer-used prefs */ |
| 9594 | 1052 gaim_prefs_remove("/core/away/auto_response/enabled"); |
| 1053 gaim_prefs_remove("/core/away/auto_response/idle_only"); | |
| 8948 | 1054 gaim_prefs_remove("/core/away/auto_response/in_active_conv"); |
| 1055 gaim_prefs_remove("/core/away/auto_response/sec_before_resend"); | |
| 9594 | 1056 gaim_prefs_remove("/core/away/auto_response"); |
| 11654 | 1057 gaim_prefs_remove("/core/away/default_message"); |
| 10353 | 1058 gaim_prefs_remove("/core/buddies/use_server_alias"); |
| 8942 | 1059 gaim_prefs_remove("/core/conversations/away_back_on_send"); |
| 8900 | 1060 gaim_prefs_remove("/core/conversations/send_urls_as_links"); |
| 8942 | 1061 gaim_prefs_remove("/core/conversations/im/show_login"); |
| 8998 | 1062 gaim_prefs_remove("/core/conversations/chat/show_join"); |
| 1063 gaim_prefs_remove("/core/conversations/chat/show_leave"); | |
| 9251 | 1064 gaim_prefs_remove("/core/conversations/combine_chat_im"); |
| 10389 | 1065 gaim_prefs_remove("/core/conversations/use_alias_for_title"); |
| 11698 | 1066 gaim_prefs_remove("/core/logging/log_signon_signoff"); |
| 1067 gaim_prefs_remove("/core/logging/log_idle_state"); | |
| 1068 gaim_prefs_remove("/core/logging/log_away_state"); | |
| 1069 gaim_prefs_remove("/core/logging/log_own_states"); | |
| 11959 | 1070 gaim_prefs_remove("/plugins/core/autorecon/hide_connected_error"); |
| 1071 gaim_prefs_remove("/plugins/core/autorecon/hide_connecting_error"); | |
| 1072 gaim_prefs_remove("/plugins/core/autorecon/hide_reconnecting_dialog"); | |
| 1073 gaim_prefs_remove("/plugins/core/autorecon/restore_state"); | |
| 1074 gaim_prefs_remove("/plugins/core/autorecon"); | |
| 8900 | 1075 } |
| 10443 | 1076 |
| 1077 void * | |
| 1078 gaim_prefs_get_handle(void) | |
| 1079 { | |
| 1080 static int handle; | |
| 1081 | |
| 1082 return &handle; | |
| 1083 } | |
| 1084 | |
| 1085 void | |
| 1086 gaim_prefs_init(void) | |
| 1087 { | |
| 1088 void *handle = gaim_prefs_get_handle(); | |
| 1089 | |
| 1090 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 1091 | |
| 1092 gaim_prefs_connect_callback(handle, "/", prefs_save_cb, NULL); | |
| 1093 | |
| 1094 gaim_prefs_add_none("/core"); | |
| 1095 gaim_prefs_add_none("/plugins"); | |
| 1096 gaim_prefs_add_none("/plugins/core"); | |
| 1097 gaim_prefs_add_none("/plugins/lopl"); | |
| 1098 gaim_prefs_add_none("/plugins/prpl"); | |
| 1099 | |
| 1100 /* Away */ | |
| 1101 gaim_prefs_add_none("/core/away"); | |
| 12573 | 1102 gaim_prefs_add_string("/core/away/idle_reporting", "system"); |
| 10443 | 1103 gaim_prefs_add_bool("/core/away/away_when_idle", TRUE); |
| 1104 gaim_prefs_add_int("/core/away/mins_before_away", 5); | |
| 1105 | |
| 1106 /* Away -> Auto-Reply */ | |
| 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 | 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 | 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 | 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 | 1126 gaim_prefs_add_string("/core/away/auto_reply", "away"); |
| 1127 } | |
| 1128 } | |
| 1129 } | |
| 1130 | |
| 1131 /* Buddies */ | |
| 1132 gaim_prefs_add_none("/core/buddies"); | |
| 1133 | |
| 1134 /* Contact Priority Settings */ | |
| 1135 gaim_prefs_add_none("/core/contact"); | |
| 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 | 1140 } |
| 1141 | |
| 1142 void | |
| 1143 gaim_prefs_uninit() | |
| 1144 { | |
| 1145 if (save_timer != 0) | |
| 1146 { | |
| 1147 gaim_timeout_remove(save_timer); | |
| 1148 save_timer = 0; | |
| 1149 sync_prefs(); | |
| 1150 } | |
| 1151 | |
| 1152 gaim_prefs_disconnect_by_handle(gaim_prefs_get_handle()); | |
| 1153 } |
