Mercurial > libervia-desktop-kivy
comparison 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 |
comparison
equal
deleted
inserted
replaced
116:8576d70ff803 | 117:f0291755b07c |
---|---|
30 from sat_frontends.quick_frontend import quick_widgets | 30 from sat_frontends.quick_frontend import quick_widgets |
31 from sat_frontends.quick_frontend import quick_chat | 31 from sat_frontends.quick_frontend import quick_chat |
32 from sat_frontends.tools import jid | 32 from sat_frontends.tools import jid |
33 from cagou.core import cagou_widget | 33 from cagou.core import cagou_widget |
34 from cagou.core.image import Image | 34 from cagou.core.image import Image |
35 from cagou.core.common import JidWidget | 35 from cagou.core.common import IconButton, JidWidget |
36 from kivy.uix.dropdown import DropDown | 36 from kivy.uix.dropdown import DropDown |
37 from cagou import G | 37 from cagou import G |
38 import mimetypes | 38 import mimetypes |
39 | 39 |
40 | 40 |
120 | 120 |
121 class MessagesWidget(GridLayout): | 121 class MessagesWidget(GridLayout): |
122 pass | 122 pass |
123 | 123 |
124 | 124 |
125 class EncryptionButton(IconButton): | |
126 | |
127 def __init__(self, chat, **kwargs): | |
128 """ | |
129 @param chat(Chat): Chat instance | |
130 """ | |
131 # for now we do a simple ContextMenu as we have only OTR | |
132 self.otr_menu = OtrMenu(chat) | |
133 super(EncryptionButton, self).__init__(**kwargs) | |
134 self.bind(on_release=self.otr_menu.open) | |
135 | |
136 | |
137 class OtrMenu(DropDown): | |
138 | |
139 def __init__(self, chat, **kwargs): | |
140 """ | |
141 @param chat(Chat): Chat instance | |
142 """ | |
143 self.chat = chat | |
144 super(OtrMenu, self).__init__(**kwargs) | |
145 | |
146 def otr_start(self): | |
147 self.dismiss() | |
148 G.host.launchMenu( | |
149 C.MENU_SINGLE, | |
150 (u"otr", u"start/refresh"), | |
151 {u'jid': self.chat.target}, | |
152 None, | |
153 C.NO_SECURITY_LIMIT, | |
154 self.chat.profile | |
155 ) | |
156 | |
157 def otr_end(self): | |
158 self.dismiss() | |
159 G.host.launchMenu( | |
160 C.MENU_SINGLE, | |
161 (u"otr", u"end session"), | |
162 {u'jid': self.chat.target}, | |
163 None, | |
164 C.NO_SECURITY_LIMIT, | |
165 self.chat.profile | |
166 ) | |
167 | |
168 def otr_authenticate(self): | |
169 self.dismiss() | |
170 G.host.launchMenu( | |
171 C.MENU_SINGLE, | |
172 (u"otr", u"authenticate"), | |
173 {u'jid': self.chat.target}, | |
174 None, | |
175 C.NO_SECURITY_LIMIT, | |
176 self.chat.profile | |
177 ) | |
178 | |
179 | |
125 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | 180 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
126 message_input = properties.ObjectProperty() | 181 message_input = properties.ObjectProperty() |
127 messages_widget = properties.ObjectProperty() | 182 messages_widget = properties.ObjectProperty() |
128 | 183 |
129 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): | 184 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): |
130 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) | 185 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
131 cagou_widget.CagouWidget.__init__(self) | 186 cagou_widget.CagouWidget.__init__(self) |
187 if type_ == C.CHAT_ONE2ONE: | |
188 self.headerInputAddExtra(EncryptionButton(self)) | |
132 self.header_input.hint_text = u"{}".format(target) | 189 self.header_input.hint_text = u"{}".format(target) |
133 self.host.addListener('progressError', self.onProgressError, profiles) | 190 self.host.addListener('progressError', self.onProgressError, profiles) |
134 self.host.addListener('progressFinished', self.onProgressFinished, profiles) | 191 self.host.addListener('progressFinished', self.onProgressFinished, profiles) |
135 self._waiting_pids = {} # waiting progress ids | 192 self._waiting_pids = {} # waiting progress ids |
136 self.postInit() | 193 self.postInit() |