Show
Ignore:
Timestamp:
05/09/08 14:35:25 (4 months ago)
Author:
js
Message:

Added OTR support.
Work done by Kjell Braden <fnord@…>.
Some fixes done by me.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chat_control.py

    r9601 r9602  
    11771177 
    11781178        def update_ui(self): 
     1179                if gajim.otr_module: 
     1180                        self.update_otr(True) 
    11791181                # The name banner is drawn here 
    11801182                ChatControlBase.update_ui(self) 
     1183 
     1184        def update_otr(self, print_status=False): 
     1185                # retrieve the OTR context from the chat's contact data 
     1186                ctx = gajim.otr_module.otrl_context_find(gajim.otr_userstates[self.account], 
     1187                        self.contact.get_full_jid().encode(), 
     1188                        gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 1, 
     1189                        (gajim.otr_add_appdata, self.account))[0] 
     1190                 
     1191                enc_status = False 
     1192                otr_status_text = "" 
     1193                if ctx.msgstate == gajim.otr_module.OTRL_MSGSTATE_ENCRYPTED: 
     1194                        enc_status = True 
     1195                        if ctx.active_fingerprint.trust: 
     1196                                otr_status_text = u"authenticated secure OTR connection" 
     1197                        else: 
     1198                                otr_status_text = u'*unauthenticated* secure OTR connection' 
     1199                elif ctx.msgstate == gajim.otr_module.OTRL_MSGSTATE_FINISHED: 
     1200                        enc_status = True 
     1201                        otr_status_text = u"finished OTR connection" 
     1202                else: 
     1203                        # nothing to print 
     1204                        print_status = False 
     1205                self._show_lock_image(enc_status, u'OTR', enc_status, True) 
     1206                if print_status: 
     1207                        self.print_conversation_line(u" [OTR] %s"%otr_status_text, 'status', 
     1208                                        '', None) 
    11811209 
    11821210        def _update_banner_state_image(self): 
     
    16971725                toggle_gpg_menuitem = xml.get_widget('toggle_gpg_menuitem') 
    16981726                toggle_e2e_menuitem = xml.get_widget('toggle_e2e_menuitem') 
     1727                otr_submenu = xml.get_widget('otr_submenu') 
     1728                otr_settings_menuitem = xml.get_widget('otr_settings_menuitem') 
     1729                smp_otr_menuitem = xml.get_widget('smp_otr_menuitem') 
     1730                start_otr_menuitem = xml.get_widget('start_otr_menuitem') 
     1731                end_otr_menuitem = xml.get_widget('end_otr_menuitem') 
    16991732                add_to_roster_menuitem = xml.get_widget('add_to_roster_menuitem') 
    17001733                send_file_menuitem = xml.get_widget('send_file_menuitem') 
     
    17821815                        self._on_convert_to_gc_menuitem_activate) 
    17831816                self.handlers[id] = convert_to_gc_menuitem 
     1817 
     1818                if gajim.otr_module: 
     1819                        otr_submenu.show() 
     1820                        id = otr_settings_menuitem.connect('activate', 
     1821                                self._on_otr_settings_menuitem_activate) 
     1822                        self.handlers[id] = otr_settings_menuitem 
     1823                        id = start_otr_menuitem.connect('activate', 
     1824                                self._on_start_otr_menuitem_activate) 
     1825                        self.handlers[id] = start_otr_menuitem 
     1826                        id = end_otr_menuitem.connect('activate', 
     1827                                self._on_end_otr_menuitem_activate) 
     1828                        self.handlers[id] = end_otr_menuitem 
     1829                        id = smp_otr_menuitem.connect('activate', 
     1830                                self._on_smp_otr_menuitem_activate) 
     1831                        self.handlers[id] = smp_otr_menuitem 
     1832 
     1833                        ctx = gajim.otr_module.otrl_context_find(gajim.otr_userstates[self.account], 
     1834                                self.contact.get_full_jid().encode(), 
     1835                                gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 1, 
     1836                                (gajim.otr_add_appdata, self.account))[0] 
     1837                        # can end only when PLAINTEXT 
     1838                        end_otr_menuitem.set_sensitive(ctx.msgstate != 
     1839                                gajim.otr_module.OTRL_MSGSTATE_PLAINTEXT) 
     1840                        # can SMP only when ENCRYPTED 
     1841                        smp_otr_menuitem.set_sensitive(ctx.msgstate == 
     1842                                gajim.otr_module.OTRL_MSGSTATE_ENCRYPTED) 
     1843 
    17841844                menu.connect('selection-done', self.destroy_menu, history_menuitem, 
    17851845                        information_menuitem) 
     
    22602320                        self.session.negotiate_e2e(False) 
    22612321 
     2322        def _on_start_otr_menuitem_activate(self, widget): 
     2323                # ?OTR? gets replaced with a better message internally in otrl_message_sending 
     2324                MessageControl.send_message(self, u"?OTR?", type="chat") 
     2325        def _on_end_otr_menuitem_activate(self, widget): 
     2326                fjid = self.contact.get_full_jid() 
     2327                gajim.otr_module.otrl_message_disconnect(gajim.otr_userstates[self.account], 
     2328                                (gajim.otr_ui_ops, {'account':self.account,'urgent':True}), 
     2329                                gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 
     2330                                fjid.encode()) 
     2331                gajim.otr_ui_ops.gajim_log("Private conversation with %s lost."%fjid, 
     2332                                self.account, fjid.encode()) 
     2333                self.update_ui() 
     2334        def _on_otr_settings_menuitem_activate(self, widget): 
     2335                gajim.otr_windows.ContactOtrWindow(self.contact, self.account, self) 
     2336        def _on_smp_otr_menuitem_activate(self, widget): 
     2337                ctx = gajim.otr_module.otrl_context_find(gajim.otr_userstates[self.account], 
     2338                        self.contact.get_full_jid().encode(), 
     2339                        gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 1, 
     2340                        (gajim.otr_add_appdata, self.account))[0] 
     2341                ctx.app_data.show(False) 
     2342 
    22622343        def got_connected(self): 
    22632344                ChatControlBase.got_connected(self)