From da97249ef6218b0f268ae6d7e1b8ae46289cac04 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 15 Nov 2010 16:50:54 +0100 Subject: [PATCH] use NEC to handle bad GPG passphrase events --- src/common/connection.py | 3 ++- src/common/connection_handlers.py | 3 ++- src/common/connection_handlers_events.py | 12 +++++++++++- src/gui_interface.py | 18 ++++++++---------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 0788e545c..b21936026 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -223,7 +223,8 @@ class CommonConnection: if signed == 'BAD_PASSPHRASE': self.USE_GPG = False signed = '' - self.dispatch('BAD_PASSPHRASE', ()) + gajim.nec.push_incoming_event(BadGPGPassphrase(None, + conn=self)) return signed def _on_disconnected(self): diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index b211f54e9..634ca64ad 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -2027,7 +2027,8 @@ ConnectionJingle, ConnectionIBBytestream): if sign_msg and not signed: signed = self.get_signed_presence(msg) if signed is None: - self.dispatch('BAD_PASSPHRASE', ()) + gajim.nec.push_incoming_event(BadGPGPassphraseEvent(None, + conn=self)) self.USE_GPG = False signed = '' self.connected = gajim.SHOW_LIST.index(show) diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index da1836d11..94dd281ba 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1302,4 +1302,14 @@ class AgentRemovedEvent(nec.NetworkIncomingEvent): for jid in gajim.contacts.get_jid_list(self.conn.name): if jid.endswith('@' + self.agent): self.jid_list.append(jid) - return True \ No newline at end of file + return True + +class BadGPGPassphraseEvent(nec.NetworkIncomingEvent): + name = 'bad-gpg-passphrase' + base_network_events = [] + + def generate(self): + self.account = self.conn.name + self.use_gpg_agent = gajim.config.get('use_gpg_agent') + self.keyID = gajim.config.get_per('accounts', account, 'keyid') + return True diff --git a/src/gui_interface.py b/src/gui_interface.py index 957ebacb3..5536a8e39 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -859,23 +859,21 @@ class Interface: del self.gpg_passphrase[keyid] return False - def handle_event_bad_passphrase(self, account, array): + def handle_event_bad_gpg_passphrase(self, obj): #('BAD_PASSPHRASE', account, ()) - use_gpg_agent = gajim.config.get('use_gpg_agent') - sectext = '' - if use_gpg_agent: + if obj.use_gpg_agent: sectext = _('You configured Gajim to use GPG agent, but there is no' - ' GPG agent running or it returned a wrong passphrase.\n') + ' GPG agent running or it returned a wrong passphrase.\n') sectext += _('You are currently connected without your OpenPGP ' 'key.') dialogs.WarningDialog(_('Your passphrase is incorrect'), sectext) else: path = gtkgui_helpers.get_icon_path('gajim-warning', 48) + account = obj.conn.name notify.popup('warning', account, account, 'warning', path, - _('OpenGPG Passphrase Incorrect'), - _('You are currently connected without your OpenPGP key.')) - keyID = gajim.config.get_per('accounts', account, 'keyid') - self.forget_gpg_passphrase(keyID) + _('OpenGPG Passphrase Incorrect'), + _('You are currently connected without your OpenPGP key.')) + self.forget_gpg_passphrase(obj.keyID) def handle_event_gpg_password_required(self, account, array): #('GPG_PASSWORD_REQUIRED', account, (callback,)) @@ -1755,7 +1753,6 @@ class Interface: 'GC_NOTIFY': [self.handle_event_gc_notify], 'GC_SUBJECT': [self.handle_event_gc_subject], 'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change], - 'BAD_PASSPHRASE': [self.handle_event_bad_passphrase], 'CONNECTION_LOST': [self.handle_event_connection_lost], 'FILE_REQUEST': [self.handle_event_file_request], 'FILE_REQUEST_ERROR': [self.handle_event_file_request_error], @@ -1790,6 +1787,7 @@ class Interface: 'INSECURE_PASSWORD': [self.handle_event_insecure_password], 'PEP_RECEIVED': [self.handle_event_pep_received], 'CAPS_RECEIVED': [self.handle_event_caps_received], + 'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase], 'bookmarks-received': [self.handle_event_bookmarks], 'gc-invitation-received': [self.handle_event_gc_invitation], 'gc-presence-received': [self.handle_event_gc_presence],