From 227cdb742bc37084f72d996fd0f969330a4bf585 Mon Sep 17 00:00:00 2001 From: Stefan Bethge Date: Sat, 30 Sep 2006 18:23:47 +0000 Subject: [PATCH] proper handling of normal accounts with the name 'Local', don't use account's name but is_zeroconf flag for checks --- src/common/zeroconf/connection_zeroconf.py | 8 ++------ src/common/zeroconf/zeroconf.py | 11 +++++------ src/config.py | 17 ++++++++++++++--- src/gajim.py | 2 +- src/roster_window.py | 6 +++--- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index fd507f357..6b2543ac3 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -140,13 +140,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): self.email = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_email') # END __init__ - def put_event(self, ev): - if gajim.handlers.has_key(ev[0]): - gajim.handlers[ev[0]](self.name, ev[1]) - def dispatch(self, event, data): - '''always passes account name as first param''' - self.put_event((event, data)) + if gajim.handlers.has_key(event): + gajim.handlers[event](self.name, data) def _reconnect(self): gajim.log.debug('reconnect') diff --git a/src/common/zeroconf/zeroconf.py b/src/common/zeroconf/zeroconf.py index 0924b0869..fccf1a635 100755 --- a/src/common/zeroconf/zeroconf.py +++ b/src/common/zeroconf/zeroconf.py @@ -74,18 +74,18 @@ class Zeroconf: def new_service_callback(self, interface, protocol, name, stype, domain, flags): gajim.log.debug('Found service %s in domain %s on %i.%i.' % (name, domain, interface, protocol)) - if not self.connected: - return + # if not self.connected: + # return - #synchronous resolving + # synchronous resolving self.server.ResolveService( int(interface), int(protocol), name, stype, \ domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \ reply_handler=self.service_resolved_callback, error_handler=self.error_callback) def remove_service_callback(self, interface, protocol, name, stype, domain, flags): gajim.log.debug('Service %s in domain %s on %i.%i disappeared.' % (name, domain, interface, protocol)) - #if not self.connected: - # return + # if not self.connected: + # return if name != self.name: for key in self.contacts.keys(): if self.contacts[key][C_BARE_NAME] == name: @@ -98,7 +98,6 @@ class Zeroconf: if self.service_browser: return - object_path = self.server.ServiceBrowserNew(interface, protocol, \ stype, domain, dbus.UInt32(0)) diff --git a/src/config.py b/src/config.py index 9aaf81caa..897907c31 100644 --- a/src/config.py +++ b/src/config.py @@ -1357,6 +1357,9 @@ class AccountModificationWindow: config['custom_host'] = self.xml.get_widget( 'custom_host_entry').get_text().decode('utf-8') + # update in case the name changed to local accounts name + config['is_zeroconf'] = False + config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8') if config['keyname'] == '': #no key selected config['keyid'] = '' @@ -1804,7 +1807,7 @@ class AccountsWindow: w.set_active(st) if os.name == 'nt' or (avahi_error and not w.get_active()): w.set_sensitive(False) - w.connect('toggled', self.on_enable_zeroconf_checkbutton_toggled) + self.zeroconf_toggled_id = w.connect('toggled', self.on_enable_zeroconf_checkbutton_toggled) def on_accounts_window_key_press_event(self, widget, event): if event.keyval == gtk.keysyms.Escape: @@ -1845,7 +1848,7 @@ class AccountsWindow: dialogs.ErrorDialog(_('Unread events'), _('Read all pending events before removing this account.')) return - if account == gajim.ZEROCONF_ACC_NAME: + if gajim.config.get_per('accounts', account, 'is_zeroconf'): w = self.xml.get_widget('enable_zeroconf_checkbutton') w.set_active(False) else: @@ -1871,7 +1874,7 @@ class AccountsWindow: self.show_modification_window(account) def show_modification_window(self, account): - if account == gajim.ZEROCONF_ACC_NAME: + if gajim.config.get_per('accounts', account, 'is_zeroconf'): if gajim.interface.instances.has_key('zeroconf_properties'): gajim.interface.instances['zeroconf_properties'].window.present() else: @@ -1902,6 +1905,14 @@ class AccountsWindow: def on_enable_zeroconf_checkbutton_toggled(self, widget): + # don't do anything if there is an account with the local name but is a normal account + if gajim.connections.has_key(gajim.ZEROCONF_ACC_NAME) and not gajim.connections[gajim.ZEROCONF_ACC_NAME].is_zeroconf: + gajim.connections[gajim.ZEROCONF_ACC_NAME].dispatch('ERROR', (_('Account Local already exists.'),_('Please rename or remove it before enabling link-local messaging.'))) + widget.disconnect(self.zeroconf_toggled_id) + widget.set_active(False) + self.zeroconf_toggled_id = widget.connect('toggled', self.on_enable_zeroconf_checkbutton_toggled) + return + if gajim.config.get('enable_zeroconf'): #disable gajim.interface.roster.close_all(gajim.ZEROCONF_ACC_NAME) diff --git a/src/gajim.py b/src/gajim.py index 70d8bfe54..3ebd09993 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1888,7 +1888,7 @@ class Interface: if gajim.config.get('enable_zeroconf'): gajim.connections[gajim.ZEROCONF_ACC_NAME] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(gajim.ZEROCONF_ACC_NAME) for account in gajim.config.get_per('accounts'): - if account != gajim.ZEROCONF_ACC_NAME: + if not gajim.config.get_per('accounts', account, 'is_zeroconf'): gajim.connections[account] = common.connection.Connection(account) # gtk hooks diff --git a/src/roster_window.py b/src/roster_window.py index 8a385e8a5..96f78cab6 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1369,7 +1369,7 @@ class RosterWindow: if not contact: return - if account == gajim.ZEROCONF_ACC_NAME: + if gajim.config.get_per('accounts', account, 'is_zeroconf'): xml = gtkgui_helpers.get_glade('zeroconf_contact_context_menu.glade') zeroconf_contact_context_menu = xml.get_widget('zeroconf_contact_context_menu') @@ -3730,7 +3730,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid) account_dest, c_dest, path) return - if account_dest == gajim.ZEROCONF_ACC_NAME: + if gajim.config.get_per('accounts', account_dest, 'is_zeroconf'): # drop on zeroconf account, no contact adds possible return @@ -3745,7 +3745,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid) return if type_dest == 'account' and account_source == account_dest: return - if account_source == gajim.ZEROCONF_ACC_NAME: + if gajim.config.get_per('accounts', account_source, 'is_zeroconf'): return it = iter_source while model[it][C_TYPE] == 'contact':