From f011f1c5ab329280f5d96714948566cbca21673c Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 3 Nov 2022 22:42:57 +0200 Subject: [PATCH] Switch [WIP] --- plugin-manifest.json | 21 +++++++++++++++++++++ plugin.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 plugin-manifest.json diff --git a/plugin-manifest.json b/plugin-manifest.json new file mode 100644 index 0000000..55570b0 --- /dev/null +++ b/plugin-manifest.json @@ -0,0 +1,21 @@ +{ + "authors": [ + "Pavel R ", + "Bohdan Horbeshko " + ], + "config_dialog": false, + "description": "Off-the-Record encryption", + "homepage": "https://dev.narayana.im/gajim-otrplugin", + "name": "otrplugin", + "platforms": [ + "others", + "linux", + "darwin", + "win32" + ], + "requirements": [ + "gajim>=1.5,<1.6" + ], + "short_name": "otrplugin", + "version": "0.4" +} diff --git a/plugin.py b/plugin.py index 5b9cced..b4c1f73 100644 --- a/plugin.py +++ b/plugin.py @@ -22,6 +22,8 @@ ERROR = None import logging from gajim.plugins import GajimPlugin from gajim.common import app +from gajim.common.modules.contacts import BareContact +from gi.repository import Gtk log = logging.getLogger('gajim.p.otr') @@ -52,6 +54,8 @@ class OTRPlugin(GajimPlugin): self.modules = [module] self.gui_extension_points = { 'encrypt' + self.encryption_name: (self._encrypt_message, None), + 'message_actions_box': (self._actions_hack_activate, self._actions_hack_deactivate), + 'switch_contact': (self._switch_contact, None), } @staticmethod @@ -68,8 +72,33 @@ class OTRPlugin(GajimPlugin): def encrypt_file(file, account, callback): callback(file) + def toggle_otr(self): + pass + # encrypt message # def _encrypt_message(self,con,event,callback): if not event.message or event.type_ != 'chat': return # drop empty and non-chat messages otr = self.get_otr(event.account) otr.otr.encrypt(event,callback) + + def _actions_hack_activate(self, grid, box): + self.switch_box = Gtk.VBox() + label = Gtk.Label(label='OTR') + self.switch = Gtk.Switch() + self.switch_box.pack_start(label, False, True, 0) + self.switch_box.pack_start(self.switch, True, True, 0) + box.pack_start(self.switch_box, False, True, 0) + self.switch.connect('activate', self.toggle_otr) + self._update_switch_visibility(app.window.get_chat_stack()._get_current_contact()) + + def _actions_hack_deactivate(self, grid, box): + box.remove(self.switch_box) + + def _update_switch_visibility(self, contact): + if isinstance(contact, BareContact): + self.switch_box.show_all() + else: + self.switch_box.hide() + + def _switch_contact(self, contact): + self._update_switch_visibility(contact)