cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / coreconnectdlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "coreconnectdlg.h"
22
23 #include <QDialogButtonBox>
24 #include <QVBoxLayout>
25
26 #include "clientsettings.h"
27 #include "coreaccountsettingspage.h"
28 #include "icon.h"
29
30 CoreConnectDlg::CoreConnectDlg(QWidget* parent)
31     : QDialog(parent)
32 {
33     _settingsPage = new CoreAccountSettingsPage(this);
34     _settingsPage->setStandAlone(true);
35     _settingsPage->load();
36
37     CoreAccountSettings s;
38     AccountId lastAccount = s.lastAccount();
39     if (lastAccount.isValid())
40         _settingsPage->setSelectedAccount(lastAccount);
41
42     setWindowTitle(tr("Connect to Core"));
43     setWindowIcon(icon::get("network-disconnect"));
44
45     auto* layout = new QVBoxLayout(this);
46     layout->addWidget(_settingsPage);
47
48     auto* buttonBox = new QDialogButtonBox(this);
49     buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
50     layout->addWidget(buttonBox);
51
52     connect(_settingsPage, &CoreAccountSettingsPage::connectToCore, this, &QDialog::accept);
53     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
54     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
55 }
56
57 AccountId CoreConnectDlg::selectedAccount() const
58 {
59     return _settingsPage->selectedAccount();
60 }
61
62 void CoreConnectDlg::accept()
63 {
64     _settingsPage->save();
65     QDialog::accept();
66 }
67
68 /******** CoreConnectAuthDlg ****************************************************************/
69
70 CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount* account, QWidget* parent)
71     : QDialog(parent)
72     , _account(account)
73 {
74     ui.setupUi(this);
75
76     connect(ui.user, &QLineEdit::textChanged, this, &CoreConnectAuthDlg::setButtonStates);
77     connect(ui.password, &QLineEdit::textChanged, this, &CoreConnectAuthDlg::setButtonStates);
78
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());
83
84     if (ui.user->text().isEmpty())
85         ui.user->setFocus();
86     else
87         ui.password->setFocus();
88 }
89
90 void CoreConnectAuthDlg::accept()
91 {
92     _account->setUser(ui.user->text());
93     _account->setPassword(ui.password->text());
94     _account->setStorePassword(ui.rememberPasswd->isChecked());
95
96     QDialog::accept();
97 }
98
99 void CoreConnectAuthDlg::setButtonStates()
100 {
101     bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty());
102     ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
103 }