quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans

This commit is contained in:
Goffi 2015-02-23 18:04:16 +01:00
commit e541547e23

View file

@ -68,8 +68,8 @@ class QuickContactList(QuickWidget):
self.show_resources = False
self.show_status = False
# TODO: this may lead to two successive UI refresh and needs an optimization
self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self.showEmptyGroups)
self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self.showOfflineContacts)
self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups)
self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts)
def __contains__(self, entity):
"""Check if entity is in contact list
@ -268,9 +268,9 @@ class QuickContactList(QuickWidget):
def entityToShow(self, entity, check_resource=False):
"""Tell if the contact should be showed or hidden.
@param contact (jid.JID): jid of the contact
@param entity (jid.JID): jid of the contact
@param check_resource (bool): True if resource must be significant
@return: True if that contact should be showed in the list
@return (bool): True if that contact should be showed in the list
"""
show = self.getCache(entity, C.PRESENCE_SHOW)
@ -341,7 +341,10 @@ class QuickContactList(QuickWidget):
cache[C.CONTACT_RESOURCES].clear()
cache[C.CONTACT_MAIN_RESOURCE]= None
else:
del cache[C.CONTACT_RESOURCES][entity.resource]
try:
del cache[C.CONTACT_RESOURCES][entity.resource]
except KeyError:
log.error("Presence unavailable received for an unknown resource [{}]".format(entity))
if not cache[C.CONTACT_RESOURCES]:
cache[C.CONTACT_MAIN_RESOURCE] = None
else:
@ -377,15 +380,25 @@ class QuickContactList(QuickWidget):
self._alerts.add(entity)
self.update()
def _showOfflineContacts(self, show_str):
self.showOfflineContacts(C.bool(show_str))
def showOfflineContacts(self, show):
show = C.bool(show)
"""Tell if offline contacts should shown
@param show(bool): True if offline contacts should be shown
"""
assert isinstance(show, bool)
if self.show_disconnected == show:
return
self.show_disconnected = show
self.update()
def _showEmptyGroups(self, show_str):
self.showEmptyGroups(C.bool(show_str))
def showEmptyGroups(self, show):
show = C.bool(show)
assert isinstance(show, bool)
if self.show_empty_groups == show:
return
self.show_empty_groups = show