Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 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 |
comparison
equal
deleted
inserted
replaced
121:c498178d8122 | 122:dcd6fbb3f010 |
---|---|
44 "description": _(u"instant messaging with one person or a group"), | 44 "description": _(u"instant messaging with one person or a group"), |
45 "icon_small": u"{media}/icons/muchoslava/png/chat_new_32.png", | 45 "icon_small": u"{media}/icons/muchoslava/png/chat_new_32.png", |
46 "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png" | 46 "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png" |
47 } | 47 } |
48 | 48 |
49 # following const are here temporary, they should move to quick frontend | |
50 OTR_STATE_UNTRUSTED = 'untrusted' | |
51 OTR_STATE_TRUSTED = 'trusted' | |
52 OTR_STATE_TRUST = (OTR_STATE_UNTRUSTED, OTR_STATE_TRUSTED) | |
53 OTR_STATE_UNENCRYPTED = 'unencrypted' | |
54 OTR_STATE_ENCRYPTED = 'encrypted' | |
55 OTR_STATE_ENCRYPTION = (OTR_STATE_UNENCRYPTED, OTR_STATE_ENCRYPTED) | |
56 | |
49 | 57 |
50 class MessAvatar(Image): | 58 class MessAvatar(Image): |
51 pass | 59 pass |
52 | 60 |
53 | 61 |
126 | 134 |
127 def __init__(self, chat, **kwargs): | 135 def __init__(self, chat, **kwargs): |
128 """ | 136 """ |
129 @param chat(Chat): Chat instance | 137 @param chat(Chat): Chat instance |
130 """ | 138 """ |
139 self.chat = chat | |
131 # for now we do a simple ContextMenu as we have only OTR | 140 # for now we do a simple ContextMenu as we have only OTR |
132 self.otr_menu = OtrMenu(chat) | 141 self.otr_menu = OtrMenu(chat) |
133 super(EncryptionButton, self).__init__(**kwargs) | 142 super(EncryptionButton, self).__init__(**kwargs) |
134 self.bind(on_release=self.otr_menu.open) | 143 self.bind(on_release=self.otr_menu.open) |
144 | |
145 def getIconSource(self): | |
146 """get path of icon""" | |
147 # TODO: use a more generic method to get icon name | |
148 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: | |
149 icon_name = 'cadenas_ouvert' | |
150 else: | |
151 if self.chat.otr_state_trust == OTR_STATE_TRUSTED: | |
152 icon_name = 'cadenas_ferme' | |
153 else: | |
154 icon_name = 'cadenas_ferme_pas_authenthifie' | |
155 | |
156 return G.host.app.expand("{media}/icons/muchoslava/png/" + icon_name + "_30.png") | |
135 | 157 |
136 | 158 |
137 class OtrMenu(DropDown): | 159 class OtrMenu(DropDown): |
138 | 160 |
139 def __init__(self, chat, **kwargs): | 161 def __init__(self, chat, **kwargs): |
181 message_input = properties.ObjectProperty() | 203 message_input = properties.ObjectProperty() |
182 messages_widget = properties.ObjectProperty() | 204 messages_widget = properties.ObjectProperty() |
183 | 205 |
184 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): | 206 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): |
185 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) | 207 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
208 self.otr_state_encryption = OTR_STATE_UNENCRYPTED | |
209 self.otr_state_trust = OTR_STATE_UNTRUSTED | |
186 cagou_widget.CagouWidget.__init__(self) | 210 cagou_widget.CagouWidget.__init__(self) |
187 if type_ == C.CHAT_ONE2ONE: | 211 if type_ == C.CHAT_ONE2ONE: |
188 self.headerInputAddExtra(EncryptionButton(self)) | 212 self.encryption_btn = EncryptionButton(self) |
213 self.headerInputAddExtra(self.encryption_btn) | |
189 self.header_input.hint_text = u"{}".format(target) | 214 self.header_input.hint_text = u"{}".format(target) |
190 self.host.addListener('progressError', self.onProgressError, profiles) | 215 self.host.addListener('progressError', self.onProgressError, profiles) |
191 self.host.addListener('progressFinished', self.onProgressFinished, profiles) | 216 self.host.addListener('progressFinished', self.onProgressFinished, profiles) |
192 self._waiting_pids = {} # waiting progress ids | 217 self._waiting_pids = {} # waiting progress ids |
193 self.postInit() | 218 self.postInit() |
409 def _onDelete(self): | 434 def _onDelete(self): |
410 self.host.removeListener('progressFinished', self.onProgressFinished) | 435 self.host.removeListener('progressFinished', self.onProgressFinished) |
411 self.host.removeListener('progressError', self.onProgressError) | 436 self.host.removeListener('progressError', self.onProgressError) |
412 return super(Chat, self).onDelete() | 437 return super(Chat, self).onDelete() |
413 | 438 |
439 def onOTRState(self, state, dest_jid, profile): | |
440 assert profile in self.profiles | |
441 if state in OTR_STATE_ENCRYPTION: | |
442 self.otr_state_encryption = state | |
443 elif state in OTR_STATE_TRUST: | |
444 self.otr_state_trust = state | |
445 else: | |
446 log.error(_(u"Unknown OTR state received: {}".format(state))) | |
447 return | |
448 self.encryption_btn.source = self.encryption_btn.getIconSource() | |
449 | |
414 def onDelete(self, force=False): | 450 def onDelete(self, force=False): |
415 if force==True: | 451 if force==True: |
416 return self._onDelete() | 452 return self._onDelete() |
417 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: | 453 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: |
418 # we don't keep duplicate widgets | 454 # we don't keep duplicate widgets |