Mercurial > libervia-web
changeset 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 | 44df078187b9 |
children | a90cc8fc9605 09a6126f89b9 |
files | src/browser/sat_browser/plugin_sec_otr.py |
diffstat | 1 files changed, 15 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py Tue Mar 17 22:18:25 2015 +0100 +++ b/src/browser/sat_browser/plugin_sec_otr.py Tue Mar 17 22:20:36 2015 +0100 @@ -39,7 +39,7 @@ NS_OTR = "otr_plugin" PRIVATE_KEY = "PRIVATE KEY" -MAIN_MENU = D_('OTR encryption') +MAIN_MENU = D_('OTR') # TODO: get this constant directly from backend's plugin DIALOG_EOL = "<br />" AUTH_TRUSTED = D_("Verified") @@ -396,7 +396,7 @@ self._gotMenusListener = self.gotMenusListener # FIXME: these listeners are never removed, can't be removed by themselves (it modifies the list while looping), maybe need a 'one_shot' argument self.host.addListener('profilePlugged', self._profilePluggedListener) - # self.host.addListener('gotMenus', self._gotMenusListener) + self.host.addListener('gotMenus', self._gotMenusListener) @classmethod def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): @@ -421,20 +421,12 @@ else: return OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust()) - def gotMenusListener(self, menus, profile): - menus_to_delete = [] - for menu in menus: - id_, type_, path, path_i18n = menu - if path[0] == 'OTR': - menus_to_delete.append(menu) - for menu in menus_to_delete: - menus.remove(menu) - # FIXME: handle help strings too - menus.extend([(self._startRefresh, C.MENU_SINGLE, (MAIN_MENU, "Start / refresh"), (MAIN_MENU, D_("Start / refresh"))), - (self._endSession, C.MENU_SINGLE, (MAIN_MENU, "Stop encryption"), (MAIN_MENU, D_("Stop encryption"))), - (self._authenticate, C.MENU_SINGLE, (MAIN_MENU, "Authenticate correspondent"), (MAIN_MENU, D_("Authenticate correspondent"))), - (self._dropPrivkey, C.MENU_SINGLE, (MAIN_MENU, "Drop your private key"), (MAIN_MENU, D_("Drop your private key"))), - ]) + def gotMenusListener(self,): + # TODO: get menus paths to hook directly from backend's OTR plugin + self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Start/Refresh")), callback=self._startRefresh) + self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"End session")), callback=self._endSession) + self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Authenticate")), callback=self._authenticate) + self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Drop private key")), callback=self._dropPrivkey) def profilePluggedListener(self, profile): # 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) @@ -528,7 +520,7 @@ # Menu callbacks - def _startRefresh(self, menu_data): + def _startRefresh(self, caller, menu_data, profile): """Start or refresh an OTR session @param menu_data: %(menu_data)s @@ -538,7 +530,7 @@ if otrctx: otrctx.sendQueryMessage() - other_jid = menu_data['jid'] + other_jid = jid.JID(menu_data['jid']) clist = self.host.contact_list if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None: dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show() @@ -554,14 +546,14 @@ else: # on query reception we ask always, if we initiate we just ask the first time query(other_jid) - def _endSession(self, menu_data): + def _endSession(self, caller, menu_data, profile): """End an OTR session @param menu_data: %(menu_data)s """ - self.endSession(menu_data['jid']) + self.endSession(jid.JID(menu_data['jid'])) - def _authenticate(self, menu_data, profile): + def _authenticate(self, caller, menu_data, profile): """Authenticate other user and see our own fingerprint @param menu_data: %(menu_data)s @@ -570,7 +562,7 @@ def not_available(): dialog.InfoDialog(AUTH_TRUST_NA_TITLE, AUTH_TRUST_NA_TXT, AddStyleName="maxWidthLimit").show() - to_jid = menu_data['jid'] + to_jid = jid.JID(menu_data['jid']) # checking for private key existence is not needed, context checking is enough otrctx = self.context_manager.getContextForUser(to_jid, start=False) @@ -585,7 +577,7 @@ else: not_available() - def _dropPrivkey(self, menu_data, profile): + def _dropPrivkey(self, caller, menu_data, profile): """Drop our private Key @param menu_data: %(menu_data)s