summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/contact.py13
-rw-r--r--src/roster.py2
-rw-r--r--src/tabs.py16
-rw-r--r--src/windows.py10
4 files changed, 31 insertions, 10 deletions
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 = '<Contact: %s' % self.bare_jid
diff --git a/src/roster.py b/src/roster.py
index a3741f82..67e81da9 100644
--- a/src/roster.py
+++ b/src/roster.py
@@ -188,7 +188,7 @@ class Roster(object):
len(contact) == 0:
continue
length += 1 # One for the contact's line
- if not contact.folded:
+ if not contact.folded(group.name):
# One for each resource, if the contact is unfolded
length += len(contact)
if not self.contact_filter or before != length:
diff --git a/src/tabs.py b/src/tabs.py
index 609c57c0..a74dcd69 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -2777,10 +2777,22 @@ class RosterInfoTab(Tab):
if isinstance(self.input, windows.Input):
return
selected_row = self.roster_win.get_selected_row()
- if isinstance(selected_row, RosterGroup) or\
- isinstance(selected_row, Contact):
+ if isinstance(selected_row, RosterGroup):
selected_row.toggle_folded()
return True
+ elif isinstance(selected_row, Contact):
+ group = "none"
+ found_group = False
+ pos = self.roster_win.pos
+ while not found_group and pos >= 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