Mercurial > libervia-desktop-kivy
diff 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 |
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.py Thu Jan 03 10:42:43 2019 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Thu Jan 03 10:52:57 2019 +0100 @@ -31,10 +31,10 @@ from sat_frontends.quick_frontend import quick_chat from sat_frontends.tools import jid from cagou.core import cagou_widget +from cagou.core import xmlui from cagou.core.image import Image from cagou.core.common import SymbolButton, JidButton from kivy.uix.dropdown import DropDown -from kivy.uix.button import Button from kivy.core.window import Window from cagou import G from functools import partial @@ -181,11 +181,33 @@ return 'lock' -class EncryptionButton(Button): +class TrustManagementButton(SymbolButton): + pass + + +class EncryptionButton(BoxLayout): selected = properties.BooleanProperty(False) + text = properties.StringProperty() + trust_button = properties.BooleanProperty(False) + best_width = properties.NumericProperty(0) + + def __init__(self, **kwargs): + self.register_event_type('on_release') + self.register_event_type('on_trust_release') + super(EncryptionButton, self).__init__(**kwargs) + if self.trust_button: + self.add_widget(TrustManagementButton()) + + def on_release(self): + pass + + def on_trust_release(self): + pass class EncryptionMenu(DropDown): + # best with to display all algorithms buttons + trust buttons + best_width = properties.NumericProperty(0) def __init__(self, chat, **kwargs): """ @@ -204,6 +226,8 @@ btn = EncryptionButton( text=plugin[u'name'], on_release=partial(self.startEncryption, plugin=plugin), + on_trust_release=partial(self.getTrustUI, plugin=plugin), + trust_button=True, ) self.add_widget(btn) log.info("added encryption: {}".format(plugin['name'])) @@ -224,8 +248,8 @@ G.host.bridge.messageEncryptionStop( unicode(self.chat.target), self.chat.profile, - callback=partial(self.messageEncryptionStopCb), - errback=partial(self.messageEncryptionStopEb)) + callback=self.messageEncryptionStopCb, + errback=self.messageEncryptionStopEb) def messageEncryptionStartCb(self, plugin): log.info(_(u"Session with {destinee} is now encrypted with {encr_name}").format( @@ -252,7 +276,33 @@ True, self.chat.profile, callback=partial(self.messageEncryptionStartCb, plugin=plugin), - errback=partial(self.messageEncryptionStartEb)) + errback=self.messageEncryptionStartEb) + + def encryptionTrustUIGetCb(self, xmlui_raw): + xml_ui = xmlui.create( + G.host, xmlui_raw, profile=self.chat.profile) + xml_ui.show() + + def encryptionTrustUIGetEb(self, failure_): + msg = _(u"Trust manager interface can't be retrieved: {reason}").format( + reason = failure_) + log.warning(msg) + G.host.addNote(_(u"encryption trust management problem"), msg, + C.XMLUI_DATA_LVL_ERROR) + + def getTrustUI(self, button, plugin): + """Request and display trust management UI + + @param button(EncryptionButton): button which has been pressed + @param plugin(dict): plugin data + """ + self.dismiss() + G.host.bridge.encryptionTrustUIGet( + unicode(self.chat.target), + plugin['namespace'], + self.chat.profile, + callback=self.encryptionTrustUIGetCb, + errback=self.encryptionTrustUIGetEb) def otr_start(self): self.dismiss() @@ -547,8 +597,9 @@ try: progress_id = progress_data['progress'] except KeyError: - xmlui = progress_data['xmlui'] - G.host.showUI(xmlui) + # FIXME: following code doesn't looks right, XMLUI should be created first + xml_ui = progress_data['xmlui'] + G.host.showUI(xml_ui) else: self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)