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