changeset 242:c2503168fab7

plugin chat (encryption): added a button to display trust management UI.
author Goffi <goffi@goffi.org>
date Thu, 03 Jan 2019 10:52:57 +0100
parents 661b9cf7b4e4
children 50f7c000b4ae
files cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 79 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.kv	Thu Jan 03 10:42:43 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Thu Jan 03 10:52:57 2019 +0100
@@ -134,16 +134,29 @@
     color: self.getColor()
     symbol: self.getSymbol()
 
+<TrustManagementButton>:
+    symbol: "shield"
+    padding: dp(5), dp(10)
+    bg_color: app.c_prim_dark
+    size_hint: None, 1
+    width: dp(30)
+    on_release: self.parent.dispatch("on_trust_release")
+
 <EncryptionButton>:
-    group: 'encryption'
     size_hint: None, None
-    width: max(self.texture_size[0], self.parent.minimum_width if self.parent else 0)
-    height: self.texture_size[1]
-    padding: dp(5), dp(10)
-    color: 0, 0, 0, 1
-    bold: True
-    background_normal: app.expand('{media}/misc/borders/border_filled_black.png')
-    background_color: app.c_sec if self.selected else app.c_prim_dark
+    width: self.parent.parent.best_width if self.parent is not None else 30
+    height: dp(30)
+    on_best_width: self.parent.parent.best_width = max(self.parent.parent.best_width, args[1])
+    Button:
+        text: root.text
+        size_hint: 1, 1
+        padding: dp(5), dp(10)
+        color: 0, 0, 0, 1
+        bold: True
+        background_normal: app.expand('{media}/misc/borders/border_filled_black.png')
+        background_color: app.c_sec if root.selected else app.c_prim_dark
+        on_release: root.dispatch("on_release")
+        on_texture_size: root.best_width = self.texture_size[0] + (dp(30) if root.trust_button else 0)
 
 <EncryptionMenu>:
     size_hint_x: None
--- a/cagou/plugins/plugin_wid_chat.py	Thu Jan 03 10:42:43 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Thu Jan 03 10:52:57 2019 +0100
@@ -31,10 +31,10 @@
 from sat_frontends.quick_frontend import quick_chat
 from sat_frontends.tools import jid
 from cagou.core import cagou_widget
+from cagou.core import xmlui
 from cagou.core.image import Image
 from cagou.core.common import SymbolButton, JidButton
 from kivy.uix.dropdown import DropDown
-from kivy.uix.button import Button
 from kivy.core.window import Window
 from cagou import G
 from functools import partial
@@ -181,11 +181,33 @@
             return 'lock'
 
 
-class EncryptionButton(Button):
+class TrustManagementButton(SymbolButton):
+    pass
+
+
+class EncryptionButton(BoxLayout):
     selected = properties.BooleanProperty(False)
+    text = properties.StringProperty()
+    trust_button = properties.BooleanProperty(False)
+    best_width = properties.NumericProperty(0)
+
+    def __init__(self, **kwargs):
+        self.register_event_type('on_release')
+        self.register_event_type('on_trust_release')
+        super(EncryptionButton, self).__init__(**kwargs)
+        if self.trust_button:
+            self.add_widget(TrustManagementButton())
+
+    def on_release(self):
+        pass
+
+    def on_trust_release(self):
+        pass
 
 
 class EncryptionMenu(DropDown):
+    # best with to display all algorithms buttons + trust buttons
+    best_width = properties.NumericProperty(0)
 
     def __init__(self, chat, **kwargs):
         """
@@ -204,6 +226,8 @@
             btn = EncryptionButton(
                 text=plugin[u'name'],
                 on_release=partial(self.startEncryption, plugin=plugin),
+                on_trust_release=partial(self.getTrustUI, plugin=plugin),
+                trust_button=True,
                 )
             self.add_widget(btn)
             log.info("added encryption: {}".format(plugin['name']))
@@ -224,8 +248,8 @@
         G.host.bridge.messageEncryptionStop(
             unicode(self.chat.target),
             self.chat.profile,
-            callback=partial(self.messageEncryptionStopCb),
-            errback=partial(self.messageEncryptionStopEb))
+            callback=self.messageEncryptionStopCb,
+            errback=self.messageEncryptionStopEb)
 
     def messageEncryptionStartCb(self, plugin):
         log.info(_(u"Session with {destinee} is now encrypted with {encr_name}").format(
@@ -252,7 +276,33 @@
             True,
             self.chat.profile,
             callback=partial(self.messageEncryptionStartCb, plugin=plugin),
-            errback=partial(self.messageEncryptionStartEb))
+            errback=self.messageEncryptionStartEb)
+
+    def encryptionTrustUIGetCb(self, xmlui_raw):
+        xml_ui = xmlui.create(
+            G.host, xmlui_raw, profile=self.chat.profile)
+        xml_ui.show()
+
+    def encryptionTrustUIGetEb(self, failure_):
+        msg = _(u"Trust manager interface can't be retrieved: {reason}").format(
+            reason = failure_)
+        log.warning(msg)
+        G.host.addNote(_(u"encryption trust management problem"), msg,
+                       C.XMLUI_DATA_LVL_ERROR)
+
+    def getTrustUI(self, button, plugin):
+        """Request and display trust management UI
+
+        @param button(EncryptionButton): button which has been pressed
+        @param plugin(dict): plugin data
+        """
+        self.dismiss()
+        G.host.bridge.encryptionTrustUIGet(
+            unicode(self.chat.target),
+            plugin['namespace'],
+            self.chat.profile,
+            callback=self.encryptionTrustUIGetCb,
+            errback=self.encryptionTrustUIGetEb)
 
     def otr_start(self):
         self.dismiss()
@@ -547,8 +597,9 @@
         try:
             progress_id = progress_data['progress']
         except KeyError:
-            xmlui = progress_data['xmlui']
-            G.host.showUI(xmlui)
+            # FIXME: following code doesn't looks right, XMLUI should be created first
+            xml_ui = progress_data['xmlui']
+            G.host.showUI(xml_ui)
         else:
             self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)