primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
This commit is contained in:
parent
8c9161bc87
commit
73a8db4e64
2 changed files with 19 additions and 3 deletions
|
|
@ -49,6 +49,8 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
||||||
urwid.connect_signal(self, 'click', on_click, user_data)
|
urwid.connect_signal(self, 'click', on_click, user_data)
|
||||||
if on_change:
|
if on_change:
|
||||||
urwid.connect_signal(self, 'change', on_change, user_data)
|
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):
|
def update(self, entities=None, type_=None, profile=None):
|
||||||
"""Update display, keep focus"""
|
"""Update display, keep focus"""
|
||||||
|
|
@ -151,6 +153,14 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
||||||
self.host.modeHint(C.MODE_INSERTION)
|
self.host.modeHint(C.MODE_INSERTION)
|
||||||
self._emit('click', entity)
|
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
|
# 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):
|
def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None):
|
||||||
|
|
|
||||||
|
|
@ -607,18 +607,24 @@ class QuickApp(object):
|
||||||
def getNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
|
def getNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
|
||||||
"""return notifications for given entity
|
"""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
|
None to get general notifications
|
||||||
|
C.ENTITY_ALL to get all notifications
|
||||||
@param type_(unicode, None): notification type to filter
|
@param type_(unicode, None): notification type to filter
|
||||||
None to get all notifications
|
None to get all notifications
|
||||||
@return (list[dict]): list of notifications
|
@return (list[dict]): list of notifications
|
||||||
"""
|
"""
|
||||||
notif_dict = self.profiles[profile].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 = '' if entity is None else entity.bare
|
||||||
key_notifs = notif_dict.setdefault(key, {})
|
key_notifs = notif_dict.setdefault(key, {})
|
||||||
if type_ is not None:
|
if type_ is not None:
|
||||||
return key_notifs.get(type_, [])
|
return key_notifs.get(type_, ret)
|
||||||
ret = []
|
|
||||||
for notifs_list in key_notifs.itervalues():
|
for notifs_list in key_notifs.itervalues():
|
||||||
ret.extend(notifs_list)
|
ret.extend(notifs_list)
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue