comparison src/prefs.c @ 10087:9fdbfe832fac

[gaim-migrate @ 11098] gaim_prefs_connect_callback() now takes a handle that can be used to disconnect the callbacks later on. The callback id's remain, so people can still use those if they want, although I'm not sure if there's any need for them any more. I also switched the order for initializing the prefs subsystem and statically compiled protocol plugins so that prpl prefs can work for statically compiled prpls. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 12 Oct 2004 00:49:19 +0000
parents 15d09e546cee
children 655c48791b3c
comparison
equal deleted inserted replaced
10086:6cd2b467e303 10087:9fdbfe832fac
42 42
43 struct pref_cb { 43 struct pref_cb {
44 GaimPrefCallback func; 44 GaimPrefCallback func;
45 gpointer data; 45 gpointer data;
46 guint id; 46 guint id;
47 void *handle;
47 }; 48 };
48 49
49 struct gaim_pref { 50 struct gaim_pref {
50 GaimPrefType type; 51 GaimPrefType type;
51 char *name; 52 char *name;
94 } 95 }
95 96
96 void gaim_prefs_init() { 97 void gaim_prefs_init() {
97 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); 98 prefs_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
98 99
99 gaim_prefs_connect_callback("/", prefs_save_cb, NULL); 100 gaim_prefs_connect_callback(NULL, "/", prefs_save_cb, NULL);
100 101
101 gaim_prefs_add_none("/core"); 102 gaim_prefs_add_none("/core");
102 gaim_prefs_add_none("/plugins"); 103 gaim_prefs_add_none("/plugins");
103 gaim_prefs_add_none("/plugins/core"); 104 gaim_prefs_add_none("/plugins/core");
104 gaim_prefs_add_none("/plugins/lopl"); 105 gaim_prefs_add_none("/plugins/lopl");
632 remove_pref(oldpref); 633 remove_pref(oldpref);
633 } 634 }
634 635
635 void gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname) { 636 void gaim_prefs_rename_boolean_toggle(const char *oldname, const char *newname) {
636 struct gaim_pref *oldpref, *newpref; 637 struct gaim_pref *oldpref, *newpref;
637 638
638 gaim_debug_info("prefs", "Attempting to rename and toggle %s to %s\n", oldname, newname); 639 gaim_debug_info("prefs", "Attempting to rename and toggle %s to %s\n", oldname, newname);
639 640
640 oldpref = find_pref(oldname); 641 oldpref = find_pref(oldname);
641 newpref = find_pref(newname); 642 newpref = find_pref(newname);
642 643
646 647
647 g_return_if_fail(newpref != NULL); /* the new one needs to be created */ 648 g_return_if_fail(newpref != NULL); /* the new one needs to be created */
648 g_return_if_fail(oldpref->type == newpref->type); 649 g_return_if_fail(oldpref->type == newpref->type);
649 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN); 650 g_return_if_fail(oldpref->type == GAIM_PREF_BOOLEAN);
650 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */ 651 g_return_if_fail(oldpref->first_child == NULL); /* can't rename parents */
651 652
652 gaim_prefs_set_bool(newname, !(oldpref->value.boolean)); 653 gaim_prefs_set_bool(newname, !(oldpref->value.boolean));
653 654
654 remove_pref(oldpref); 655 remove_pref(oldpref);
655 656
656 } 657 }
657 658
658 guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) 659 guint gaim_prefs_connect_callback(void *handle, const char *name, GaimPrefCallback func, gpointer data)
659 { 660 {
660 struct gaim_pref *pref; 661 struct gaim_pref *pref;
661 struct pref_cb *cb; 662 struct pref_cb *cb;
662 static guint cb_id = 0; 663 static guint cb_id = 0;
663 664
668 cb = g_new0(struct pref_cb, 1); 669 cb = g_new0(struct pref_cb, 1);
669 670
670 cb->func = func; 671 cb->func = func;
671 cb->data = data; 672 cb->data = data;
672 cb->id = ++cb_id; 673 cb->id = ++cb_id;
674 cb->handle = handle;
673 675
674 pref->callbacks = g_slist_append(pref->callbacks, cb); 676 pref->callbacks = g_slist_append(pref->callbacks, cb);
675 677
676 return cb->id; 678 return cb->id;
677 } 679 }
678 680
679 gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) { 681 static gboolean disco_callback_helper(struct gaim_pref *pref, guint callback_id) {
680 GSList *cbs; 682 GSList *cbs;
681 struct gaim_pref *child; 683 struct gaim_pref *child;
682 684
683 if(!pref) 685 if(!pref)
684 return FALSE; 686 return FALSE;
700 return FALSE; 702 return FALSE;
701 } 703 }
702 704
703 void gaim_prefs_disconnect_callback(guint callback_id) { 705 void gaim_prefs_disconnect_callback(guint callback_id) {
704 disco_callback_helper(&prefs, callback_id); 706 disco_callback_helper(&prefs, callback_id);
707 }
708
709 static void disco_callback_helper_handle(struct gaim_pref *pref, void *handle) {
710 GSList *cbs;
711 struct gaim_pref *child;
712
713 if(!pref)
714 return;
715
716 cbs = pref->callbacks;
717 while (cbs != NULL) {
718 struct pref_cb *cb = cbs->data;
719 if(cb->handle == handle) {
720 pref->callbacks = g_slist_remove(pref->callbacks, cb);
721 g_free(cb);
722 cbs = pref->callbacks;
723 } else
724 cbs = cbs->next;
725 }
726
727 for(child = pref->first_child; child; child = child->sibling)
728 disco_callback_helper_handle(child, handle);
729 }
730
731 void gaim_prefs_disconnect_by_handle(void *handle) {
732 g_return_if_fail(handle != NULL);
733 disco_callback_helper_handle(&prefs, handle);
705 } 734 }
706 735
707 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) { 736 static void gaim_prefs_write(FILE *f, struct gaim_pref *pref, int depth) {
708 struct gaim_pref *tmp; 737 struct gaim_pref *tmp;
709 char *esc; 738 char *esc;