diff frontends/src/primitivus/contact_list.py @ 1229:03661d1b216a

primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
author souliane <souliane@mailoo.org>
date Mon, 06 Oct 2014 12:44:58 +0200
parents f36d7068a44b
children 3abc6563a0d2
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Mon Oct 06 12:22:14 2014 +0200
+++ b/frontends/src/primitivus/contact_list.py	Mon Oct 06 12:44:58 2014 +0200
@@ -24,7 +24,7 @@
 from sat_frontends.quick_frontend.quick_utils import unescapePrivate
 from sat_frontends.tools.jid import JID
 from sat_frontends.primitivus.status import StatusBar
-from sat_frontends.primitivus.constants import Const
+from sat_frontends.primitivus.constants import Const as C
 from sat_frontends.primitivus.keys import action_key_map as a_key
 from sat.core import log as logging
 log = logging.getLogger(__name__)
@@ -41,6 +41,7 @@
         self.alert_jid=set()
         self.show_status = False
         self.show_disconnected = False
+        self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts)
 
         #we now build the widget
         self.host.status_bar = StatusBar(host)
@@ -77,8 +78,7 @@
             self.show_status = not self.show_status
             self.update()
         elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts
-            self.show_disconnected = not self.show_disconnected
-            self.update()
+            self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.str(not self.show_disconnected), "General", profile_key=self.host.profile)
         return super(ContactList, self).keypress(size, key)
 
     def __contains__(self, jid):
@@ -100,7 +100,7 @@
                     # contact group
                     value = widget.getValue()
                 elif isinstance(widget, sat_widgets.SelectableText):
-                    if  widget.data.startswith(Const.PRIVATE_PREFIX):
+                    if  widget.data.startswith(C.PRIVATE_PREFIX):
                         # muc private dialog
                         value = widget.getValue()
                     else:
@@ -150,7 +150,7 @@
         widgets = [] #list of built widgets
 
         for contact in contacts:
-            if contact.startswith(Const.PRIVATE_PREFIX):
+            if contact.startswith(C.PRIVATE_PREFIX):
                 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact))
                 show_icon = ''
                 status = ''
@@ -165,7 +165,7 @@
                 if (not self.show_disconnected and show == "unavailable"
                     and not contact in self.alert_jid and contact != self.selected):
                     continue
-                show_icon, show_attr = Const.PRESENCE.get(show, ('', 'default'))
+                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]
             if self.show_status:
@@ -319,3 +319,10 @@
         #XXX: for the moment, we ignore presence updates for special entities
         if jid.bare not in self.specials:
             QuickContactList.updatePresence(self, jid, show, priority, statuses)
+
+    def showOfflineContacts(self, show):
+        show = C.bool(show)
+        if self.show_disconnected == show:
+            return
+        self.show_disconnected = show
+        self.update()