diff frontends/src/primitivus/contact_list.py @ 502:debcf5dd404a

QuickFrontend, Primitivus, Wix: special entities management: - MUC rooms are special entities - Primitivus: special entities are shown at the top of the contacts list above a divider, presence updates are temporary ignored for them
author Goffi <goffi@goffi.org>
date Tue, 25 Sep 2012 23:10:22 +0200
parents e9634d2e7b38
children f98bef71a918
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Tue Sep 25 00:58:34 2012 +0200
+++ b/frontends/src/primitivus/contact_list.py	Tue Sep 25 23:10:22 2012 +0200
@@ -32,6 +32,7 @@
         self.host = host
         self.selected = None
         self.groups={}
+        self.special={}
         self.alert_jid=set()
         self.show_status = False
         self.show_disconnected = False
@@ -76,9 +77,12 @@
         """give focus to the first group or contact with the given name"""
         idx = 0
         for widget in self.frame.body.body:
-            if widget.getValue() == name:
-                self.frame.body.set_focus(idx)
-                return
+            try:
+                if widget.getValue() == name:
+                    self.frame.body.set_focus(idx)
+                    return
+            except AttributeError:
+                pass
             idx+=1
 
     def putAlert(self, jid):
@@ -141,9 +145,32 @@
             content.append(widget)
             urwid.connect_signal(widget, 'change', self.__contactClicked)
 
+    def __buildSpecials(self, content):
+        """Build the special entities"""
+        specials = self.special.keys()
+        specials.sort()
+        for special in specials:
+            jid=JID(special) 
+            name = self.getCache(jid, 'name')
+            nick = self.getCache(jid, 'nick')
+            special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short)
+            display = [ "  " , special_disp]
+            header = '(*) ' if special in self.alert_jid else ''
+            widget = sat_widgets.SelectableText(display,
+                                                selected = special==self.selected,
+                                                header=header)
+            widget.data = special
+            content.append(widget)
+            urwid.connect_signal(widget, 'change', self.__contactClicked)
+
     def __buildList(self):
         """Build the main contact list widget"""
         content = urwid.SimpleListWalker([])
+        
+        self.__buildSpecials(content)
+        if self.special:
+            content.append(urwid.Divider('='))
+
         group_keys = self.groups.keys()
         group_keys.sort(key = lambda x: x.lower() if x else x)
         for key in group_keys:
@@ -178,6 +205,8 @@
 
     def replace(self, jid, groups=None, attributes=None):
         """add a contact to the list if doesn't exist, else update it"""
+        if jid.short in self.special:
+            return
         if not groups:
             groups = [None]
         if not attributes:
@@ -216,3 +245,21 @@
         """add a contact to the list"""
         self.replace(jid,param_groups)
 
+    def setSpecial(self, special_jid, special_type):
+        """Set entity as a special
+        @param jid: jid of the entity
+        @param _type: special type (e.g.: "MUC")
+        """
+        self.special[special_jid.short] = special_type
+        if None in self.groups:
+            folded,group_jids = self.groups[None]
+            for group_jid in group_jids:
+                if JID(group_jid).short == special_jid.short:
+                    group_jids.remove(group_jid)
+                    break
+        self.update()
+
+    def updatePresence(self, jid, show, priority, statuses):
+        #XXX: for the moment, we ignore presence updates for special entities
+        if jid.short not in self.special:
+            QuickContactList.updatePresence(self, jid, show, priority, statuses)