Mercurial > libervia-desktop-kivy
changeset 122:dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Feb 2017 21:47:16 +0100 |
parents | c498178d8122 |
children | e89350dd3eca |
files | src/cagou/core/cagou_main.py src/cagou/plugins/plugin_wid_chat.kv src/cagou/plugins/plugin_wid_chat.py |
diffstat | 3 files changed, 50 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py Tue Jan 31 23:11:49 2017 +0100 +++ b/src/cagou/core/cagou_main.py Wed Feb 01 21:47:16 2017 +0100 @@ -306,6 +306,7 @@ yield w def onBridgeConnected(self): + self.registerSignal("otrState", iface="plugin") self.bridge.getReady(self.onBackendReady) def _bridgeEb(self, failure): @@ -614,6 +615,15 @@ self.menus.addMenu(C.MENU_GLOBAL, (_(u"Help"), _(u"About")), callback=main_menu.onAbout) main_menu.update(C.MENU_GLOBAL) + ## bridge handlers ## + + def otrStateHandler(self, state, dest_jid, profile): + """OTR state has changed for on destinee""" + # XXX: this method could be in QuickApp but it's here as + # it's only used by Cagou so far + for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)): + widget.onOTRState(state, dest_jid, profile) + ## misc ## def plugging_profiles(self):
--- a/src/cagou/plugins/plugin_wid_chat.kv Tue Jan 31 23:11:49 2017 +0100 +++ b/src/cagou/plugins/plugin_wid_chat.kv Wed Feb 01 21:47:16 2017 +0100 @@ -116,12 +116,13 @@ <EncryptionButton>: size_hint: None, 1 width: dp(30) - source: app.expand("{media}/icons/muchoslava/png/cadenas_ouvert_30.png") + allow_stretch: True + source: self.getIconSource() <OtrButton@Button>: size_hint: None, None size: self.texture_size - padding: 5, 5 + padding: dp(5), dp(10) <OtrMenu>: size_hint_x: None
--- a/src/cagou/plugins/plugin_wid_chat.py Tue Jan 31 23:11:49 2017 +0100 +++ b/src/cagou/plugins/plugin_wid_chat.py Wed Feb 01 21:47:16 2017 +0100 @@ -46,6 +46,14 @@ "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png" } +# following const are here temporary, they should move to quick frontend +OTR_STATE_UNTRUSTED = 'untrusted' +OTR_STATE_TRUSTED = 'trusted' +OTR_STATE_TRUST = (OTR_STATE_UNTRUSTED, OTR_STATE_TRUSTED) +OTR_STATE_UNENCRYPTED = 'unencrypted' +OTR_STATE_ENCRYPTED = 'encrypted' +OTR_STATE_ENCRYPTION = (OTR_STATE_UNENCRYPTED, OTR_STATE_ENCRYPTED) + class MessAvatar(Image): pass @@ -128,11 +136,25 @@ """ @param chat(Chat): Chat instance """ + self.chat = chat # 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) + def getIconSource(self): + """get path of icon""" + # TODO: use a more generic method to get icon name + if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: + icon_name = 'cadenas_ouvert' + else: + if self.chat.otr_state_trust == OTR_STATE_TRUSTED: + icon_name = 'cadenas_ferme' + else: + icon_name = 'cadenas_ferme_pas_authenthifie' + + return G.host.app.expand("{media}/icons/muchoslava/png/" + icon_name + "_30.png") + class OtrMenu(DropDown): @@ -183,9 +205,12 @@ 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) + self.otr_state_encryption = OTR_STATE_UNENCRYPTED + self.otr_state_trust = OTR_STATE_UNTRUSTED cagou_widget.CagouWidget.__init__(self) if type_ == C.CHAT_ONE2ONE: - self.headerInputAddExtra(EncryptionButton(self)) + self.encryption_btn = EncryptionButton(self) + self.headerInputAddExtra(self.encryption_btn) self.header_input.hint_text = u"{}".format(target) self.host.addListener('progressError', self.onProgressError, profiles) self.host.addListener('progressFinished', self.onProgressFinished, profiles) @@ -411,6 +436,17 @@ self.host.removeListener('progressError', self.onProgressError) return super(Chat, self).onDelete() + def onOTRState(self, state, dest_jid, profile): + assert profile in self.profiles + if state in OTR_STATE_ENCRYPTION: + self.otr_state_encryption = state + elif state in OTR_STATE_TRUST: + self.otr_state_trust = state + else: + log.error(_(u"Unknown OTR state received: {}".format(state))) + return + self.encryption_btn.source = self.encryption_btn.getIconSource() + def onDelete(self, force=False): if force==True: return self._onDelete()