adding tons of ifdefs so quassel will build again without ssl support
[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   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
231   startSync();
232 }
233
234 /*****************************************************
235  * Connecting to the Core
236  ****************************************************/
237
238 /*** Phase One: initializing the core connection ***/
239
240 void CoreConnectDlg::connectToCore() {
241   ui.secureConnection->hide();
242   ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
243   ui.connectLabel->setText(tr("Connect to %1").arg(accountData["Host"].toString()));
244   ui.coreInfoLabel->setText("");
245   ui.loginStack->setCurrentWidget(ui.loginEmptyPage);
246   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
247   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
248   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
249   disconnect(ui.loginButtonBox, 0, this, 0);
250   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
251
252   clientSyncer->connectToCore(accountData);
253 }
254
255 void CoreConnectDlg::initPhaseError(const QString &error) {
256   doingAutoConnect = false;
257   ui.secureConnection->hide();
258   ui.connectIcon->setPixmap(BarIcon("dialog-error"));
259   //ui.connectLabel->setBrush(QBrush("red"));
260   ui.connectLabel->setText(tr("<div style=color:red;>Connection to %1 failed!</div>").arg(accountData["Host"].toString()));
261   ui.coreInfoLabel->setText(error);
262   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Retry|QDialogButtonBox::Cancel);
263   ui.loginButtonBox->button(QDialogButtonBox::Retry)->setFocus();
264   disconnect(ui.loginButtonBox, 0, this, 0);
265   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(restartPhaseNull()));
266   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
267 }
268
269 void CoreConnectDlg::initPhaseMsg(const QString &msg) {
270   ui.coreInfoLabel->setText(msg);
271 }
272
273 void CoreConnectDlg::encrypted(bool useSsl) {
274   if(useSsl)
275     ui.secureConnection->show();
276   else
277     ui.secureConnection->hide();
278 }
279
280 void CoreConnectDlg::initPhaseSocketState(QAbstractSocket::SocketState state) {
281   QString s;
282   QString host = accountData["Host"].toString();
283   switch(state) {
284     case QAbstractSocket::UnconnectedState: s = tr("Not connected to %1.").arg(host); break;
285     case QAbstractSocket::HostLookupState: s = tr("Looking up %1...").arg(host); break;
286     case QAbstractSocket::ConnectingState: s = tr("Connecting to %1...").arg(host); break;
287     case QAbstractSocket::ConnectedState: s = tr("Connected to %1").arg(host); break;
288     default: s = tr("Unknown connection state to %1"); break;
289   }
290   ui.connectLabel->setText(s);
291 }
292
293 void CoreConnectDlg::restartPhaseNull() {
294   doingAutoConnect = false;
295   ui.stackedWidget->setCurrentWidget(ui.accountPage);
296   clientSyncer->disconnectFromCore();
297 }
298
299 /*********************************************************
300  * Phase Two: Login
301  *********************************************************/
302
303 void CoreConnectDlg::startLogin() {
304   ui.connectIcon->setPixmap(BarIcon("network-connect"));
305   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
306   //ui.loginStack->setMinimumSize(ui.loginStack->sizeHint()); ui.loginStack->updateGeometry();
307   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
308   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
309   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
310   if(!accountData["User"].toString().isEmpty()) {
311     ui.user->setText(accountData["User"].toString());
312     if(accountData["RememberPasswd"].toBool()) {
313       ui.password->setText(accountData["Password"].toString());
314       ui.rememberPasswd->setChecked(true);
315       ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
316     } else {
317       ui.rememberPasswd->setChecked(false);
318       ui.password->setFocus();
319     }
320   } else ui.user->setFocus();
321   disconnect(ui.loginButtonBox, 0, this, 0);
322   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
323   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
324   if(doingAutoConnect) doLogin();
325 }
326
327 void CoreConnectDlg::doLogin() {
328   QVariantMap loginData;
329   loginData["User"] = ui.user->text();
330   loginData["Password"] = ui.password->text();
331   loginData["RememberPasswd"] = ui.rememberPasswd->isChecked();
332   doLogin(loginData);
333 }
334
335 void CoreConnectDlg::doLogin(const QVariantMap &loginData) {
336   disconnect(ui.loginButtonBox, 0, this, 0);
337   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
338   connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
339   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
340   ui.loginGroup->setTitle(tr("Logging in..."));
341   ui.user->setDisabled(true);
342   ui.password->setDisabled(true);
343   ui.rememberPasswd->setDisabled(true);
344   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
345   accountData["User"] = loginData["User"];
346   accountData["RememberPasswd"] = loginData["RememberPasswd"];
347   if(loginData["RememberPasswd"].toBool()) accountData["Password"] = loginData["Password"];
348   else accountData.remove("Password");
349   ui.user->setText(loginData["User"].toString());
350   ui.password->setText(loginData["Password"].toString());
351   ui.rememberPasswd->setChecked(loginData["RememberPasswd"].toBool());
352   CoreAccountSettings s;
353   s.storeAccountData(account, accountData);
354   clientSyncer->loginToCore(loginData["User"].toString(), loginData["Password"].toString());
355 }
356
357 void CoreConnectDlg::setLoginWidgetStates() {
358   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.user->text().isEmpty() || ui.password->text().isEmpty());
359 }
360
361 void CoreConnectDlg::loginFailed(const QString &error) {
362   if(wizard) {
363     wizard->reject();
364   }
365   ui.connectIcon->setPixmap(BarIcon("dialog-error"));
366   ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
367   ui.loginGroup->setTitle(tr("Login"));
368   ui.user->setEnabled(true);
369   ui.password->setEnabled(true);
370   ui.rememberPasswd->setEnabled(true);
371   ui.coreInfoLabel->setText(error);
372   ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
373   ui.password->setFocus();
374   doingAutoConnect = false;
375 }
376
377 void CoreConnectDlg::startCoreConfig(const QVariantList &backends) {
378   storageBackends = backends;
379   ui.loginStack->setCurrentWidget(ui.coreConfigPage);
380
381   //on_launchCoreConfigWizard_clicked();
382
383 }
384
385 void CoreConnectDlg::on_launchCoreConfigWizard_clicked() {
386   Q_ASSERT(!wizard);
387   wizard = new CoreConfigWizard(storageBackends, this);
388   connect(wizard, SIGNAL(setupCore(const QVariant &)), clientSyncer, SLOT(doCoreSetup(const QVariant &)));
389   connect(wizard, SIGNAL(loginToCore(const QVariantMap &)), this, SLOT(doLogin(const QVariantMap &)));
390   connect(clientSyncer, SIGNAL(coreSetupSuccess()), wizard, SLOT(coreSetupSuccess()));
391   connect(clientSyncer, SIGNAL(coreSetupFailed(const QString &)), wizard, SLOT(coreSetupFailed(const QString &)));
392   connect(wizard, SIGNAL(accepted()), this, SLOT(configWizardAccepted()));
393   connect(wizard, SIGNAL(rejected()), this, SLOT(configWizardRejected()));
394   connect(clientSyncer, SIGNAL(loginSuccess()), wizard, SLOT(loginSuccess()));
395   connect(clientSyncer, SIGNAL(syncFinished()), wizard, SLOT(syncFinished()));
396   wizard->show();
397 }
398
399 void CoreConnectDlg::configWizardAccepted() {
400
401   wizard->deleteLater();
402   wizard = 0;
403 }
404
405 void CoreConnectDlg::configWizardRejected() {
406
407   wizard->deleteLater();
408   wizard = 0;
409   //exit(1); // FIXME
410 }
411
412
413 /************************************************************
414  * Phase Three: Syncing
415  ************************************************************/
416
417 void CoreConnectDlg::startSync() {
418   ui.sessionProgress->setRange(0, 1);
419   ui.sessionProgress->setValue(0);
420   ui.networksProgress->setRange(0, 1);
421   ui.networksProgress->setValue(0);
422
423   ui.stackedWidget->setCurrentWidget(ui.syncPage);
424   // clean up old page
425   ui.loginGroup->setTitle(tr("Login"));
426   ui.user->setEnabled(true);
427   ui.password->setEnabled(true);
428   ui.rememberPasswd->setEnabled(true);
429   if(ui.loginButtonBox->standardButtons() & QDialogButtonBox::Ok) // in mono mode we don't show an Ok Button
430     ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
431 }
432
433 void CoreConnectDlg::coreSessionProgress(quint32 val, quint32 max) {
434   ui.sessionProgress->setRange(0, max);
435   ui.sessionProgress->setValue(val);
436
437 }
438
439 void CoreConnectDlg::coreNetworksProgress(quint32 val, quint32 max) {
440   if(max == 0) {
441     ui.networksProgress->setFormat("0/0");
442     ui.networksProgress->setRange(0, 1);
443     ui.networksProgress->setValue(1);
444   } else {
445     ui.networksProgress->setFormat("%v/%m");
446     ui.networksProgress->setRange(0, max);
447     ui.networksProgress->setValue(val);
448   }
449 }
450
451 void CoreConnectDlg::syncFinished() {
452   if(!wizard) accept();
453   else {
454     hide();
455     disconnect(wizard, 0, this, 0);
456     connect(wizard, SIGNAL(finished(int)), this, SLOT(accept()));
457   }
458 }
459
460 AccountId CoreConnectDlg::findFreeAccountId() {
461   for(AccountId i = 1;; i++) {
462     if(!accounts.contains(i) && i != _internalAccountId)
463       return i;
464   }
465 }
466
467 /*****************************************************************************************
468  * CoreAccountEditDlg
469  *****************************************************************************************/
470 CoreAccountEditDlg::CoreAccountEditDlg(AccountId id, const QVariantMap &acct, const QStringList &_existing, QWidget *parent)
471   : QDialog(parent)
472 {
473   ui.setupUi(this);
474   ui.useSsl->setIcon(SmallIcon("document-encrypt"));
475
476   existing = _existing;
477   if(id.isValid()) {
478     account = acct;
479
480     existing.removeAll(acct["AccountName"].toString());
481     ui.host->setText(acct["Host"].toString());
482     ui.port->setValue(acct["Port"].toUInt());
483     ui.accountName->setText(acct["AccountName"].toString());
484 #ifdef HAVE_SSL
485     ui.useSsl->setChecked(acct["useSsl"].toBool());
486 #else
487     ui.useSsl->setChecked(false);
488     ui.useSsl->setEnabled(false);
489 #endif
490     ui.useProxy->setChecked(acct["useProxy"].toBool());
491     ui.proxyHost->setText(acct["proxyHost"].toString());
492     ui.proxyPort->setValue(acct["proxyPort"].toUInt());
493     ui.proxyType->setCurrentIndex(acct["proxyType"].toInt() == QNetworkProxy::Socks5Proxy ? 0 : 1);
494     ui.proxyUser->setText(acct["proxyUser"].toString());
495     ui.proxyPassword->setText(acct["proxyPassword"].toString());
496   } else {
497     setWindowTitle(tr("Add Core Account"));
498 #ifndef HAVE_SSL
499     ui.useSsl->setChecked(false);
500     ui.useSsl->setEnabled(false);
501 #endif
502   }
503 }
504
505 QVariantMap CoreAccountEditDlg::accountData() {
506   account["AccountName"] = ui.accountName->text().trimmed();
507   account["Host"] = ui.host->text().trimmed();
508   account["Port"] = ui.port->value();
509   account["useSsl"] = ui.useSsl->isChecked();
510   account["useProxy"] = ui.useProxy->isChecked();
511   account["proxyHost"] = ui.proxyHost->text().trimmed();
512   account["proxyPort"] = ui.proxyPort->value();
513   account["proxyType"] = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
514   account["proxyUser"] = ui.proxyUser->text().trimmed();
515   account["proxyPassword"] = ui.proxyPassword->text().trimmed();
516   return account;
517 }
518
519 void CoreAccountEditDlg::setWidgetStates() {
520   bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && !ui.host->text().isEmpty();
521   ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
522 }
523
524 void CoreAccountEditDlg::on_host_textChanged(const QString &text) {
525   Q_UNUSED(text);
526   setWidgetStates();
527 }
528
529 void CoreAccountEditDlg::on_accountName_textChanged(const QString &text) {
530   Q_UNUSED(text);
531   setWidgetStates();
532 }