From 27d85a0961f7aad312538213f68862e2db09726b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 3 Feb 2013 23:31:27 +0100 Subject: Fix the folding of contacts in multiple groups (add a defaultdict to keep the folded state in each group) --- src/contact.py | 13 ++++++++++--- src/roster.py | 2 +- src/tabs.py | 16 ++++++++++++++-- src/windows.py | 10 ++++++---- 4 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/contact.py b/src/contact.py index 62092057..d235fae2 100644 --- a/src/contact.py +++ b/src/contact.py @@ -15,6 +15,7 @@ log = logging.getLogger(__name__) from sleekxmpp import JID from common import safeJID +from collections import defaultdict class Resource(object): """ @@ -63,7 +64,7 @@ class Contact(object): item: a SleekXMPP RosterItem pointing to that contact """ self.__item = item - self.folded = True # Folded by default + self.folded_states = defaultdict(lambda: True) @property def groups(self): @@ -165,11 +166,17 @@ class Contact(object): return resources[-1] return None - def toggle_folded(self): + def folded(self, group_name='none'): + """ + Return the Folded state of a contact for this group + """ + return self.folded_states[group_name] + + def toggle_folded(self, group='none'): """ Fold if it's unfolded, and vice versa """ - self.folded = not self.folded + self.folded_states[group] = not self.folded_states[group] def __repr__(self): ret = '= 0: + row = self.roster_win.roster_cache[pos] + pos -= 1 + log.debug(row) + if isinstance(row, RosterGroup): + found_group = True + group = row.name + selected_row.toggle_folded(group) + return True return False def get_contact_version(self): diff --git a/src/windows.py b/src/windows.py index c2d4ab60..63e66cea 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1786,7 +1786,7 @@ class RosterWin(Win): if not show_offline and len(contact) == 0: continue # ignore offline contacts self.roster_cache.append(contact) - if not contact.folded: + if not contact.folded(group.name): for resource in contact.get_resources(): self.roster_cache.append(resource) @@ -1797,6 +1797,7 @@ class RosterWin(Win): self._win.move(0, 0) self.draw_roster_information(roster) y = 1 + group = "none" # draw the roster from the cache for item in self.roster_cache[self.start_pos-1:self.start_pos+self.height]: @@ -1807,8 +1808,9 @@ class RosterWin(Win): if isinstance(item, RosterGroup): self.draw_group(y, item, draw_selected) + group = item.name elif isinstance(item, Contact): - self.draw_contact_line(y, item, draw_selected) + self.draw_contact_line(y, item, draw_selected, group) elif isinstance(item, Resource): self.draw_resource_line(y, item, draw_selected) @@ -1859,7 +1861,7 @@ class RosterWin(Win): return name return name[:self.width - added - 1] + '…' - def draw_contact_line(self, y, contact, colored): + def draw_contact_line(self, y, contact, colored, group): """ Draw on a line all informations about one contact. This is basically the highest priority resource's informations @@ -1883,7 +1885,7 @@ class RosterWin(Win): self.addstr(' ') if resource: - self.addstr('[+] ' if contact.folded else '[-] ') + self.addstr('[+] ' if contact.folded(group) else '[-] ') added += 4 if contact.ask: added += 1 -- cgit v1.2.3