common: Port remote nicks to NickHighlightMatcher
[quassel.git] / src / qtui / coreconnectdlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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) : QDialog(parent)
31 {
32     _settingsPage = new CoreAccountSettingsPage(this);
33     _settingsPage->setStandAlone(true);
34     _settingsPage->load();
35
36     CoreAccountSettings s;
37     AccountId lastAccount = s.lastAccount();
38     if (lastAccount.isValid())
39         _settingsPage->setSelectedAccount(lastAccount);
40
41     setWindowTitle(tr("Connect to Core"));
42     setWindowIcon(icon::get("network-disconnect"));
43
44     QVBoxLayout *layout = new QVBoxLayout(this);
45     layout->addWidget(_settingsPage);
46
47     QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
48     buttonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
49     layout->addWidget(buttonBox);
50
51     connect(_settingsPage, SIGNAL(connectToCore(AccountId)), SLOT(accept()));
52     connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
53     connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
54 }
55
56
57 AccountId CoreConnectDlg::selectedAccount() const
58 {
59     return _settingsPage->selectedAccount();
60 }
61
62
63 void CoreConnectDlg::accept()
64 {
65     _settingsPage->save();
66     QDialog::accept();
67 }
68
69
70 /******** CoreConnectAuthDlg ****************************************************************/
71
72 CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount *account, QWidget *parent)
73     : QDialog(parent),
74     _account(account)
75 {
76     ui.setupUi(this);
77
78     connect(ui.user, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
79     connect(ui.password, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
80
81     ui.label->setText(tr("Please enter your credentials for %1:").arg(account->accountName()));
82     ui.user->setText(account->user());
83     ui.password->setText(account->password());
84     ui.rememberPasswd->setChecked(account->storePassword());
85
86     if (ui.user->text().isEmpty())
87         ui.user->setFocus();
88     else
89         ui.password->setFocus();
90 }
91
92
93 void CoreConnectAuthDlg::accept()
94 {
95     _account->setUser(ui.user->text());
96     _account->setPassword(ui.password->text());
97     _account->setStorePassword(ui.rememberPasswd->isChecked());
98
99     QDialog::accept();
100 }
101
102
103 void CoreConnectAuthDlg::setButtonStates()
104 {
105     bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty());
106     ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
107 }