summaryrefslogtreecommitdiff
path: root/src/windows.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-05-11 20:51:11 +0200
committermathieui <mathieui@mathieui.net>2013-05-11 20:51:11 +0200
commita1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4 (patch)
treee4c44c7e373101336d3ca04f8bcf882d3a3814f7 /src/windows.py
parentcb61d5efaa5c500a376bbbbfee3e0b1381f73c93 (diff)
downloadpoezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.gz
poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.bz2
poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.xz
poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.zip
Handle the roster order cache as a real cache
When an external (or internal) event may cause the order of the cache to be modified, or new elements to be added, schedule it for a rebuild. Otherwise, don’t, and only rebuild it when refreshing (that should improve refresh speed a lot). Also, if the position in the roster is further than the total size of the roster, go back to the top instead of displaying an empty window with “+++”.
Diffstat (limited to 'src/windows.py')
-rw-r--r--src/windows.py53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/windows.py b/src/windows.py
index 49e76ff5..0040ee0c 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -1830,34 +1830,43 @@ class RosterWin(Win):
self.start_pos = 1
return self.start_pos != pos
+ def build_roster_cache(self, roster):
+ """
+ Regenerates the roster cache if needed
+ """
+ with g_lock:
+ if roster.needs_rebuild:
+ log.debug('The roster has changed, rebuilding the cache…')
+ show_offline = config.get('roster_show_offline', 'false') == 'true'
+ sort = config.get('roster_sort', 'jid:show') or 'jid:show'
+ group_sort = config.get('roster_group_sort', 'name') or 'name'
+ self.roster_cache = []
+ # build the cache
+ for group in roster.get_groups(group_sort):
+ contacts_filtered = group.get_contacts(roster.contact_filter)
+ if (not show_offline and group.get_nb_connected_contacts() == 0) or not contacts_filtered:
+ continue # Ignore empty groups
+ self.roster_cache.append(group)
+ if group.folded:
+ continue # ignore folded groups
+ for contact in group.get_contacts(roster.contact_filter, sort):
+ if not show_offline and len(contact) == 0:
+ continue # ignore offline contacts
+ self.roster_cache.append(contact)
+ if not contact.folded(group.name):
+ for resource in contact.get_resources():
+ self.roster_cache.append(resource)
+
def refresh(self, roster):
"""
- We get the roster object
+ We display a number of lines from the roster cache
+ (and rebuild it if needed)
"""
log.debug('Refresh: %s',self.__class__.__name__)
- self.roster_cache = []
- show_offline = config.get('roster_show_offline', 'false') == 'true'
- sort = config.get('roster_sort', 'jid:show') or 'jid:show'
- group_sort = config.get('roster_group_sort', 'name') or 'name'
- # build the cache
- for group in roster.get_groups(group_sort):
- contacts_filtered = group.get_contacts(roster.contact_filter)
- if (not show_offline and group.get_nb_connected_contacts() == 0) or not contacts_filtered:
- continue # Ignore empty groups
- self.roster_cache.append(group)
- if group.folded:
- continue # ignore folded groups
- for contact in group.get_contacts(roster.contact_filter, sort):
- if not show_offline and len(contact) == 0:
- continue # ignore offline contacts
- self.roster_cache.append(contact)
- if not contact.folded(group.name):
- for resource in contact.get_resources():
- self.roster_cache.append(resource)
-
+ self.build_roster_cache(roster)
with g_lock:
self.roster_len = len(roster);
- self.move_cursor_up(self.roster_len - self.pos if self.pos >= self.roster_len else 0)
+ self.move_cursor_up(self.roster_len + self.pos if self.pos >= self.roster_len else 0)
self._win.erase()
self._win.move(0, 0)
self.draw_roster_information(roster)