diff frontends/src/primitivus/contact_list.py @ 497:50dd2a0196c0

primitivus: contacts list improvments: - icon and color are used to show availability (away, do not disturb, etc) - status are shown with meta-s (hidden by default)
author Goffi <goffi@goffi.org>
date Tue, 04 Sep 2012 01:15:19 +0200
parents 2a072735e459
children 28f4ce741ae5
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Tue Sep 04 01:12:52 2012 +0200
+++ b/frontends/src/primitivus/contact_list.py	Tue Sep 04 01:15:19 2012 +0200
@@ -33,6 +33,7 @@
         self.selected = None
         self.groups={}
         self.alert_jid=set()
+        self.show_status = False
         
         #we now build the widget
         self.frame = urwid.Frame(self.__buildList())
@@ -44,6 +45,13 @@
             urwid.connect_signal(self, 'change', on_change, user_data)
         QuickContactList.__init__(self, CM)
 
+    def keypress(self, size, key):
+        if key == "meta s": #user wants to (un)hide contacts' statuses
+            self.show_status = not self.show_status
+            self.frame.body = self.__buildList()
+            self.host.redraw()
+        return super(ContactList, self).keypress(size, key) 
+    
     def __contains__(self, jid):
         for group in self.groups:
             if jid.short in self.groups[group][1]:
@@ -93,10 +101,21 @@
             jid=JID(contact) 
             name = self.CM.getAttr(jid,'name')
             nick = self.CM.getAttr(jid,'nick')
-            display = nick or name or jid.node or jid.short
+            status = self.CM.getAttr(jid, 'status')
+            show = self.CM.getAttr(jid, 'show')
+            show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
+            contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short)
+            display = [ show_icon + " " , contact_disp]
+            display_selected = [ show_icon + " " , "[ %s ]" % contact_disp[1]]
+            if self.show_status:
+                status_disp = ('status',"\n" + status) if status else ""
+                display.append(status_disp)
+                display_selected.append(status_disp)
             header = '(*) ' if contact in self.alert_jid else ''
-            widget = sat_widgets.SelectableText(('alert' if contact in self.alert_jid else 'default',display),
-                                                    selected = contact==self.selected, header=header)
+            widget = sat_widgets.SelectableText(display,
+                                                selected_text = display_selected,
+                                                selected = contact==self.selected,
+                                                header=header)
             widget.data = contact
             content.append(widget)
             urwid.connect_signal(widget, 'change', self.__contactClicked)