674 } |
674 } |
675 |
675 |
676 // buddy_setgroup() |
676 // buddy_setgroup() |
677 // Change the group of current buddy |
677 // Change the group of current buddy |
678 // |
678 // |
679 // Warning! This function changes current_buddy! |
679 // Warning! This function changes the specified buddy! |
680 // Warning! Old buddy is deleted, so you can't acces to its jid/name after |
680 // Warning! Old buddy is deleted, so you can't access to its jid/name after |
681 // calling this function. |
681 // calling this function (they are free'd). |
682 void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
682 void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
683 { |
683 { |
684 roster *roster_usr = rosterdata; |
684 roster *roster_usr = rosterdata; |
685 GSList **sl_group; |
685 GSList **sl_group; |
686 GSList *sl_clone; |
686 GSList *sl_clone; |
687 roster *roster_clone; |
687 roster *roster_clone; |
688 int is_alternate; |
|
689 |
688 |
690 // A group has no group :) |
689 // A group has no group :) |
691 if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
690 if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
692 |
691 |
693 // Remove the buddy from current group |
692 // Remove the buddy from current group |
707 if (roster_usr->name) g_free((gchar*)roster_usr->name); |
706 if (roster_usr->name) g_free((gchar*)roster_usr->name); |
708 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); |
707 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); |
709 free_all_resources(&roster_usr->resource); |
708 free_all_resources(&roster_usr->resource); |
710 g_free(roster_usr); |
709 g_free(roster_usr); |
711 |
710 |
712 // If new new group is folded, the curren_buddy will be lost, and the |
|
713 // chat window won't be correctly refreshed. So we make sure it isn't... |
|
714 ((roster*)((GSList*)roster_clone->list)->data)->flags &= ~ROSTER_FLAG_HIDE; |
|
715 |
|
716 // Little trick to have current_body pointing to the cloned buddy |
|
717 is_alternate = (alternate_buddy == current_buddy); |
|
718 buddylist = g_list_append(buddylist, roster_clone); |
711 buddylist = g_list_append(buddylist, roster_clone); |
719 current_buddy = g_list_find(buddylist, roster_clone); |
712 // We must have current_buddy pointing to the cloned buddy, if this is |
720 if (is_alternate) |
713 // the one we have moved. Same for alternate_buddy. |
721 alternate_buddy = current_buddy; |
714 if (rosterdata == BUDDATA(current_buddy)) { |
|
715 current_buddy = g_list_find(buddylist, roster_clone); |
|
716 // If new new group is folded, the current_buddy will be lost, and the |
|
717 // chat window won't be correctly refreshed. So we make sure it isn't... |
|
718 ((roster*)((GSList*)roster_clone->list)->data)->flags &= ~ROSTER_FLAG_HIDE; |
|
719 } |
|
720 if (alternate_buddy && BUDDATA(alternate_buddy) == rosterdata) |
|
721 alternate_buddy = g_list_find(buddylist, roster_clone); |
722 |
722 |
723 buddylist_build(); |
723 buddylist_build(); |
724 } |
724 } |
725 |
725 |
726 void buddy_setname(gpointer rosterdata, char *newname) |
726 void buddy_setname(gpointer rosterdata, char *newname) |