comparison cagou/plugins/plugin_wid_chat.py @ 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 ba8f3a4a5ac7
children 5bd94bc08f5c
comparison
equal deleted inserted replaced
241:661b9cf7b4e4 242:c2503168fab7
29 from kivy import properties 29 from kivy import properties
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 import xmlui
34 from cagou.core.image import Image 35 from cagou.core.image import Image
35 from cagou.core.common import SymbolButton, JidButton 36 from cagou.core.common import SymbolButton, JidButton
36 from kivy.uix.dropdown import DropDown 37 from kivy.uix.dropdown import DropDown
37 from kivy.uix.button import Button
38 from kivy.core.window import Window 38 from kivy.core.window import Window
39 from cagou import G 39 from cagou import G
40 from functools import partial 40 from functools import partial
41 import mimetypes 41 import mimetypes
42 42
179 return 'lock-filled' 179 return 'lock-filled'
180 else: 180 else:
181 return 'lock' 181 return 'lock'
182 182
183 183
184 class EncryptionButton(Button): 184 class TrustManagementButton(SymbolButton):
185 pass
186
187
188 class EncryptionButton(BoxLayout):
185 selected = properties.BooleanProperty(False) 189 selected = properties.BooleanProperty(False)
190 text = properties.StringProperty()
191 trust_button = properties.BooleanProperty(False)
192 best_width = properties.NumericProperty(0)
193
194 def __init__(self, **kwargs):
195 self.register_event_type('on_release')
196 self.register_event_type('on_trust_release')
197 super(EncryptionButton, self).__init__(**kwargs)
198 if self.trust_button:
199 self.add_widget(TrustManagementButton())
200
201 def on_release(self):
202 pass
203
204 def on_trust_release(self):
205 pass
186 206
187 207
188 class EncryptionMenu(DropDown): 208 class EncryptionMenu(DropDown):
209 # best with to display all algorithms buttons + trust buttons
210 best_width = properties.NumericProperty(0)
189 211
190 def __init__(self, chat, **kwargs): 212 def __init__(self, chat, **kwargs):
191 """ 213 """
192 @param chat(Chat): Chat instance 214 @param chat(Chat): Chat instance
193 """ 215 """
202 self.add_widget(btn) 224 self.add_widget(btn)
203 for plugin in G.host.encryption_plugins: 225 for plugin in G.host.encryption_plugins:
204 btn = EncryptionButton( 226 btn = EncryptionButton(
205 text=plugin[u'name'], 227 text=plugin[u'name'],
206 on_release=partial(self.startEncryption, plugin=plugin), 228 on_release=partial(self.startEncryption, plugin=plugin),
229 on_trust_release=partial(self.getTrustUI, plugin=plugin),
230 trust_button=True,
207 ) 231 )
208 self.add_widget(btn) 232 self.add_widget(btn)
209 log.info("added encryption: {}".format(plugin['name'])) 233 log.info("added encryption: {}".format(plugin['name']))
210 234
211 def messageEncryptionStopCb(self): 235 def messageEncryptionStopCb(self):
222 def unencrypted(self, button): 246 def unencrypted(self, button):
223 self.dismiss() 247 self.dismiss()
224 G.host.bridge.messageEncryptionStop( 248 G.host.bridge.messageEncryptionStop(
225 unicode(self.chat.target), 249 unicode(self.chat.target),
226 self.chat.profile, 250 self.chat.profile,
227 callback=partial(self.messageEncryptionStopCb), 251 callback=self.messageEncryptionStopCb,
228 errback=partial(self.messageEncryptionStopEb)) 252 errback=self.messageEncryptionStopEb)
229 253
230 def messageEncryptionStartCb(self, plugin): 254 def messageEncryptionStartCb(self, plugin):
231 log.info(_(u"Session with {destinee} is now encrypted with {encr_name}").format( 255 log.info(_(u"Session with {destinee} is now encrypted with {encr_name}").format(
232 destinee = self.chat.target, 256 destinee = self.chat.target,
233 encr_name = plugin['name'])) 257 encr_name = plugin['name']))
250 unicode(self.chat.target), 274 unicode(self.chat.target),
251 plugin['namespace'], 275 plugin['namespace'],
252 True, 276 True,
253 self.chat.profile, 277 self.chat.profile,
254 callback=partial(self.messageEncryptionStartCb, plugin=plugin), 278 callback=partial(self.messageEncryptionStartCb, plugin=plugin),
255 errback=partial(self.messageEncryptionStartEb)) 279 errback=self.messageEncryptionStartEb)
280
281 def encryptionTrustUIGetCb(self, xmlui_raw):
282 xml_ui = xmlui.create(
283 G.host, xmlui_raw, profile=self.chat.profile)
284 xml_ui.show()
285
286 def encryptionTrustUIGetEb(self, failure_):
287 msg = _(u"Trust manager interface can't be retrieved: {reason}").format(
288 reason = failure_)
289 log.warning(msg)
290 G.host.addNote(_(u"encryption trust management problem"), msg,
291 C.XMLUI_DATA_LVL_ERROR)
292
293 def getTrustUI(self, button, plugin):
294 """Request and display trust management UI
295
296 @param button(EncryptionButton): button which has been pressed
297 @param plugin(dict): plugin data
298 """
299 self.dismiss()
300 G.host.bridge.encryptionTrustUIGet(
301 unicode(self.chat.target),
302 plugin['namespace'],
303 self.chat.profile,
304 callback=self.encryptionTrustUIGetCb,
305 errback=self.encryptionTrustUIGetEb)
256 306
257 def otr_start(self): 307 def otr_start(self):
258 self.dismiss() 308 self.dismiss()
259 G.host.launchMenu( 309 G.host.launchMenu(
260 C.MENU_SINGLE, 310 C.MENU_SINGLE,
545 595
546 def fileTransferCb(self, progress_data, cleaning_cb): 596 def fileTransferCb(self, progress_data, cleaning_cb):
547 try: 597 try:
548 progress_id = progress_data['progress'] 598 progress_id = progress_data['progress']
549 except KeyError: 599 except KeyError:
550 xmlui = progress_data['xmlui'] 600 # FIXME: following code doesn't looks right, XMLUI should be created first
551 G.host.showUI(xmlui) 601 xml_ui = progress_data['xmlui']
602 G.host.showUI(xml_ui)
552 else: 603 else:
553 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb) 604 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)
554 605
555 def onTransferOK(self, file_path, cleaning_cb, transfer_type): 606 def onTransferOK(self, file_path, cleaning_cb, transfer_type):
556 if transfer_type == C.TRANSFER_UPLOAD: 607 if transfer_type == C.TRANSFER_UPLOAD: