don't traceback when remove a disabled account. Fixes

This commit is contained in:
Yann Leboulanger 2010-03-10 13:51:55 +01:00
parent 31d1d35b17
commit ccde9e4382
1 changed files with 41 additions and 28 deletions

View File

@ -1893,9 +1893,9 @@ class AccountsWindow:
return return
win_opened = False win_opened = False
if gajim.interface.msg_win_mgr.get_controls(acct = account): if gajim.interface.msg_win_mgr.get_controls(acct=account):
win_opened = True win_opened = True
else: elif account in gajim.interface.instances:
for key in gajim.interface.instances[account]: for key in gajim.interface.instances[account]:
if gajim.interface.instances[account][key] and key != \ if gajim.interface.instances[account][key] and key != \
'remove_account': 'remove_account':
@ -1903,10 +1903,13 @@ class AccountsWindow:
break break
# Detect if we have opened windows for this account # Detect if we have opened windows for this account
def remove(account): def remove(account):
if 'remove_account' in gajim.interface.instances[account]: if account in gajim.interface.instances and \
'remove_account' in gajim.interface.instances[account]:
gajim.interface.instances[account]['remove_account'].window.\ gajim.interface.instances[account]['remove_account'].window.\
present() present()
else: else:
if not account in gajim.interface.instances:
gajim.interface.instances[account] = {}
gajim.interface.instances[account]['remove_account'] = \ gajim.interface.instances[account]['remove_account'] = \
RemoveAccountWindow(account) RemoveAccountWindow(account)
if win_opened: if win_opened:
@ -2871,12 +2874,19 @@ class RemoveAccountWindow:
def on_remove_button_clicked(self, widget): def on_remove_button_clicked(self, widget):
def remove(): def remove():
if gajim.connections[self.account].connected and \ if self.account in gajim.connections and \
gajim.connections[self.account].connected and \
not self.remove_and_unregister_radiobutton.get_active(): not self.remove_and_unregister_radiobutton.get_active():
# change status to offline only if we will not remove this JID from # change status to offline only if we will not remove this JID from
# server # server
gajim.connections[self.account].change_status('offline', 'offline') gajim.connections[self.account].change_status('offline', 'offline')
if self.remove_and_unregister_radiobutton.get_active(): if self.remove_and_unregister_radiobutton.get_active():
if not self.account in gajim.connections:
dialogs.ErrorDialog(
_('Account is disabled'),
_('To unregister from a server, account must be '
'enabled.'))
return
if not gajim.connections[self.account].password: if not gajim.connections[self.account].password:
def on_ok(passphrase, checked): def on_ok(passphrase, checked):
if passphrase == -1: if passphrase == -1:
@ -2896,11 +2906,12 @@ class RemoveAccountWindow:
else: else:
self._on_remove_success(True) self._on_remove_success(True)
if gajim.connections[self.account].connected: if self.account in gajim.connections and \
gajim.connections[self.account].connected:
dialogs.ConfirmationDialog( dialogs.ConfirmationDialog(
_('Account "%s" is connected to the server') % self.account, _('Account "%s" is connected to the server') % self.account,
_('If you remove it, the connection will be lost.'), _('If you remove it, the connection will be lost.'),
on_response_ok=remove) on_response_ok=remove)
else: else:
remove() remove()
@ -2920,29 +2931,31 @@ class RemoveAccountWindow:
on_response_ok=self.on_remove_responce_ok, is_modal=False) on_response_ok=self.on_remove_responce_ok, is_modal=False)
return return
# Close all opened windows # Close all opened windows
gajim.interface.roster.close_all(self.account, force = True) gajim.interface.roster.close_all(self.account, force=True)
gajim.connections[self.account].disconnect(on_purpose = True) if self.account in gajim.connections:
del gajim.connections[self.account] gajim.connections[self.account].disconnect(on_purpose=True)
del gajim.connections[self.account]
gajim.logger.remove_roster(gajim.get_jid_from_account(self.account)) gajim.logger.remove_roster(gajim.get_jid_from_account(self.account))
gajim.config.del_per('accounts', self.account) gajim.config.del_per('accounts', self.account)
gajim.interface.save_config() gajim.interface.save_config()
del gajim.interface.instances[self.account] del gajim.interface.instances[self.account]
del gajim.interface.minimized_controls[self.account] if self.account in gajim.nicks:
del gajim.nicks[self.account] del gajim.interface.minimized_controls[self.account]
del gajim.block_signed_in_notifications[self.account] del gajim.nicks[self.account]
del gajim.groups[self.account] del gajim.block_signed_in_notifications[self.account]
gajim.contacts.remove_account(self.account) del gajim.groups[self.account]
del gajim.gc_connected[self.account] gajim.contacts.remove_account(self.account)
del gajim.automatic_rooms[self.account] del gajim.gc_connected[self.account]
del gajim.to_be_removed[self.account] del gajim.automatic_rooms[self.account]
del gajim.newly_added[self.account] del gajim.to_be_removed[self.account]
del gajim.sleeper_state[self.account] del gajim.newly_added[self.account]
del gajim.encrypted_chats[self.account] del gajim.sleeper_state[self.account]
del gajim.last_message_time[self.account] del gajim.encrypted_chats[self.account]
del gajim.status_before_autoaway[self.account] del gajim.last_message_time[self.account]
del gajim.transport_avatar[self.account] del gajim.status_before_autoaway[self.account]
del gajim.gajim_optional_features[self.account] del gajim.transport_avatar[self.account]
del gajim.caps_hash[self.account] del gajim.gajim_optional_features[self.account]
del gajim.caps_hash[self.account]
if len(gajim.connections) >= 2: # Do not merge accounts if only one exists if len(gajim.connections) >= 2: # Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts') gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else: else: