reconnect using reannounce and check if port has changed,

change global account variable
This commit is contained in:
Stefan Bethge 2006-09-25 20:14:17 +00:00
parent 29160807eb
commit f5e00e916c
4 changed files with 126 additions and 104 deletions

View File

@ -121,7 +121,7 @@ SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible']
# zeroconf account name
LOCAL_ACC = 'local'
ZEROCONF_ACC_NAME = 'Local'
def get_nick_from_jid(jid):
pos = jid.find('@')

View File

@ -70,7 +70,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.bookmarks = []
#we don't need a password, but must be non-empty
self.password = gajim.LOCAL_ACC
self.password = 'zeroconf'
#XXX use that somewhere
self.autoconnect = False
@ -104,38 +104,39 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
def get_config_values_or_default(self):
''' get name, host, port from config, or
create zeroconf account with default values'''
if not self.username:
self.username = unicode(getpass.getuser())
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'name', self.username)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name', self.username)
else:
self.username = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'name')
if not gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'name'):
self.username = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name')
if not gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name'):
print 'Creating zeroconf account'
gajim.config.add_per('accounts', gajim.LOCAL_ACC)
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'autoconnect', True)
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'no_log_for', '')
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'password', 'zeroconf')
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'sync_with_global_status', True)
gajim.config.add_per('accounts', gajim.ZEROCONF_ACC_NAME)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect', True)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for', '')
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'password', 'zeroconf')
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status', True)
#XXX make sure host is US-ASCII
self.host = unicode(socket.gethostname())
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'hostname', self.host)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'hostname', self.host)
self.port = 5298
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'custom_port', self.port)
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'is_zeroconf', True)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port', self.port)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'is_zeroconf', True)
else:
self.host = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'hostname')
self.port = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'custom_port')
self.autoconnect = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'autoconnect')
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', gajim.LOCAL_ACC, 'no_log_for')
self.first = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_first_name')
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')
self.host = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'hostname')
self.port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port')
self.autoconnect = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect')
self.sync_with_global_status = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status')
self.no_log_for = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for')
self.first = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_first_name')
self.last = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_last_name')
self.jabber_id = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_jabber_id')
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])
@ -237,9 +238,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.call_resolve_timeout = True
gobject.timeout_add(10000, self._on_resolve_timeout)
else:
notify.popup(_('Connection problem:'), gajim.LOCAL_ACC, None,
title=_('Can not get connection'),
text=_('Please check if avahi-daemon is running.') )
self.dispatch('STATUS', 'offline')
self.status = 'offline'
@ -254,12 +252,28 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.call_resolve_timeout = False
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 reconnect(self, new_port, use_tls):
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')
txt2 = {}
for key, val in txt.iteritems():
if val != '':
txt2[key] = val
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 = txt2
self.zeroconf.port = port
self.zeroconf.announce()
def change_status(self, show, msg, sync = False, auto = False):
if not show in STATUS_LIST:
@ -299,7 +313,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
if check:
self.dispatch('STATUS', show)
else:
notify.popup(_('Connection problem:'), gajim.LOCAL_ACC, None,
notify.popup(_('Connection problem:'), gajim.ZEROCONF_ACC_NAME, None,
title=_('Could not change status'),
text=_('Please check if avahi-daemon is running.') )
self.dispatch('STATUS', 'offline')

View File

@ -1825,7 +1825,7 @@ class AccountsWindow:
self.show_modification_window(account)
def show_modification_window(self, account):
if account == gajim.LOCAL_ACC:
if account == gajim.ZEROCONF_ACC_NAME:
if gajim.interface.instances.has_key('zeroconf_properties'):
gajim.interface.instances['zeroconf_properties'].window.present()
else:
@ -1857,23 +1857,23 @@ class AccountsWindow:
def on_enable_zeroconf_checkbutton_toggled(self, widget):
if gajim.config.get('enable_zeroconf'):
#disable
gajim.interface.roster.close_all(gajim.LOCAL_ACC)
gajim.connections[gajim.LOCAL_ACC].disable_account()
del gajim.connections[gajim.LOCAL_ACC]
gajim.interface.roster.close_all(gajim.ZEROCONF_ACC_NAME)
gajim.connections[gajim.ZEROCONF_ACC_NAME].disable_account()
del gajim.connections[gajim.ZEROCONF_ACC_NAME]
gajim.interface.save_config()
del gajim.interface.instances[gajim.LOCAL_ACC]
del gajim.nicks[gajim.LOCAL_ACC]
del gajim.block_signed_in_notifications[gajim.LOCAL_ACC]
del gajim.groups[gajim.LOCAL_ACC]
gajim.contacts.remove_account(gajim.LOCAL_ACC)
del gajim.gc_connected[gajim.LOCAL_ACC]
del gajim.automatic_rooms[gajim.LOCAL_ACC]
del gajim.to_be_removed[gajim.LOCAL_ACC]
del gajim.newly_added[gajim.LOCAL_ACC]
del gajim.sleeper_state[gajim.LOCAL_ACC]
del gajim.encrypted_chats[gajim.LOCAL_ACC]
del gajim.last_message_time[gajim.LOCAL_ACC]
del gajim.status_before_autoaway[gajim.LOCAL_ACC]
del gajim.interface.instances[gajim.ZEROCONF_ACC_NAME]
del gajim.nicks[gajim.ZEROCONF_ACC_NAME]
del gajim.block_signed_in_notifications[gajim.ZEROCONF_ACC_NAME]
del gajim.groups[gajim.ZEROCONF_ACC_NAME]
gajim.contacts.remove_account(gajim.ZEROCONF_ACC_NAME)
del gajim.gc_connected[gajim.ZEROCONF_ACC_NAME]
del gajim.automatic_rooms[gajim.ZEROCONF_ACC_NAME]
del gajim.to_be_removed[gajim.ZEROCONF_ACC_NAME]
del gajim.newly_added[gajim.ZEROCONF_ACC_NAME]
del gajim.sleeper_state[gajim.ZEROCONF_ACC_NAME]
del gajim.encrypted_chats[gajim.ZEROCONF_ACC_NAME]
del gajim.last_message_time[gajim.ZEROCONF_ACC_NAME]
del gajim.status_before_autoaway[gajim.ZEROCONF_ACC_NAME]
if len(gajim.connections) >= 2: # Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
@ -1885,23 +1885,23 @@ class AccountsWindow:
else:
# enable (will create new account if not present)
gajim.connections[gajim.LOCAL_ACC] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(gajim.LOCAL_ACC)
gajim.connections[gajim.ZEROCONF_ACC_NAME] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(gajim.ZEROCONF_ACC_NAME)
# update variables
gajim.interface.instances[gajim.LOCAL_ACC] = {'infos': {}, 'disco': {},
gajim.interface.instances[gajim.ZEROCONF_ACC_NAME] = {'infos': {}, 'disco': {},
'gc_config': {}}
gajim.connections[gajim.LOCAL_ACC].connected = 0
gajim.groups[gajim.LOCAL_ACC] = {}
gajim.contacts.add_account(gajim.LOCAL_ACC)
gajim.gc_connected[gajim.LOCAL_ACC] = {}
gajim.automatic_rooms[gajim.LOCAL_ACC] = {}
gajim.newly_added[gajim.LOCAL_ACC] = []
gajim.to_be_removed[gajim.LOCAL_ACC] = []
gajim.nicks[gajim.LOCAL_ACC] = gajim.LOCAL_ACC
gajim.block_signed_in_notifications[gajim.LOCAL_ACC] = True
gajim.sleeper_state[gajim.LOCAL_ACC] = 'off'
gajim.encrypted_chats[gajim.LOCAL_ACC] = []
gajim.last_message_time[gajim.LOCAL_ACC] = {}
gajim.status_before_autoaway[gajim.LOCAL_ACC] = ''
gajim.connections[gajim.ZEROCONF_ACC_NAME].connected = 0
gajim.groups[gajim.ZEROCONF_ACC_NAME] = {}
gajim.contacts.add_account(gajim.ZEROCONF_ACC_NAME)
gajim.gc_connected[gajim.ZEROCONF_ACC_NAME] = {}
gajim.automatic_rooms[gajim.ZEROCONF_ACC_NAME] = {}
gajim.newly_added[gajim.ZEROCONF_ACC_NAME] = []
gajim.to_be_removed[gajim.ZEROCONF_ACC_NAME] = []
gajim.nicks[gajim.ZEROCONF_ACC_NAME] = gajim.ZEROCONF_ACC_NAME
gajim.block_signed_in_notifications[gajim.ZEROCONF_ACC_NAME] = True
gajim.sleeper_state[gajim.ZEROCONF_ACC_NAME] = 'off'
gajim.encrypted_chats[gajim.ZEROCONF_ACC_NAME] = []
gajim.last_message_time[gajim.ZEROCONF_ACC_NAME] = {}
gajim.status_before_autoaway[gajim.ZEROCONF_ACC_NAME] = ''
# refresh accounts window
if gajim.interface.instances.has_key('accounts'):
gajim.interface.instances['accounts'].init_accounts()
@ -1913,7 +1913,7 @@ class AccountsWindow:
gajim.interface.roster.draw_roster()
gajim.interface.roster.actions_menu_needs_rebuild = True
gajim.interface.save_config()
gajim.connections[gajim.LOCAL_ACC].change_status('online', '')
gajim.connections[gajim.ZEROCONF_ACC_NAME].change_status('online', '')
self.on_checkbutton_toggled(widget, 'enable_zeroconf')
@ -3053,53 +3053,53 @@ class ZeroconfPropertiesWindow:
self.window.set_transient_for(gajim.interface.roster.window)
self.xml.signal_autoconnect(self)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'autoconnect')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect')
if st:
self.xml.get_widget('autoconnect_checkbutton').set_active(st)
list_no_log_for = gajim.config.get_per('accounts', gajim.LOCAL_ACC,'no_log_for').split()
if gajim.LOCAL_ACC in list_no_log_for:
list_no_log_for = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,'no_log_for').split()
if gajim.ZEROCONF_ACC_NAME in list_no_log_for:
self.xml.get_widget('log_history_checkbutton').set_active(0)
else:
self.xml.get_widget('log_history_checkbutton').set_active(1)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'sync_with_global_status')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status')
if st:
self.xml.get_widget('sync_with_global_status_checkbutton').set_active(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_first_name')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_first_name')
if st:
self.xml.get_widget('first_name_entry').set_text(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_last_name')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_last_name')
if st:
self.xml.get_widget('last_name_entry').set_text(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_jabber_id')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_jabber_id')
if st:
self.xml.get_widget('jabber_id_entry').set_text(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'zeroconf_email')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_email')
if st:
self.xml.get_widget('email_entry').set_text(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'use_ssl')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'use_ssl')
if st:
self.xml.get_widget('use_tls_checkbutton').set_active(st)
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'custom_port')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port')
if st:
self.xml.get_widget('custom_port_entry').set_text(str(st))
st = gajim.config.get_per('accounts', gajim.LOCAL_ACC, 'use_custom_host')
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'use_custom_host')
if st:
self.xml.get_widget('custom_port_checkbutton').set_active(st)
self.xml.get_widget('custom_port_entry').set_sensitive(bool(st))
if not st:
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'custom_port', '5298')
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port', '5298')
self.xml.get_widget('save_button').grab_focus()
self.window.show_all()
@ -3118,44 +3118,52 @@ class ZeroconfPropertiesWindow:
def on_save_button_clicked(self, widget):
st = self.xml.get_widget('autoconnect_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'autoconnect', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect', st)
list_no_log_for = gajim.config.get_per('accounts',
gajim.LOCAL_ACC, 'no_log_for').split()
if gajim.LOCAL_ACC in list_no_log_for:
list_no_log_for.remove(gajim.LOCAL_ACC)
gajim.ZEROCONF_ACC_NAME, 'no_log_for').split()
if gajim.ZEROCONF_ACC_NAME in list_no_log_for:
list_no_log_for.remove(gajim.ZEROCONF_ACC_NAME)
if not self.xml.get_widget('log_history_checkbutton').get_active():
list_no_log_for.append(gajim.LOCAL_ACC)
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'no_log_for', ' '.join(list_no_log_for))
list_no_log_for.append(gajim.ZEROCONF_ACC_NAME)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for', ' '.join(list_no_log_for))
st = self.xml.get_widget('sync_with_global_status_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'sync_with_global_status', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status', st)
st = self.xml.get_widget('first_name_entry').get_text()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'zeroconf_first_name', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_first_name', st)
st = self.xml.get_widget('last_name_entry').get_text()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'zeroconf_last_name', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_last_name', st)
st = self.xml.get_widget('jabber_id_entry').get_text()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'zeroconf_jabber_id', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_jabber_id', st)
st = self.xml.get_widget('email_entry').get_text()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'zeroconf_email', st)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_email', st)
st = self.xml.get_widget('use_tls_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'use_ssl', st)
use_tls = self.xml.get_widget('use_tls_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'use_ssl', use_tls)
st = self.xml.get_widget('custom_port_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'use_custom_host', st)
use_custom_port = self.xml.get_widget('custom_port_checkbutton').get_active()
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'use_custom_host', use_custom_port)
if st:
st = self.xml.get_widget('custom_port_entry').get_text()
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'custom_port', st)
old_port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port')
if use_custom_port:
port = self.xml.get_widget('custom_port_entry').get_text()
else:
gajim.config.set_per('accounts', gajim.LOCAL_ACC, 'custom_port', '5298')
if gajim.connections.has_key(gajim.LOCAL_ACC):
gajim.connections[gajim.LOCAL_ACC].reconnect()
port = '5298'
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port', port)
# force restart of listener (because port has changed)
if port != old_port:
use_custom_port = True
else:
use_custom_port = False
if gajim.connections.has_key(gajim.ZEROCONF_ACC_NAME):
gajim.connections[gajim.ZEROCONF_ACC_NAME].reconnect(use_custom_port, use_tls)
self.window.destroy()

View File

@ -1869,9 +1869,9 @@ class Interface:
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
self.register_handlers()
if gajim.config.get('enable_zeroconf'):
gajim.connections[gajim.LOCAL_ACC] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(gajim.LOCAL_ACC)
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.LOCAL_ACC:
if account != gajim.ZEROCONF_ACC_NAME:
gajim.connections[account] = common.connection.Connection(account)
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')