we write the new account option in the config file only when the account has been successfully registered
This commit is contained in:
parent
dc1a13ff8e
commit
61558b8942
|
@ -759,40 +759,39 @@ class Connection:
|
||||||
return
|
return
|
||||||
common.xmpp.features.register(self.connection, agent, info) # FIXME: Blocking
|
common.xmpp.features.register(self.connection, agent, info) # FIXME: Blocking
|
||||||
|
|
||||||
def new_account(self, hostname, login, password, name, resource, prio, \
|
def new_account(self, name, config):
|
||||||
use_proxy, proxyhost, proxyport):
|
|
||||||
# If a connection already exist we cannot create a new account
|
# If a connection already exist we cannot create a new account
|
||||||
if self.connection:
|
if self.connection:
|
||||||
return
|
return
|
||||||
if use_proxy:
|
if config['use_proxy']:
|
||||||
proxy = {'host': proxyhost, 'port': proxyport}
|
proxy = {'host': config['proxyhost'], 'port': config['proxyport']}
|
||||||
else:
|
else:
|
||||||
proxy = None
|
proxy = None
|
||||||
c = common.xmpp.Client(server = hostname, debug = [])
|
c = common.xmpp.Client(server = config['hostname'], debug = [])
|
||||||
try:
|
try:
|
||||||
c.connect(proxy = proxy)
|
c.connect(proxy = proxy)
|
||||||
except:
|
except:
|
||||||
gajim.log.debug('Couldn\'t connect to %s' % hostname)
|
gajim.log.debug('Couldn\'t connect to %s' % config['hostname'])
|
||||||
self.dispatch('ERROR', _('Couldn\'t connect to ') + hostname)
|
self.dispatch('ERROR', _('Couldn\'t connect to ') + config['hostname'])
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
gajim.log.debug(_('Connected to server'))
|
gajim.log.debug(_('Connected to server'))
|
||||||
req = common.xmpp.features.getRegInfo(c, hostname).asDict() # FIXME! This blocks!
|
req = common.xmpp.features.getRegInfo(c, config['hostname']).asDict() # FIXME! This blocks!
|
||||||
req['username'] = login
|
req['username'] = config['name']
|
||||||
req['password'] = password
|
req['password'] = config['password']
|
||||||
if not common.xmpp.features.register(c, hostname,req): #FIXME: error
|
if not common.xmpp.features.register(c, config['hostname'], req): #FIXME: error
|
||||||
self.dispatch('ERROR', _('Error: ') + c.lastErr)
|
self.dispatch('ERROR', _('Error: ') + c.lastErr)
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
self.password = password
|
self.password = config['password']
|
||||||
if USE_GPG:
|
if USE_GPG:
|
||||||
self.gpg = GnuPG.GnuPG()
|
self.gpg = GnuPG.GnuPG()
|
||||||
gajim.config.set('usegpg', True)
|
gajim.config.set('usegpg', True)
|
||||||
else:
|
else:
|
||||||
gajim.config.set('usegpg', False)
|
gajim.config.set('usegpg', False)
|
||||||
self.dispatch('ACC_OK', (hostname, login, password, name,
|
gajim.connections[name] = self
|
||||||
resource, prio, use_proxy, proxyhost, proxyport))
|
self.dispatch('ACC_OK', (name, config))
|
||||||
|
|
||||||
def account_changed(self, new_name):
|
def account_changed(self, new_name):
|
||||||
self.name = new_name
|
self.name = new_name
|
||||||
|
|
185
src/config.py
185
src/config.py
|
@ -1005,20 +1005,35 @@ class Account_modification_window:
|
||||||
|
|
||||||
def on_save_button_clicked(self, widget):
|
def on_save_button_clicked(self, widget):
|
||||||
'''When save button is clicked: Save information in config file'''
|
'''When save button is clicked: Save information in config file'''
|
||||||
save_password = self.xml.get_widget(
|
config = {}
|
||||||
'save_password_checkbutton').get_active()
|
|
||||||
password = self.xml.get_widget('password_entry').get_text()
|
|
||||||
resource = self.xml.get_widget('resource_entry').get_text()
|
|
||||||
priority = self.xml.get_widget('priority_spinbutton').get_value_as_int()
|
|
||||||
new_account_checkbutton = self.xml.get_widget('new_account_checkbutton')
|
|
||||||
name = self.xml.get_widget('name_entry').get_text()
|
name = self.xml.get_widget('name_entry').get_text()
|
||||||
if gajim.connections.has_key(self.account):
|
if gajim.connections.has_key(self.account):
|
||||||
if name != self.account and \
|
if name != self.account and \
|
||||||
gajim.connections[self.account].connected != 0:
|
gajim.connections[self.account].connected != 0:
|
||||||
dialogs.Error_dialog(_('You must be offline to change the account\'s name'))
|
dialogs.Error_dialog(_('You must be offline to change the account\'s name'))
|
||||||
return
|
return
|
||||||
|
if (name == ''):
|
||||||
|
dialogs.Error_dialog(_('You must enter a name for this account'))
|
||||||
|
return
|
||||||
|
if name.find(' ') != -1:
|
||||||
|
dialogs.Error_dialog(_('Spaces are not permited in account name'))
|
||||||
|
return
|
||||||
jid = self.xml.get_widget('jid_entry').get_text()
|
jid = self.xml.get_widget('jid_entry').get_text()
|
||||||
autoconnect = self.xml.get_widget('autoconnect_checkbutton').get_active()
|
if jid == '' or jid.count('@') != 1:
|
||||||
|
dialogs.Error_dialog(_('You must enter a Jabber ID for this account\nFor example: someone@someserver.org'))
|
||||||
|
return
|
||||||
|
new_account = self.xml.get_widget('new_account_checkbutton').get_active()
|
||||||
|
config['savepass'] = self.xml.get_widget(
|
||||||
|
'save_password_checkbutton').get_active()
|
||||||
|
config['password'] = self.xml.get_widget('password_entry').get_text()
|
||||||
|
if new_account and config['password'] == '':
|
||||||
|
dialogs.Error_dialog(_('You must enter a password to register a new account'))
|
||||||
|
return
|
||||||
|
config['resource'] = self.xml.get_widget('resource_entry').get_text()
|
||||||
|
config['priority'] = self.xml.get_widget('priority_spinbutton').\
|
||||||
|
get_value_as_int()
|
||||||
|
config['autoconnect'] = self.xml.get_widget('autoconnect_checkbutton').\
|
||||||
|
get_active()
|
||||||
|
|
||||||
if self.account:
|
if self.account:
|
||||||
list_no_log_for = gajim.config.get_per('accounts',
|
list_no_log_for = gajim.config.get_per('accounts',
|
||||||
|
@ -1029,51 +1044,42 @@ class Account_modification_window:
|
||||||
list_no_log_for.remove(self.account)
|
list_no_log_for.remove(self.account)
|
||||||
if not self.xml.get_widget('log_history_checkbutton').get_active():
|
if not self.xml.get_widget('log_history_checkbutton').get_active():
|
||||||
list_no_log_for.append(name)
|
list_no_log_for.append(name)
|
||||||
|
config['no_log_for'] = ' '.join(list_no_log_for)
|
||||||
sync_with_global_status = self.xml.get_widget(
|
|
||||||
|
config['sync_with_global_status'] = self.xml.get_widget(
|
||||||
'sync_with_global_status_checkbutton').get_active()
|
'sync_with_global_status_checkbutton').get_active()
|
||||||
|
|
||||||
use_proxy = self.xml.get_widget('use_proxy_checkbutton').get_active()
|
config['use_proxy'] = self.xml.get_widget('use_proxy_checkbutton').\
|
||||||
proxyhost = self.xml.get_widget('proxyhost_entry').get_text()
|
get_active()
|
||||||
proxyport = self.xml.get_widget('proxyport_entry').get_text()
|
config['proxyhost'] = self.xml.get_widget('proxyhost_entry').get_text()
|
||||||
if (name == ''):
|
config['proxyport'] = self.xml.get_widget('proxyport_entry').get_text()
|
||||||
dialogs.Error_dialog(_('You must enter a name for this account'))
|
if config['use_proxy']:
|
||||||
return
|
if config['proxyport'] != '':
|
||||||
if name.find(' ') != -1:
|
|
||||||
dialogs.Error_dialog(_('Spaces are not permited in account name'))
|
|
||||||
return
|
|
||||||
if jid == '' or jid.count('@') != 1:
|
|
||||||
dialogs.Error_dialog(_('You must enter a Jabber ID for this account\nFor example: someone@someserver.org'))
|
|
||||||
return
|
|
||||||
if new_account_checkbutton.get_active() and password == '':
|
|
||||||
dialogs.Error_dialog(_('You must enter a password to register a new account'))
|
|
||||||
return
|
|
||||||
if use_proxy:
|
|
||||||
if proxyport != '':
|
|
||||||
try:
|
try:
|
||||||
proxyport = int(proxyport)
|
config['proxyport'] = int(config['proxyport'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
dialogs.Error_dialog(_('Proxy Port must be a port number'))
|
dialogs.Error_dialog(_('Proxy Port must be a port number'))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
dialogs.Error_dialog(_('You must enter a proxy port to use proxy'))
|
dialogs.Error_dialog(_('You must enter a proxy port to use proxy'))
|
||||||
return
|
return
|
||||||
if proxyhost == '':
|
if config['proxyhost'] == '':
|
||||||
dialogs.Error_dialog(_('You must enter a proxy host to use proxy'))
|
dialogs.Error_dialog(_('You must enter a proxy host to use proxy'))
|
||||||
return
|
return
|
||||||
|
|
||||||
usetls = self.xml.get_widget('use_tls_checkbutton').get_active()
|
config['usetls'] = self.xml.get_widget('use_tls_checkbutton').get_active()
|
||||||
(login, hostname) = jid.split('@')
|
(config['name'], config['hostname']) = jid.split('@')
|
||||||
key_name = self.xml.get_widget('gpg_name_label').get_text()
|
config['keyname'] = self.xml.get_widget('gpg_name_label').get_text()
|
||||||
if key_name == '': #no key selected
|
if config['keyname'] == '': #no key selected
|
||||||
keyID = ''
|
config['keyid'] = ''
|
||||||
save_gpg_password = False
|
config['savegpgpass'] = False
|
||||||
gpg_password = ''
|
config['gpgpassword'] = ''
|
||||||
else:
|
else:
|
||||||
keyID = self.xml.get_widget('gpg_key_label').get_text()
|
config['keyid'] = self.xml.get_widget('gpg_key_label').get_text()
|
||||||
save_gpg_password = self.xml.get_widget(
|
config['savegpgpass'] = self.xml.get_widget(
|
||||||
'gpg_save_password_checkbutton').get_active()
|
'gpg_save_password_checkbutton').get_active()
|
||||||
gpg_password = self.xml.get_widget('gpg_password_entry').get_text()
|
config['gpgpassword'] = self.xml.get_widget('gpg_password_entry').\
|
||||||
|
get_text()
|
||||||
#if we are modifying an account
|
#if we are modifying an account
|
||||||
if self.modify:
|
if self.modify:
|
||||||
#if we modify the name of the account
|
#if we modify the name of the account
|
||||||
|
@ -1112,26 +1118,8 @@ class Account_modification_window:
|
||||||
gajim.config.del_per('accounts', self.account)
|
gajim.config.del_per('accounts', self.account)
|
||||||
gajim.config.add_per('accounts', name)
|
gajim.config.add_per('accounts', name)
|
||||||
|
|
||||||
gajim.config.set_per('accounts', name, 'name', login)
|
for opt in config:
|
||||||
gajim.config.set_per('accounts', name, 'hostname', hostname)
|
gajim.config.set_per('accounts', name, opt, config[opt])
|
||||||
gajim.config.set_per('accounts', name, 'savepass', save_password)
|
|
||||||
gajim.config.set_per('accounts', name, 'password', password)
|
|
||||||
gajim.config.set_per('accounts', name, 'resource', resource)
|
|
||||||
gajim.config.set_per('accounts', name, 'priority', priority)
|
|
||||||
gajim.config.set_per('accounts', name, 'autoconnect', autoconnect)
|
|
||||||
gajim.config.set_per('accounts', name, 'use_proxy', use_proxy)
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyhost', proxyhost)
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyport', proxyport)
|
|
||||||
gajim.config.set_per('accounts', name, 'usetls', usetls)
|
|
||||||
gajim.config.set_per('accounts', name, 'keyid', keyID)
|
|
||||||
gajim.config.set_per('accounts', name, 'keyname', key_name)
|
|
||||||
gajim.config.set_per('accounts', name, 'savegpgpass', \
|
|
||||||
save_gpg_password)
|
|
||||||
gajim.config.set_per('accounts', name, 'gpgpassword', gpg_password)
|
|
||||||
gajim.config.set_per('accounts', name, 'sync_with_global_status', \
|
|
||||||
sync_with_global_status)
|
|
||||||
gajim.config.set_per('accounts', name, 'no_log_for', \
|
|
||||||
' '.join(list_no_log_for))
|
|
||||||
if save_password:
|
if save_password:
|
||||||
gajim.connections[name].password = password
|
gajim.connections[name].password = password
|
||||||
#refresh accounts window
|
#refresh accounts window
|
||||||
|
@ -1146,35 +1134,19 @@ class Account_modification_window:
|
||||||
if name in gajim.connections:
|
if name in gajim.connections:
|
||||||
dialogs.Error_dialog(_('An account already has this name'))
|
dialogs.Error_dialog(_('An account already has this name'))
|
||||||
return
|
return
|
||||||
gajim.config.add_per('accounts', name)
|
con = connection.Connection(name)
|
||||||
gajim.connections[name] = connection.Connection(name)
|
self.plugin.register_handlers(con)
|
||||||
self.plugin.register_handlers(gajim.connections[name])
|
|
||||||
#if we neeed to register a new account
|
#if we neeed to register a new account
|
||||||
if new_account_checkbutton.get_active():
|
if new_account:
|
||||||
gajim.connections[name].new_account(hostname, login, password, name, \
|
con.new_account(name, config)
|
||||||
resource, priority, use_proxy, proxyhost, proxyport)
|
|
||||||
return
|
return
|
||||||
gajim.config.set_per('accounts', name, 'name', login)
|
# The account we add already exists on the server
|
||||||
gajim.config.set_per('accounts', name, 'hostname', hostname)
|
gajim.connections[name] = con
|
||||||
gajim.config.set_per('accounts', name, 'savepass', save_password)
|
gajim.config.add_per('accounts', name)
|
||||||
gajim.config.set_per('accounts', name, 'password', password)
|
for opt in config:
|
||||||
gajim.config.set_per('accounts', name, 'resource', resource)
|
gajim.config.set_per('accounts', name, opt, config[opt])
|
||||||
gajim.config.set_per('accounts', name, 'priority', priority)
|
if config['savepass']:
|
||||||
gajim.config.set_per('accounts', name, 'autoconnect', autoconnect)
|
gajim.connections[name].password = config['password']
|
||||||
gajim.config.set_per('accounts', name, 'use_proxy', use_proxy)
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyhost', proxyhost)
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyport', proxyport)
|
|
||||||
gajim.config.set_per('accounts', name, 'usetls', usetls)
|
|
||||||
gajim.config.set_per('accounts', name, 'keyid', keyID)
|
|
||||||
gajim.config.set_per('accounts', name, 'keyname', key_name)
|
|
||||||
gajim.config.set_per('accounts', name, 'savegpgpass', \
|
|
||||||
save_gpg_password)
|
|
||||||
gajim.config.set_per('accounts', name, 'gpgpassword', gpg_password)
|
|
||||||
gajim.config.set_per('accounts', name, 'sync_with_global_status', True)
|
|
||||||
gajim.config.set_per('accounts', name, 'no_log_for', \
|
|
||||||
' '.join(list_no_log_for))
|
|
||||||
if save_password:
|
|
||||||
gajim.connections[name].password = password
|
|
||||||
#update variables
|
#update variables
|
||||||
self.plugin.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, \
|
self.plugin.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, \
|
||||||
'gc_config': {}}
|
'gc_config': {}}
|
||||||
|
@ -1184,7 +1156,7 @@ class Account_modification_window:
|
||||||
self.plugin.roster.contacts[name] = {}
|
self.plugin.roster.contacts[name] = {}
|
||||||
self.plugin.roster.newly_added[name] = []
|
self.plugin.roster.newly_added[name] = []
|
||||||
self.plugin.roster.to_be_removed[name] = []
|
self.plugin.roster.to_be_removed[name] = []
|
||||||
self.plugin.nicks[name] = login
|
self.plugin.nicks[name] = config['name']
|
||||||
self.plugin.sleeper_state[name] = 0
|
self.plugin.sleeper_state[name] = 0
|
||||||
#refresh accounts window
|
#refresh accounts window
|
||||||
if self.plugin.windows.has_key('accounts'):
|
if self.plugin.windows.has_key('accounts'):
|
||||||
|
@ -1208,47 +1180,6 @@ class Account_modification_window:
|
||||||
self.xml.get_widget('new_account_checkbutton').set_active(False)
|
self.xml.get_widget('new_account_checkbutton').set_active(False)
|
||||||
self.modify = True
|
self.modify = True
|
||||||
self.account = acct
|
self.account = acct
|
||||||
jid = self.xml.get_widget('jid_entry').get_text()
|
|
||||||
(login, hostname) = jid.split('@')
|
|
||||||
password = self.xml.get_widget('password_entry').get_text()
|
|
||||||
resource = self.xml.get_widget('resource_entry').get_text()
|
|
||||||
priority = self.xml.get_widget('priority_spinbutton').get_value_as_int()
|
|
||||||
autoconnect = self.xml.get_widget('autoconnect_checkbutton').get_active()
|
|
||||||
use_proxy = self.xml.get_widget('use_proxy_checkbutton').get_active()
|
|
||||||
proxyhost = self.xml.get_widget('proxyhost_entry').get_text()
|
|
||||||
proxyport = self.xml.get_widget('proxyport_entry').get_text()
|
|
||||||
key_name = self.xml.get_widget('gpg_name_label').get_text()
|
|
||||||
save_password = self.xml.get_widget(
|
|
||||||
'save_password_checkbutton').get_active()
|
|
||||||
if key_name == '': #no key selected
|
|
||||||
keyID = ''
|
|
||||||
save_gpg_password = False
|
|
||||||
gpg_password = ''
|
|
||||||
else:
|
|
||||||
keyID = self.xml.get_widget('gpg_key_label').get_text()
|
|
||||||
save_gpg_password = self.xml.get_widget(
|
|
||||||
'gpg_save_password_checkbutton').get_active()
|
|
||||||
gpg_password = self.xml.get_widget('gpg_password_entry').get_text()
|
|
||||||
no_log_for = ''
|
|
||||||
if self.xml.get_widget('log_history_checkbutton').get_active():
|
|
||||||
no_log_for = acct
|
|
||||||
gajim.config.set_per('accounts', acct, 'name', login)
|
|
||||||
gajim.config.set_per('accounts', acct, 'hostname', hostname)
|
|
||||||
gajim.config.set_per('accounts', acct, 'savepass', save_password)
|
|
||||||
gajim.config.set_per('accounts', acct, 'password', password)
|
|
||||||
gajim.config.set_per('accounts', acct, 'resource', resource)
|
|
||||||
gajim.config.set_per('accounts', acct, 'priority', priority)
|
|
||||||
gajim.config.set_per('accounts', acct, 'autoconnect', autoconnect)
|
|
||||||
gajim.config.set_per('accounts', acct, 'use_proxy', use_proxy)
|
|
||||||
gajim.config.set_per('accounts', acct, 'proxyhost', proxyhost)
|
|
||||||
gajim.config.set_per('accounts', acct, 'proxyport', proxyport)
|
|
||||||
gajim.config.set_per('accounts', acct, 'keyid', keyID)
|
|
||||||
gajim.config.set_per('accounts', acct, 'keyname', key_name)
|
|
||||||
gajim.config.set_per('accounts', acct, 'savegpgpass', \
|
|
||||||
save_gpg_password)
|
|
||||||
gajim.config.set_per('accounts', acct, 'gpgpassword', gpg_password)
|
|
||||||
gajim.config.set_per('accounts', acct, 'sync_with_global_status', True)
|
|
||||||
gajim.config.set_per('accounts', acct, 'no_log_for', no_log_for)
|
|
||||||
|
|
||||||
def on_edit_details_button_clicked(self, widget):
|
def on_edit_details_button_clicked(self, widget):
|
||||||
if not self.plugin.windows.has_key(self.account):
|
if not self.plugin.windows.has_key(self.account):
|
||||||
|
|
21
src/gajim.py
21
src/gajim.py
|
@ -370,24 +370,17 @@ class Interface:
|
||||||
array[2], array[3])
|
array[2], array[3])
|
||||||
|
|
||||||
def handle_event_acc_ok(self, account, array):
|
def handle_event_acc_ok(self, account, array):
|
||||||
#('ACC_OK', account, (hostname, login, pasword, name, resource, prio,
|
#('ACC_OK', account, (name, config))
|
||||||
#use_proxy, proxyhost, proxyport))
|
name = array[0]
|
||||||
name = array[3]
|
gajim.config.add_per('accounts', name)
|
||||||
|
for opt in array[1]:
|
||||||
|
gajim.config.set_per('accounts', name, opt, array[1][opt])
|
||||||
if self.windows['account_modification']:
|
if self.windows['account_modification']:
|
||||||
self.windows['account_modification'].account_is_ok(array[1])
|
self.windows['account_modification'].account_is_ok(array[0])
|
||||||
else:
|
|
||||||
gajim.config.set_per('accounts', name, 'name', array[1])
|
|
||||||
gajim.config.set_per('accounts', name, 'hostname', array[0])
|
|
||||||
gajim.config.set_per('accounts', name, 'password', array[2])
|
|
||||||
gajim.config.set_per('accounts', name, 'resource', array[4])
|
|
||||||
gajim.config.set_per('accounts', name, 'priority', array[5])
|
|
||||||
gajim.config.set_per('accounts', name, 'use_proxy', array[6])
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyhost', array[7])
|
|
||||||
gajim.config.set_per('accounts', name, 'proxyport', array[8])
|
|
||||||
self.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, 'gc_config': {}}
|
self.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, 'gc_config': {}}
|
||||||
self.queues[name] = {}
|
self.queues[name] = {}
|
||||||
gajim.connections[name].connected = 0
|
gajim.connections[name].connected = 0
|
||||||
self.nicks[name] = array[1]
|
self.nicks[name] = array[1]['name']
|
||||||
self.roster.groups[name] = {}
|
self.roster.groups[name] = {}
|
||||||
self.roster.contacts[name] = {}
|
self.roster.contacts[name] = {}
|
||||||
self.roster.newly_added[name] = []
|
self.roster.newly_added[name] = []
|
||||||
|
|
Loading…
Reference in New Issue