changeset 1333:7c2289090b9b frontends_multi_profiles

quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:04:16 +0100
parents e9888db0eb0c
children 15e177584d82
files frontends/src/quick_frontend/quick_contact_list.py
diffstat 1 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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