diff src/browser/sat_browser/plugin_sec_otr.py @ 543:d02335553b5d

browser_side (plugin OTR): display OTR states with icons instead of a text
author souliane <souliane@mailoo.org>
date Mon, 08 Sep 2014 15:32:33 +0200
parents e903a9f79172
children ad18eb65b6db
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py	Mon Sep 08 14:54:47 2014 +0200
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Mon Sep 08 15:32:33 2014 +0200
@@ -96,11 +96,20 @@
     'WHITESPACE_START_AKE': False,  # FIXME: we need to complete messageReceivedTrigger before turning this to True
 }
 
-# list a couple of texts (untrusted, trusted) for each state
+# list a couple of texts or htmls (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')]
+    otr.context.STATE_PLAINTEXT: [
+        '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key_delete.png" />',
+        '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key.png" />'
+    ],
+    otr.context.STATE_ENCRYPTED: [
+        '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key_delete.png" />',
+        '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key.png" />'
+    ],
+    otr.context.STATE_FINISHED: [
+        '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key_delete.png" />',
+        '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key.png" />'
+    ]
 }
 
 
@@ -153,12 +162,6 @@
     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):
         if status == otr.context.STATUS_AKE_INIT:
             return
@@ -182,7 +185,7 @@
             elif msg_state == otr.context.STATE_FINISHED:
                 feedback = END_FINISHED
 
-        self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)})
+        self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': OTR.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))
@@ -205,7 +208,7 @@
         otr.context.Context.setCurrentTrust(self, new_trust)
         if old_trust != new_trust:
             feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower())
-            self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)})
+            self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': OTR.getInfoText(self.state, new_trust)})
 
     def fingerprintAuthCb(self):
         """OTR v2 authentication using manual fingerprint comparison"""
@@ -349,6 +352,12 @@
         self.last_resources = {}
         self.host.bridge._registerMethods(["skipOTR"])
 
+    @classmethod
+    def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''):
+        if not state:
+            state = OTR_MSG_STATES.keys()[0]
+        return OTR_MSG_STATES[state][1 if trust else 0]
+
     def inhibitMenus(self):
         """Tell the caller which dynamic menus should be inhibited"""
         return ["OTR"]  # menu categories name to inhibit