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