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