Changeset 9614

Show
Ignore:
Timestamp:
05/11/08 03:19:59 (3 months ago)
Author:
bct
Message:

merged in session_centric branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/chat_control.py

    r9607 r9614  
    77## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net> 
    88##                    Julien Pivotto <roidelapluie@gmail.com> 
    9 ##                    Stephan Erb <steve-e@h3c.de>  
     9##                    Stephan Erb <steve-e@h3c.de> 
    1010## 
    1111## This file is part of Gajim. 
     
    105105 
    106106        def draw_banner(self): 
    107                 '''Draw the fat line at the top of the window that  
    108                 houses the icon, jid, ...  
     107                '''Draw the fat line at the top of the window that 
     108                houses the icon, jid, ... 
    109109                ''' 
    110110                self.draw_banner_text() 
     
    134134                helpers.launch_browser_mailer('url', url) 
    135135 
    136         def __init__(self, type_id, parent_win, widget_name, contact, acct,  
     136        def __init__(self, type_id, parent_win, widget_name, contact, acct, 
    137137        resource = None): 
    138138                MessageControl.__init__(self, type_id, parent_win, widget_name, 
     
    239239                        gtk.DEST_DEFAULT_HIGHLIGHT, 
    240240                        self.dnd_list, gtk.gdk.ACTION_COPY) 
    241          
     241 
    242242                self.update_font() 
    243243 
     
    267267                                # iterating on a copy 
    268268                                for lang in dict(langs): 
    269                                         try:  
     269                                        try: 
    270270                                                spell.set_language(langs[lang]) 
    271271                                        except: 
     
    331331                menu.show_all() 
    332332 
    333         # moved from ChatControl  
     333        # moved from ChatControl 
    334334        def _on_banner_eventbox_button_press_event(self, widget, event): 
    335335                '''If right-clicked, show popup''' 
     
    363363                self.disconnect_style_event(self.banner_status_label) 
    364364                if bgcolor: 
    365                         banner_eventbox.modify_bg(gtk.STATE_NORMAL,  
     365                        banner_eventbox.modify_bg(gtk.STATE_NORMAL, 
    366366                                gtk.gdk.color_parse(bgcolor)) 
    367367                        default_bg = False 
     
    392392                        widget.disconnect(id) 
    393393                        del self.handlers[id] 
    394          
     394 
    395395        def connect_style_event(self, widget, set_fg = False, set_bg = False): 
    396396                self.disconnect_style_event(widget) 
     
    399399 
    400400        def _on_style_set_event(self, widget, style, *opts): 
    401                 '''set style of widget from style class *.Frame.Eventbox  
     401                '''set style of widget from style class *.Frame.Eventbox 
    402402                        opts[0] == True -> set fg color 
    403403                        opts[1] == True -> set bg color''' 
     
    565565                                else: # ENTER 
    566566                                        send_message = True 
    567                                  
     567 
    568568                        if gajim.connections[self.account].connected < 2: # we are not connected 
    569569                                dialogs.ErrorDialog(_('A connection is not available'), 
     
    645645                max_size = gajim.config.get('key_up_lines') 
    646646                if size >= max_size: 
    647                         for i in xrange(0, size - 1):  
     647                        for i in xrange(0, size - 1): 
    648648                                self.sent_history[i] = self.sent_history[i + 1] 
    649649                        self.sent_history[max_size - 1] = message 
     
    694694                                # we want to have save this message in events list 
    695695                                # other_tags_for_text == ['marked'] --> highlighted gc message 
    696                                 type_ = 'printed_' + self.type_id 
    697                                 event = 'message_received' 
    698696                                if gc_message: 
    699697                                        if 'marked' in other_tags_for_text: 
     
    702700                                                type_ = 'printed_gc_msg' 
    703701                                        event = 'gc_message_received' 
     702                                else: 
     703                                        type_ = 'printed_' + self.type_id 
     704                                        event = 'message_received' 
    704705                                show_in_roster = notify.get_show_in_roster(event, 
    705                                         self.account, self.contact
     706                                        self.account, self.contact, self.session
    706707                                show_in_systray = notify.get_show_in_systray(event, 
    707708                                        self.account, self.contact, type_) 
     709 
    708710                                event = gajim.events.create_event(type_, None, 
    709711                                        show_in_roster = show_in_roster, 
     
    723725                kind in ('incoming', 'incoming_queue'): 
    724726                        self.parent_win.redraw_tab(self) 
    725                         ctrl = gajim.interface.msg_win_mgr.get_control(full_jid, self.account) 
    726727                        if not self.parent_win.is_active(): 
    727                                 self.parent_win.show_title(True, ctrl) # Enabled Urgent hint 
     728                                self.parent_win.show_title(True, self) # Enabled Urgent hint 
    728729                        else: 
    729                                 self.parent_win.show_title(False, ctrl) # Disabled Urgent hint 
     730                                self.parent_win.show_title(False, self) # Disabled Urgent hint 
    730731 
    731732        def toggle_emoticons(self): 
     
    857858                # we don't want to always resize in height the message_textview 
    858859                # so we have minimum on conversation_textview's scrolled window 
    859                 # but we also want to avoid window resizing so if we reach that  
     860                # but we also want to avoid window resizing so if we reach that 
    860861                # minimum for conversation_textview and maximum for message_textview 
    861862                # we set to automatic the scrollbar policy 
     
    868869                                        # scroll only when scrollbar appear 
    869870                                        if policy != gtk.POLICY_AUTOMATIC: 
    870                                                 self.msg_scrolledwindow.set_property('vscrollbar-policy',  
     871                                                self.msg_scrolledwindow.set_property('vscrollbar-policy', 
    871872                                                        gtk.POLICY_AUTOMATIC) 
    872                                                 self.msg_scrolledwindow.set_property('height-request',  
     873                                                self.msg_scrolledwindow.set_property('height-request', 
    873874                                                        message_height + conversation_height - min_height) 
    874875                                                self.bring_scroll_to_end(msg_textview) 
    875876                        else: 
    876                                 self.msg_scrolledwindow.set_property('vscrollbar-policy',  
     877                                self.msg_scrolledwindow.set_property('vscrollbar-policy', 
    877878                                        gtk.POLICY_NEVER) 
    878879                                self.msg_scrolledwindow.set_property('height-request', -1) 
     
    884885                # if message we have in message_textview is too big 
    885886                if requisition.width > message_width: 
    886                         self.msg_scrolledwindow.set_property('hscrollbar-policy',  
     887                        self.msg_scrolledwindow.set_property('hscrollbar-policy', 
    887888                                gtk.POLICY_AUTOMATIC) 
    888889                else: 
    889                         self.msg_scrolledwindow.set_property('hscrollbar-policy',  
     890                        self.msg_scrolledwindow.set_property('hscrollbar-policy', 
    890891                                gtk.POLICY_NEVER) 
    891892 
     
    917918 
    918919                if not len(gajim.events.get_events(self.account, jid, types_list)): 
    919                         return  
     920                        return 
    920921                if not self.parent_win: 
    921922                        return 
     
    924925                self.parent_win.window.is_active(): 
    925926                        # we are at the end 
    926                         if not gajim.events.remove_events(self.account, self.get_full_jid(), 
    927                         types = types_list): 
     927                        if not self.session.remove_events(types_list): 
    928928                                # There were events to remove 
    929929                                self.redraw_after_event_removed(jid) 
    930930 
    931931        def redraw_after_event_removed(self, jid): 
    932                 ''' We just removed a 'printed_*' event, redraw contact in roster or  
     932                ''' We just removed a 'printed_*' event, redraw contact in roster or 
    933933                gc_roster and titles in roster and msg_win ''' 
    934934                self.parent_win.redraw_tab(self) 
     
    937937                if self.type_id == message_control.TYPE_PM: 
    938938                        room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) 
    939                         groupchat_control = gajim.interface.msg_win_mgr.get_control( 
     939                        groupchat_control = gajim.interface.msg_win_mgr.get_gc_control( 
    940940                                room_jid, self.account) 
    941941                        if room_jid in gajim.interface.minimized_controls[self.account]: 
     
    948948                                gajim.interface.roster.draw_contact(room_jid, self.account) 
    949949                        groupchat_control.draw_contact(nick) 
    950                         mw = gajim.interface.msg_win_mgr.get_window(room_jid, self.account) 
    951                         if mw: 
    952                                 mw.redraw_tab(groupchat_control) 
     950                        if groupchat_control.parent_win: 
     951                                groupchat_control.parent_win.redraw_tab(groupchat_control) 
    953952                else: 
    954953                        gajim.interface.roster.draw_contact(jid, self.account) 
     
    956955 
    957956        def sent_messages_scroll(self, direction, conv_buf): 
    958                 size = len(self.sent_history)  
     957                size = len(self.sent_history) 
    959958                if self.orig_msg is None: 
    960959                        # user was typing something and then went into history, so save 
     
    10541053                self.widget_set_visible(self.xml.get_widget('banner_eventbox'), 
    10551054                        gajim.config.get('hide_chat_banner')) 
    1056                  
     1055 
    10571056                # Add lock image to show chat encryption 
    10581057                self.lock_image = self.xml.get_widget('lock_image') 
     
    10811080                gajim.connections[self.account].is_zeroconf: 
    10821081                        convert_to_gc_button.set_sensitive(False) 
    1083                  
     1082 
    10841083                # keep timeout id and window obj for possible big avatar 
    10851084                # it is on enter-notify and leave-notify so no need to be per jid 
     
    11271126                        msg = _('GPG encryption enabled') 
    11281127                        ChatControlBase.print_conversation_line(self, msg, 'status', '', None) 
    1129                          
     1128 
    11301129                        if self.session: 
    11311130                                self.session.loggable = gajim.config.get('log_encrypted_sessions') 
    11321131                        self._show_lock_image(self.gpg_is_active, 'GPG', self.gpg_is_active, self.session and \ 
    11331132                                        self.session.is_loggable()) 
    1134                  
     1133 
    11351134                self.status_tooltip = gtk.Tooltips() 
    11361135 
     
    11551154                avatar_w = avatar_pixbuf.get_width() 
    11561155                avatar_h = avatar_pixbuf.get_height() 
    1157                  
     1156 
    11581157                scaled_buf = self.xml.get_widget('avatar_image').get_pixbuf() 
    11591158                scaled_buf_w = scaled_buf.get_width() 
    11601159                scaled_buf_h = scaled_buf.get_height() 
    1161                  
     1160 
    11621161                # do we have something bigger to show? 
    11631162                if avatar_w > scaled_buf_w or avatar_h > scaled_buf_h: 
     
    11651164                        self.show_bigger_avatar_timeout_id = gobject.timeout_add(500, 
    11661165                                self.show_bigger_avatar, widget) 
    1167                  
     1166 
    11681167        def on_avatar_eventbox_leave_notify_event(self, widget, event): 
    11691168                '''we left the eventbox area that holds the avatar img''' 
     
    11771176                        menu = gtk.Menu() 
    11781177                        menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) 
    1179                         id = menuitem.connect('activate',  
     1178                        id = menuitem.connect('activate', 
    11801179                                gtkgui_helpers.on_avatar_save_as_menuitem_activate, 
    11811180                                self.contact.jid, self.account, self.contact.get_shown_name() + \ 
     
    11841183                        menu.append(menuitem) 
    11851184                        menu.show_all() 
    1186                         menu.connect('selection-done', lambda w:w.destroy())    
     1185                        menu.connect('selection-done', lambda w:w.destroy()) 
    11871186                        # show the menu 
    11881187                        menu.show_all() 
     
    12691268 
    12701269        def draw_banner_text(self): 
    1271                 '''Draw the text in the fat line at the top of the window that  
    1272                 houses the name, jid.  
     1270                '''Draw the text in the fat line at the top of the window that 
     1271                houses the name, jid. 
    12731272                ''' 
    12741273                contact = self.contact 
     
    12771276                banner_name_label = self.xml.get_widget('banner_name_label') 
    12781277                banner_eventbox = self.xml.get_widget('banner_eventbox') 
    1279                  
     1278 
    12801279                name = contact.get_shown_name() 
    12811280                if self.resource: 
     
    13641363                        self.gpg_is_active = False 
    13651364                        msg = _('GPG encryption disabled') 
    1366                         ChatControlBase.print_conversation_line(self, msg, 'status', '', None)  
     1365                        ChatControlBase.print_conversation_line(self, msg, 'status', '', None) 
    13671366                        if self.session: 
    13681367                                self.session.loggable = True 
     
    13891388                gajim.config.set_per('contacts', self.contact.jid, 'gpg_enabled', 
    13901389                        self.gpg_is_active) 
    1391                  
     1390 
    13921391                self._show_lock_image(self.gpg_is_active, 'GPG', self.gpg_is_active, self.session and \ 
    13931392                                self.session.is_loggable()) 
    1394          
     1393 
    13951394        def _show_lock_image(self, visible, enc_type = '', enc_enabled = False, chat_logged = False): 
    1396                 '''Set lock icon visibiity and create tooltip'''  
     1395                '''Set lock icon visibiity and create tooltip''' 
    13971396                status_string = enc_enabled and 'is' or 'is NOT' 
    13981397                logged_string = chat_logged and 'will' or 'will NOT' 
     
    15501549                # True refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds! 
    15511550                self.reset_kbd_mouse_timeout_vars() 
    1552                 return True # loop forever              
     1551                return True # loop forever 
    15531552 
    15541553        def check_for_possible_inactive_chatstate(self, arg): 
     
    16021601                        ChatControlBase.print_conversation_line(self, msg, 'status', '', None) 
    16031602                self._show_lock_image(e2e_is_active, 'E2E', e2e_is_active, self.session and \ 
    1604                                 self.session.is_loggable())  
     1603                                self.session.is_loggable()) 
    16051604 
    16061605        def print_conversation(self, text, frm='', tim=None, encrypted=False, 
     
    16261625                                if not encrypted: 
    16271626                                        msg = _('The following message was NOT encrypted') 
    1628                                         ChatControlBase.print_conversation_line(self, msg,  
     1627                                        ChatControlBase.print_conversation_line(self, msg, 
    16291628                                                'status', '', tim) 
    16301629                        else: 
     
    16321631                                if encrypted and not self.gpg_is_active: 
    16331632                                        msg = _('The following message was encrypted') 
    1634                                         ChatControlBase.print_conversation_line(self, msg,  
     1633                                        ChatControlBase.print_conversation_line(self, msg, 
    16351634                                                'status', '', tim) 
    16361635                                        self._toggle_gpg() 
     
    16731672                        unread = '[' + unicode(num_unread) + ']' 
    16741673 
    1675                 # Draw tab label using chatstate  
     1674                # Draw tab label using chatstate 
    16761675                theme = gajim.config.get('roster_theme') 
    16771676                color = None 
     
    17011700                else: # active or not chatstate, get color from gtk 
    17021701                        color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE] 
    1703                  
     1702 
    17041703 
    17051704                name = self.contact.get_shown_name() 
     
    17201719                # Set tab image (always 16x16); unread messages show the 'event' image 
    17211720                tab_img = None 
    1722                  
     1721 
    17231722                if num_unread and gajim.config.get('show_unread_tab_icon'): 
    17241723                        img_16 = gajim.interface.roster.get_appropriate_state_images( 
     
    17611760                muc_icon = gtkgui_helpers.load_icon('muc_active') 
    17621761                if muc_icon: 
    1763                         convert_to_gc_menuitem.set_image(muc_icon)  
     1762                        convert_to_gc_menuitem.set_image(muc_icon) 
    17641763 
    17651764                ag = gtk.accel_groups_from_object(self.parent_win.window)[0] 
     
    17751774                contact = self.parent_win.get_active_contact() 
    17761775                jid = contact.jid 
    1777                  
     1776 
    17781777                # check if we support and use gpg 
    17791778                if not gajim.config.get_per('accounts', self.account, 'keyid') or\ 
     
    18151814 
    18161815                # connect signals 
    1817                 id = history_menuitem.connect('activate',  
     1816                id = history_menuitem.connect('activate', 
    18181817                        self._on_history_menuitem_activate) 
    18191818                self.handlers[id] = history_menuitem 
    1820                 id = send_file_menuitem.connect('activate',  
     1819                id = send_file_menuitem.connect('activate', 
    18211820                        self._on_send_file_menuitem_activate) 
    1822                 self.handlers[id] = send_file_menuitem  
     1821                self.handlers[id] = send_file_menuitem 
    18231822                id = add_to_roster_menuitem.connect('activate', 
    18241823                        self._on_add_to_roster_menuitem_activate) 
     
    18271826                        self._on_toggle_gpg_menuitem_activate) 
    18281827                self.handlers[id] = toggle_gpg_menuitem 
    1829                 id = toggle_e2e_menuitem.connect('activate',  
     1828                id = toggle_e2e_menuitem.connect('activate', 
    18301829                        self._on_toggle_e2e_menuitem_activate) 
    1831                 self.handlers[id] = toggle_e2e_menuitem  
    1832                 id = information_menuitem.connect('activate',  
     1830                self.handlers[id] = toggle_e2e_menuitem 
     1831                id = information_menuitem.connect('activate', 
    18331832                        self._on_contact_information_menuitem_activate) 
    18341833                self.handlers[id] = information_menuitem 
     
    18861885                # this function checks for that and just returns so it's safe to call it 
    18871886                # with same state. 
    1888                  
     1887 
    18891888                # This functions also checks for violation in state transitions 
    18901889                # and raises RuntimeException with appropriate message 
     
    19151914                        return 
    19161915 
    1917                 # if the new state we wanna send (state) equals  
     1916                # if the new state we wanna send (state) equals 
    19181917                # the current state (contact.our_chatstate) then return 
    19191918                if contact.our_chatstate == state: 
     
    19271926                        # for that procedure so return to make sure we send only once 
    19281927                        # 'active' until we know peer supports jep85 
    1929                         return  
     1928                        return 
    19301929 
    19311930                if contact.our_chatstate == 'ask': 
     
    19471946                        contact.our_chatstate = 'active' 
    19481947                        self.reset_kbd_mouse_timeout_vars() 
    1949                  
     1948 
    19501949                # if we're inactive prevent composing (JEP violation) 
    19511950                elif contact.our_chatstate == 'inactive' and state == 'composing': 
     
    19641963                # destroy banner tooltip - bug #pygtk for that! 
    19651964                self.status_tooltip.destroy() 
     1965 
    19661966                # Send 'gone' chatstate 
    19671967                self.send_chatstate('gone', self.contact) 
    19681968                self.contact.chatstate = None 
    19691969                self.contact.our_chatstate = None 
     1970 
     1971                # terminate session 
     1972                self.session.control = None 
     1973 
    19701974                # Disconnect timer callbacks 
    19711975                gobject.source_remove(self.possible_paused_timeout_id) 
     
    19871991 
    19881992        def allow_shutdown(self, method): 
     1993                print repr(self.get_full_jid()) 
     1994                print repr(gajim.last_message_time[self.account]) 
    19891995                if time.time() - gajim.last_message_time[self.account]\ 
    19901996                [self.get_full_jid()] < 2: 
     
    21742180                        self.print_esession_details() 
    21752181 
    2176                 # Is it a pm ? 
    2177                 is_pm = False 
    2178                 room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) 
    2179                 control = gajim.interface.msg_win_mgr.get_control(room_jid, self.account) 
    2180                 if control and control.type_id == message_control.TYPE_GC: 
    2181                         is_pm = True 
    21822182                # list of message ids which should be marked as read 
    21832183                message_ids = [] 
     
    22042204 
    22052205                typ = 'chat' # Is it a normal chat or a pm ? 
     2206 
    22062207                # reset to status image in gc if it is a pm 
    2207                 if is_pm: 
     2208                # Is it a pm ? 
     2209                room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) 
     2210                control = gajim.interface.msg_win_mgr.get_gc_control(room_jid, 
     2211                        self.account) 
     2212                if control and control.type_id == message_control.TYPE_GC: 
    22082213                        control.update_ui() 
    22092214                        control.parent_win.show_title() 
     
    22662271                if gtk.gtk_version >= (2, 10, 0) and gtk.pygtk_version >= (2, 10, 0): 
    22672272                        window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP) 
    2268                  
     2273 
    22692274                window.realize() 
    22702275                window.window.set_back_pixmap(pixmap, False) # make it transparent 
    22712276                window.window.shape_combine_mask(mask, 0, 0) 
    22722277 
    2273                 # make the bigger avatar window show up centered  
     2278                # make the bigger avatar window show up centered 
    22742279                x0, y0 = small_avatar.window.get_origin() 
    22752280                x0 += small_avatar.allocation.x 
     
    22772282                center_x= x0 + (small_avatar.allocation.width / 2) 
    22782283                center_y = y0 + (small_avatar.allocation.height / 2) 
    2279                 pos_x, pos_y = center_x - (avatar_w / 2), center_y - (avatar_h / 2)  
     2284                pos_x, pos_y = center_x - (avatar_w / 2), center_y - (avatar_h / 2) 
    22802285                window.move(pos_x, pos_y) 
    22812286                # make the cursor invisible so we can see the image 
     
    23082313                else: 
    23092314                        c = self.contact 
    2310                 gajim.interface.instances['file_transfers'].show_file_send_request(  
     2315                gajim.interface.instances['file_transfers'].show_file_send_request( 
    23112316                        self.account, c) 
    23122317 
     
    23182323 
    23192324        def _on_toggle_gpg_menuitem_activate(self, widget): 
    2320                 self._toggle_gpg()      
     2325                self._toggle_gpg() 
    23212326 
    23222327        def _on_convert_to_gc_menuitem_activate(self, widget): 
  • trunk/src/common/connection_handlers.py

    r9607 r9614  
    5050        from music_track_listener import MusicTrackListener 
    5151 
    52 from common.stanza_session import EncryptedStanzaSession  
     52from session import ChatControlSession 
     53import tictactoe 
    5354 
    5455STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', 
     
    995996 
    996997                self.awaiting_answers[id] = (VCARD_PUBLISHED, iq2) 
    997          
     998 
    998999        def _IqCB(self, con, iq_obj): 
    9991000                id = iq_obj.getID() 
     
    10471048                        if iq_obj.getType() == 'error' and jid == our_jid: 
    10481049                                # our server doesn't support vcard 
     1050                                gajim.log.debug('xxx error xxx') 
    10491051                                self.vcard_supported = False 
    10501052                        if not iq_obj.getTag('vCard') or iq_obj.getType() == 'error': 
     
    12621264 
    12631265                        con.send(reply) 
    1264                  
     1266 
    12651267                raise common.xmpp.NodeProcessed 
    12661268 
     
    12921294                errcode = iq_obj.getErrorCode() 
    12931295                self.dispatch('ERROR_ANSWER', (id, jid_from, errmsg, errcode)) 
    1294          
     1296 
    12951297        def _PrivateCB(self, con, iq_obj): 
    12961298                ''' 
     
    15001502        def _messageCB(self, con, msg): 
    15011503                '''Called when we receive a message''' 
     1504                gajim.log.debug('MessageCB') 
     1505 
    15021506                frm = helpers.get_full_jid_from_iq(msg) 
    15031507                mtype = msg.getType() 
     
    15071511                        mtype = 'normal' 
    15081512 
    1509                 if not mtype == 'groupchat': 
    1510                         session = self.get_session(frm, thread_id, mtype) 
     1513                game_invite = msg.getTag('invite', namespace='http://jabber.org/protocol/games') 
     1514                if game_invite: 
     1515                        game = game_invite.getTag('game') 
     1516 
     1517                        if game.getAttr('var') == \ 
     1518                        'http://jabber.org/protocol/games/tictactoe': 
     1519                                klass = tictactoe.TicTacToeSession 
     1520 
     1521                        # this assumes that the invitation came with a thread_id we haven't 
     1522                        # seen 
     1523                        session = self.make_new_session(frm, thread_id, klass=klass) 
     1524 
     1525                        session.invited(msg) 
     1526 
     1527                        return 
     1528                elif mtype != 'groupchat': 
     1529                        session = self.get_or_create_session(frm, thread_id) 
    15111530 
    15121531                        if thread_id and not session.received_thread_id: 
     
    15171536                        self._pubsubEventCB(con, msg) 
    15181537                        return 
    1519                 # check if the message is a xep70-confirmation-request 
    1520                 if msg.getTag('confirm') and msg.getTag('confirm').namespace == \ 
    1521                 common.xmpp.NS_HTTP_AUTH
     1538 
     1539                # check if the message is a XEP-0070 confirmation request 
     1540                if msg.getTag('confirm', namespace=common.xmpp.NS_HTTP_AUTH)
    15221541                        self._HttpAuthCB(con, msg) 
    15231542                        return 
    1524                 if msg.getTag('feature') and msg.getTag('feature').namespace == \ 
    1525                 common.xmpp.NS_FEATURE: 
     1543 
     1544                # check if the message is a XEP-0020 feature negotiation request 
     1545                if msg.getTag('feature', namespace=common.xmpp.NS_FEATURE): 
    15261546                        if gajim.HAVE_PYCRYPTO: 
    15271547                                self._FeatureNegCB(con, msg, session) 
    15281548                        return 
    1529                 if msg.getTag('init') and msg.getTag('init').namespace == \ 
    1530                 common.xmpp.NS_ESESSION_INIT: 
     1549                if msg.getTag('init', namespace=common.xmpp.NS_ESESSION_INIT): 
    15311550                        self._InitE2ECB(con, msg, session) 
    1532                  
     1551 
    15331552                encrypted = False 
    15341553                tim = msg.getTimestamp() 
     
    15361555                tim = localtime(timegm(tim)) 
    15371556 
    1538                 e2e_tag = msg.getTag('c', namespace = common.xmpp.NS_STANZA_CRYPTO) 
    1539                 if e2e_tag: 
     1557                if msg.getTag('c', namespace=common.xmpp.NS_STANZA_CRYPTO): 
    15401558                        encrypted = True 
    15411559 
     
    15431561                                msg = session.decrypt_stanza(msg) 
    15441562                        except: 
    1545                                 self.dispatch('FAILED_DECRYPT', (frm, tim)) 
     1563                                self.dispatch('FAILED_DECRYPT', (frm, tim, session)) 
    15461564 
    15471565                msgtxt = msg.getBody() 
    1548                 msghtml = msg.getXHTML() 
    15491566                subject = msg.getSubject() # if not there, it's None 
    1550                 tim = msg.getTimestamp() 
    1551                 tim = helpers.datetime_tuple(tim) 
    1552                 tim = localtime(timegm(tim)) 
     1567 
    15531568                frm = helpers.get_full_jid_from_iq(msg) 
    15541569                jid = helpers.get_jid_from_iq(msg) 
     1570 
    15551571                addressTag = msg.getTag('addresses', namespace = common.xmpp.NS_ADDRESS) 
     1572 
    15561573                # Be sure it comes from one of our resource, else ignore address element 
    15571574                if addressTag and jid == gajim.get_jid_from_account(self.name): 
     
    15601577                                frm = address.getAttr('jid') 
    15611578                                jid = gajim.get_jid_without_resource(frm) 
    1562                 no_log_for = gajim.config.get_per('accounts', self.name, 
    1563                         'no_log_for') 
    1564                 if not no_log_for: 
    1565                         no_log_for = '' 
    1566                 no_log_for = no_log_for.split() 
    1567                 chatstate = None 
    1568                 encTag = msg.getTag('x', namespace = common.xmpp.NS_ENCRYPTED) 
    1569                 decmsg = '' 
     1579 
    15701580                # invitations 
    15711581                invite = None 
     1582                encTag = msg.getTag('x', namespace=common.xmpp.NS_ENCRYPTED) 
     1583 
    15721584                if not encTag: 
    15731585                        invite = msg.getTag('x', namespace = common.xmpp.NS_MUC_USER) 
    15741586                        if invite and not invite.getTag('invite'): 
    15751587                                invite = None 
    1576                 delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) is not None 
    1577                 msg_id = None 
    1578                 composing_xep = None 
     1588 
    15791589                # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED 
    15801590                # invitation 
     
    15901600                                        is_continued)) 
    15911601                                return 
    1592                 form_node = None 
    1593                 for xtag in xtags: 
    1594                         if xtag.getNamespace() == common.xmpp.NS_DATA: 
    1595                                 form_node = xtag 
    1596                                 break 
    1597                 # chatstates - look for chatstate tags in a message if not delayed 
    1598                 if not delayed: 
    1599                         composing_xep = False 
    1600                         children = msg.getChildren() 
    1601                         for child in children: 
    1602                                 if child.getNamespace() == 'http://jabber.org/protocol/chatstates': 
    1603                                         chatstate = child.getName() 
    1604                                         composing_xep = 'XEP-0085' 
    1605                                         break 
    1606                         # No XEP-0085 support, fallback to XEP-0022 
    1607                         if not chatstate: 
    1608                                 chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) 
    1609                                 if chatstate_child: 
    1610                                         chatstate = 'active' 
    1611                                         composing_xep = 'XEP-0022' 
    1612                                         if not msgtxt and chatstate_child.getTag('composing'): 
    1613                                                 chatstate = 'composing' 
    1614                 # XEP-0172 User Nickname 
    1615                 user_nick = msg.getTagData('nick') 
    1616                 if not user_nick: 
    1617                         user_nick = '' 
    16181602 
    16191603                if encTag and self.USE_GPG: 
    1620                         #decrypt 
    16211604                        encmsg = encTag.getData() 
    16221605 
     
    16251608                                decmsg = self.gpg.decrypt(encmsg, keyID) 
    16261609                                # \x00 chars are not allowed in C (so in GTK) 
    1627                                 decmsg = decmsg.replace('\x00', '') 
    1628                 if decmsg: 
    1629                         msgtxt = decmsg 
    1630                         encrypted = True 
     1610                                msgtxt = decmsg.replace('\x00', '') 
     1611                                encrypted = True 
    16311612                if mtype == 'error': 
    1632                         error_msg = msg.getErrorMsg() 
    1633                         if not error_msg: 
    1634                                 error_msg = msgtxt 
    1635                                 msgtxt = None 
    1636                         if session.is_loggable(): 
    1637                                 try: 
    1638                                         gajim.logger.write('error', frm, error_msg, tim = tim, 
    1639                                                 subject = subject) 
    1640                                 except exceptions.PysqliteOperationalError, e: 
    1641                                         self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
    1642                         self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt, 
    1643                                 tim)) 
    1644                         return 
     1613                        self.dispatch_error_message(msg, msgtxt, session, frm, tim, subject) 
    16451614                elif mtype == 'groupchat': 
    1646                         has_timestamp = False 
    1647                         if msg.timestamp: 
    1648                                 has_timestamp = True 
    1649                         if subject is not None: 
    1650                                 self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) 
     1615                        self.dispatch_gc_message(msg, subject, frm, msgtxt, jid, tim) 
     1616        &