changeset 536:048ae7314156

browser_side: temporary way to display the OTR state in the LiberviaWidget header
author souliane <souliane@mailoo.org>
date Sun, 07 Sep 2014 16:40:33 +0200
parents 331cb6ea0235
children cd492c18b366
files src/browser/libervia_main.py src/browser/public/libervia.css src/browser/sat_browser/base_widget.py src/browser/sat_browser/panels.py src/browser/sat_browser/plugin_sec_otr.py
diffstat 5 files changed, 70 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/libervia_main.py	Sun Sep 07 16:40:33 2014 +0200
@@ -734,8 +734,10 @@
                 lib_wid.printInfo(msg)
             else:
                 lib_wid.printMessage(from_jid, msg, extra)
+            if 'header_info' in extra:
+                lib_wid.setHeaderInfo(extra['header_info'])
         else:
-            # FIXME: "info" message will be lost here
+            # FIXME: "info" message and header info will be lost here
             if not self.contact_panel.isContactInRoster(other.bare):
                 self.contact_panel.updateContact(other.bare, {}, [C.GROUP_NOT_IN_ROSTER])
             # The message has not been shown, we must indicate it
--- a/src/browser/public/libervia.css	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/public/libervia.css	Sun Sep 07 16:40:33 2014 +0200
@@ -745,6 +745,13 @@
     margin-top: 4px;
 }
 
+.widgetHeader_info {
+    position: absolute;
+    right: 90px;  # FIXME: temporary dirty setting to fit a header menu with 3 icon buttons
+    margin-top: 4px !important;
+    color: white !important;
+}
+
 .widgetHeader_buttonsWrapper {
     position: absolute;
     top: 0;
--- a/src/browser/sat_browser/base_widget.py	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/sat_browser/base_widget.py	Sun Sep 07 16:40:33 2014 +0200
@@ -23,6 +23,7 @@
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.ScrollPanel import ScrollPanel
 from pyjamas.ui.FlexTable import FlexTable
 from pyjamas.ui.TabPanel import TabPanel
@@ -199,15 +200,26 @@
 
 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
 
-    def __init__(self, parent, host, title):
+    def __init__(self, parent, host, title, info=None):
+        """
+        @param parent (LiberviaWidget): LiberWidget instance
+        @param host (SatWebFrontend): SatWebFrontend instance
+        @param title (Widget): text widget instance
+        @param info (Widget): text widget instance
+        """
         AbsolutePanel.__init__(self)
         self.add(title)
-        button_group_wrapper = SimplePanel()
+        if info:
+            # FIXME: temporary design to display the info near the menu
+            button_group_wrapper = HorizontalPanel()
+            button_group_wrapper.add(info)
+        else:
+            button_group_wrapper = SimplePanel()
         button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
         button_group = WidgetMenuBar(parent, host)
         button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting'))
         button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose'))
-        button_group_wrapper.setWidget(button_group)
+        button_group_wrapper.add(button_group)
         self.add(button_group_wrapper)
         self.addStyleName('widgetHeader')
         LiberviaDragWidget.__init__(self, "", "WIDGET", parent)
@@ -216,11 +228,12 @@
 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
     """Libervia's widget which can replace itself with a dropped widget on DnD"""
 
-    def __init__(self, host, title='', selectable=False):
+    def __init__(self, host, title='', info='', selectable=False):
         """Init the widget
-        @param host: SatWebFrontend object
-        @param title: title show in the header of the widget
-        @param selectable: True is widget can be selected by user"""
+        @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 selectable (bool): True is widget can be selected by user"""
         VerticalPanel.__init__(self)
         DropCell.__init__(self, host)
         ClickHandler.__init__(self)
@@ -230,8 +243,13 @@
         self.__close_button_id = HTMLPanel.createUniqueId()
         self.__title = Label(title)
         self.__title.setStyleName('widgetHeader_title')
+        if info:
+            self.__info = Label(info)
+            self.__info.setStyleName('widgetHeader_info')
+        else:
+            self.__info = None
         self._close_listeners = []
-        header = WidgetHeader(self, host, self.__title)
+        header = WidgetHeader(self, host, self.__title, self.__info)
         self.add(header)
         self.setSize('100%', '100%')
         self.addStyleName('widget')
@@ -370,6 +388,14 @@
         @param text: text of the new title"""
         self.__title.setText(text)
 
+    def setHeaderInfo(self, text):
+        """change the info in the header of the widget
+        @param text: text of the new title"""
+        try:
+            self.__info.setText(text)
+        except AttributeError:
+            log.error("LiberviaWidget.setInfo: info widget has not been initialized!")
+
     def isSelectable(self):
         return self.__selectable
 
--- a/src/browser/sat_browser/panels.py	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/sat_browser/panels.py	Sun Sep 07 16:40:33 2014 +0200
@@ -1119,7 +1119,11 @@
             return
         self.target = target
         self.type = type_
-        base_widget.LiberviaWidget.__init__(self, host, title=target.bare, selectable=True)
+
+        # FIXME: temporary dirty initialization to display the OTR state
+        header_info = _('Encryption: none') if type_ == 'one2one' else None
+
+        base_widget.LiberviaWidget.__init__(self, host, title=target.bare, info=header_info, selectable=True)
         self.__body = AbsolutePanel()
         self.__body.setStyleName('chatPanel_body')
         chat_area = HorizontalPanel()
--- a/src/browser/sat_browser/plugin_sec_otr.py	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Sun Sep 07 16:40:33 2014 +0200
@@ -52,6 +52,13 @@
     'REQUIRE_ENCRYPTION': False,
 }
 
