| | 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) |
| | 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 | |
| | 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 | |