diff frontends/src/primitivus/primitivus @ 1972:02d21a589be2

quick_frontend, primitivus: notifications refactoring replaced old "alerts" system by a more generic one which use listeners and can activate callbacks on notification click.
author Goffi <goffi@goffi.org>
date Mon, 27 Jun 2016 22:36:22 +0200
parents 9421e721d5e2
children da6d1988dfcb
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Mon Jun 27 21:45:13 2016 +0200
+++ b/frontends/src/primitivus/primitivus	Mon Jun 27 22:36:22 2016 +0200
@@ -586,11 +586,24 @@
         else:
             self.notif_bar.addPopUp(pop_up_widget)
 
-    def notify(self, message):
+    def barNotify(self, message):
         """"Notify message to user via notification bar"""
         self.notif_bar.addMessage(message)
         self.redraw()
 
+    def notify(self, type_, entity=None, message=None, subject=None, callback=None, cb_args=None, widget=None, profile=C.PROF_KEY_NONE):
+        if widget is None or widget is not None and widget != self.selected_widget:
+            # we ignore notification if the widget is selected but we can
+            # still do a desktop notification is the X window has not the focus
+            super(PrimitivusApp, self).notify(type_, entity, message, subject, callback, cb_args, widget, profile)
+        if not self.x_notify.hasFocus():
+            if message is None:
+                message = _("{app}: a new event has just happened{entity}").format(
+                    app=C.APP_NAME,
+                    entity=u' ({})'.format(entity) if entity else '')
+            self.x_notify.sendNotification(message)
+
+
     def newWidget(self, widget):
         if self.selected_widget is None:
             self.selectWidget(widget)
@@ -651,6 +664,7 @@
             # we have clicked on a private MUC conversation
             chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, force_hash = Chat.getPrivateHash(contact_list.profile, entity), profile=contact_list.profile)
         else:
+            self.clearNotifs(entity, profile=contact_list.profile)
             chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, profile=contact_list.profile)
         self.selectWidget(chat_widget)
         self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET)