better handling of multiple gajim instances on one machine
This commit is contained in:
parent
25b5b85aaa
commit
5d1410d17a
2 changed files with 25 additions and 12 deletions
|
@ -179,7 +179,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
|
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
|
||||||
# keyID, timestamp))
|
# keyID, timestamp))
|
||||||
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0))
|
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0))
|
||||||
print 'connection_zeroconf:186'
|
|
||||||
|
|
||||||
|
|
||||||
def connect(self, data = None, show = 'online'):
|
def connect(self, data = None, show = 'online'):
|
||||||
|
@ -203,7 +202,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
gobject.timeout_add(1000, self._on_resolve_timeout)
|
gobject.timeout_add(1000, self._on_resolve_timeout)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# display visual notification that we could not connect to avahi
|
#TODO: display visual notification that we could not connect to avahi
|
||||||
|
|
||||||
def connect_and_init(self, show, msg, signed):
|
def connect_and_init(self, show, msg, signed):
|
||||||
self.continue_connect_info = [show, msg, signed]
|
self.continue_connect_info = [show, msg, signed]
|
||||||
|
|
|
@ -50,6 +50,8 @@ class Zeroconf:
|
||||||
self.entrygroup = None
|
self.entrygroup = None
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.announced = False
|
self.announced = False
|
||||||
|
self.invalid_self_contact = {}
|
||||||
|
|
||||||
|
|
||||||
## handlers for dbus callbacks
|
## handlers for dbus callbacks
|
||||||
|
|
||||||
|
@ -58,14 +60,12 @@ class Zeroconf:
|
||||||
print "Error:", str(err)
|
print "Error:", str(err)
|
||||||
|
|
||||||
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||||
# we don't want to see ourselves in the list
|
# print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
||||||
if name != self.name:
|
|
||||||
# print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
|
||||||
|
|
||||||
#synchronous resolving
|
#synchronous resolving
|
||||||
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
||||||
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
|
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
|
||||||
reply_handler=self.service_resolved_callback, error_handler=self.print_error_callback)
|
reply_handler=self.service_resolved_callback, error_handler=self.print_error_callback)
|
||||||
|
|
||||||
def remove_service_callback(self, interface, protocol, name, stype, domain, flags):
|
def remove_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||||
# print "Service '%s' in domain '%s' on %i.%i disappeared." % (name, domain, interface, protocol)
|
# print "Service '%s' in domain '%s' on %i.%i disappeared." % (name, domain, interface, protocol)
|
||||||
|
@ -112,9 +112,18 @@ class Zeroconf:
|
||||||
if name.find('@') == -1:
|
if name.find('@') == -1:
|
||||||
name = name + '@' + name
|
name = name + '@' + name
|
||||||
|
|
||||||
self.contacts[name] = (name, domain, interface, protocol, host, address, port,
|
# we don't want to see ourselves in the list
|
||||||
|
if name != self.name:
|
||||||
|
self.contacts[name] = (name, domain, interface, protocol, host, address, port,
|
||||||
bare_name, txt)
|
bare_name, txt)
|
||||||
self.new_serviceCB(name)
|
self.new_serviceCB(name)
|
||||||
|
else:
|
||||||
|
# remember data
|
||||||
|
# In case this is not our own record but of another
|
||||||
|
# gajim instance on the same machine,
|
||||||
|
# it will be used when we get a new name.
|
||||||
|
self.invalid_self_contact[name] = (name, domain, interface, protocol, host, address, port, bare_name, txt)
|
||||||
|
|
||||||
|
|
||||||
# different handler when resolving all contacts
|
# different handler when resolving all contacts
|
||||||
def service_resolved_all_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
def service_resolved_all_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
||||||
|
@ -139,8 +148,13 @@ class Zeroconf:
|
||||||
|
|
||||||
def service_add_fail_callback(self, err):
|
def service_add_fail_callback(self, err):
|
||||||
print 'Error while adding service:', str(err)
|
print 'Error while adding service:', str(err)
|
||||||
|
old_name = self.name
|
||||||
self.name = self.server.GetAlternativeServiceName(self.name)
|
self.name = self.server.GetAlternativeServiceName(self.name)
|
||||||
self.create_service()
|
self.create_service()
|
||||||
|
if self.invalid_self_contact.has_key(old_name):
|
||||||
|
self.contacts[old_name] = self.invalid_self_contact[old_name]
|
||||||
|
self.new_serviceCB(old_name)
|
||||||
|
del self.invalid_self_contact[old_name]
|
||||||
|
|
||||||
def server_state_changed_callback(self, state, error):
|
def server_state_changed_callback(self, state, error):
|
||||||
print 'server.state %s' % state
|
print 'server.state %s' % state
|
||||||
|
@ -249,7 +263,7 @@ class Zeroconf:
|
||||||
db.connect_to_signal('ItemNew', self.new_domain_callback)
|
db.connect_to_signal('ItemNew', self.new_domain_callback)
|
||||||
else:
|
else:
|
||||||
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain)
|
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue