changeset 135:091e288838e1

plugin chat: use new Symbol widget to display encryption button
author Goffi <goffi@goffi.org>
date Fri, 06 Apr 2018 16:13:08 +0200
parents 1cca97e27a69
children 84b18c131a81
files cagou/core/common.py cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 3 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/common.py	Fri Apr 06 16:13:08 2018 +0200
+++ b/cagou/core/common.py	Fri Apr 06 16:13:08 2018 +0200
@@ -75,3 +75,7 @@
             log.warning(_(u"Invalid symbol {symbol}").format(symbol=symbol))
         else:
             self.text = unichr(code)
+
+
+class SymbolButton(ButtonBehavior, Symbol):
+    pass
--- a/cagou/plugins/plugin_wid_chat.kv	Fri Apr 06 16:13:08 2018 +0200
+++ b/cagou/plugins/plugin_wid_chat.kv	Fri Apr 06 16:13:08 2018 +0200
@@ -126,8 +126,8 @@
 <EncryptionButton>:
     size_hint: None, 1
     width: dp(30)
-    allow_stretch: True
-    source: self.getIconSource()
+    color: self.getColor()
+    symbol: self.getSymbol()
 
 <OtrButton@Button>:
     size_hint: None, None
--- a/cagou/plugins/plugin_wid_chat.py	Fri Apr 06 16:13:08 2018 +0200
+++ b/cagou/plugins/plugin_wid_chat.py	Fri Apr 06 16:13:08 2018 +0200
@@ -32,7 +32,7 @@
 from sat_frontends.tools import jid
 from cagou.core import cagou_widget
 from cagou.core.image import Image
-from cagou.core.common import IconButton, JidWidget
+from cagou.core.common import SymbolButton, JidWidget
 from kivy.uix.dropdown import DropDown
 from cagou import G
 import mimetypes
@@ -130,7 +130,7 @@
     pass
 
 
-class EncryptionButton(IconButton):
+class EncryptionButton(SymbolButton):
 
     def __init__(self, chat, **kwargs):
         """
@@ -142,18 +142,21 @@
         super(EncryptionButton, self).__init__(**kwargs)
         self.bind(on_release=self.otr_menu.open)
 
-    def getIconSource(self):
-        """get path of icon"""
-        # TODO: use a more generic method to get icon name
+    def getColor(self):
         if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED:
-            icon_name = 'cadenas_ouvert'
+            return  (0.4, 0.4, 0.4, 1)
+        elif self.chat.otr_state_trust == OTR_STATE_TRUSTED:
+            return (0.29,0.87,0.0,1)
         else:
-            if self.chat.otr_state_trust == OTR_STATE_TRUSTED:
-                icon_name = 'cadenas_ferme'
-            else:
-                icon_name = 'cadenas_ferme_pas_authenthifie'
+            return  (0.4, 0.4, 0.4, 1)
 
-        return G.host.app.expand("{media}/icons/muchoslava/png/" + icon_name + "_30.png")
+    def getSymbol(self):
+        if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED:
+            return 'lock-open'
+        elif self.chat.otr_state_trust == OTR_STATE_TRUSTED:
+            return 'lock-filled'
+        else:
+            return 'lock'
 
 
 class OtrMenu(DropDown):
@@ -445,7 +448,8 @@
         else:
             log.error(_(u"Unknown OTR state received: {}".format(state)))
             return
-        self.encryption_btn.source = self.encryption_btn.getIconSource()
+        self.encryption_btn.symbol = self.encryption_btn.getSymbol()
+        self.encryption_btn.color = self.encryption_btn.getColor()
 
     def onDelete(self, force=False):
         if force==True: