# HG changeset patch # User Goffi # Date 1485459575 -3600 # Node ID f0291755b07cda5f40ebc1e4544e383fac925adc # Parent 8576d70ff803e71d26ddd97431a8c9a27cf05721 chat: OTR integration first draft: an encryption button is added in Chat header, launching the start/refresh, end session and authenticate menus. diff -r 8576d70ff803 -r f0291755b07c src/cagou/plugins/plugin_wid_chat.kv --- 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) + +: + size_hint: None, 1 + width: dp(30) + source: app.expand("{media}/icons/muchoslava/png/cadenas_ouvert_30.png") + +: + size_hint: None, None + size: self.texture_size + padding: 5, 5 + +: + 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() diff -r 8576d70ff803 -r f0291755b07c src/cagou/plugins/plugin_wid_chat.py --- 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)