Fix initializing the switch on Gajim startup [WIP]
This commit is contained in:
parent
f011f1c5ab
commit
c745cb4b60
39
plugin.py
39
plugin.py
|
@ -54,9 +54,24 @@ class OTRPlugin(GajimPlugin):
|
||||||
self.modules = [module]
|
self.modules = [module]
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
'encrypt' + self.encryption_name: (self._encrypt_message, None),
|
'encrypt' + self.encryption_name: (self._encrypt_message, None),
|
||||||
'message_actions_box': (self._actions_hack_activate, self._actions_hack_deactivate),
|
'message_actions_box': (self._message_actions_box_activate, self._message_actions_box_deactivate),
|
||||||
'switch_contact': (self._switch_contact, None),
|
'switch_contact': (self._switch_contact, None),
|
||||||
}
|
}
|
||||||
|
self.switch = None
|
||||||
|
self.switch_box = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_box():
|
||||||
|
return app.window.get_chat_stack().get_message_action_box()._ui.box
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
if app.window is not None:
|
||||||
|
box = self._get_box()
|
||||||
|
self._actions_hack_activate(box)
|
||||||
|
|
||||||
|
def deactivate(self):
|
||||||
|
box = self._get_box()
|
||||||
|
self._actions_hack_deactivate(box)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_otr(account):
|
def get_otr(account):
|
||||||
|
@ -73,7 +88,7 @@ class OTRPlugin(GajimPlugin):
|
||||||
callback(file)
|
callback(file)
|
||||||
|
|
||||||
def toggle_otr(self):
|
def toggle_otr(self):
|
||||||
pass
|
print('toggle')
|
||||||
|
|
||||||
# encrypt message #
|
# encrypt message #
|
||||||
def _encrypt_message(self,con,event,callback):
|
def _encrypt_message(self,con,event,callback):
|
||||||
|
@ -81,21 +96,35 @@ class OTRPlugin(GajimPlugin):
|
||||||
otr = self.get_otr(event.account)
|
otr = self.get_otr(event.account)
|
||||||
otr.otr.encrypt(event,callback)
|
otr.otr.encrypt(event,callback)
|
||||||
|
|
||||||
def _actions_hack_activate(self, grid, box):
|
def _message_actions_box_activate(self, grid, box):
|
||||||
|
if self.switch_box is None:
|
||||||
|
self._actions_hack_activate(box)
|
||||||
|
|
||||||
|
def _message_actions_box_deactivate(self, grid, box):
|
||||||
|
if self.switch_box is not None:
|
||||||
|
self._actions_hack_deactivate(box)
|
||||||
|
|
||||||
|
def _actions_hack_activate(self, box):
|
||||||
self.switch_box = Gtk.VBox()
|
self.switch_box = Gtk.VBox()
|
||||||
label = Gtk.Label(label='OTR')
|
label = Gtk.Label(label='OTR')
|
||||||
self.switch = Gtk.Switch()
|
self.switch = Gtk.Switch()
|
||||||
self.switch_box.pack_start(label, False, True, 0)
|
self.switch_box.pack_start(label, False, True, 0)
|
||||||
self.switch_box.pack_start(self.switch, True, True, 0)
|
self.switch_box.pack_start(self.switch, False, True, 0)
|
||||||
|
self.switch_box.set_center_widget(self.switch)
|
||||||
box.pack_start(self.switch_box, False, True, 0)
|
box.pack_start(self.switch_box, False, True, 0)
|
||||||
self.switch.connect('activate', self.toggle_otr)
|
self.switch.connect('activate', self.toggle_otr)
|
||||||
|
if app.window is not None and hasattr(app.window, '_chat_page'):
|
||||||
self._update_switch_visibility(app.window.get_chat_stack()._get_current_contact())
|
self._update_switch_visibility(app.window.get_chat_stack()._get_current_contact())
|
||||||
|
|
||||||
def _actions_hack_deactivate(self, grid, box):
|
def _actions_hack_deactivate(self, box):
|
||||||
box.remove(self.switch_box)
|
box.remove(self.switch_box)
|
||||||
|
self.switch_box = None
|
||||||
|
self.switch = None
|
||||||
|
|
||||||
def _update_switch_visibility(self, contact):
|
def _update_switch_visibility(self, contact):
|
||||||
if isinstance(contact, BareContact):
|
if isinstance(contact, BareContact):
|
||||||
|
otr = self.get_otr(contact._account)
|
||||||
|
self.switch.set_active(contact.jid.new_as_bare() in otr.otr.ctxs)
|
||||||
self.switch_box.show_all()
|
self.switch_box.show_all()
|
||||||
else:
|
else:
|
||||||
self.switch_box.hide()
|
self.switch_box.hide()
|
||||||
|
|
Loading…
Reference in a new issue