From c4f7d9b98a229ad52e834313ab93f0f9ebc77884 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 13 Nov 2011 18:34:52 +0100 Subject: Add a setkey command for the /gpg command. --- plugins/gpg/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'plugins/gpg') diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py index 7151b8ff..01ca6ab2 100644 --- a/plugins/gpg/__init__.py +++ b/plugins/gpg/__init__.py @@ -56,7 +56,7 @@ class Plugin(BasePlugin): self.add_event_handler('conversation_say_after', self.on_conversation_say) self.add_event_handler('conversation_msg', self.on_conversation_msg) - self.add_command('gpg', self.command_gpg, "Usage: /gpg \nGpg: Force or disable gpg encryption with this fulljid.", self.gpg_completion) + self.add_command('gpg', self.command_gpg, "Usage: /gpg [JID] [keyid]\nGpg: Force or disable gpg encryption with the fulljid of the current conversation. The setkey argument lets you associate a keyid with the given bare JID.", self.gpg_completion) ConversationTab.add_information_element('gpg', self.display_encryption_status) def cleanup(self): @@ -159,7 +159,7 @@ class Plugin(BasePlugin): return '' status = self.contacts[jid.full] self.core.information('%s' % (status,)) - if status in ('valid', 'invalid'): + if status in ('valid', 'invalid', 'signed'): return ' GPG Key: %s (%s)' % (status, 'encrypted' if status == 'valid' else 'NOT encrypted',) else: return ' GPG: Encryption %s' % (status,) @@ -177,7 +177,7 @@ class Plugin(BasePlugin): if isinstance(self.core.current_tab(), ConversationTab): jid = JID(self.core.current_tab().get_name()) command = args[0] - if command == 'force': + if command == 'force' or command == 'enable': # we can force encryption only with contact having an associated # key, otherwise we cannot encrypt at all if self.config.has_section('keys') and jid.bare in self.config.options('keys'): @@ -186,10 +186,17 @@ class Plugin(BasePlugin): self.core.information('Cannot force encryption: no key associated with %s' % (jid.bare), 'Info') elif command == 'disable': self.contacts[JID(jid).full] = 'disabled' + elif command == 'setkey': + if len(args) != 3: + return self.core.command_help("gpg") + if not self.config.has_section('keys'): + self.config.add_section('keys') + self.config.set(jid.bare, args[2], 'keys') + self.config.write() self.core.refresh_window() - def gpg_completion(self, args): - pass + def gpg_completion(self, the_input): + return the_input.auto_completion(['force', 'disable', 'setkey'], ' ') def remove_gpg_headers(self, text): lines = text.splitlines() -- cgit v1.2.3