Commit 354b4f17 authored by sb's avatar sb

changed zeroconf account name to local,

properties window fixes,
use all fields from it in txt record,
saving prefs automatically reconnects
parent c180efba
...@@ -120,6 +120,9 @@ status_before_autoaway = {} ...@@ -120,6 +120,9 @@ status_before_autoaway = {}
SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible'] 'invisible']
# zeroconf account name
LOCAL_ACC = 'local'
def get_nick_from_jid(jid): def get_nick_from_jid(jid):
pos = jid.find('@') pos = jid.find('@')
return jid[:pos] return jid[:pos]
......
...@@ -68,7 +68,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -68,7 +68,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.bookmarks = [] self.bookmarks = []
#we don't need a password, but must be non-empty #we don't need a password, but must be non-empty
self.password = 'zeroconf' self.password = gajim.LOCAL_ACC
#XXX use that somewhere #XXX use that somewhere
self.autoconnect = False self.autoconnect = False
...@@ -88,37 +88,40 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -88,37 +88,40 @@ 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.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 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'''
if not gajim.config.get_per('accounts', 'zeroconf', 'name'): if not gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'name'):
print 'Creating zeroconf account' print 'Creating zeroconf account'
gajim.config.add_per('accounts', 'zeroconf') gajim.config.add_per('accounts', gajim.LOCAL_ACC)
gajim.config.set_per('accounts', 'zeroconf', 'autoconnect', True) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'autoconnect', True)
gajim.config.set_per('accounts', 'zeroconf', 'no_log_for', '') gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'no_log_for', '')
gajim.config.set_per('accounts', 'zeroconf', 'password', 'zeroconf') gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'password', 'zeroconf')
gajim.config.set_per('accounts', 'zeroconf', 'sync_with_global_status', True) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'sync_with_global_status', True)
username = unicode(getpass.getuser()) self.username = unicode(getpass.getuser())
gajim.config.set_per('accounts', 'zeroconf', 'name', username) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'name', self.username)
#XXX make sure host is US-ASCII #XXX make sure host is US-ASCII
host = unicode(socket.gethostname()) self.host = unicode(socket.gethostname())
gajim.config.set_per('accounts', 'zeroconf', 'hostname', host) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'hostname', self.host)
port = 5298 self.port = 5298
gajim.config.set_per('accounts', 'zeroconf', 'custom_port', port) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'custom_port', self.port)
gajim.config.set_per('accounts', 'zeroconf', 'is_zeroconf', True) gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'is_zeroconf', True)
else: else:
username = gajim.config.get_per('accounts', 'zeroconf', 'name') self.username = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'name')
host = gajim.config.get_per('accounts', 'zeroconf', 'hostname') self.host = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'hostname')
port = gajim.config.get_per('accounts', 'zeroconf', 'custom_port') self.port = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'custom_port')
self.autoconnect = gajim.config.get_per('accounts', 'zeroconf', 'autoconnect') self.autoconnect = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'autoconnect')
self.sync_with_global_status = gajim.config.get_per('accounts', 'zeroconf', 'sync_with_global_status') self.sync_with_global_status = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'sync_with_global_status')
self.no_log_for = gajim.config.get_per('accounts', 'zeroconf', 'no_log_for') self.no_log_for = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'no_log_for')
self.first = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_first_name')
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service, username, host, port) self.last = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_last_name')
self.jabber_id = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_jabber_id')
self.email = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_email')
# END __init__ # END __init__
def put_event(self, ev): def put_event(self, ev):
...@@ -190,8 +193,19 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -190,8 +193,19 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
# keyID, timestamp)) # keyID, timestamp))
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 = ''):
self.get_config_values_or_default()
self.zeroconf.txt['status'] = show
self.zeroconf.txt['msg'] = msg
self.zeroconf.txt['1st'] = self.first
self.zeroconf.txt['last'] = self.last
self.zeroconf.txt['jid'] = self.jabber_id
self.zeroconf.txt['email'] = self.email
self.zeroconf.username = self.username
self.zeroconf.host = self.host
self.zeroconf.port = self.port
def connect(self, data = None, show = 'online'):
if self.connection: if self.connection:
return self.connection, '' return self.connection, ''
...@@ -211,16 +225,11 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -211,16 +225,11 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.call_resolve_timeout = True self.call_resolve_timeout = True
gobject.timeout_add(10000, self._on_resolve_timeout) gobject.timeout_add(10000, self._on_resolve_timeout)
else: else:
pass notify.popup(_('Connection problem:'), gajim.LOCAL_ACC, None,
#TODO: display visual notification that we could not connect to avahi title=_('Can not get connection'),
text=_('Please check if avahi-daemon is running.') )
def connect_and_init(self, show, msg, signed): self.dispatch('STATUS', 'offline')
self.continue_connect_info = [show, msg, signed] self.status = 'offline'
self.zeroconf.txt['status'] = show
self.zeroconf.txt['msg'] = msg
self.connect('',show)
def disconnect(self, on_purpose = False): def disconnect(self, on_purpose = False):
self.connected = 0 self.connected = 0
...@@ -233,15 +242,23 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -233,15 +242,23 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.call_resolve_timeout = False self.call_resolve_timeout = False
self.zeroconf.disconnect() self.zeroconf.disconnect()
def reconnect(self):
status = self.status
if status != 'offline':
msg = self.zeroconf.txt['msg']
self.change_status('offline', msg)
self.change_status(status, msg)
def change_status(self, show, msg, sync = False, auto = False): def change_status(self, show, msg, sync = False, auto = False):
if not show in STATUS_LIST: if not show in STATUS_LIST:
return -1 return -1
self.status = show
check = True #to check for errors from zeroconf check = True #to check for errors from zeroconf
# 'connect' # 'connect'
if show != 'offline' and not self.connected: if show != 'offline' and not self.connected:
self.connect_and_init(show, msg, '') self.connect(None, show, msg)
if show != 'invisible': if show != 'invisible':
check = self.zeroconf.announce() check = self.zeroconf.announce()
else: else:
...@@ -270,11 +287,11 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): ...@@ -270,11 +287,11 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
if check: if check:
self.dispatch('STATUS', show) self.dispatch('STATUS', show)
else: else:
# self.dispatch('ERROR', 'Could not change status. Please check if avahi-daemon is running.') notify.popup(_('Connection problem:'), gajim.LOCAL_ACC, None,
notify.popup(_('Connection problem:'), 'zeroconf', None,
title=_('Could not change status'), title=_('Could not change status'),
text=_('Please check if avahi-daemon is running.') ) text=_('Please check if avahi-daemon is running.') )
self.dispatch('STATUS', 'offline') self.dispatch('STATUS', 'offline')
self.status = 'offline'
def get_status(self): def get_status(self):
return STATUS_LIST[self.connected] return STATUS_LIST[self.connected]
......
...@@ -106,8 +106,8 @@ class Zeroconf: ...@@ -106,8 +106,8 @@ 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))
bare_name = name bare_name = name
if name.find('@') == -1: if name.find('@') == -1:
name = name + '@' + name name = name + '@' + name
...@@ -127,8 +127,8 @@ class Zeroconf: ...@@ -127,8 +127,8 @@ class Zeroconf:
# 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):
#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)))
bare_name = name bare_name = name
if name.find('@') == -1: if name.find('@') == -1:
name = name + '@' + name name = name + '@' + name
......
This diff is collapsed.
...@@ -1853,13 +1853,11 @@ class Interface: ...@@ -1853,13 +1853,11 @@ class Interface:
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue) gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
self.register_handlers() self.register_handlers()
if gajim.config.get('enable_zeroconf'): if gajim.config.get('enable_zeroconf'):
gajim.connections['zeroconf'] = common.zeroconf.connection_zeroconf.ConnectionZeroconf('zeroconf') gajim.connections[gajim.LOCAL_ACC] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(gajim.LOCAL_ACC)
for account in gajim.config.get_per('accounts'): for account in gajim.config.get_per('accounts'):
if account != 'zeroconf': if account != gajim.LOCAL_ACC:
gajim.connections[account] = common.connection.Connection(account) gajim.connections[account] = common.connection.Connection(account)
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail') gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
gtk.about_dialog_set_url_hook(self.on_launch_browser_mailer, 'url') gtk.about_dialog_set_url_hook(self.on_launch_browser_mailer, 'url')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment