From e1dadf48c15eb06fc510de38f90b4e7ee20c1b2e Mon Sep 17 00:00:00 2001 From: Stefan Bethge Date: Mon, 2 Oct 2006 14:15:51 +0000 Subject: [PATCH] only restart listener or reconnect upon changing preferences if necessary --- data/glade/zeroconf_properties_window.glade | 1 + src/common/zeroconf/connection_zeroconf.py | 29 ++++++++++++--------- src/config.py | 23 +++++++++------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/data/glade/zeroconf_properties_window.glade b/data/glade/zeroconf_properties_window.glade index 49c7e887b..c296fe4d5 100644 --- a/data/glade/zeroconf_properties_window.glade +++ b/data/glade/zeroconf_properties_window.glade @@ -566,6 +566,7 @@ You might consider to change possible firewall settings. True + False True True False diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 6b2543ac3..b7d86ac11 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -189,8 +189,10 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): diffs = self.roster.getDiffs() for key in diffs: self.roster.setItem(key) - self.dispatch('ROSTER_INFO', (key, self.roster.getName(key), 'both', 'no', self.roster.getGroups(key))) - self.dispatch('NOTIFY', (key, self.roster.getStatus(key), self.roster.getMessage(key), 'local', 0, None, 0)) + self.dispatch('ROSTER_INFO', (key, self.roster.getName(key), + 'both', 'no', self.roster.getGroups(key))) + self.dispatch('NOTIFY', (key, self.roster.getStatus(key), + self.roster.getMessage(key), 'local', 0, None, 0)) #XXX open chat windows don't get refreshed (full name), add that return self.call_resolve_timeout @@ -259,28 +261,29 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): # stop calling the timeout self.call_resolve_timeout = False self.zeroconf.disconnect() - - def reconnect(self, new_port): + + def reconnect(self): if self.connected: txt = {} txt['1st'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_first_name') txt['last'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_last_name') txt['jid'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_jabber_id') txt['email'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_email') - - port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port') - - if new_port or use_tls: - self.connection.kill_all_connections() - self.connection.listener.disconnect() - self.connection.start_listener(port) - + self.zeroconf.remove_announce() self.zeroconf.txt = txt - self.zeroconf.port = port + self.zeroconf.port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port') self.zeroconf.username = self.username self.zeroconf.announce() + def restart_listener(self): + if self.connection: + port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port') + self.connection.kill_all_connections() + if self.connection.listener: + self.connection.listener.disconnect() + self.connection.start_listener(port) + def change_status(self, show, msg, sync = False, auto = False): if not show in STATUS_LIST: return -1 diff --git a/src/config.py b/src/config.py index d2b7a05d6..316f24050 100644 --- a/src/config.py +++ b/src/config.py @@ -3233,14 +3233,8 @@ class ZeroconfPropertiesWindow: if use_custom_port: port = self.xml.get_widget('custom_port_entry').get_text() else: - port = '5298' - - # force restart of listener (because port has changed) - if port != old_port: - use_custom_port = True - else: - use_custom_port = False - + port = 5298 + config['custom_port'] = port config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8') @@ -3255,11 +3249,20 @@ class ZeroconfPropertiesWindow: config['gpgpassword'] = self.xml.get_widget('gpg_password_entry' ).get_text().decode('utf-8') - for opt in config: + reconnect = False + for opt in ('zeroconf_first_name','zeroconf_last_name', 'zeroconf_jabber_id', 'zeroconf_email', 'custom_port'): + if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, opt) != config[opt]: + reconnect = True + + for opt in config: gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, opt, config[opt]) if gajim.connections.has_key(gajim.ZEROCONF_ACC_NAME): - gajim.connections[gajim.ZEROCONF_ACC_NAME].reconnect(use_custom_port) + if port != old_port: + # restart listener if port has changed + gajim.connections[gajim.ZEROCONF_ACC_NAME].restart_listener() + if reconnect: + gajim.connections[gajim.ZEROCONF_ACC_NAME].reconnect() self.window.destroy()