Mercurial > libervia-desktop-kivy
diff src/cagou/plugins/plugin_wid_chat.py @ 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 | c3952922ca56 |
children | 51e804dbf608 |
line wrap: on
line diff
--- 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)