Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/roster.c @ 2291:0d350e979bde
Don't rebuild the buddylist multiple times before a screen refresh
author | franky |
---|---|
date | Tue, 01 Nov 2016 08:39:07 +0100 |
parents | ece02eb9c81d |
children | f181418db215 |
comparison
equal
deleted
inserted
replaced
2290:71ec41732035 | 2291:0d350e979bde |
---|---|
119 static guchar display_filter; | 119 static guchar display_filter; |
120 static GSList *groups; | 120 static GSList *groups; |
121 static GSList *unread_list; | 121 static GSList *unread_list; |
122 static GHashTable *unread_jids; | 122 static GHashTable *unread_jids; |
123 GList *buddylist; | 123 GList *buddylist; |
124 static gboolean _rebuild_buddylist = FALSE; | |
124 GList *current_buddy; | 125 GList *current_buddy; |
125 GList *alternate_buddy; | 126 GList *alternate_buddy; |
126 GList *last_activity_buddy; | 127 GList *last_activity_buddy; |
127 | 128 |
128 static roster roster_special; | 129 static roster roster_special; |
470 sl_group_listptr = &((roster*)(sl_group->data))->list; | 471 sl_group_listptr = &((roster*)(sl_group->data))->list; |
471 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); | 472 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); |
472 | 473 |
473 // We need to rebuild the list | 474 // We need to rebuild the list |
474 if (current_buddy) | 475 if (current_buddy) |
475 buddylist_build(); | 476 buddylist_defer_build(); |
476 // TODO What we could do, too, is to check if the deleted node is | 477 // TODO What we could do, too, is to check if the deleted node is |
477 // current_buddy, in which case we could move current_buddy to the | 478 // current_buddy, in which case we could move current_buddy to the |
478 // previous (or next) node. | 479 // previous (or next) node. |
479 } | 480 } |
480 | 481 |
516 if (groups) { | 517 if (groups) { |
517 g_slist_free(groups); | 518 g_slist_free(groups); |
518 groups = NULL; | 519 groups = NULL; |
519 // Update (i.e. free) buddylist | 520 // Update (i.e. free) buddylist |
520 if (buddylist) | 521 if (buddylist) |
521 buddylist_build(); | 522 buddylist_defer_build(); |
522 } | 523 } |
523 } | 524 } |
524 | 525 |
525 // roster_setstatus() | 526 // roster_setstatus() |
526 // Note: resname, role, affil and realjid are for room members only | 527 // Note: resname, role, affil and realjid are for room members only |
716 // Actually the "else" part is useless, because the group | 717 // Actually the "else" part is useless, because the group |
717 // ROSTER_FLAG_MSG should already be set... | 718 // ROSTER_FLAG_MSG should already be set... |
718 } | 719 } |
719 | 720 |
720 if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr))) | 721 if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr))) |
721 buddylist_build(); | 722 buddylist_defer_build(); |
722 | 723 |
723 roster_msg_setflag_return: | 724 roster_msg_setflag_return: |
724 if (unread_list_modified) { | 725 if (unread_list_modified) { |
725 hlog_save_state(); | 726 hlog_save_state(); |
726 roster_unread_check(); | 727 roster_unread_check(); |
947 guchar buddylist_get_filter(void) | 948 guchar buddylist_get_filter(void) |
948 { | 949 { |
949 return display_filter; | 950 return display_filter; |
950 } | 951 } |
951 | 952 |
953 void buddylist_defer_build(void) | |
954 { | |
955 _rebuild_buddylist = TRUE; | |
956 } | |
957 | |
952 // buddylist_build() | 958 // buddylist_build() |
953 // Creates the buddylist from the roster entries. | 959 // Creates the buddylist from the roster entries. |
954 void buddylist_build(void) | 960 void buddylist_build(void) |
955 { | 961 { |
956 GSList *sl_roster_elt = groups; | 962 GSList *sl_roster_elt = groups; |
957 roster *roster_elt; | 963 roster *roster_elt; |
958 roster *roster_current_buddy = NULL; | 964 roster *roster_current_buddy = NULL; |
959 roster *roster_alternate_buddy = NULL; | 965 roster *roster_alternate_buddy = NULL; |
960 roster *roster_last_activity_buddy = NULL; | 966 roster *roster_last_activity_buddy = NULL; |
961 int shrunk_group; | 967 int shrunk_group; |
968 | |
969 if (_rebuild_buddylist == FALSE) | |
970 return; | |
971 _rebuild_buddylist = FALSE; | |
962 | 972 |
963 // We need to remember which buddy is selected. | 973 // We need to remember which buddy is selected. |
964 if (current_buddy) | 974 if (current_buddy) |
965 roster_current_buddy = BUDDATA(current_buddy); | 975 roster_current_buddy = BUDDATA(current_buddy); |
966 current_buddy = NULL; | 976 current_buddy = NULL; |
1092 // Add the buddy to its new group | 1102 // Add the buddy to its new group |
1093 roster_usr->list = sl_newgroup; // (my_newgroup SList element) | 1103 roster_usr->list = sl_newgroup; // (my_newgroup SList element) |
1094 my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr, | 1104 my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr, |
1095 (GCompareFunc)&roster_compare_name); | 1105 (GCompareFunc)&roster_compare_name); |
1096 | 1106 |
1097 buddylist_build(); | 1107 buddylist_defer_build(); |
1098 } | 1108 } |
1099 | 1109 |
1100 void buddy_setname(gpointer rosterdata, char *newname) | 1110 void buddy_setname(gpointer rosterdata, char *newname) |
1101 { | 1111 { |
1102 roster *roster_usr = rosterdata; | 1112 roster *roster_usr = rosterdata; |
1116 | 1126 |
1117 // We need to resort the group list | 1127 // We need to resort the group list |
1118 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | 1128 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
1119 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); | 1129 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); |
1120 | 1130 |
1121 buddylist_build(); | 1131 buddylist_defer_build(); |
1122 } | 1132 } |
1123 | 1133 |
1124 const char *buddy_getname(gpointer rosterdata) | 1134 const char *buddy_getname(gpointer rosterdata) |
1125 { | 1135 { |
1126 roster *roster_usr = rosterdata; | 1136 roster *roster_usr = rosterdata; |
1550 GList *buddy_search_jid(const char *jid) | 1560 GList *buddy_search_jid(const char *jid) |
1551 { | 1561 { |
1552 GList *buddy; | 1562 GList *buddy; |
1553 roster *roster_usr; | 1563 roster *roster_usr; |
1554 | 1564 |
1565 buddylist_build(); | |
1555 if (!buddylist) return NULL; | 1566 if (!buddylist) return NULL; |
1556 | 1567 |
1557 for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { | 1568 for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { |
1558 roster_usr = (roster*)buddy->data; | 1569 roster_usr = (roster*)buddy->data; |
1559 if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) | 1570 if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) |
1568 // return NULL; | 1579 // return NULL; |
1569 GList *buddy_search(char *string) | 1580 GList *buddy_search(char *string) |
1570 { | 1581 { |
1571 GList *buddy = current_buddy; | 1582 GList *buddy = current_buddy; |
1572 roster *roster_usr; | 1583 roster *roster_usr; |
1584 buddylist_build(); | |
1573 if (!buddylist || !current_buddy) return NULL; | 1585 if (!buddylist || !current_buddy) return NULL; |
1574 for (;;) { | 1586 for (;;) { |
1575 gchar *jid_locale, *name_locale; | 1587 gchar *jid_locale, *name_locale; |
1576 char *found = NULL; | 1588 char *found = NULL; |
1577 | 1589 |