better handling of log messages (internal stuff only)
[quassel.git] / src / qtui / coreconnectdlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include <QDebug>
22 #include <QMessageBox>
23 #include <QNetworkProxy>
24
25 #include "coreconnectdlg.h"
26
27 #include "client.h"
28 #include "clientsettings.h"
29 #include "clientsyncer.h"
30 #include "coreconfigwizard.h"
31 #include "iconloader.h"
32 #include "quassel.h"
33
34 CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent)
35   : QDialog(parent)
36 {
37   ui.setupUi(this);
38   ui.editAccount->setIcon(SmallIcon("document-properties"));
39   ui.addAccount->setIcon(SmallIcon("list-add"));
40   ui.deleteAccount->setIcon(SmallIcon("list-remove"));
41   ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
42   ui.secureConnection->setPixmap(SmallIcon("document-encrypt"));
43
44   if(Quassel::runMode() != Quassel::Monolithic) {
45     ui.useInternalCore->hide();
46   }
47
48   // make it look more native under Mac OS X:
49   setWindowFlags(Qt::Sheet);
50
51   clientSyncer = new ClientSyncer(this);
52   connect(this, SIGNAL(newClientSyncer(ClientSyncer *)), Client::instance(), SIGNAL(newClientSyncer(ClientSyncer *)));
53   emit newClientSyncer(clientSyncer); // announce the new client syncer via the client.
54
55   wizard = 0;
56
57   doingAutoConnect = false;
58
59   ui.stackedWidget->setCurrentWidget(ui.accountPage);
60
61   CoreAccountSettings s;
62   AccountId lastacc = s.lastAccount();
63   autoConnectAccount = s.autoConnectAccount();
64   QListWidgetItem *currentItem = 0;
65   foreach(AccountId id, s.knownAccounts()) {
66     if(!id.isValid()) continue;
67     QVariantMap data = s.retrieveAccountData(id);
68     data["AccountId"] = QVariant::fromValue<AccountId>(id);
69     accounts[id] = data;
70     QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList);
71     item->setData(Qt::UserRole, QVariant::fromValue<AccountId>(id));
72     if(id == lastacc) currentItem = item;
73   }
74   if(currentItem) ui.accountList->setCurrentItem(currentItem);
75   else ui.accountList->setCurrentRow(0);
76
77   setAccountWidgetStates();
78
79   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setFocus();
80   //ui.accountButtonBox->button(QDialogButtonBox::Ok)->setAutoDefault(true);
81
82   connect(clientSyncer, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)),this, SLOT(initPhaseSocketState(QAbstractSocket::SocketState)));
83   connect(clientSyncer, SIGNAL(connectionError(const QString &)), this, SLOT(initPhaseError(const QString &)));
84   connect(clientSyncer, SIGNAL(connectionMsg(const QString &)), this, SLOT(initPhaseMsg(const QString &)));
85   connect(clientSyncer, SIGNAL(encrypted(bool)), this, SLOT(encrypted(bool)));
86   connect(clientSyncer, SIGNAL(startLogin()), this, SLOT(startLogin()));
87   connect(clientSyncer, SIGNAL(loginFailed(const QString &)), this, SLOT(loginFailed(const QString &)));
88   connect(clientSyncer, SIGNAL(loginSuccess()), this, SLOT(startSync()));
89   connect(clientSyncer, SIGNAL(startCoreSetup(const QVariantList &)), this, SLOT(startCoreConfig(const QVariantList &)));
90   connect(clientSyncer, SIGNAL(sessionProgress(quint32, quint32)), this, SLOT(coreSessionProgress(quint32, quint32)));
91   connect(clientSyncer, SIGNAL(networksProgress(quint32, quint32)), this, SLOT(coreNetworksProgress(quint32, quint32)));
92   connect(clientSyncer, SIGNAL(syncFinished()), this, SLOT(syncFinished()));
93
94   connect(ui.user, SIGNAL(textChanged(const QString &)), this, SLOT(setLoginWidgetStates()));
95   connect(ui.password, SIGNAL(textChanged(const QString &)), this, SLOT(setLoginWidgetStates()));
96
97   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
98   connect(ui.syncButtonBox->button(QDialogButtonBox::Abort), SIGNAL(clicked()), this, SLOT(restartPhaseNull()));
99
100   if(autoconnect && ui.accountList->count() && autoConnectAccount.isValid()
101      && autoConnectAccount == ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>()) {
102     doingAutoConnect = true;
103     on_accountButtonBox_accepted();
104   }
105 }
106
107 CoreConnectDlg::~CoreConnectDlg() {
108   if(ui.accountList->selectedItems().count()) {
109     CoreAccountSettings s;
110     s.setLastAccount(ui.accountList->selectedItems()[0]->data(Qt::UserRole).value<AccountId>());
111   }
112 }
113
114
115 /****************************************************
116  * Account Management
117  ***************************************************/
118
119 void CoreConnectDlg::on_accountList_itemSelectionChanged() {
120   setAccountWidgetStates();
121 }
122
123 void CoreConnectDlg::setAccountWidgetStates() {
124   QList<QListWidgetItem *> selectedItems = ui.accountList->selectedItems();
125   ui.editAccount->setEnabled(selectedItems.count());
126   ui.deleteAccount->setEnabled(selectedItems.count());
127   ui.autoConnect->setEnabled(selectedItems.count());
128   if(selectedItems.count()) {
129     ui.autoConnect->setChecked(selectedItems[0]->data(Qt::UserRole).value<AccountId>() == autoConnectAccount);
130   }
131   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setEnabled(ui.accountList->count());
132 }
133
134 void CoreConnectDlg::on_autoConnect_clicked(bool state) {
135   if(!state) {
136     autoConnectAccount = 0;
137   } else {
138     if(ui.accountList->selectedItems().count()) {
139       autoConnectAccount = ui.accountList->selectedItems()[0]->data(Qt::UserRole).value<AccountId>();
140     } else {
141       qWarning() << "Checked auto connect without an enabled item!";  // should never happen!
142       autoConnectAccount = 0;
143     }
144   }
145   setAccountWidgetStates();
146 }
147
148 void CoreConnectDlg::on_addAccount_clicked() {
149   QStringList existing;
150   for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text();
151   CoreAccountEditDlg dlg(0, QVariantMap(), existing, this);
152   if(dlg.exec() == QDialog::Accepted) {
153     // find free ID
154     AccountId id = accounts.count() + 1;
155     for(AccountId i = 1; i <= accounts.count(); i++) {
156       if(!accounts.keys().contains(i)) {
157         id = i;
158         break;
159       }
160     }
161     QVariantMap data = dlg.accountData();
162     data["AccountId"] = QVariant::fromValue<AccountId>(id);
163     accounts[id] = data;
164     QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList);
165     item->setData(Qt::UserRole, QVariant::fromValue<AccountId>(id));
166     ui.accountList->setCurrentItem(item);
167   }
168 }
169
170 void CoreConnectDlg::on_editAccount_clicked() {
171   QStringList existing;
172   for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text();
173   AccountId id = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
174   QVariantMap acct = accounts[id];
175   CoreAccountEditDlg dlg(id, acct, existing, this);
176   if(dlg.exec() == QDialog::Accepted) {
177     QVariantMap data = dlg.accountData();
178     ui.accountList->currentItem()->setText(data["AccountName"].toString());
179     accounts[id] = data;
180   }
181 }
182
183 void CoreConnectDlg::on_deleteAccount_clicked() {
184   AccountId id = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
185   int ret = QMessageBox::question(this, tr("Remove Account Settings"),
186                                   tr("Do you really want to remove your local settings for this Quassel Core account?<br>"
187                                   "Note: This will <em>not</em> remove or change any data on the Core itself!"),
188                                   QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
189   if(ret == QMessageBox::Yes) {
190     int idx = ui.accountList->currentRow();
191     delete ui.accountList->takeItem(idx);
192     ui.accountList->setCurrentRow(qMin(idx, ui.accountList->count()-1));
193     accounts[id]["Delete"] = true;  // we only flag this here, actual deletion happens on accept!
194     setAccountWidgetStates();
195   }
196 }
197
198 void CoreConnectDlg::on_accountList_itemDoubleClicked(QListWidgetItem *item) {
199   Q_UNUSED(item);
200   on_accountButtonBox_accepted();
201 }
202
203 void CoreConnectDlg::on_accountButtonBox_accepted() {
204   // save accounts
205   CoreAccountSettings s;
206   foreach(QVariantMap acct, accounts.values()) {
207     AccountId id = acct["AccountId"].value<AccountId>();
208     if(acct.contains("Delete")) {
209       s.removeAccount(id);
210     } else {
211       s.storeAccountData(id, acct);
212     }
213   }
214   s.setAutoConnectAccount(autoConnectAccount);
215
216   ui.stackedWidget->setCurrentWidget(ui.loginPage);
217   account = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
218   accountData = accounts[account];
219   s.setLastAccount(account);
220   connectToCore();
221 }
222
223 void CoreConnectDlg::on_useInternalCore_clicked() {
224   clientSyncer->useInternalCore();
225   startSync();
226 }
227
228 /*****************************************************
229  * Connecting to the Core
230  ****************************************************/
231
232 /*** Phase One: initializing the core connection ***/
233
234 void CoreConnectDlg::connectToCore() {
235   ui.secureConnection->hide();
236   ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
237   ui.connectLabel->setText(tr("Connect to %1").arg(accountData["Host"].toString()));
238   ui.coreInfoLabel->setText("");
239   ui.loginStack->setCurrentWidget(ui.loginEmptyPage);
240   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
241   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
242   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
243   disconnect(ui.loginButtonBox, 0, this, 0);
244   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
245
246   clientSyncer->connectToCore(accountData);
247 }
248
249 void CoreConnectDlg::initPhaseError(const QString &error) {
250   doingAutoConnect = false;
251   ui.secureConnection->hide();
252   ui.connectIcon->setPixmap(BarIcon("dialog-error"));
253   //ui.connectLabel->setBrush(QBrush("red"));
254   ui.connectLabel->setText(tr("<div style=color:red;>Connection to %1 failed!</div>").arg(accountData["Host"].toString()));
255   ui.coreInfoLabel->setText(error);
256   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Retry|QDialogButtonBox::Cancel);
257   ui.loginButtonBox->button(QDialogButtonBox::Retry)->setFocus();
258   disconnect(ui.loginButtonBox, 0, this, 0);
259   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(restartPhaseNull()));
260   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
261 }
262
263 void CoreConnectDlg::initPhaseMsg(const QString &msg) {
264   ui.coreInfoLabel->setText(msg);
265 }
266
267 void CoreConnectDlg::encrypted(bool useSsl) {
268   if(useSsl)
269     ui.secureConnection->show();
270   else
271     ui.secureConnection->hide();
272 }
273
274 void CoreConnectDlg::initPhaseSocketState(QAbstractSocket::SocketState state) {
275   QString s;
276   QString host = accountData["Host"].toString();
277   switch(state) {
278     case QAbstractSocket::UnconnectedState: s = tr("Not connected to %1.").arg(host); break;
279     case QAbstractSocket::HostLookupState: s = tr("Looking up %1...").arg(host); break;
280     case QAbstractSocket::ConnectingState: s = tr("Connecting to %1...").arg(host); break;
281     case QAbstractSocket::ConnectedState: s = tr("Connected to %1").arg(host); break;
282     default: s = tr("Unknown connection state to %1"); break;
283   }
284   ui.connectLabel->setText(s);
285 }
286
287 void CoreConnectDlg::restartPhaseNull() {
288   doingAutoConnect = false;
289   ui.stackedWidget->setCurrentWidget(ui.accountPage);
290   clientSyncer->disconnectFromCore();
291 }
292
293 /*********************************************************
294  * Phase Two: Login
295  *********************************************************/
296
297 void CoreConnectDlg::startLogin() {
298   ui.connectIcon->setPixmap(BarIcon("network-connect"));
299   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
300   //ui.loginStack->setMinimumSize(ui.loginStack->sizeHint()); ui.loginStack->updateGeometry();
301   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
302   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
303   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
304   if(!accountData["User"].toString().isEmpty()) {
305     ui.user->setText(accountData["User"].toString());
306     if(accountData["RememberPasswd"].toBool()) {
307       ui.password->setText(accountData["Password"].toString());
308       ui.rememberPasswd->setChecked(true);
309       ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
310     } else {
311       ui.rememberPasswd->setChecked(false);
312       ui.password->setFocus();
313     }
314   } else ui.user->setFocus();
315   disconnect(ui.loginButtonBox, 0, this, 0);
316   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
317   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
318   if(doingAutoConnect) doLogin();
319 }
320
321 void CoreConnectDlg::doLogin() {
322   QVariantMap loginData;
323   loginData["User"] = ui.user->text();
324   loginData["Password"] = ui.password->text();
325   loginData["RememberPasswd"] = ui.rememberPasswd->isChecked();
326   doLogin(loginData);
327 }
328
329 void CoreConnectDlg::doLogin(const QVariantMap &loginData) {
330   disconnect(ui.loginButtonBox, 0, this, 0);
331   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
332   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
333   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
334   ui.loginGroup->setTitle(tr("Logging in..."));
335   ui.user->setDisabled(true);
336   ui.password->setDisabled(true);
337   ui.rememberPasswd->setDisabled(true);
338   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
339   accountData["User"] = loginData["User"];
340   accountData["RememberPasswd"] = loginData["RememberPasswd"];
341   if(loginData["RememberPasswd"].toBool()) accountData["Password"] = loginData["Password"];
342   else accountData.remove("Password");
343   ui.user->setText(loginData["User"].toString());
344   ui.password->setText(loginData["Password"].toString());
345   ui.rememberPasswd->setChecked(loginData["RememberPasswd"].toBool());
346   CoreAccountSettings s;
347   s.storeAccountData(account, accountData);
348   clientSyncer->loginToCore(loginData["User"].toString(), loginData["Password"].toString());
349 }
350
351 void CoreConnectDlg::setLoginWidgetStates() {
352   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.user->text().isEmpty() || ui.password->text().isEmpty());
353 }
354
355 void CoreConnectDlg::loginFailed(const QString &error) {
356   if(wizard) {
357     wizard->reject();
358   }
359   ui.connectIcon->setPixmap(BarIcon("dialog-error"));
360   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
361   ui.loginGroup->setTitle(tr("Login"));
362   ui.user->setEnabled(true);
363   ui.password->setEnabled(true);
364   ui.rememberPasswd->setEnabled(true);
365   ui.coreInfoLabel->setText(error);
366   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
367   ui.password->setFocus();
368   doingAutoConnect = false;
369 }
370
371 void CoreConnectDlg::startCoreConfig(const QVariantList &backends) {
372   storageBackends = backends;
373   ui.loginStack->setCurrentWidget(ui.coreConfigPage);
374
375   //on_launchCoreConfigWizard_clicked();
376
377 }
378
379 void CoreConnectDlg::on_launchCoreConfigWizard_clicked() {
380   Q_ASSERT(!wizard);
381   wizard = new CoreConfigWizard(storageBackends, this);
382   connect(wizard, SIGNAL(setupCore(const QVariant &)), clientSyncer, SLOT(doCoreSetup(const QVariant &)));
383   connect(wizard, SIGNAL(loginToCore(const QVariantMap &)), this, SLOT(doLogin(const QVariantMap &)));
384   connect(clientSyncer, SIGNAL(coreSetupSuccess()), wizard, SLOT(coreSetupSuccess()));
385   connect(clientSyncer, SIGNAL(coreSetupFailed(const QString &)), wizard, SLOT(coreSetupFailed(const QString &)));
386   connect(wizard, SIGNAL(accepted()), this, SLOT(configWizardAccepted()));
387   connect(wizard, SIGNAL(rejected()), this, SLOT(configWizardRejected()));
388   connect(clientSyncer, SIGNAL(loginSuccess()), wizard, SLOT(loginSuccess()));
389   connect(clientSyncer, SIGNAL(syncFinished()), wizard, SLOT(syncFinished()));
390   wizard->show();
391 }
392
393 void CoreConnectDlg::configWizardAccepted() {
394
395   wizard->deleteLater();
396   wizard = 0;
397 }
398
399 void CoreConnectDlg::configWizardRejected() {
400
401   wizard->deleteLater();
402   wizard = 0;
403   //exit(1); // FIXME
404 }
405
406
407 /************************************************************
408  * Phase Three: Syncing
409  ************************************************************/
410
411 void CoreConnectDlg::startSync() {
412   ui.sessionProgress->setRange(0, 1);
413   ui.sessionProgress->setValue(0);
414   ui.networksProgress->setRange(0, 1);
415   ui.networksProgress->setValue(0);
416
417   ui.stackedWidget->setCurrentWidget(ui.syncPage);
418   // clean up old page
419   ui.loginGroup->setTitle(tr("Login"));
420   ui.user->setEnabled(true);
421   ui.password->setEnabled(true);
422   ui.rememberPasswd->setEnabled(true);
423   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
424 }
425
426 void CoreConnectDlg::coreSessionProgress(quint32 val, quint32 max) {
427   ui.sessionProgress->setRange(0, max);
428   ui.sessionProgress->setValue(val);
429
430 }
431
432 void CoreConnectDlg::coreNetworksProgress(quint32 val, quint32 max) {
433   if(max == 0) {
434     ui.networksProgress->setFormat("0/0");
435     ui.networksProgress->setRange(0, 1);
436     ui.networksProgress->setValue(1);
437   } else {
438     ui.networksProgress->setFormat("%v/%m");
439     ui.networksProgress->setRange(0, max);
440     ui.networksProgress->setValue(val);
441   }
442 }
443
444 void CoreConnectDlg::syncFinished() {
445   if(!wizard) accept();
446   else {
447     hide();
448     disconnect(wizard, 0, this, 0);
449     connect(wizard, SIGNAL(finished(int)), this, SLOT(accept()));
450   }
451 }
452
453 /*****************************************************************************************
454  * CoreAccountEditDlg
455  *****************************************************************************************/
456 CoreAccountEditDlg::CoreAccountEditDlg(AccountId id, const QVariantMap &acct, const QStringList &_existing, QWidget *parent)
457   : QDialog(parent)
458 {
459   ui.setupUi(this);
460   ui.useSsl->setIcon(SmallIcon("document-encrypt"));
461
462   existing = _existing;
463   if(id.isValid()) {
464     existing.removeAll(acct["AccountName"].toString());
465     ui.host->setText(acct["Host"].toString());
466     ui.port->setValue(acct["Port"].toUInt());
467     ui.accountName->setText(acct["AccountName"].toString());
468 #ifdef HAVE_SSL
469     ui.useSsl->setChecked(acct["useSsl"].toBool());
470 #else
471     ui.useSsl->setChecked(false);
472     ui.useSsl->setEnabled(false);
473 #endif
474     ui.useProxy->setChecked(acct["useProxy"].toBool());
475     ui.proxyHost->setText(acct["proxyHost"].toString());
476     ui.proxyPort->setValue(acct["proxyPort"].toUInt());
477     ui.proxyType->setCurrentIndex(acct["proxyType"].toInt() == QNetworkProxy::Socks5Proxy ? 0 : 1);
478     ui.proxyUser->setText(acct["proxyUser"].toString());
479     ui.proxyPassword->setText(acct["proxyPassword"].toString());
480   } else {
481     setWindowTitle(tr("Add Core Account"));
482 #ifndef HAVE_SSL
483     ui.useSsl->setChecked(false);
484     ui.useSsl->setEnabled(false);
485 #endif
486   }
487 }
488
489 QVariantMap CoreAccountEditDlg::accountData() {
490   account["AccountName"] = ui.accountName->text().trimmed();
491   account["Host"] = ui.host->text().trimmed();
492   account["Port"] = ui.port->value();
493   account["useSsl"] = ui.useSsl->isChecked();
494   account["useProxy"] = ui.useProxy->isChecked();
495   account["proxyHost"] = ui.proxyHost->text().trimmed();
496   account["proxyPort"] = ui.proxyPort->value();
497   account["proxyType"] = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
498   account["proxyUser"] = ui.proxyUser->text().trimmed();
499   account["proxyPassword"] = ui.proxyPassword->text().trimmed();
500   return account;
501 }
502
503 void CoreAccountEditDlg::setWidgetStates() {
504   bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && !ui.host->text().isEmpty();
505   ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
506 }
507
508 void CoreAccountEditDlg::on_host_textChanged(const QString &text) {
509   Q_UNUSED(text);
510   setWidgetStates();
511 }
512
513 void CoreAccountEditDlg::on_accountName_textChanged(const QString &text) {
514   Q_UNUSED(text);
515   setWidgetStates();
516 }