From 30e054df49eaf4f9f3c296208845cf60848430e7 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 28 Nov 2010 11:00:53 +0100 Subject: [PATCH] use NEC to handle zeroconf name conflict event --- src/common/connection_handlers_events.py | 4 ++++ src/common/zeroconf/connection_zeroconf.py | 3 ++- src/gui_interface.py | 16 ++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 86a20c312..27004fe50 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1554,3 +1554,7 @@ class MetacontactsReceivedEvent(nec.NetworkIncomingEvent): else: self.meta_list[tag] = [data] return True + +class ZeroconfNameConflictEvent(nec.NetworkIncomingEvent): + name = 'zeroconf-name-conflict' + base_network_events = [] diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 3d08d1ade..79e7d5eac 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -178,7 +178,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf): self.disconnect() gajim.nec.push_incoming_event(OurShowEvent(None, conn=self, show='offline')) - self.dispatch('ZC_NAME_CONFLICT', alt_name) + gajim.nec.push_incoming_event(ZeroconfNameConflictEvent(None, conn=self, + alt_name=alt_name)) def _on_error(self, message): self.dispatch('ERROR', (_('Avahi error'), diff --git a/src/gui_interface.py b/src/gui_interface.py index 05c987498..ed0d3ec7b 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1083,19 +1083,19 @@ class Interface: if ctrl: ctrl.begin_e2e_negotiation() - def handle_event_zc_name_conflict(self, account, data): + def handle_event_zc_name_conflict(self, obj): def on_ok(new_name): gajim.config.set_per('accounts', account, 'name', new_name) - show = gajim.connections[account].old_show - status = gajim.connections[account].status - gajim.connections[account].username = new_name - gajim.connections[account].change_status(show, status) + show = obj.conn.old_show + status = obj.conn.status + obj.conn.username = new_name + obj.conn.change_status(show, status) def on_cancel(): - gajim.connections[account].change_status('offline', '') + obj.conn.change_status('offline', '') dlg = dialogs.InputDialog(_('Username Conflict'), _('Please type a new username for your local account'), - input_str=data, is_modal=True, ok_handler=on_ok, + input_str=obj.alt_name, is_modal=True, ok_handler=on_ok, cancel_handler=on_cancel) def handle_event_resource_conflict(self, obj): @@ -1420,7 +1420,6 @@ class Interface: 'FILE_SEND_ERROR': [self.handle_event_file_send_error], 'SIGNED_IN': [self.handle_event_signed_in], 'FAILED_DECRYPT': [self.handle_event_failed_decrypt], - 'ZC_NAME_CONFLICT': [self.handle_event_zc_name_conflict], 'PASSWORD_REQUIRED': [self.handle_event_password_required], 'atom-entry-received': [self.handle_atom_entry], 'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase], @@ -1463,6 +1462,7 @@ class Interface: 'unsubscribed-presence-received': [ self.handle_event_unsubscribed_presence], 'vcard-received': [self.handle_event_vcard], + 'zeroconf-name-conflict': [self.handle_event_zc_name_conflict], } def register_core_handlers(self):