1 /***************************************************************************
2 * Copyright (C) 2009 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QDialogButtonBox>
22 #include <QVBoxLayout>
24 #include "coreconnectdlg.h"
26 #include "iconloader.h"
27 #include "clientsettings.h"
28 #include "coreaccountsettingspage.h"
30 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
31 _settingsPage = new CoreAccountSettingsPage(this);
32 _settingsPage->setStandAlone(true);
33 _settingsPage->load();
35 CoreAccountSettings s;
36 AccountId lastAccount = s.lastAccount();
37 if(lastAccount.isValid())
38 _settingsPage->setSelectedAccount(lastAccount);
40 setWindowTitle(tr("Connect to Core"));
41 setWindowIcon(SmallIcon("network-disconnect"));
43 QVBoxLayout *layout = new QVBoxLayout(this);
44 layout->addWidget(_settingsPage);
46 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
47 buttonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
48 layout->addWidget(buttonBox);
50 connect(_settingsPage, SIGNAL(connectToCore(AccountId)), SLOT(accept()));
51 connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
52 connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
55 AccountId CoreConnectDlg::selectedAccount() const {
56 return _settingsPage->selectedAccount();
59 void CoreConnectDlg::accept() {
60 _settingsPage->save();
64 /******** CoreConnectAuthDlg ****************************************************************/
66 CoreConnectAuthDlg::CoreConnectAuthDlg(CoreAccount *account, QWidget *parent)
72 connect(ui.user, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
73 connect(ui.password, SIGNAL(textChanged(QString)), SLOT(setButtonStates()));
75 ui.label->setText(tr("Please enter your credentials for %1:").arg(account->accountName()));
76 ui.user->setText(account->user());
77 ui.password->setText(account->password());
78 ui.rememberPasswd->setChecked(account->storePassword());
80 if(ui.user->text().isEmpty())
83 ui.password->setFocus();
86 void CoreConnectAuthDlg::accept() {
87 _account->setUser(ui.user->text());
88 _account->setPassword(ui.password->text());
89 _account->setStorePassword(ui.rememberPasswd->isChecked());
94 void CoreConnectAuthDlg::setButtonStates() {
95 bool valid = !(ui.user->text().isEmpty() || ui.password->text().isEmpty());
96 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);