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