diff frontends/src/primitivus/contact_list.py @ 2009:90134b2e3dc4

primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
author Goffi <goffi@goffi.org>
date Sun, 17 Jul 2016 17:32:46 +0200
parents a9908e751c42
children 20fb71b656e3
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Sun Jul 17 17:12:42 2016 +0200
+++ b/frontends/src/primitivus/contact_list.py	Sun Jul 17 17:32:46 2016 +0200
@@ -49,6 +49,8 @@
             urwid.connect_signal(self, 'click', on_click, user_data)
         if on_change:
             urwid.connect_signal(self, 'change', on_change, user_data)
+        self.host.addListener('notification', self.onNotification, [self.profile])
+        self.host.addListener('notificationsClear', self.onNotification, [self.profile])
 
     def update(self, entities=None, type_=None, profile=None):
         """Update display, keep focus"""
@@ -151,6 +153,14 @@
         self.host.modeHint(C.MODE_INSERTION)
         self._emit('click', entity)
 
+    def onNotification(self, entity, notif, profile):
+        notifs = self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)
+        if notifs:
+            self.title_dynamic = u"({})".format(len(notifs))
+        else:
+            self.title_dynamic = None
+        self.host.redraw()  # FIXME: should not be necessary
+
     # Methods to build the widget
 
     def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None):