Yann Leboulanger pushed to branch gajim_0.16 at gajim / gajim

Commits:

3 changed files:

Changes:

  • src/common/connection_handlers_events.py
    ... ... @@ -1657,6 +1657,20 @@ class AnonymousAuthEvent(nec.NetworkIncomingEvent):
    1657 1657
        name = 'anonymous-auth'
    
    1658 1658
        base_network_events = []
    
    1659 1659
    
    
    1660
    class JingleSessionInitiateSendingEvent(nec.NetworkOutgoingEvent, HelperEvent):
    
    1661
        name = 'jingle-session-initiate-sending'
    
    1662
        base_network_events = []
    
    1663
    
    
    1664
        def init(self):
    
    1665
            self.jingle_content = None
    
    1666
            self.FT_content = None
    
    1667
    
    
    1668
        def generate(self):
    
    1669
            self.get_id()
    
    1670
            self.fjid = self.conn._ft_get_from(self.stanza)
    
    1671
            self.jid = gajim.get_jid_without_resource(self.fjid)
    
    1672
            return True
    
    1673
    
    
    1660 1674
    class JingleRequestReceivedEvent(nec.NetworkIncomingEvent):
    
    1661 1675
        name = 'jingle-request-received'
    
    1662 1676
        base_network_events = []
    

  • src/common/jingle_ft.py
    ... ... @@ -31,7 +31,8 @@ from common.jingle_ftstates import StateCandReceived, JingleTransportSocks5, \
    31 31
    from common.jingle_transport import TransportType
    
    32 32
    from jingle_content import contents, JingleContent
    
    33 33
    from common import helpers
    
    34
    from common.connection_handlers_events import FileRequestReceivedEvent
    
    34
    from common.connection_handlers_events import FileRequestReceivedEvent, \
    
    35
        JingleSessionInitiateSendingEvent
    
    35 36
    import threading
    
    36 37
    import logging
    
    37 38
    
    
    ... ... @@ -140,7 +141,10 @@ class JingleFileTransfer(JingleContent):
    140 141
                self.session.accept_session()
    
    141 142
    
    
    142 143
        def __on_session_initiate_sent(self, stanza, content, error, action):
    
    143
            pass
    
    144
            log.debug("Jingle FT session initiate sending")
    
    145
            gajim.nec.push_outgoing_event(JingleSessionInitiateSendingEvent(None,
    
    146
                conn=self.session.connection, stanza=stanza, jingle_content=content,
    
    147
                FT_content=self))
    
    144 148
    
    
    145 149
        def __send_hash(self):
    
    146 150
            # Send hash in a session info
    

  • src/gui_interface.py
    ... ... @@ -970,32 +970,32 @@ class Interface:
    970 970
            session = gajim.connections[account].get_jingle_session(jid=None,
    
    971 971
                sid=file_props.sid)
    
    972 972
            ft_win = self.instances['file_transfers']
    
    973
            if not file_props.hash_:
    
    974
                # We disn't get the hash, sender probably don't support that
    
    975
                jid = unicode(file_props.sender)
    
    976
                self.popup_ft_result(account, jid, file_props)
    
    977
                ft_win.set_status(file_props, 'ok')
    
    978 973
            h = Hashes()
    
    974
            hash_ = None
    
    979 975
            try:
    
    980 976
                file_ = open(file_props.file_name, 'rb')
    
    977
                hash_ = h.calculateHash(file_props.algo, file_)
    
    978
                file_.close()
    
    981 979
            except:
    
    982
                return
    
    983
            hash_ = h.calculateHash(file_props.algo, file_)
    
    984
            file_.close()
    
    980
                pass
    
    985 981
            # If the hash we received and the hash of the file are the same,
    
    986 982
            # then the file is not corrupt
    
    987 983
            jid = unicode(file_props.sender)
    
    988
            if file_props.hash_ == hash_:
    
    984
            if hash_ and file_props.hash_ == hash_:
    
    989 985
                gobject.idle_add(self.popup_ft_result, account, jid, file_props)
    
    990 986
                gobject.idle_add(ft_win.set_status, file_props, 'ok')
    
    987
                # End jingle session
    
    988
                if session:
    
    989
                    session.end_session()
    
    991 990
            else:
    
    992 991
                # wrong hash, we need to get the file again!
    
    993 992
                file_props.error = -10
    
    994 993
                gobject.idle_add(self.popup_ft_result, account, jid, file_props)
    
    995 994
                gobject.idle_add(ft_win.set_status, file_props, 'hash_error')
    
    996
            # End jingle session
    
    997
            if session:
    
    998
                session.end_session()
    
    995
                # End jingle session
    
    996
                # TODO: send media-error
    
    997
                if session:
    
    998
                    session.end_session()
    
    999 999
    
    
    1000 1000
        def handle_event_file_rcv_completed(self, account, file_props):
    
    1001 1001
            ft = self.instances['file_transfers']
    
    ... ... @@ -1009,14 +1009,25 @@ class Interface:
    1009 1009
            if file_props.stalled or file_props.paused:
    
    1010 1010
                return
    
    1011 1011
    
    
    1012
            if file_props.type_ == 'r' and file_props.hash_: # we receive a file
    
    1012
            if file_props.type_ == 'r': # we receive a file
    
    1013 1013
                gajim.socks5queue.remove_receiver(file_props.sid, True, True)
    
    1014
                # we compare hashes
    
    1015 1014
                if file_props.session_type == 'jingle':
    
    1016
                    # Compare hashes in a new thread
    
    1017
                    self.hashThread = Thread(target=self.__compare_hashes,
    
    1018
                        args=(account, file_props))
    
    1019
                    self.hashThread.start()
    
    1015
                    if file_props.hash_:
    
    1016
                        # We compare hashes in a new thread
    
    1017
                        self.hashThread = Thread(target=self.__compare_hashes,
    
    1018
                            args=(account, file_props))
    
    1019
                        self.hashThread.start()
    
    1020
                    else:
    
    1021
                        # We disn't get the hash, sender probably don't support that
    
    1022
                        jid = unicode(file_props.sender)
    
    1023
                        self.popup_ft_result(account, jid, file_props)
    
    1024
                        ft.set_status(file_props, 'ok')
    
    1025
                        session = gajim.connections[account].get_jingle_session(jid=None,
    
    1026
                            sid=file_props.sid)
    
    1027
                        # End jingle session
    
    1028
                        # TODO: only if there are no other parallel downloads in this session
    
    1029
                        if session:
    
    1030
                            session.end_session()
    
    1020 1031
            else: # we send a file
    
    1021 1032
                jid = unicode(file_props.receiver)
    
    1022 1033
                gajim.socks5queue.remove_sender(file_props.sid, True, True)