changeset 1336:2ecc07a8f91b frontends_multi_profiles

primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:04:25 +0100
parents 2c6c93438f74
children f29beedb33b0
files frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py
diffstat 2 files changed, 21 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Mon Feb 23 18:04:25 2015 +0100
+++ b/frontends/src/primitivus/primitivus	Mon Feb 23 18:04:25 2015 +0100
@@ -530,8 +530,8 @@
 
     def removeWindow(self):
         """Remove window showed on the right column"""
-        #TODO: to a better Window management than this crappy hack
-        assert(len(self.center_part.widget_list)<=2)
+        #TODO: better Window management than this hack
+        assert len(self.center_part.widget_list) <= 2
         wid_idx = len(self.center_part.widget_list)-1
         self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text(''))
         self.center_part.focus_position = 0
@@ -556,21 +556,6 @@
         self.selectWidget(chat_widget)
         self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET)
 
-    def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile):
-        QuickApp.newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile)
-
-        if not from_jid in self.contact_lists[profile] and from_jid.bare != self.profiles[profile].whoami.bare:
-            #XXX: needed to show entities which haven't sent any
-            #     presence information and which are not in roster
-            self.contact_lists[profile].setContact(from_jid)
-        visible = False
-        for widget in self.visible_widgets:
-            if isinstance(widget, Chat) and widget.manageMessage(from_jid, type_):
-                visible = True
-                break
-        if not visible:
-            self.contact_lists[profile].setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid)
-
     def _dialogOkCb(self, widget, data):
         self.removePopUp()
         answer_cb = data[0]
--- a/frontends/src/quick_frontend/quick_app.py	Mon Feb 23 18:04:25 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Mon Feb 23 18:04:25 2015 +0100
@@ -211,7 +211,7 @@
         self.registerSignal("connected")
         self.registerSignal("disconnected")
         self.registerSignal("newContact")
-        self.registerSignal("newMessage", self._newMessage)
+        self.registerSignal("newMessage")
         self.registerSignal("newAlert")
         self.registerSignal("presenceUpdate")
         self.registerSignal("subscribe")
@@ -406,24 +406,37 @@
         _groups = list(groups)
         self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
 
-    def _newMessage(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
+    def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
         from_jid = jid.JID(from_jid_s)
         to_jid = jid.JID(to_jid_s)
-        self.newMessageHandler(from_jid, to_jid, msg, type_, extra, profile)
-
-    def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile):
         from_me = from_jid.bare == self.profiles[profile].whoami.bare
         target = to_jid if from_me else from_jid
 
         chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE
+        contact_list = self.contact_lists[profile]
 
-        chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, profile=profile)
+        chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, on_new_widget=None, profile=profile)
 
         self.current_action_ids = set() # FIXME: to be removed
         self.current_action_ids_cb = {} # FIXME: to be removed
 
+        if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare:
+            #XXX: needed to show entities which haven't sent any
+            #     presence information and which are not in roster
+            contact_list.setContact(from_jid)
+
+        # we display the message in the widget
         chat_widget.newMessage(from_jid, target, msg, type_, extra, profile)
 
+        # ContactList alert
+        visible = False
+        for widget in self.visible_widgets:
+            if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_):
+                visible = True
+                break
+        if not visible:
+            contact_list.setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid)
+
     def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
         if callback is None:
             callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy