Mercurial > libervia-backend
changeset 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 | 8a749ec21c50 |
children | d2144d04065e |
files | frontends/src/primitivus/contact_list.py frontends/src/quick_frontend/quick_app.py |
diffstat | 2 files changed, 19 insertions(+), 3 deletions(-) [+] |
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):
--- a/frontends/src/quick_frontend/quick_app.py Sun Jul 17 17:12:42 2016 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Sun Jul 17 17:32:46 2016 +0200 @@ -607,18 +607,24 @@ def getNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE): """return notifications for given entity - @param entity(jid.JID, None): bare jid of the entity to check + @param entity(jid.JID, None, C.ENTITY_ALL): bare jid of the entity to check None to get general notifications + C.ENTITY_ALL to get all notifications @param type_(unicode, None): notification type to filter None to get all notifications @return (list[dict]): list of notifications """ notif_dict = self.profiles[profile].notifications + ret = [] + if entity == C.ENTITY_ALL: + for type_notifs in notif_dict.itervalues(): + for notifs_list in type_notifs.itervalues(): + ret.extend(notifs_list) + return ret key = '' if entity is None else entity.bare key_notifs = notif_dict.setdefault(key, {}) if type_ is not None: - return key_notifs.get(type_, []) - ret = [] + return key_notifs.get(type_, ret) for notifs_list in key_notifs.itervalues(): ret.extend(notifs_list) return ret