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