changeset 117:f0291755b07c

chat: OTR integration first draft: an encryption button is added in Chat header, launching the start/refresh, end session and authenticate menus.
author Goffi <goffi@goffi.org>
date Thu, 26 Jan 2017 20:39:35 +0100
parents 8576d70ff803
children a574133aa4a8
files src/cagou/plugins/plugin_wid_chat.kv src/cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 89 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/cagou/plugins/plugin_wid_chat.kv	Thu Jan 26 20:39:32 2017 +0100
+++ b/src/cagou/plugins/plugin_wid_chat.kv	Thu Jan 26 20:39:35 2017 +0100
@@ -112,3 +112,34 @@
             size_hint: None, 1
             width: max(self.texture_size[0], dp(40))
             on_release: TransferMenu(callback=root.onTransferOK).show(self)
+
+<EncryptionButton>:
+    size_hint: None, 1
+    width: dp(30)
+    source: app.expand("{media}/icons/muchoslava/png/cadenas_ouvert_30.png")
+
+<OtrButton@Button>:
+    size_hint: None, None
+    size: self.texture_size
+    padding: 5, 5
+
+<OtrMenu>:
+    size_hint_x: None
+    width: start_btn.width
+    auto_width: False
+    canvas.before:
+        Color:
+            rgba: 0, 0, 0, 1
+        Rectangle:
+            pos: self.pos
+            size: self.size
+    OtrButton:
+        id: start_btn
+        text: _(u"Start/Refresh encrypted session")
+        on_release: root.otr_start()
+    OtrButton:
+        text: _(u"Finish encrypted session")
+        on_release: root.otr_end()
+    OtrButton:
+        text: _(u"Authenticate destinee")
+        on_release: root.otr_authenticate()
--- a/src/cagou/plugins/plugin_wid_chat.py	Thu Jan 26 20:39:32 2017 +0100
+++ b/src/cagou/plugins/plugin_wid_chat.py	Thu Jan 26 20:39:35 2017 +0100
@@ -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 JidWidget
+from cagou.core.common import IconButton, JidWidget
 from kivy.uix.dropdown import DropDown
 from cagou import G
 import mimetypes
@@ -122,6 +122,61 @@
     pass
 
 
+class EncryptionButton(IconButton):
+
+    def __init__(self, chat, **kwargs):
+        """
+        @param chat(Chat): Chat instance
+        """
+        # for now we do a simple ContextMenu as we have only OTR
+        self.otr_menu = OtrMenu(chat)
+        super(EncryptionButton, self).__init__(**kwargs)
+        self.bind(on_release=self.otr_menu.open)
+
+
+class OtrMenu(DropDown):
+
+    def __init__(self, chat, **kwargs):
+        """
+        @param chat(Chat): Chat instance
+        """
+        self.chat = chat
+        super(OtrMenu, self).__init__(**kwargs)
+
+    def otr_start(self):
+        self.dismiss()
+        G.host.launchMenu(
+            C.MENU_SINGLE,
+            (u"otr", u"start/refresh"),
+            {u'jid': self.chat.target},
+            None,
+            C.NO_SECURITY_LIMIT,
+            self.chat.profile
+            )
+
+    def otr_end(self):
+        self.dismiss()
+        G.host.launchMenu(
+            C.MENU_SINGLE,
+            (u"otr", u"end session"),
+            {u'jid': self.chat.target},
+            None,
+            C.NO_SECURITY_LIMIT,
+            self.chat.profile
+            )
+
+    def otr_authenticate(self):
+        self.dismiss()
+        G.host.launchMenu(
+            C.MENU_SINGLE,
+            (u"otr", u"authenticate"),
+            {u'jid': self.chat.target},
+            None,
+            C.NO_SECURITY_LIMIT,
+            self.chat.profile
+            )
+
+
 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget):
     message_input = properties.ObjectProperty()
     messages_widget = properties.ObjectProperty()
@@ -129,6 +184,8 @@
     def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None):
         quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles)
         cagou_widget.CagouWidget.__init__(self)
+        if type_ == C.CHAT_ONE2ONE:
+            self.headerInputAddExtra(EncryptionButton(self))
         self.header_input.hint_text = u"{}".format(target)
         self.host.addListener('progressError', self.onProgressError, profiles)
         self.host.addListener('progressFinished', self.onProgressFinished, profiles)