2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
|
|
|
|
# Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com>
|
|
|
|
# Stéphan Kochen <stephan AT kochen.nl>
|
|
|
|
# Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
# Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
|
|
|
|
# Copyright (C) 2006-2007 Travis Shirk <travis AT pobox.com>
|
|
|
|
# Stefan Bethge <stefan AT lanpartei.de>
|
|
|
|
# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Copyright (C) 2007 James Newton <redshodan AT gmail.com>
|
|
|
|
# Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
# Copyright (C) 2007-2008 Stephan Erb <steve-e AT h3c.de>
|
|
|
|
# Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2004-05-15 18:50:38 +02:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GObject
|
2017-06-13 23:58:06 +02:00
|
|
|
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim.common import app
|
|
|
|
from gajim.common.i18n import _
|
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import dialogs
|
2018-10-28 15:36:43 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gui_menu_builder
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.dialogs import ConfirmationDialog
|
|
|
|
from gajim.gtk.dialogs import ConfirmationDialogDoubleRadio
|
|
|
|
from gajim.gtk.dialogs import ErrorDialog
|
2018-11-18 22:13:24 +01:00
|
|
|
from gajim.gtk.util import get_builder
|
2004-05-15 18:50:38 +02:00
|
|
|
|
2005-06-09 00:05:45 +02:00
|
|
|
|
2018-09-16 11:56:56 +02:00
|
|
|
class FakeDataForm(Gtk.Table):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Class for forms that are in XML format <entry1>value1</entry1> infos in a
|
|
|
|
table {entry1: value1}
|
|
|
|
"""
|
|
|
|
|
2013-04-14 08:49:10 +02:00
|
|
|
def __init__(self, infos, selectable=False):
|
2012-12-23 16:23:43 +01:00
|
|
|
GObject.GObject.__init__(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.infos = infos
|
2013-04-14 08:49:10 +02:00
|
|
|
self.selectable = selectable
|
2010-02-08 15:08:40 +01:00
|
|
|
self.entries = {}
|
|
|
|
self._draw_table()
|
|
|
|
|
|
|
|
def _draw_table(self):
|
|
|
|
"""
|
|
|
|
Draw the table
|
|
|
|
"""
|
|
|
|
nbrow = 0
|
|
|
|
if 'instructions' in self.infos:
|
|
|
|
nbrow = 1
|
2018-09-18 12:06:01 +02:00
|
|
|
self.resize(rows=nbrow, columns=2)
|
2012-12-23 16:23:43 +01:00
|
|
|
label = Gtk.Label(label=self.infos['instructions'])
|
2013-04-14 08:49:10 +02:00
|
|
|
if self.selectable:
|
|
|
|
label.set_selectable(True)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.attach(label, 0, 2, 0, 1, 0, 0, 0, 0)
|
|
|
|
for name in self.infos.keys():
|
|
|
|
if name in ('key', 'instructions', 'x', 'registered'):
|
|
|
|
continue
|
|
|
|
if not name:
|
|
|
|
continue
|
|
|
|
|
|
|
|
nbrow = nbrow + 1
|
2018-09-18 12:06:01 +02:00
|
|
|
self.resize(rows=nbrow, columns=2)
|
2012-12-23 16:23:43 +01:00
|
|
|
label = Gtk.Label(label=name.capitalize() + ':')
|
2010-02-08 15:08:40 +01:00
|
|
|
self.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0)
|
2012-12-23 16:23:43 +01:00
|
|
|
entry = Gtk.Entry()
|
2010-02-08 15:08:40 +01:00
|
|
|
entry.set_activates_default(True)
|
|
|
|
if self.infos[name]:
|
|
|
|
entry.set_text(self.infos[name])
|
|
|
|
if name == 'password':
|
|
|
|
entry.set_visibility(False)
|
|
|
|
self.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0)
|
|
|
|
self.entries[name] = entry
|
|
|
|
if nbrow == 1:
|
|
|
|
entry.grab_focus()
|
|
|
|
|
|
|
|
def get_infos(self):
|
2018-09-17 22:34:15 +02:00
|
|
|
for name in self.entries:
|
2013-01-01 19:44:25 +01:00
|
|
|
self.infos[name] = self.entries[name].get_text()
|
2010-02-08 15:08:40 +01:00
|
|
|
return self.infos
|
2007-06-03 12:04:20 +02:00
|
|
|
|
2005-06-10 23:14:16 +02:00
|
|
|
#---------- RemoveAccountWindow class -------------#
|
|
|
|
class RemoveAccountWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Ask for removing from gajim only or from gajim and server too and do
|
|
|
|
removing of the account given
|
|
|
|
"""
|
|
|
|
|
|
|
|
def on_remove_account_window_destroy(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.account in app.interface.instances:
|
|
|
|
del app.interface.instances[self.account]['remove_account']
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_cancel_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def __init__(self, account):
|
|
|
|
self.account = account
|
2018-11-18 22:13:24 +01:00
|
|
|
xml = get_builder('remove_account_window.ui')
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window = xml.get_object('remove_account_window')
|
2018-03-07 19:28:17 +01:00
|
|
|
active_window = app.app.get_active_window()
|
|
|
|
self.window.set_transient_for(active_window)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.remove_and_unregister_radiobutton = xml.get_object(
|
|
|
|
'remove_and_unregister_radiobutton')
|
|
|
|
self.window.set_title(_('Removing %s account') % self.account)
|
|
|
|
xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
def on_remove_button_clicked(self, widget):
|
|
|
|
def remove():
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.account in app.connections and \
|
|
|
|
app.connections[self.account].connected and \
|
2010-02-08 15:08:40 +01:00
|
|
|
not self.remove_and_unregister_radiobutton.get_active():
|
|
|
|
# change status to offline only if we will not remove this JID from
|
|
|
|
# server
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].change_status('offline', 'offline')
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.remove_and_unregister_radiobutton.get_active():
|
2017-08-13 13:18:56 +02:00
|
|
|
if not self.account in app.connections:
|
2018-07-16 23:22:33 +02:00
|
|
|
ErrorDialog(
|
2010-03-10 13:51:55 +01:00
|
|
|
_('Account is disabled'),
|
|
|
|
_('To unregister from a server, account must be '
|
2018-03-07 19:28:17 +01:00
|
|
|
'enabled.'),
|
|
|
|
transient_for=self.window)
|
2010-03-10 13:51:55 +01:00
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.connections[self.account].password:
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_ok(passphrase, checked):
|
|
|
|
if passphrase == -1:
|
|
|
|
# We don't remove account cause we canceled pw window
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].password = passphrase
|
|
|
|
app.connections[self.account].unregister_account(
|
2010-02-08 15:08:40 +01:00
|
|
|
self._on_remove_success)
|
|
|
|
|
|
|
|
dialogs.PassphraseDialog(
|
|
|
|
_('Password Required'),
|
|
|
|
_('Enter your password for account %s') % self.account,
|
2018-03-07 19:28:17 +01:00
|
|
|
_('Save password'), ok_handler=on_ok,
|
|
|
|
transient_for=self.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].unregister_account(
|
2010-02-08 15:08:40 +01:00
|
|
|
self._on_remove_success)
|
|
|
|
else:
|
|
|
|
self._on_remove_success(True)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.account in app.connections and \
|
|
|
|
app.connections[self.account].connected:
|
2018-07-16 23:22:33 +02:00
|
|
|
ConfirmationDialog(
|
2010-03-10 13:51:55 +01:00
|
|
|
_('Account "%s" is connected to the server') % self.account,
|
|
|
|
_('If you remove it, the connection will be lost.'),
|
2018-03-07 19:28:17 +01:00
|
|
|
on_response_ok=remove,
|
|
|
|
transient_for=self.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
remove()
|
|
|
|
|
|
|
|
def on_remove_responce_ok(self, is_checked):
|
|
|
|
if is_checked[0]:
|
|
|
|
self._on_remove_success(True)
|
|
|
|
|
|
|
|
def _on_remove_success(self, res):
|
|
|
|
# action of unregistration has failed, we don't remove the account
|
|
|
|
# Error message is send by connect_and_auth()
|
|
|
|
if not res:
|
2018-07-16 23:22:33 +02:00
|
|
|
ConfirmationDialogDoubleRadio(
|
2010-02-08 15:08:40 +01:00
|
|
|
_('Connection to server %s failed') % self.account,
|
|
|
|
_('What would you like to do?'),
|
|
|
|
_('Remove only from Gajim'),
|
|
|
|
_('Don\'t remove anything. I\'ll try again later'),
|
2018-03-07 19:28:17 +01:00
|
|
|
on_response_ok=self.on_remove_responce_ok, is_modal=False,
|
|
|
|
transient_for=self.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
# Close all opened windows
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.close_all(self.account, force=True)
|
|
|
|
if self.account in app.connections:
|
2018-12-03 14:11:25 +01:00
|
|
|
app.connections[self.account].disconnect(reconnect=False)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].cleanup()
|
|
|
|
del app.connections[self.account]
|
|
|
|
app.logger.remove_roster(app.get_jid_from_account(self.account))
|
|
|
|
app.config.del_per('accounts', self.account)
|
|
|
|
del app.interface.instances[self.account]
|
|
|
|
if self.account in app.nicks:
|
|
|
|
del app.interface.minimized_controls[self.account]
|
|
|
|
del app.nicks[self.account]
|
|
|
|
del app.block_signed_in_notifications[self.account]
|
|
|
|
del app.groups[self.account]
|
|
|
|
app.contacts.remove_account(self.account)
|
|
|
|
del app.gc_connected[self.account]
|
|
|
|
del app.automatic_rooms[self.account]
|
|
|
|
del app.to_be_removed[self.account]
|
|
|
|
del app.newly_added[self.account]
|
|
|
|
del app.sleeper_state[self.account]
|
|
|
|
del app.last_message_time[self.account]
|
|
|
|
del app.status_before_autoaway[self.account]
|
|
|
|
del app.gajim_optional_features[self.account]
|
|
|
|
del app.caps_hash[self.account]
|
|
|
|
if len(app.connections) >= 2: # Do not merge accounts if only one exists
|
|
|
|
app.interface.roster.regroup = app.config.get('mergeaccounts')
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.regroup = False
|
|
|
|
app.interface.roster.setup_and_draw_roster()
|
|
|
|
app.app.remove_account_actions(self.account)
|
2017-01-26 21:34:54 +01:00
|
|
|
gui_menu_builder.build_accounts_menu()
|
2018-08-16 20:47:54 +02:00
|
|
|
|
|
|
|
window = app.get_app_window('AccountsWindow')
|
|
|
|
if window is not None:
|
|
|
|
window.remove_account(self.account)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|