1 /***************************************************************************
2 * Copyright (C) 2005-2016 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 <QDialogButtonBox>
23 #include <QVBoxLayout>
25 #include "coreconnectdlg.h"
27 #include "clientsettings.h"
28 #include "coreaccountsettingspage.h"
30 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent)
32 _settingsPage = new CoreAccountSettingsPage(this);
33 _settingsPage->setStandAlone(true);
34 _settingsPage->load();
36 CoreAccountSettings s;
37 AccountId lastAccount = s.lastAccount();
38 if (lastAccount.isValid())
39 _settingsPage->setSelectedAccount(lastAccount);
41 setWindowTitle(tr("Connect to Core"));
42 setWindowIcon(QIcon::fromTheme("network-disconnect"));
44 QVBoxLayout *layout = new QVBoxLayout(this);
45 layout->addWidget(_settingsPage);
47 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
48 buttonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
49 layout->addWidget(buttonBox);
51 connect(_settingsPage, SIGNAL(connectToCore(AccountId)), SLOT(accept()));
52 connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
53 connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
57 AccountId CoreConnectDlg::selectedAccount() const
59 return _settingsPage->selectedAccount();
63 void CoreConnectDlg::accept()
65 _settingsPage->save();
70 /******** CoreConnectAuthDlg ****************************************************************/
72 CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount *account, QWidget *parent)
78 connect(ui.user, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
79 connect(ui.password, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
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());
86 if (ui.user->text().isEmpty())
89 ui.password->setFocus();
93 void CoreConnectAuthDlg::accept()
95 _account->setUser(ui.user->text());
96 _account->setPassword(ui.password->text());
97 _account->setStorePassword(ui.rememberPasswd->isChecked());
103 void CoreConnectAuthDlg::setButtonStates()
105 bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty());
106 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);