Mercurial > pidgin
comparison src/prefs.c @ 6693:8c1b5dd87fbf
[gaim-migrate @ 7219]
sean might think this is contact support, but it isn't. this will be useful
when we figure out where prefs should have been in the first place
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 02 Sep 2003 03:29:53 +0000 |
parents | 4bc050b1af34 |
children | 0c5637b5462e |
comparison
equal
deleted
inserted
replaced
6692:429db0c1dcd8 | 6693:8c1b5dd87fbf |
---|---|
161 } | 161 } |
162 | 162 |
163 static char *pref_full_name(struct gaim_pref *pref) { | 163 static char *pref_full_name(struct gaim_pref *pref) { |
164 GString *name; | 164 GString *name; |
165 struct gaim_pref *parent; | 165 struct gaim_pref *parent; |
166 char *ret; | |
167 | |
166 if(!pref) | 168 if(!pref) |
167 return NULL; | 169 return NULL; |
168 | 170 |
169 if(pref == &prefs) | 171 if(pref == &prefs) |
170 return g_strdup("/"); | 172 return g_strdup("/"); |
174 | 176 |
175 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { | 177 for(parent = pref->parent; parent && parent->name; parent = parent->parent) { |
176 name = g_string_prepend_c(name, '/'); | 178 name = g_string_prepend_c(name, '/'); |
177 name = g_string_prepend(name, parent->name); | 179 name = g_string_prepend(name, parent->name); |
178 } | 180 } |
181 ret = name->str; | |
179 g_string_free(name, FALSE); | 182 g_string_free(name, FALSE); |
180 return name->str; | 183 return ret; |
181 } | 184 } |
182 | 185 |
183 static struct gaim_pref *find_pref(const char *name) | 186 static struct gaim_pref *find_pref(const char *name) |
184 { | 187 { |
185 if(!name || name[0] != '/') { | 188 if(!name || name[0] != '/') { |
314 char *name; | 317 char *name; |
315 | 318 |
316 if(!pref || pref == &prefs) | 319 if(!pref || pref == &prefs) |
317 return; | 320 return; |
318 | 321 |
322 while(pref->first_child) | |
323 remove_pref(pref->first_child); | |
324 | |
319 if(pref->parent->first_child == pref) { | 325 if(pref->parent->first_child == pref) { |
320 pref->parent->first_child = pref->sibling; | 326 pref->parent->first_child = pref->sibling; |
321 } else { | 327 } else { |
322 struct gaim_pref *sib = pref->parent->first_child; | 328 struct gaim_pref *sib = pref->parent->first_child; |
323 while(sib->sibling != pref) | 329 while(sib->sibling != pref) |
325 sib->sibling = pref->sibling; | 331 sib->sibling = pref->sibling; |
326 } | 332 } |
327 | 333 |
328 name = pref_full_name(pref); | 334 name = pref_full_name(pref); |
329 | 335 |
336 gaim_debug(GAIM_DEBUG_INFO, "prefs", "removing pref %s\n", name); | |
337 | |
330 g_hash_table_remove(prefs_hash, name); | 338 g_hash_table_remove(prefs_hash, name); |
331 g_free(name); | 339 g_free(name); |
332 | 340 |
333 free_pref_value(pref); | 341 free_pref_value(pref); |
334 | 342 |
337 g_free(pref); | 345 g_free(pref); |
338 } | 346 } |
339 | 347 |
340 void gaim_prefs_remove(const char *name) { | 348 void gaim_prefs_remove(const char *name) { |
341 struct gaim_pref *pref = find_pref(name); | 349 struct gaim_pref *pref = find_pref(name); |
342 struct gaim_pref *child, *child2; | |
343 | 350 |
344 if(!pref) | 351 if(!pref) |
345 return; | 352 return; |
346 child = pref->first_child; | |
347 while(child) { | |
348 child2 = child; | |
349 child = child->sibling; | |
350 remove_pref(child2); | |
351 } | |
352 | 353 |
353 remove_pref(pref); | 354 remove_pref(pref); |
354 } | 355 } |
355 | 356 |
356 void gaim_prefs_destroy() { | 357 void gaim_prefs_destroy() { |
567 | 568 |
568 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) | 569 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) |
569 ret = g_list_append(ret, g_strdup(tmp->data)); | 570 ret = g_list_append(ret, g_strdup(tmp->data)); |
570 | 571 |
571 return ret; | 572 return ret; |
573 } | |
574 | |
575 void gaim_prefs_rename(const char *oldname, const char *newname) { | |
576 struct gaim_pref *oldpref, *newpref; | |
577 | |
578 oldpref = find_pref(oldname); | |
579 newpref = find_pref(newname); | |
580 | |
581 /* it's already been renamed, call off the dogs */ | |
582 if(!oldpref) | |
583 return; | |
584 | |
585 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ | |
586 g_return_if_fail(oldpref->type == newpref->type); | |
587 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ | |
588 | |
589 switch(oldpref->type) { | |
590 case GAIM_PREF_NONE: | |
591 break; | |
592 case GAIM_PREF_BOOLEAN: | |
593 gaim_prefs_set_bool(newname, oldpref->value.boolean); | |
594 break; | |
595 case GAIM_PREF_INT: | |
596 gaim_prefs_set_int(newname, oldpref->value.integer); | |
597 break; | |
598 case GAIM_PREF_STRING: | |
599 gaim_prefs_set_string(newname, oldpref->value.string); | |
600 break; | |
601 case GAIM_PREF_STRING_LIST: | |
602 gaim_prefs_set_string_list(newname, oldpref->value.stringlist); | |
603 break; | |
604 } | |
605 | |
606 remove_pref(oldpref); | |
607 } | |
608 | |
609 void gaim_prefs_rename_old() { | |
610 /* This doesn't actually do anything yet, but it will */ | |
572 } | 611 } |
573 | 612 |
574 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) | 613 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) |
575 { | 614 { |
576 struct gaim_pref *pref = find_pref(name); | 615 struct gaim_pref *pref = find_pref(name); |