summaryrefslogtreecommitdiff
path: root/src/roster.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-06-13 01:00:53 +0200
committermathieui <mathieui@mathieui.net>2013-06-13 01:00:53 +0200
commit833faa4f370f26f2b2296114da27473d2cb6bfb5 (patch)
tree882c3aa12cc95e9f2b7afa04a0b26da121b02c9e /src/roster.py
parent2b4c06b6f81f46e9f712882877fdd261aae84065 (diff)
downloadpoezio-833faa4f370f26f2b2296114da27473d2cb6bfb5.tar.gz
poezio-833faa4f370f26f2b2296114da27473d2cb6bfb5.tar.bz2
poezio-833faa4f370f26f2b2296114da27473d2cb6bfb5.tar.xz
poezio-833faa4f370f26f2b2296114da27473d2cb6bfb5.zip
Improve the roster search
- now case-insensitive - search in the bare jid instead of userpart only (and still in roster names) - do not display groups when searching - display offline contacts - do not expand resources if they were before the search
Diffstat (limited to 'src/roster.py')
-rw-r--r--src/roster.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/roster.py b/src/roster.py
index 5ddbdbb2..8c1b8f3e 100644
--- a/src/roster.py
+++ b/src/roster.py
@@ -115,8 +115,6 @@ class Roster(object):
key=lambda x: x.name.lower() if x.name else ''
)
- log.debug("Current groups: %s", group_list)
-
for sorting in sort.split(':'):
if sorting == 'reverse':
group_list = list(reversed(group_list))
@@ -145,6 +143,28 @@ class Roster(object):
"""
return [self[jid] for jid in self.jids()]
+ def get_contacts_sorted_filtered(self, sort=''):
+ """
+ Return a list of all the contacts sorted with a criteria
+ """
+ contact_list = []
+ for contact in self.get_contacts():
+ if contact.bare_jid != self.jid:
+ if self.contact_filter:
+ if self.contact_filter[0](contact, self.contact_filter[1]):
+ contact_list.append(contact)
+ else:
+ contact_list.append(contact)
+ contact_list = sorted(contact_list, key=SORTING_METHODS['name'])
+
+ for sorting in sort.split(':'):
+ if sorting == 'reverse':
+ contact_list = list(reversed(contact_list))
+ else:
+ method = SORTING_METHODS.get(sorting, lambda x: 0)
+ contact_list = sorted(contact_list, key=method)
+ return contact_list
+
def save_to_config_file(self):
"""
Save various information to the config file
@@ -184,28 +204,11 @@ class Roster(object):
def __len__(self):
"""
- Return the number of line that would be printed
- for the whole roster
+ Return the number of contacts
+ (used to return the display size, but now we have
+ the display cache in RosterWin for that)
"""
- length = 0
- show_offline = config.get('roster_show_offline', 'false') == 'true'
- for group in self.groups.values():
- if not show_offline and group.get_nb_connected_contacts() == 0:
- continue
- before = length
- if not group.name in self.folded_groups:
- for contact in group.get_contacts(self.contact_filter):
- # We do not count the offline contacts (depending on config)
- if not show_offline and\
- len(contact) == 0:
- continue
- length += 1 # One for the contact's line
- 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:
- length += 1 # One for the group's line itself if needed
- return length
+ return len(self.contacts)
def __repr__(self):
ret = '== Roster:\nContacts:\n'