Mercurial > hg
comparison mcabber/src/roster.c @ 620:97dd14e22b2a
Rewrite buddy_setgroup()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 16 Dec 2005 23:48:42 +0100 |
parents | 0e8247cf2bd1 |
children | f20c1934a8a7 |
comparison
equal
deleted
inserted
replaced
619:44ddf9bec3a5 | 620:97dd14e22b2a |
---|---|
737 } | 737 } |
738 | 738 |
739 // buddy_setgroup() | 739 // buddy_setgroup() |
740 // Change the group of current buddy | 740 // Change the group of current buddy |
741 // | 741 // |
742 // Warning! This function changes the specified buddy! | |
743 // Warning! Old buddy is deleted, so you can't access to its jid/name after | |
744 // calling this function (they are free'd). | |
745 void buddy_setgroup(gpointer rosterdata, char *newgroupname) | 742 void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
746 { | 743 { |
747 roster *roster_usr = rosterdata; | 744 roster *roster_usr = rosterdata; |
748 GSList **sl_group; | 745 GSList **sl_group; |
749 GSList *sl_clone; | 746 GSList *sl_newgroup; |
750 roster *roster_clone; | 747 roster *my_newgroup; |
751 | 748 |
752 // A group has no group :) | 749 // A group has no group :) |
753 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | 750 if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
751 | |
752 // Add newgroup if necessary | |
753 if (!newgroupname) newgroupname = ""; | |
754 sl_newgroup = roster_add_group(newgroupname); | |
755 if (!sl_newgroup) return; | |
756 my_newgroup = (roster*)sl_newgroup->data; | |
754 | 757 |
755 // Remove the buddy from current group | 758 // Remove the buddy from current group |
756 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | 759 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
757 *sl_group = g_slist_remove(*sl_group, rosterdata); | 760 *sl_group = g_slist_remove(*sl_group, rosterdata); |
758 | 761 |
759 // Add the buddy to its new group; actually we "clone" this buddy... | 762 // Add the buddy to its new group |
760 sl_clone = roster_add_user(roster_usr->jid, roster_usr->name, newgroupname, | 763 roster_usr->list = sl_newgroup; // (my_newgroup SList element) |
761 roster_usr->type, roster_usr->subscription); | 764 my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr, |
762 roster_clone = (roster*)sl_clone->data; | 765 (GCompareFunc)&roster_compare_name); |
763 roster_clone->subscription = roster_usr->subscription; | |
764 roster_clone->flags = roster_usr->flags; | |
765 | |
766 roster_clone->resource = roster_usr->resource; | |
767 roster_usr->resource = NULL; | |
768 roster_clone->nickname = roster_usr->nickname; | |
769 roster_usr->nickname = NULL; | |
770 roster_clone->topic = roster_usr->topic; | |
771 roster_usr->topic = NULL; | |
772 | |
773 // Free old buddy | |
774 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); | |
775 if (roster_usr->name) g_free((gchar*)roster_usr->name); | |
776 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); | |
777 if (roster_usr->topic) g_free((gchar*)roster_usr->topic); | |
778 free_all_resources(&roster_usr->resource); | |
779 g_free(roster_usr); | |
780 | |
781 buddylist = g_list_append(buddylist, roster_clone); | |
782 // We must have current_buddy pointing to the cloned buddy, if this is | |
783 // the one we have moved. Same for alternate_buddy. | |
784 if (rosterdata == BUDDATA(current_buddy)) { | |
785 current_buddy = g_list_find(buddylist, roster_clone); | |
786 // If new new group is folded, the current_buddy will be lost, and the | |
787 // chat window won't be correctly refreshed. So we make sure it isn't... | |
788 ((roster*)((GSList*)roster_clone->list)->data)->flags &= ~ROSTER_FLAG_HIDE; | |
789 } | |
790 if (alternate_buddy && BUDDATA(alternate_buddy) == rosterdata) | |
791 alternate_buddy = g_list_find(buddylist, roster_clone); | |
792 | 766 |
793 buddylist_build(); | 767 buddylist_build(); |
794 } | 768 } |
795 | 769 |
796 void buddy_setname(gpointer rosterdata, char *newname) | 770 void buddy_setname(gpointer rosterdata, char *newname) |