starting the internal core on demand
[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 "clientsettings.h"
28 #include "clientsyncer.h"
29 #include "coreconfigwizard.h"
30 #include "iconloader.h"
31 #include "monoapplication.h"
32
33 CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent)
34   : QDialog(parent)
35 {
36   ui.setupUi(this);
37   ui.editAccount->setIcon(SmallIcon("document-properties"));
38   ui.addAccount->setIcon(SmallIcon("list-add"));
39   ui.deleteAccount->setIcon(SmallIcon("list-remove"));
40   ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
41   ui.secureConnection->setPixmap(SmallIcon("document-encrypt"));
42
43   // make it look more native under Mac OS X:
44   setWindowFlags(Qt::Sheet);
45
46   clientSyncer = new ClientSyncer(this);
47
48   wizard = 0;
49
50   doingAutoConnect = false;
51
52   ui.stackedWidget->setCurrentWidget(ui.accountPage);
53
54   CoreAccountSettings s;
55   AccountId lastacc = s.lastAccount();
56   autoConnectAccount = s.autoConnectAccount();
57   QListWidgetItem *currentItem = 0;
58   foreach(AccountId id, s.knownAccounts()) {
59     if(!id.isValid()) continue;
60     QVariantMap data = s.retrieveAccountData(id);
61     data["AccountId"] = QVariant::fromValue<AccountId>(id);
62     accounts[id] = data;
63     QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList);
64     item->setData(Qt::UserRole, QVariant::fromValue<AccountId>(id));
65     if(id == lastacc) currentItem = item;
66   }
67   if(currentItem) ui.accountList->setCurrentItem(currentItem);
68   else ui.accountList->setCurrentRow(0);
69
70   setAccountWidgetStates();
71
72   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setFocus();
73   //ui.accountButtonBox->button(QDialogButtonBox::Ok)->setAutoDefault(true);
74
75   connect(clientSyncer, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)),this, SLOT(initPhaseSocketState(QAbstractSocket::SocketState)));
76   connect(clientSyncer, SIGNAL(connectionError(const QString &)), this, SLOT(initPhaseError(const QString &)));
77   connect(clientSyncer, SIGNAL(connectionMsg(const QString &)), this, SLOT(initPhaseMsg(const QString &)));
78   connect(clientSyncer, SIGNAL(encrypted(bool)), this, SLOT(encrypted(bool)));
79   connect(clientSyncer, SIGNAL(startLogin()), this, SLOT(startLogin()));
80   connect(clientSyncer, SIGNAL(loginFailed(const QString &)), this, SLOT(loginFailed(const QString &)));
81   connect(clientSyncer, SIGNAL(loginSuccess()), this, SLOT(startSync()));
82   connect(clientSyncer, SIGNAL(startCoreSetup(const QVariantList &)), this, SLOT(startCoreConfig(const QVariantList &)));
83   connect(clientSyncer, SIGNAL(sessionProgress(quint32, quint32)), this, SLOT(coreSessionProgress(quint32, quint32)));
84   connect(clientSyncer, SIGNAL(networksProgress(quint32, quint32)), this, SLOT(coreNetworksProgress(quint32, quint32)));
85   connect(clientSyncer, SIGNAL(syncFinished()), this, SLOT(syncFinished()));
86
87   connect(ui.user, SIGNAL(textChanged(const QString &)), this, SLOT(setLoginWidgetStates()));
88   connect(ui.password, SIGNAL(textChanged(const QString &)), this, SLOT(setLoginWidgetStates()));
89
90   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
91   connect(ui.syncButtonBox->button(QDialogButtonBox::Abort), SIGNAL(clicked()), this, SLOT(restartPhaseNull()));
92
93   if(autoconnect && ui.accountList->count() && autoConnectAccount.isValid()
94      && autoConnectAccount == ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>()) {
95     doingAutoConnect = true;
96     on_accountButtonBox_accepted();
97   }
98 }
99
100 CoreConnectDlg::~CoreConnectDlg() {
101   if(ui.accountList->selectedItems().count()) {
102     CoreAccountSettings s;
103     s.setLastAccount(ui.accountList->selectedItems()[0]->data(Qt::UserRole).value<AccountId>());
104   }
105 }
106
107
108 /****************************************************
109  * Account Management
110  ***************************************************/
111
112 void CoreConnectDlg::on_accountList_itemSelectionChanged() {
113   setAccountWidgetStates();
114 }
115
116 void CoreConnectDlg::setAccountWidgetStates() {
117   QList<QListWidgetItem *> selectedItems = ui.accountList->selectedItems();
118   ui.editAccount->setEnabled(selectedItems.count());
119   ui.deleteAccount->setEnabled(selectedItems.count());
120   ui.autoConnect->setEnabled(selectedItems.count());
121   if(selectedItems.count()) {
122     ui.autoConnect->setChecked(selectedItems[0]->data(Qt::UserRole).value<AccountId>() == autoConnectAccount);
123   }
124   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setEnabled(ui.accountList->count());
125 }
126
127 void CoreConnectDlg::on_autoConnect_clicked(bool state) {
128   if(!state) {
129     autoConnectAccount = 0;
130   } else {
131     if(ui.accountList->selectedItems().count()) {
132       autoConnectAccount = ui.accountList->selectedItems()[0]->data(Qt::UserRole).value<AccountId>();
133     } else {
134       qWarning() << "Checked auto connect without an enabled item!";  // should never happen!
135       autoConnectAccount = 0;
136     }
137   }
138   setAccountWidgetStates();
139 }
140
141 void CoreConnectDlg::on_addAccount_clicked() {
142   QStringList existing;
143   for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text();
144   CoreAccountEditDlg dlg(0, QVariantMap(), existing, this);
145   if(dlg.exec() == QDialog::Accepted) {
146     // find free ID
147     AccountId id = accounts.count() + 1;
148     for(AccountId i = 1; i <= accounts.count(); i++) {
149       if(!accounts.keys().contains(i)) {
150         id = i;
151         break;
152       }
153     }
154     QVariantMap data = dlg.accountData();
155     data["AccountId"] = QVariant::fromValue<AccountId>(id);
156     accounts[id] = data;
157     QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList);
158     item->setData(Qt::UserRole, QVariant::fromValue<AccountId>(id));
159     ui.accountList->setCurrentItem(item);
160   }
161 }
162
163 void CoreConnectDlg::on_editAccount_clicked() {
164   QStringList existing;
165   for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text();
166   AccountId id = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
167   QVariantMap acct = accounts[id];
168   CoreAccountEditDlg dlg(id, acct, existing, this);
169   if(dlg.exec() == QDialog::Accepted) {
170     QVariantMap data = dlg.accountData();
171     ui.accountList->currentItem()->setText(data["AccountName"].toString());
172     accounts[id] = data;
173   }
174 }
175
176 void CoreConnectDlg::on_deleteAccount_clicked() {
177   AccountId id = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
178   int ret = QMessageBox::question(this, tr("Remove Account Settings"),
179                                   tr("Do you really want to remove your local settings for this Quassel Core account?<br>"
180                                   "Note: This will <em>not</em> remove or change any data on the Core itself!"),
181                                   QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
182   if(ret == QMessageBox::Yes) {
183     int idx = ui.accountList->currentRow();
184     delete ui.accountList->takeItem(idx);
185     ui.accountList->setCurrentRow(qMin(idx, ui.accountList->count()-1));
186     accounts[id]["Delete"] = true;  // we only flag this here, actual deletion happens on accept!
187     setAccountWidgetStates();
188   }
189 }
190
191 void CoreConnectDlg::on_accountList_itemDoubleClicked(QListWidgetItem *item) {
192   Q_UNUSED(item);
193   on_accountButtonBox_accepted();
194 }
195
196 void CoreConnectDlg::on_accountButtonBox_accepted() {
197   // save accounts
198   CoreAccountSettings s;
199   foreach(QVariantMap acct, accounts.values()) {
200     AccountId id = acct["AccountId"].value<AccountId>();
201     if(acct.contains("Delete")) {
202       s.removeAccount(id);
203     } else {
204       s.storeAccountData(id, acct);
205     }
206   }
207   s.setAutoConnectAccount(autoConnectAccount);
208
209   ui.stackedWidget->setCurrentWidget(ui.loginPage);
210   account = ui.accountList->currentItem()->data(Qt::UserRole).value<AccountId>();
211   accountData = accounts[account];
212   s.setLastAccount(account);
213   connectToCore();
214 }
215
216 void CoreConnectDlg::on_useInternalCore_clicked() {
217   // FIXME: this needs to be a qobject_cast - therefore MonolithicApplication needs to be a proper QObject... :/
218   MonolithicApplication *monoApp = static_cast<MonolithicApplication *>(QApplication::instance());
219   if(monoApp) {
220     qDebug() << "starting core...";
221     monoApp->startInternalCore();
222     monoApp->connectClientSyncer(clientSyncer);
223   }
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.useInternal->setChecked(acct["UseInternal"].toBool());
468     ui.accountName->setText(acct["AccountName"].toString());
469 #ifdef HAVE_SSL
470     ui.useSsl->setChecked(acct["useSsl"].toBool());
471 #else
472     ui.useSsl->setChecked(false);
473     ui.useSsl->setEnabled(false);
474 #endif
475     ui.useProxy->setChecked(acct["useProxy"].toBool());
476     ui.proxyHost->setText(acct["proxyHost"].toString());
477     ui.proxyPort->setValue(acct["proxyPort"].toUInt());
478     ui.proxyType->setCurrentIndex(acct["proxyType"].toInt() == QNetworkProxy::Socks5Proxy ? 0 : 1);
479     ui.proxyUser->setText(acct["proxyUser"].toString());
480     ui.proxyPassword->setText(acct["proxyPassword"].toString());
481   } else {
482     setWindowTitle(tr("Add Core Account"));
483 #ifndef HAVE_SSL
484     ui.useSsl->setChecked(false);
485     ui.useSsl->setEnabled(false);
486 #endif
487   }
488
489 #ifndef BUILD_MONO
490   // if we don't have a mono build we hide the option to use the internal connection and force the setting to use remote host
491   ui.useInternal->setChecked(false);
492   ui.useInternal->hide();
493   ui.useRemote->hide();
494   ui.labelUseBuiltinCore->hide();
495 #endif
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["UseInternal"] = ui.useInternal->isChecked();
503   account["useSsl"] = ui.useSsl->isChecked();
504   account["useProxy"] = ui.useProxy->isChecked();
505   account["proxyHost"] = ui.proxyHost->text().trimmed();
506   account["proxyPort"] = ui.proxyPort->value();
507   account["proxyType"] = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
508   account["proxyUser"] = ui.proxyUser->text().trimmed();
509   account["proxyPassword"] = ui.proxyPassword->text().trimmed();
510   return account;
511 }
512
513 void CoreAccountEditDlg::setWidgetStates() {
514   bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && (ui.useInternal->isChecked() || !ui.host->text().isEmpty());
515   ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
516 }
517
518 void CoreAccountEditDlg::on_host_textChanged(const QString &text) {
519   Q_UNUSED(text);
520   setWidgetStates();
521 }
522
523 void CoreAccountEditDlg::on_accountName_textChanged(const QString &text) {
524   Q_UNUSED(text);
525   setWidgetStates();
526 }
527
528 void CoreAccountEditDlg::on_useRemote_toggled(bool state) {
529   Q_UNUSED(state);
530   setWidgetStates();
531 }