changeset 63c35c953516 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=63c35c953516
description: fix traceback when adding a new contact. Fixes #6054

diffstat:

 src/common/connection_handlers_events.py            |  97 +++++++++++++++++++++
 src/common/zeroconf/connection_handlers_zeroconf.py |   3 +
 src/dialogs.py                                      |  16 +-
 src/gui_interface.py                                |   3 +-
 src/session.py                                      |  25 +++--
 5 files changed, 124 insertions(+), 20 deletions(-)

diffs (240 lines):

diff -r 976186d6b39f -r 63c35c953516 src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Wed Dec 15 22:08:42 2010 +0100
+++ b/src/common/connection_handlers_events.py  Thu Dec 16 07:15:29 2010 +0100
@@ -1829,3 +1829,100 @@
             self.prompt = None
             self.prompt_jid = None
         return True
+
+class NotificationEvent(nec.NetworkIncomingEvent):
+    name = 'notification'
+    base_network_events = ['decrypted-message-received']
+
+    def detect_type(self):
+        if self.base_event.name == 'decrypted-message-received':
+            self.notif_type='msg'
+
+    def get_focused(self):
+        self.control_focused = False
+        if self.control:
+            parent_win = self.control.parent_win
+            if parent_win and self.control == parent_win.get_active_control() \
+            and parent_win.window.has_focus:
+                self.control_focused = True
+
+    def handle_incoming_msg_event(self, msg_obj):
+        self.control = msg_obj.session.control
+        self.get_focused()
+        if not self.control and not gajim.events.get_events(self.conn.name, \
+        self.control.jid, [msg_obj.mtype]):
+            self.first_unread = True
+
+        if msg_obj.mtype == 'pm':
+            nick = msg_obj.resource
+        else:
+            nick = gajim.get_name_from_jid(self.conn.name, msg_obj.jid)
+
+        if self.first_unread:
+            self.sound_event = 'first_message_received'
+        elif self.control_focused:
+            self.sound_event = 'next_message_received_focused'
+        else:
+            self.sound_event = 'next_message_received_unfocused'
+
+        if gajim.config.get('notification_preview_message'):
+            self.popup_text = msg_obj.msgtxt
+            if self.popup_text.startswith('/me ') or 
self.popup_text.startswith(
+            '/me\n'):
+                self.popup_text = '* ' + nick + self.popup_text[3:]
+            else:
+                # We don't want message preview, do_preview = False
+                self.popup_text = ''
+        if msg_obj.mtype == 'normal': # single message
+            self.popup_event_type = _('New Single Message')
+            self.popup_image = 'gajim-single_msg_recv'
+            self.popup_title = _('New Single Message from %(nickname)s') % \
+                {'nickname': nick}
+        elif msg_obj.mtype == 'pm':
+            self.popup_event_type = _('New Private Message')
+            self.popup_image = 'gajim-priv_msg_recv'
+            self.popup_title = _('New Private Message from group chat %s') % \
+                msg_obj.jid
+            if self.popup_text:
+                self.popup_text = _('%(nickname)s: %(message)s') % \
+                    {'nickname': nick, 'message': self.popup_text}
+            else:
+                self.popup_text = _('Messaged by %(nickname)s') % \
+                    {'nickname': nick}
+        else: # chat message
+            self.popup_event_type = _('New Message')
+            self.popup_image = 'gajim-chat_msg_recv'
+            self.popup_title = _('New Message from %(nickname)s') % \
+                {'nickname': nick}
+
+        self.popup_image = gtkgui_helpers.get_icon_path(self.popup_image, 48)
+
+    def handle_incoming_msg_event(self, msg_obj):
+        pass
+
+    def generate(self):
+        # what's needed to compute output
+        self.control = None
+        self.control_focused = False
+        self.first_unread = False
+
+        # For output
+        self.sound_event = ''
+        self.show_popup = False
+        self.popup_title = ''
+        self.popup_text = ''
+        self.popup_event_type = ''
+        self.popup_image = ''
+        self.open_chat = False
+        self.activate_urgency_hint = False
+        self.command_to_run = ''
+        self.show_in_notification_area = False
+        self.show_in_roster = False
+
+        self.detect_type()
+
+        if self.notif_type == 'msg':
+            self.handle_incoming_msg_event(self.base_event)
+        elif self.notif_type == 'pres':
+            self.handle_incoming_pres_event(self.base_event)
+        return True
diff -r 976186d6b39f -r 63c35c953516 
src/common/zeroconf/connection_handlers_zeroconf.py
--- a/src/common/zeroconf/connection_handlers_zeroconf.py       Wed Dec 15 
22:08:42 2010 +0100
+++ b/src/common/zeroconf/connection_handlers_zeroconf.py       Thu Dec 16 
07:15:29 2010 +0100
@@ -133,6 +133,9 @@
                 msg = session.decrypt_stanza(msg)
             except Exception:
                 self.dispatch('FAILED_DECRYPT', (frm, tim, session))
