show input dialog when username is in conflict
This commit is contained in:
parent
354b4f17e9
commit
9c570f9588
|
@ -129,7 +129,7 @@ class P2PClient(IdleObject):
|
||||||
return False
|
return False
|
||||||
self.send(message)
|
self.send(message)
|
||||||
else:
|
else:
|
||||||
messagequeue.append(message)
|
self.messagequeue.append(message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_connect(self, conn):
|
def on_connect(self, conn):
|
||||||
|
@ -227,6 +227,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
''' class for sending file to socket over socks5 '''
|
''' class for sending file to socket over socks5 '''
|
||||||
def __init__(self, sock_hash, _sock, host = None, port = None, caller = None, on_connect = None):
|
def __init__(self, sock_hash, _sock, host = None, port = None, caller = None, on_connect = None):
|
||||||
IdleObject.__init__(self)
|
IdleObject.__init__(self)
|
||||||
|
self._owner = None
|
||||||
PlugIn.__init__(self)
|
PlugIn.__init__(self)
|
||||||
self.DBG_LINE='socket'
|
self.DBG_LINE='socket'
|
||||||
self.sendqueue = []
|
self.sendqueue = []
|
||||||
|
|
|
@ -88,10 +88,17 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.retrycount = 0
|
self.retrycount = 0
|
||||||
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
||||||
self.get_config_values_or_default()
|
self.get_config_values_or_default()
|
||||||
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service, self.username, self.host, self.port)
|
self.zeroconf = zeroconf.Zeroconf(self._on_new_service,
|
||||||
|
self._on_remove_service, self._on_name_conflictCB, self.username,
|
||||||
|
self.host, self.port)
|
||||||
self.muc_jid = {} # jid of muc server for each transport type
|
self.muc_jid = {} # jid of muc server for each transport type
|
||||||
self.vcard_supported = False
|
self.vcard_supported = False
|
||||||
|
|
||||||
|
def _on_name_conflictCB(self, alt_name):
|
||||||
|
self.disconnect()
|
||||||
|
self.dispatch('STATUS', 'offline')
|
||||||
|
self.dispatch('ZC_NAME_CONFLICT', alt_name)
|
||||||
|
|
||||||
def get_config_values_or_default(self):
|
def get_config_values_or_default(self):
|
||||||
''' get name, host, port from config, or
|
''' get name, host, port from config, or
|
||||||
create zeroconf account with default values'''
|
create zeroconf account with default values'''
|
||||||
|
@ -186,7 +193,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.dispatch('ROSTER_INFO', (jid, self.roster.getName(jid), 'both', 'no', self.roster.getGroups(jid)))
|
self.dispatch('ROSTER_INFO', (jid, self.roster.getName(jid), 'both', 'no', self.roster.getGroups(jid)))
|
||||||
self.dispatch('NOTIFY', (jid, self.roster.getStatus(jid), self.roster.getMessage(jid), 'local', 0, None, 0))
|
self.dispatch('NOTIFY', (jid, self.roster.getStatus(jid), self.roster.getMessage(jid), 'local', 0, None, 0))
|
||||||
|
|
||||||
|
|
||||||
def _on_remove_service(self,jid):
|
def _on_remove_service(self,jid):
|
||||||
self.roster.delItem(jid)
|
self.roster.delItem(jid)
|
||||||
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
|
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
|
||||||
|
@ -194,7 +200,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0))
|
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0))
|
||||||
|
|
||||||
def connect(self, data = None, show = 'online', msg = ''):
|
def connect(self, data = None, show = 'online', msg = ''):
|
||||||
|
print 'CONNECT'
|
||||||
self.get_config_values_or_default()
|
self.get_config_values_or_default()
|
||||||
|
print 'self.username', self.username
|
||||||
|
|
||||||
self.zeroconf.txt['status'] = show
|
self.zeroconf.txt['status'] = show
|
||||||
self.zeroconf.txt['msg'] = msg
|
self.zeroconf.txt['msg'] = msg
|
||||||
|
@ -206,6 +214,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.zeroconf.host = self.host
|
self.zeroconf.host = self.host
|
||||||
self.zeroconf.port = self.port
|
self.zeroconf.port = self.port
|
||||||
|
|
||||||
|
print 'self.connection', self.connection
|
||||||
if self.connection:
|
if self.connection:
|
||||||
return self.connection, ''
|
return self.connection, ''
|
||||||
|
|
||||||
|
|
|
@ -33,17 +33,20 @@ C_NAME, C_DOMAIN, C_INTERFACE, C_PROTOCOL, C_HOST, \
|
||||||
C_ADDRESS, C_PORT, C_BARE_NAME, C_TXT = range(9)
|
C_ADDRESS, C_PORT, C_BARE_NAME, C_TXT = range(9)
|
||||||
|
|
||||||
class Zeroconf:
|
class Zeroconf:
|
||||||
def __init__(self, new_serviceCB, remove_serviceCB, name, host, port):
|
def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB, name, host, port):
|
||||||
|
self.server = None
|
||||||
self.domain = None # specific domain to browse
|
self.domain = None # specific domain to browse
|
||||||
self.stype = '_presence._tcp'
|
self.stype = '_presence._tcp'
|
||||||
self.port = port # listening port that gets announced
|
self.port = port # listening port that gets announced
|
||||||
self.username = name
|
self.username = name
|
||||||
self.host = host
|
self.host = host
|
||||||
self.name = self.username+'@'+ self.host # service name
|
|
||||||
self.txt = {} # service data
|
self.txt = {} # service data
|
||||||
|
|
||||||
|
#XXX these CBs should be set to None when we destroy the object
|
||||||
|
# (go offline), because they create a circular reference
|
||||||
self.new_serviceCB = new_serviceCB
|
self.new_serviceCB = new_serviceCB
|
||||||
self.remove_serviceCB = remove_serviceCB
|
self.remove_serviceCB = remove_serviceCB
|
||||||
|
self.name_conflictCB = name_conflictCB
|
||||||
|
|
||||||
self.service_browsers = {}
|
self.service_browsers = {}
|
||||||
self.contacts = {} # all current local contacts with data
|
self.contacts = {} # all current local contacts with data
|
||||||
|
@ -54,13 +57,14 @@ class Zeroconf:
|
||||||
|
|
||||||
|
|
||||||
## handlers for dbus callbacks
|
## handlers for dbus callbacks
|
||||||
|
|
||||||
# error handler - maybe replace with gui version/gajim facilities
|
|
||||||
def print_error_callback(self, err):
|
def print_error_callback(self, err):
|
||||||
print "Error:", str(err)
|
# error handler - maybe replace with gui version/gajim facilities
|
||||||
|
gajim.log.debug(str(err))
|
||||||
|
|
||||||
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||||
# print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
||||||
|
if not self.connected:
|
||||||
|
return
|
||||||
|
|
||||||
#synchronous resolving
|
#synchronous resolving
|
||||||
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
||||||
|
@ -69,6 +73,8 @@ class Zeroconf:
|
||||||
|
|
||||||
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)
|
||||||
|
if not self.connected:
|
||||||
|
return
|
||||||
if name != self.name:
|
if name != self.name:
|
||||||
for key in self.contacts.keys():
|
for key in self.contacts.keys():
|
||||||
if self.contacts[key][C_BARE_NAME] == name:
|
if self.contacts[key][C_BARE_NAME] == name:
|
||||||
|
@ -86,9 +92,11 @@ class Zeroconf:
|
||||||
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
||||||
self.server.ServiceBrowserNew(interface, protocol, \
|
self.server.ServiceBrowserNew(interface, protocol, \
|
||||||
stype, domain, dbus.UInt32(0))),avahi.DBUS_INTERFACE_SERVICE_BROWSER)
|
stype, domain, dbus.UInt32(0))),avahi.DBUS_INTERFACE_SERVICE_BROWSER)
|
||||||
|
print 'b', dir(b), dir(self.server)
|
||||||
|
b.Free()
|
||||||
b.connect_to_signal('ItemNew', self.new_service_callback)
|
b.connect_to_signal('ItemNew', self.new_service_callback)
|
||||||
b.connect_to_signal('ItemRemove', self.remove_service_callback)
|
b.connect_to_signal('ItemRemove', self.remove_service_callback)
|
||||||
|
#~ b.Free()
|
||||||
self.service_browsers[(interface, protocol, stype, domain)] = b
|
self.service_browsers[(interface, protocol, stype, domain)] = b
|
||||||
|
|
||||||
def new_domain_callback(self,interface, protocol, domain, flags):
|
def new_domain_callback(self,interface, protocol, domain, flags):
|
||||||
|
@ -106,8 +114,10 @@ class Zeroconf:
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
||||||
# print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
||||||
# print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
|
# print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
|
||||||
|
if not self.connected:
|
||||||
|
return
|
||||||
bare_name = name
|
bare_name = name
|
||||||
if name.find('@') == -1:
|
if name.find('@') == -1:
|
||||||
name = name + '@' + name
|
name = name + '@' + name
|
||||||
|
@ -129,32 +139,35 @@ class Zeroconf:
|
||||||
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):
|
||||||
# print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
# print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
||||||
# print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
|
# print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
|
||||||
|
if not self.connected:
|
||||||
|
return
|
||||||
bare_name = name
|
bare_name = name
|
||||||
if name.find('@') == -1:
|
if name.find('@') == -1:
|
||||||
name = name + '@' + name
|
name = name + '@' + name
|
||||||
self.contacts[name] = (name, domain, interface, protocol, host, address, port, bare_name, txt)
|
self.contacts[name] = (name, domain, interface, protocol, host, address, port, bare_name, txt)
|
||||||
|
|
||||||
def service_added_callback(self):
|
def service_added_callback(self):
|
||||||
# print 'Service successfully added'
|
print 'Service successfully added'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def service_committed_callback(self):
|
def service_committed_callback(self):
|
||||||
# print 'Service successfully committed'
|
print 'Service successfully committed'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def service_updated_callback(self):
|
def service_updated_callback(self):
|
||||||
# print 'Service successfully updated'
|
print 'Service successfully updated'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def service_add_fail_callback(self, err):
|
def service_add_fail_callback(self, err):
|
||||||
print 'Error while adding service:', str(err)
|
gajim.log.debug('Error while adding service. %s' % str(err))
|
||||||
old_name = self.name
|
alternative_name = self.server.GetAlternativeServiceName(self.username)
|
||||||
self.name = self.server.GetAlternativeServiceName(self.name)
|
self.disconnect()
|
||||||
self.create_service()
|
self.name_conflictCB(alternative_name)
|
||||||
if self.invalid_self_contact.has_key(old_name):
|
#~ self.create_service()
|
||||||
self.contacts[old_name] = self.invalid_self_contact[old_name]
|
#~ if self.invalid_self_contact.has_key(old_name):
|
||||||
self.new_serviceCB(old_name)
|
#~ self.contacts[old_name] = self.invalid_self_contact[old_name]
|
||||||
del 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
|
||||||
|
@ -162,7 +175,8 @@ class Zeroconf:
|
||||||
self.create_service()
|
self.create_service()
|
||||||
elif state == avahi.SERVER_COLLISION:
|
elif state == avahi.SERVER_COLLISION:
|
||||||
self.entrygroup.Reset()
|
self.entrygroup.Reset()
|
||||||
# elif state == avahi.CLIENT_FAILURE: # TODO: add error handling (avahi daemon dies...?)
|
elif state == avahi.CLIENT_FAILURE: # TODO: add error handling (avahi daemon dies...?)
|
||||||
|
print 'CLIENT FAILURE'
|
||||||
|
|
||||||
def entrygroup_state_changed_callback(self, state, error):
|
def entrygroup_state_changed_callback(self, state, error):
|
||||||
# the name is already present, so recreate
|
# the name is already present, so recreate
|
||||||
|
@ -173,10 +187,10 @@ class Zeroconf:
|
||||||
|
|
||||||
# make zeroconf-valid names
|
# make zeroconf-valid names
|
||||||
def replace_show(self, show):
|
def replace_show(self, show):
|
||||||
if show == 'chat' or show == 'online' or show == '':
|
if show in ['chat', 'online', '']:
|
||||||
show = 'avail'
|
return 'avail'
|
||||||
elif show == 'xa':
|
elif show == 'xa':
|
||||||
show = 'away'
|
return 'away'
|
||||||
return show
|
return show
|
||||||
|
|
||||||
def create_service(self):
|
def create_service(self):
|
||||||
|
@ -205,17 +219,18 @@ class Zeroconf:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def announce(self):
|
def announce(self):
|
||||||
if self.connected:
|
print 'announce'
|
||||||
state = self.server.GetState()
|
if not self.connected:
|
||||||
|
return False
|
||||||
|
|
||||||
|
state = self.server.GetState()
|
||||||
if state == avahi.SERVER_RUNNING:
|
if state == avahi.SERVER_RUNNING:
|
||||||
self.create_service()
|
self.create_service()
|
||||||
self.announced = True
|
self.announced = True
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def remove_announce(self):
|
def remove_announce(self):
|
||||||
|
print 'remove announce'
|
||||||
if self.announced == False:
|
if self.announced == False:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
@ -234,20 +249,27 @@ class Zeroconf:
|
||||||
self.new_service_type(interface, protocol, self.stype, domain, '')
|
self.new_service_type(interface, protocol, self.stype, domain, '')
|
||||||
|
|
||||||
# connect to dbus
|
# connect to dbus
|
||||||
def connect(self):
|
def connect_dbus(self):
|
||||||
|
if self.server:
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
self.bus = dbus.SystemBus()
|
self.bus = dbus.SystemBus()
|
||||||
# is there any way to check, if a dbus name exists?
|
# is there any way to check, if a dbus name exists?
|
||||||
# that might make the Introspect Error go away...
|
# that might make the Introspect Error go away...
|
||||||
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
||||||
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
|
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
|
||||||
|
|
||||||
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
|
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
|
||||||
except dbus.dbus_bindings.DBusException, e:
|
except dbus.dbus_bindings.DBusException, e:
|
||||||
# Avahi service is not present
|
# Avahi service is not present
|
||||||
gajim.log.debug(str(e))
|
gajim.log.debug(str(e))
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
self.name = self.username + '@' + self.host # service name
|
||||||
|
if not self.connect_dbus():
|
||||||
|
return False
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
# start browsing
|
# start browsing
|
||||||
|
|
16
src/gajim.py
16
src/gajim.py
|
@ -1397,6 +1397,21 @@ class Interface:
|
||||||
if win.startswith('privacy_list_'):
|
if win.startswith('privacy_list_'):
|
||||||
self.instances[account][win].check_active_default(data)
|
self.instances[account][win].check_active_default(data)
|
||||||
|
|
||||||
|
def handle_event_zc_name_conflict(self, account, data):
|
||||||
|
dlg = dialogs.InputDialog(_('Username Conflict'),
|
||||||
|
_('Please type a new username for your local account'),
|
||||||
|
is_modal = True)
|
||||||
|
dlg.input_entry.set_text(data)
|
||||||
|
response = dlg.get_response()
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
new_name = dlg.input_entry.get_text()
|
||||||
|
print 'account, data', account, data, new_name
|
||||||
|
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'name', new_name)
|
||||||
|
status = gajim.connections[account].status
|
||||||
|
print 'status', status
|
||||||
|
gajim.connections[account].reconnect()
|
||||||
|
|
||||||
|
|
||||||
def read_sleepy(self):
|
def read_sleepy(self):
|
||||||
'''Check idle status and change that status if needed'''
|
'''Check idle status and change that status if needed'''
|
||||||
if not self.sleeper.poll():
|
if not self.sleeper.poll():
|
||||||
|
@ -1702,6 +1717,7 @@ class Interface:
|
||||||
'PRIVACY_LIST_RECEIVED': self.handle_event_privacy_list_received,
|
'PRIVACY_LIST_RECEIVED': self.handle_event_privacy_list_received,
|
||||||
'PRIVACY_LISTS_ACTIVE_DEFAULT': \
|
'PRIVACY_LISTS_ACTIVE_DEFAULT': \
|
||||||
self.handle_event_privacy_lists_active_default,
|
self.handle_event_privacy_lists_active_default,
|
||||||
|
'ZC_NAME_CONFLICT': self.handle_event_zc_name_conflict,
|
||||||
}
|
}
|
||||||
gajim.handlers = self.handlers
|
gajim.handlers = self.handlers
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue