| 1209 | | |
| 1210 | | def get_otr_status(self): |
| 1211 | | if not self.session: |
| 1212 | | return 0 |
| 1213 | | |
| 1214 | | ctx = gajim.otr_module.otrl_context_find( |
| 1215 | | self.session.conn.otr_userstates, |
| 1216 | | self.contact.get_full_jid().encode(), |
| 1217 | | gajim.get_jid_from_account(self.account).encode(), |
| 1218 | | gajim.OTR_PROTO, 1, (gajim.otr_add_appdata, |
| 1219 | | self.account))[0] |
| 1220 | | |
| 1221 | | if ctx.msgstate == gajim.otr_module.OTRL_MSGSTATE_ENCRYPTED: |
| 1222 | | if ctx.active_fingerprint.trust: |
| 1223 | | return 2 |
| 1224 | | else: |
| 1225 | | return 1 |
| 1226 | | elif ctx.msgstate == gajim.otr_module.OTRL_MSGSTATE_FINISHED: |
| 1227 | | return 3 |
| 1228 | | return 0 |
| 1229 | | |
| 1230 | | def update_otr(self, print_status=False): |
| 1231 | | otr_status_text = '' |
| 1232 | | otr_status = self.get_otr_status() |
| 1233 | | authenticated = False |
| 1234 | | |
| 1235 | | if otr_status > 0: |
| 1236 | | enc_status = True |
| 1237 | | else: |
| 1238 | | enc_status = False |
| 1239 | | |
| 1240 | | if otr_status == 1: |
| 1241 | | otr_status_text = u'*unauthenticated* secure OTR ' + \ |
| 1242 | | u'connection' |
| 1243 | | elif otr_status == 2: |
| 1244 | | otr_status_text = u'authenticated secure OTR ' + \ |
| 1245 | | u'connection' |
| 1246 | | authenticated = True |
| 1247 | | elif otr_status == 3: |
| 1248 | | otr_status_text = u'finished OTR connection' |
| 1249 | | |
| 1250 | | self._show_lock_image(enc_status, u'OTR', enc_status, True, |
| 1251 | | authenticated) |
| 1252 | | if print_status and otr_status_text != '': |
| 1253 | | self.print_conversation_line(u'[OTR] %s' % \ |
| 1254 | | otr_status_text, 'status', '', None) |
| 1661 | | msg = _('The following message was ' + \ |
| 1662 | | 'NOT encrypted') |
| 1663 | | ChatControlBase.print_conversation_line( |
| 1664 | | self, msg, 'status', '', tim) |
| 1665 | | elif gajim.otr_module and self.get_otr_status() > 0: |
| 1666 | | # OTR |
| 1667 | | # TODO: This is not shown when the window |
| 1668 | | # isn't open - needs fixing! |
| 1669 | | if not encrypted and frm == '': |
| 1896 | | if gajim.otr_module: |
| 1897 | | otr_submenu.set_sensitive(True) |
| 1898 | | id = otr_settings_menuitem.connect('activate', |
| 1899 | | self._on_otr_settings_menuitem_activate) |
| 1900 | | self.handlers[id] = otr_settings_menuitem |
| 1901 | | id = start_otr_menuitem.connect('activate', |
| 1902 | | self._on_start_otr_menuitem_activate) |
| 1903 | | self.handlers[id] = start_otr_menuitem |
| 1904 | | id = end_otr_menuitem.connect('activate', |
| 1905 | | self._on_end_otr_menuitem_activate) |
| 1906 | | self.handlers[id] = end_otr_menuitem |
| 1907 | | id = smp_otr_menuitem.connect('activate', |
| 1908 | | self._on_smp_otr_menuitem_activate) |
| 1909 | | self.handlers[id] = smp_otr_menuitem |
| 1910 | | |
| 1911 | | ctx = gajim.otr_module.otrl_context_find(gajim.connections[self.account].otr_userstates, |
| 1912 | | self.contact.get_full_jid().encode(), |
| 1913 | | gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 1, |
| 1914 | | (gajim.otr_add_appdata, self.account))[0] |
| 1915 | | # can end only when PLAINTEXT |
| 1916 | | end_otr_menuitem.set_sensitive(ctx.msgstate != |
| 1917 | | gajim.otr_module.OTRL_MSGSTATE_PLAINTEXT) |
| 1918 | | # can SMP only when ENCRYPTED |
| 1919 | | smp_otr_menuitem.set_sensitive(ctx.msgstate == |
| 1920 | | gajim.otr_module.OTRL_MSGSTATE_ENCRYPTED) |
| 1921 | | |
| 2409 | | def _on_start_otr_menuitem_activate(self, widget): |
| 2410 | | # ?OTR? gets replaced with a better message internally in otrl_message_sending |
| 2411 | | MessageControl.send_message(self, u'?OTR?', type='chat') |
| 2412 | | def _on_end_otr_menuitem_activate(self, widget): |
| 2413 | | fjid = self.contact.get_full_jid() |
| 2414 | | gajim.otr_module.otrl_message_disconnect( |
| 2415 | | self.session.conn.otr_userstates, (gajim.otr_ui_ops, |
| 2416 | | {'account': self.account, 'urgent': True}), |
| 2417 | | gajim.get_jid_from_account(self.account).encode(), |
| 2418 | | gajim.OTR_PROTO, fjid.encode()) |
| 2419 | | gajim.otr_ui_ops.gajim_log(_('Private conversation with ' \ |
| 2420 | | '%s lost.') % fjid, self.account, fjid.encode()) |
| 2421 | | self.update_otr() |
| 2422 | | def _on_otr_settings_menuitem_activate(self, widget): |
| 2423 | | gajim.otr_windows.ContactOtrWindow(self.contact, self.account, self) |
| 2424 | | def _on_smp_otr_menuitem_activate(self, widget): |
| 2425 | | ctx = gajim.otr_module.otrl_context_find(gajim.connections[self.account].otr_userstates, |
| 2426 | | self.contact.get_full_jid().encode(), |
| 2427 | | gajim.get_jid_from_account(self.account).encode(), gajim.OTR_PROTO, 1, |
| 2428 | | (gajim.otr_add_appdata, self.account))[0] |
| 2429 | | ctx.app_data.show(False) |
| 2430 | | |