1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "coreconnectdlg.h"
23 #include <QDialogButtonBox>
24 #include <QVBoxLayout>
26 #include "clientsettings.h"
27 #include "coreaccountsettingspage.h"
30 CoreConnectDlg::CoreConnectDlg(QWidget* parent)
33 _settingsPage = new CoreAccountSettingsPage(this);
34 _settingsPage->setStandAlone(true);
35 _settingsPage->load();
37 CoreAccountSettings s;
38 AccountId lastAccount = s.lastAccount();
39 if (lastAccount.isValid())
40 _settingsPage->setSelectedAccount(lastAccount);
42 setWindowTitle(tr("Connect to Core"));
43 setWindowIcon(icon::get("network-disconnect"));
45 auto* layout = new QVBoxLayout(this);
46 layout->addWidget(_settingsPage);
48 auto* buttonBox = new QDialogButtonBox(this);
49 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
50 layout->addWidget(buttonBox);
52 connect(_settingsPage, &CoreAccountSettingsPage::connectToCore, this, &QDialog::accept);
53 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
54 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
57 AccountId CoreConnectDlg::selectedAccount() const
59 return _settingsPage->selectedAccount();
62 void CoreConnectDlg::accept()
64 _settingsPage->save();
68 /******** CoreConnectAuthDlg ****************************************************************/
70 CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount* account, QWidget* parent)
76 connect(ui.user, &QLineEdit::textChanged, this, &CoreConnectAuthDlg::setButtonStates);
77 connect(ui.password, &QLineEdit::textChanged, this, &CoreConnectAuthDlg::setButtonStates);
79 ui.label->setText(tr("Please enter your credentials for %1:").arg(account->accountName()));
80 ui.user->setText(account->user());
81 ui.password->setText(account->password());
82 ui.rememberPasswd->setChecked(account->storePassword());
84 if (ui.user->text().isEmpty())
87 ui.password->setFocus();
90 void CoreConnectAuthDlg::accept()
92 _account->setUser(ui.user->text());
93 _account->setPassword(ui.password->text());
94 _account->setStorePassword(ui.rememberPasswd->isChecked());
99 void CoreConnectAuthDlg::setButtonStates()
101 bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty());
102 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);