# HG changeset patch # User Goffi # Date 1424711056 -3600 # Node ID 7c2289090b9bf2c8b2deaedfce50182854083b1a # Parent e9888db0eb0cda2c5feb26a8230d141050b18ab5 quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans diff -r e9888db0eb0c -r 7c2289090b9b frontends/src/quick_frontend/quick_contact_list.py --- a/frontends/src/quick_frontend/quick_contact_list.py Tue Feb 10 19:08:01 2015 +0100 +++ b/frontends/src/quick_frontend/quick_contact_list.py Mon Feb 23 18:04:16 2015 +0100 @@ -68,8 +68,8 @@ 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 @@ 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 @@ 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 @@ 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