comparison src/browser/sat_browser/plugin_sec_otr.py @ 678:2e087e093e7f frontends_multi_profiles

browser side(otr): restored menu hooks using new hook system
author Goffi <goffi@goffi.org>
date Tue, 17 Mar 2015 22:20:36 +0100
parents 849ffb24d5bf
children 3b185ccb70b4
comparison
equal deleted inserted replaced
677:44df078187b9 678:2e087e093e7f
37 import chat 37 import chat
38 38
39 39
40 NS_OTR = "otr_plugin" 40 NS_OTR = "otr_plugin"
41 PRIVATE_KEY = "PRIVATE KEY" 41 PRIVATE_KEY = "PRIVATE KEY"
42 MAIN_MENU = D_('OTR encryption') 42 MAIN_MENU = D_('OTR') # TODO: get this constant directly from backend's plugin
43 DIALOG_EOL = "<br />" 43 DIALOG_EOL = "<br />"
44 44
45 AUTH_TRUSTED = D_("Verified") 45 AUTH_TRUSTED = D_("Verified")
46 AUTH_UNTRUSTED = D_("Unverified") 46 AUTH_UNTRUSTED = D_("Unverified")
47 AUTH_OTHER_TITLE = D_("Authentication of {jid}") 47 AUTH_OTHER_TITLE = D_("Authentication of {jid}")
394 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) 394 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
395 self._profilePluggedListener = self.profilePluggedListener 395 self._profilePluggedListener = self.profilePluggedListener
396 self._gotMenusListener = self.gotMenusListener 396 self._gotMenusListener = self.gotMenusListener
397 # FIXME: these listeners are never removed, can't be removed by themselves (it modifies the list while looping), maybe need a 'one_shot' argument 397 # FIXME: these listeners are never removed, can't be removed by themselves (it modifies the list while looping), maybe need a 'one_shot' argument
398 self.host.addListener('profilePlugged', self._profilePluggedListener) 398 self.host.addListener('profilePlugged', self._profilePluggedListener)
399 # self.host.addListener('gotMenus', self._gotMenusListener) 399 self.host.addListener('gotMenus', self._gotMenusListener)
400 400
401 @classmethod 401 @classmethod
402 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): 402 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''):
403 """Get the widget info text for a certain message state and trust. 403 """Get the widget info text for a certain message state and trust.
404 404
419 if otrctx is None: 419 if otrctx is None:
420 return OTR.getInfoText() 420 return OTR.getInfoText()
421 else: 421 else:
422 return OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust()) 422 return OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust())
423 423
424 def gotMenusListener(self, menus, profile): 424 def gotMenusListener(self,):
425 menus_to_delete = [] 425 # TODO: get menus paths to hook directly from backend's OTR plugin
426 for menu in menus: 426 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Start/Refresh")), callback=self._startRefresh)
427 id_, type_, path, path_i18n = menu 427 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"End session")), callback=self._endSession)
428 if path[0] == 'OTR': 428 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Authenticate")), callback=self._authenticate)
429 menus_to_delete.append(menu) 429 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Drop private key")), callback=self._dropPrivkey)
430 for menu in menus_to_delete:
431 menus.remove(menu)
432 # FIXME: handle help strings too
433 menus.extend([(self._startRefresh, C.MENU_SINGLE, (MAIN_MENU, "Start / refresh"), (MAIN_MENU, D_("Start / refresh"))),
434 (self._endSession, C.MENU_SINGLE, (MAIN_MENU, "Stop encryption"), (MAIN_MENU, D_("Stop encryption"))),
435 (self._authenticate, C.MENU_SINGLE, (MAIN_MENU, "Authenticate correspondent"), (MAIN_MENU, D_("Authenticate correspondent"))),
436 (self._dropPrivkey, C.MENU_SINGLE, (MAIN_MENU, "Drop your private key"), (MAIN_MENU, D_("Drop your private key"))),
437 ])
438 430
439 def profilePluggedListener(self, profile): 431 def profilePluggedListener(self, profile):
440 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) 432 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
441 self._presenceListener = self.presenceListener 433 self._presenceListener = self.presenceListener
442 self._disconnectListener = self.disconnectListener 434 self._disconnectListener = self.disconnectListener
526 else: 518 else:
527 otrctx.finish() 519 otrctx.finish()
528 520
529 # Menu callbacks 521 # Menu callbacks
530 522
531 def _startRefresh(self, menu_data): 523 def _startRefresh(self, caller, menu_data, profile):
532 """Start or refresh an OTR session 524 """Start or refresh an OTR session
533 525
534 @param menu_data: %(menu_data)s 526 @param menu_data: %(menu_data)s
535 """ 527 """
536 def query(other_jid): 528 def query(other_jid):
537 otrctx = self.context_manager.getContextForUser(other_jid) 529 otrctx = self.context_manager.getContextForUser(other_jid)
538 if otrctx: 530 if otrctx:
539 otrctx.sendQueryMessage() 531 otrctx.sendQueryMessage()
540 532
541 other_jid = menu_data['jid'] 533 other_jid = jid.JID(menu_data['jid'])
542 clist = self.host.contact_list 534 clist = self.host.contact_list
543 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None: 535 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None:
544 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show() 536 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show()
545 return 537 return
546 538
552 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM 544 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM
553 dialog.ConfirmDialog(confirm, msg.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() 545 dialog.ConfirmDialog(confirm, msg.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show()
554 else: # on query reception we ask always, if we initiate we just ask the first time 546 else: # on query reception we ask always, if we initiate we just ask the first time
555 query(other_jid) 547 query(other_jid)
556 548
557 def _endSession(self, menu_data): 549 def _endSession(self, caller, menu_data, profile):
558 """End an OTR session 550 """End an OTR session
559 551
560 @param menu_data: %(menu_data)s 552 @param menu_data: %(menu_data)s
561 """ 553 """
562 self.endSession(menu_data['jid']) 554 self.endSession(jid.JID(menu_data['jid']))
563 555
564 def _authenticate(self, menu_data, profile): 556 def _authenticate(self, caller, menu_data, profile):
565 """Authenticate other user and see our own fingerprint 557 """Authenticate other user and see our own fingerprint
566 558
567 @param menu_data: %(menu_data)s 559 @param menu_data: %(menu_data)s
568 @param profile: %(doc_profile)s 560 @param profile: %(doc_profile)s
569 """ 561 """
570 def not_available(): 562 def not_available():
571 dialog.InfoDialog(AUTH_TRUST_NA_TITLE, AUTH_TRUST_NA_TXT, AddStyleName="maxWidthLimit").show() 563 dialog.InfoDialog(AUTH_TRUST_NA_TITLE, AUTH_TRUST_NA_TXT, AddStyleName="maxWidthLimit").show()
572 564
573 to_jid = menu_data['jid'] 565 to_jid = jid.JID(menu_data['jid'])
574 566
575 # checking for private key existence is not needed, context checking is enough 567 # checking for private key existence is not needed, context checking is enough
576 otrctx = self.context_manager.getContextForUser(to_jid, start=False) 568 otrctx = self.context_manager.getContextForUser(to_jid, start=False)
577 if otrctx is None or otrctx.state != otr.context.STATE_ENCRYPTED: 569 if otrctx is None or otrctx.state != otr.context.STATE_ENCRYPTED:
578 not_available() 570 not_available()
583 elif otr_version == otr.context.OTR_VERSION_3: 575 elif otr_version == otr.context.OTR_VERSION_3:
584 otrctx.smpAuthCb('question', None, 'asked') 576 otrctx.smpAuthCb('question', None, 'asked')
585 else: 577 else:
586 not_available() 578 not_available()
587 579
588 def _dropPrivkey(self, menu_data, profile): 580 def _dropPrivkey(self, caller, menu_data, profile):
589 """Drop our private Key 581 """Drop our private Key
590 582
591 @param menu_data: %(menu_data)s 583 @param menu_data: %(menu_data)s
592 @param profile: %(doc_profile)s 584 @param profile: %(doc_profile)s
593 """ 585 """