+# list a couple of texts (untrusted, trusted) for each state
+OTR_MSG_STATES = {
+    otr.context.STATE_PLAINTEXT: [_('none'), _('none')],
+    otr.context.STATE_ENCRYPTED: [_('untrusted'), _('trusted')],
+    otr.context.STATE_FINISHED: [_('finished'), _('finished')]
+}
+
 
 class Context(otr.context.Context):
 
@@ -101,21 +108,28 @@
     def messageErrorCb(self, error):
         log.error('error occured: %s' % error)
 
+    @classmethod
+    def getInfoText(self, state='', trust=''):
+        if not state:
+            state = OTR_MSG_STATES.keys()[0]
+        return 'Encryption: %s' % OTR_MSG_STATES[state][1 if trust else 0]
+
     def setStateCb(self, msg_state, status):
-        other_jid_s = self.peer.full()
-        feedback = _(u"Error: the state of the conversation with %s is unknown!")
-
         if status == otr.context.STATUS_AKE_INIT:
             return
 
-        elif status == otr.context.STATUS_SEND_QUERY:
+        other_jid_s = self.peer.full()
+        feedback = _(u"Error: the state of the conversation with %s is unknown!")
+        trust = self.getCurrentTrust()
+
+        if status == otr.context.STATUS_SEND_QUERY:
             if msg_state == otr.context.STATE_ENCRYPTED:
                 feedback = _('Attempting to refresh the private conversation with %s...')
             else:
                 feedback = _('Attempting to start a private conversation with %s...')
 
         elif status == otr.context.STATUS_AKE_SUCCESS:
-            trusted_str = _(u"Verified") if self.getCurrentTrust() else _(u"Unverified")
+            trusted_str = _(u"Verified") if trust else _(u"Unverified")
             if msg_state == otr.context.STATE_ENCRYPTED:
                 feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.")
             else:
@@ -129,7 +143,7 @@
             elif msg_state == otr.context.STATE_FINISHED:
                 feedback = _("%s has ended his/her private conversation with you; you should do the same.")
 
-        self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {})
+        self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)})
 
     def setCurrentTrust(self, new_trust='', act='asked', type_='trust'):
         log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act))
@@ -150,7 +164,7 @@
         otr.context.Context.setCurrentTrust(self, new_trust)
         if old_trust != new_trust:
             feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified')
-            self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {})
+            self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)})
 
     def fingerprintAuthCb(self):
         """OTR v2 authentication using manual fingerprint comparison"""