primitivus: implement parameter "Show empty groups"
This commit is contained in:
parent
e554934f31
commit
c850615a2d
3 changed files with 50 additions and 17 deletions
|
|
@ -41,6 +41,9 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
self.alert_jid=set()
|
||||
self.show_status = False
|
||||
self.show_disconnected = False
|
||||
self.show_empty_groups = True
|
||||
# TODO: this may lead to two successive UI refresh and needs an optimization
|
||||
self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=host.profile, callback=self.showEmptyGroups)
|
||||
self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts)
|
||||
|
||||
#we now build the widget
|
||||
|
|
@ -141,13 +144,13 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
self.update()
|
||||
self._emit('click')
|
||||
|
||||
def __buildContact(self, content, param_contacts):
|
||||
def __buildContact(self, content, contacts):
|
||||
"""Add contact representation in widget list
|
||||
@param content: widget list, e.g. SimpleListWalker
|
||||
@param contacts: list of JID"""
|
||||
contacts = list(param_contacts)
|
||||
|
||||
widgets = [] #list of built widgets
|
||||
@param contacts (list): list of JID userhosts"""
|
||||
if not contacts:
|
||||
return
|
||||
widgets = [] # list of built widgets
|
||||
|
||||
for contact in contacts:
|
||||
if contact.startswith(C.PRIVATE_PREFIX):
|
||||
|
|
@ -155,28 +158,27 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
show_icon = ''
|
||||
status = ''
|
||||
else:
|
||||
jid=JID(contact)
|
||||
jid = JID(contact)
|
||||
name = self.getCache(jid, 'name')
|
||||
nick = self.getCache(jid, 'nick')
|
||||
status = self.getCache(jid, 'status')
|
||||
show = self.getCache(jid, 'show')
|
||||
if show == None:
|
||||
if show is None:
|
||||
show = "unavailable"
|
||||
if (not self.show_disconnected and show == "unavailable"
|
||||
and not contact in self.alert_jid and contact != self.selected):
|
||||
if not self.contactToShow(contact):
|
||||
continue
|
||||
show_icon, show_attr = C.PRESENCE.get(show, ('', 'default'))
|
||||
contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare)
|
||||
display = [ show_icon + " " , contact_disp]
|
||||
display = [show_icon + " ", contact_disp]
|
||||
if self.show_status:
|
||||
status_disp = ('status',"\n " + status) if status else ""
|
||||
status_disp = ('status', "\n " + status) if status else ""
|
||||
display.append(status_disp)
|
||||
header = '(*) ' if contact in self.alert_jid else ''
|
||||
widget = sat_widgets.SelectableText(display,
|
||||
selected = contact==self.selected,
|
||||
selected=contact == self.selected,
|
||||
header=header)
|
||||
widget.data = contact
|
||||
widget.comp = contact_disp[1].lower() #value to use for sorting
|
||||
widget.comp = contact_disp[1].lower() # value to use for sorting
|
||||
widgets.append(widget)
|
||||
|
||||
widgets.sort(key=lambda widget: widget.comp)
|
||||
|
|
@ -212,18 +214,37 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
content.append(urwid.Divider('='))
|
||||
|
||||
group_keys = self.groups.keys()
|
||||
group_keys.sort(key = lambda x: x.lower() if x else x)
|
||||
group_keys.sort(key=lambda x: x.lower() if x else x)
|
||||
for key in group_keys:
|
||||
unfolded = self.groups[key][0]
|
||||
if key!=None:
|
||||
contacts = list(self.groups[key][1])
|
||||
if key is not None and (self.nonEmptyGroup(contacts) or self.show_empty_groups):
|
||||
header = '[-]' if unfolded else '[+]'
|
||||
widget = sat_widgets.ClickableText(key,header=header+' ')
|
||||
widget = sat_widgets.ClickableText(key, header=header + ' ')
|
||||
content.append(widget)
|
||||
urwid.connect_signal(widget, 'click', self.__groupClicked)
|
||||
if unfolded:
|
||||
self.__buildContact(content, self.groups[key][1])
|
||||
self.__buildContact(content, contacts)
|
||||
return urwid.ListBox(content)
|
||||
|
||||
def contactToShow(self, contact):
|
||||
"""Tell if the contact should be showed or hidden.
|
||||
|
||||
@param contact (str): JID userhost of the contact
|
||||
@return: True if that contact should be showed in the list"""
|
||||
return self.getCache(JID(contact), 'show') != "unavailable" or self.show_disconnected or contact in self.alert_jid or contact == self.selected
|
||||
|
||||
def nonEmptyGroup(self, contacts):
|
||||
"""Tell if a contact group contains some contacts to show.
|
||||
|
||||
@param contacts (list[str]): list of JID userhosts
|
||||
@return: bool
|
||||
"""
|
||||
for contact in contacts:
|
||||
if self.contactToShow(contact):
|
||||
return True
|
||||
return False
|
||||
|
||||
def unselectAll(self):
|
||||
"""Unselect all contacts"""
|
||||
self.selected = None
|
||||
|
|
@ -326,3 +347,10 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
return
|
||||
self.show_disconnected = show
|
||||
self.update()
|
||||
|
||||
def showEmptyGroups(self, show):
|
||||
show = C.bool(show)
|
||||
if self.show_empty_groups == show:
|
||||
return
|
||||
self.show_empty_groups = show
|
||||
self.update()
|
||||
|
|
|
|||
|
|
@ -558,6 +558,8 @@ class QuickApp(object):
|
|||
self.profiles[profile]['watched'] = value.split()
|
||||
elif (namespace, name) == ('General', C.SHOW_OFFLINE_CONTACTS):
|
||||
self.contact_list.showOfflineContacts(C.bool(value))
|
||||
elif (namespace, name) == ('General', C.SHOW_EMPTY_GROUPS):
|
||||
self.contact_list.showEmptyGroups(C.bool(value))
|
||||
|
||||
def contactDeletedHandler(self, jid, profile):
|
||||
target = JID(jid)
|
||||
|
|
|
|||
|
|
@ -107,3 +107,6 @@ class QuickContactList(object):
|
|||
|
||||
def showOfflineContacts(self, show):
|
||||
pass
|
||||
|
||||
def showEmptyGroups(self, show):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue