Mercurial > libervia-web
changeset 559:77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 23 Sep 2014 13:57:36 +0200 |
parents | b38629924602 |
children | 77bf2654ca0a |
files | src/browser/sat_browser/base_widget.py src/browser/sat_browser/panels.py src/browser/sat_browser/plugin_sec_otr.py |
diffstat | 3 files changed, 37 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py Tue Sep 23 11:48:57 2014 +0200 +++ b/src/browser/sat_browser/base_widget.py Tue Sep 23 13:57:36 2014 +0200 @@ -229,11 +229,11 @@ class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): """Libervia's widget which can replace itself with a dropped widget on DnD""" - def __init__(self, host, title='', info='', selectable=False): + def __init__(self, host, title='', info=None, selectable=False): """Init the widget @param host (SatWebFrontend): SatWebFrontend instance @param title (str): title shown in the header of the widget - @param info (str): info shown in the header of the widget + @param info (str, callable): info shown in the header of the widget @param selectable (bool): True is widget can be selected by user""" VerticalPanel.__init__(self) DropCell.__init__(self, host) @@ -244,8 +244,13 @@ self.__close_button_id = HTMLPanel.createUniqueId() self.__title = Label(title) self.__title.setStyleName('widgetHeader_title') - if info: - self.__info = HTML(info) + if info is not None: + if isinstance(info, str): + self.__info = HTML(info) + else: # the info will be set by a callback + assert(callable(info)) + self.__info = HTML() + info(self.__info.setHTML) self.__info.setStyleName('widgetHeader_info') else: self.__info = None @@ -394,7 +399,7 @@ @param text: text of the new title""" try: self.__info.setHTML(text) - except AttributeError: + except TypeError: log.error("LiberviaWidget.setInfo: info widget has not been initialized!") def isSelectable(self):
--- a/src/browser/sat_browser/panels.py Tue Sep 23 11:48:57 2014 +0200 +++ b/src/browser/sat_browser/panels.py Tue Sep 23 13:57:36 2014 +0200 @@ -1121,7 +1121,9 @@ self.type = type_ # FIXME: temporary dirty initialization to display the OTR state - header_info = host.plugins['otr'].getInfoText() if (type_ == 'one2one' and 'otr' in host.plugins) else None + def header_info_cb(cb): + host.plugins['otr'].infoTextCallback(target, cb) + header_info = header_info_cb if (type_ == 'one2one' and 'otr' in host.plugins) else None base_widget.LiberviaWidget.__init__(self, host, title=target.bare, info=header_info, selectable=True) self.__body = AbsolutePanel()
--- a/src/browser/sat_browser/plugin_sec_otr.py Tue Sep 23 11:48:57 2014 +0200 +++ b/src/browser/sat_browser/plugin_sec_otr.py Tue Sep 23 13:57:36 2014 +0200 @@ -32,6 +32,8 @@ import jid import otrjs_wrapper as otr import dialog +import panels + NS_OTR = "otr_plugin" PRIVATE_KEY = "PRIVATE KEY" @@ -365,10 +367,31 @@ @classmethod def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): + """Get the widget info text for a certain message state and trust. + + @param state (str): message state + @param trust (str): trust + @return: str + """ if not state: state = OTR_MSG_STATES.keys()[0] return OTR_MSG_STATES[state][1 if trust else 0] + def infoTextCallback(self, other_jid, cb): + """Get the current info text for a conversation and run a callback. + + @param other_jid (JID): JID of the correspondant + @paam cb (callable): method to be called with the computed info text + """ + def gotResource(other_jid): + otrctx = self.context_manager.getContextForUser(other_jid, start=False) + if otrctx is None: + cb(OTR.getInfoText()) + else: + cb(OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust())) + + self.fixResource(other_jid, gotResource) + def inhibitMenus(self): """Tell the caller which dynamic menus should be inhibited""" return ["OTR"] # menu categories name to inhibit @@ -423,6 +446,7 @@ if otrctx is None: def confirm(confirm): if confirm: + self.host.getOrCreateLiberviaWidget(panels.ChatPanel, jid) decrypt(self.context_manager.startContext(jid)) else: # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True