+                gajim.nec.push_incoming_event(FailedDecryptEvent(None,
+                    conn=self, msg_obj=obj))
+
 
         msgtxt = msg.getBody()
         subject = msg.getSubject() # if not there, it's None
diff -r 976186d6b39f -r 63c35c953516 src/dialogs.py
--- a/src/dialogs.py    Wed Dec 15 22:08:42 2010 +0100
+++ b/src/dialogs.py    Thu Dec 16 07:15:29 2010 +0100
@@ -1056,16 +1056,16 @@
             transport = self.protocol_jid_combobox.get_active_text().decode(
                 'utf-8')
             if self.account:
-                self.adding_jid = (jid, transport)
+                self.adding_jid = (jid, transport, type_)
                 gajim.connections[self.account].request_gateway_prompt(
                     transport, jid)
             else:
                 jid = jid.replace('@', '%') + '@' + transport
-                self._add_jid(jid)
+                self._add_jid(jid, type_)
         else:
-            self._add_jid(jid)
-
-    def _add_jid(self, jid):
+            self._add_jid(jid, type_)
+
+    def _add_jid(self, jid, type_):
         # check if jid is conform to RFC and stringprep it
         try:
             jid = helpers.parse_jid(jid)
@@ -1239,12 +1239,12 @@
 
     def _nec_gateway_prompt_received(self, obj):
         if self.adding_jid:
+            jid, transport, type_ = self.adding_jid
             if obj.prompt_jid:
-                self._add_jid(obj.prompt_jid)
+                self._add_jid(obj.prompt_jid, type_)
             else:
-                jid, transport = self.adding_jid
                 jid = jid.replace('@', '%') + '@' + transport
-                self._add_jid(jid)
+                self._add_jid(jid, type_)
         elif obj.jid in self.gateway_prompt:
             if obj.desc:
                 self.gateway_prompt[obj.jid]['desc'] = obj.desc
diff -r 976186d6b39f -r 63c35c953516 src/gui_interface.py
--- a/src/gui_interface.py      Wed Dec 15 22:08:42 2010 +0100
+++ b/src/gui_interface.py      Thu Dec 16 07:15:29 2010 +0100
@@ -305,7 +305,8 @@
             elif gc_control:
                 gc_control.print_conversation('Error %s: %s' % (obj.errcode,
                     obj.errmsg))
-            return
+            if gc_control and gc_control.autorejoin:
+                gc_control.autorejoin = False
 
     def handle_event_presence(self, obj):
         # 'NOTIFY' (account, (jid, status, status message, resource,
diff -r 976186d6b39f -r 63c35c953516 src/session.py
--- a/src/session.py    Wed Dec 15 22:08:42 2010 +0100
+++ b/src/session.py    Thu Dec 16 07:15:29 2010 +0100
@@ -106,14 +106,6 @@
             pm = True
             obj.mtype = 'pm'
 
-        highest_contact = gajim.contacts.get_contact_with_highest_priority(
-            self.conn.name, obj.jid)
-
-        # does this resource have the highest priority of any available?
-        is_highest = not highest_contact or not highest_contact.resource or \
-            obj.resource == highest_contact.resource or highest_contact.show 
==\
-            'offline'
-
         # Handle chat states
         contact = gajim.contacts.get_contact(self.conn.name, obj.jid,
             obj.resource)
@@ -142,13 +134,14 @@
         # THIS MUST BE AFTER chatstates handling
         # AND BEFORE playsound (else we ear sounding on chatstates!)
         if not obj.msgtxt: # empty message text
-            return
+            return True
 
         if gajim.config.get_per('accounts', self.conn.name,
         'ignore_unknown_contacts') and not gajim.contacts.get_contacts(
         self.conn.name, obj.jid) and not pm:
-            return
+            return True
 
+        #FIXME Remove after advanced_notif will be removed
         if not contact:
             # contact is not in the roster, create a fake one to display
             # notification
@@ -158,6 +151,14 @@
         advanced_notif_num = notify.get_advanced_notification(
             'message_received', self.conn.name, contact)
 
+        highest_contact = gajim.contacts.get_contact_with_highest_priority(
+            self.conn.name, obj.jid)
+
+        # does this resource have the highest priority of any available?
+        is_highest = not highest_contact or not highest_contact.resource or \
+            obj.resource == highest_contact.resource or highest_contact.show 
==\
+            'offline'
+
         if not pm and is_highest:
             jid_of_control = obj.jid
         else:
@@ -170,6 +171,7 @@
                 self.control = ctrl
                 self.control.set_session(self)
 
+        #TODO handled
         # Is it a first or next message received ?
         first = False
         if not self.control and not gajim.events.get_events(self.conn.name, \
@@ -201,8 +203,9 @@
         msg = obj.msgtxt
         if obj.subject:
             msg = _('Subject: %s') % obj.subject + '\n' + msg
+
+        #TODO handled
         focused = False
-
         if self.control:
             parent_win = self.control.parent_win
             if parent_win and self.control == parent_win.get_active_control() \
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to