From 11d59689fd6e1fe322a18b29c86d24d0803d6a2d Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 6 Nov 2009 09:58:05 +0100 Subject: [PATCH] Introduce settingspage for editing core accounts --- src/qtui/mainwin.cpp | 9 +- src/qtui/settingspages/coreaccounteditdlg.ui | 336 ++++++++++++++++++ .../settingspages/coreaccountsettingspage.cpp | 231 ++++++++++++ .../settingspages/coreaccountsettingspage.h | 95 +++++ .../settingspages/coreaccountsettingspage.ui | 238 +++++++++++++ src/qtui/settingspages/settingspages.inc | 4 +- 6 files changed, 909 insertions(+), 4 deletions(-) create mode 100644 src/qtui/settingspages/coreaccounteditdlg.ui create mode 100644 src/qtui/settingspages/coreaccountsettingspage.cpp create mode 100644 src/qtui/settingspages/coreaccountsettingspage.h create mode 100644 src/qtui/settingspages/coreaccountsettingspage.ui diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 2ff57017..21d4959b 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -105,6 +105,7 @@ #include "settingspages/chatmonitorsettingspage.h" #include "settingspages/chatviewsettingspage.h" #include "settingspages/connectionsettingspage.h" +#include "settingspages/coreaccountsettingspage.h" #include "settingspages/generalsettingspage.h" #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" @@ -311,9 +312,9 @@ void MainWin::setupActions() { connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool))); coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll, - 0, 0, QKeySequence::Find))->setCheckable(true); + 0, 0, QKeySequence::Find))->setCheckable(true); coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll, - this, SLOT(showAwayLog()))); + this, SLOT(showAwayLog()))); coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll, 0, 0, tr("Ctrl+M")))->setCheckable(true); @@ -893,6 +894,10 @@ void MainWin::showSettingsDlg() { dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg)); + if(Quassel::runMode() != Quassel::Monolithic) { + dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg)); + } + dlg->show(); } diff --git a/src/qtui/settingspages/coreaccounteditdlg.ui b/src/qtui/settingspages/coreaccounteditdlg.ui new file mode 100644 index 00000000..9477c082 --- /dev/null +++ b/src/qtui/settingspages/coreaccounteditdlg.ui @@ -0,0 +1,336 @@ + + + CoreAccountEditDlg + + + + 0 + 0 + 378 + 455 + + + + Edit Core Account + + + + + + Account Details + + + + + + Account Name: + + + + + + + Local Core + + + + + + + Hostname: + + + + + + + localhost + + + + + + + Port: + + + + + + + + 0 + 0 + + + + 1 + + + 65535 + + + 4242 + + + + + + + Qt::Horizontal + + + + 63 + 20 + + + + + + + + User: + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + Remember + + + + + + + + + + Use a Proxy + + + true + + + false + + + + + + Proxy Type: + + + + + + + + Socks 5 + + + + + HTTP + + + + + + + + Qt::Horizontal + + + + 89 + 20 + + + + + + + + Hostname: + + + + + + + localhost + + + + + + + Port: + + + + + + + + 0 + 0 + + + + 1 + + + 65535 + + + 8080 + + + + + + + Qt::Horizontal + + + + 98 + 20 + + + + + + + + User: + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 4 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CoreAccountEditDlg + accept() + + + 275 + 521 + + + 157 + 207 + + + + + buttonBox + rejected() + CoreAccountEditDlg + reject() + + + 343 + 521 + + + 286 + 207 + + + + + diff --git a/src/qtui/settingspages/coreaccountsettingspage.cpp b/src/qtui/settingspages/coreaccountsettingspage.cpp new file mode 100644 index 00000000..cd488a3a --- /dev/null +++ b/src/qtui/settingspages/coreaccountsettingspage.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + * Copyright (C) 2009 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "coreaccountsettingspage.h" + +#include "client.h" +#include "clientsettings.h" +#include "coreaccountmodel.h" +#include "iconloader.h" + +CoreAccountSettingsPage::CoreAccountSettingsPage(QWidget *parent) +: SettingsPage(tr("Misc"), tr("Core Accounts"), parent), +_lastAccountId(0), +_lastAutoConnectId(0) +{ + ui.setupUi(this); + initAutoWidgets(); + ui.addAccountButton->setIcon(SmallIcon("list-add")); + ui.editAccountButton->setIcon(SmallIcon("document-edit")); + ui.deleteAccountButton->setIcon(SmallIcon("edit-delete")); + + _model = new CoreAccountModel(Client::coreAccountModel(), this); + ui.accountView->setModel(_model); + ui.autoConnectAccount->setModel(_model); + + connect(model(), SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), SLOT(rowsAboutToBeRemoved(QModelIndex, int, int))); + connect(model(), SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(rowsInserted(QModelIndex, int, int))); + + connect(ui.accountView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(setWidgetStates())); + setWidgetStates(); +} + +void CoreAccountSettingsPage::load() { + _model->update(Client::coreAccountModel()); + + SettingsPage::load(); + ui.accountView->setCurrentIndex(model()->index(0, 0)); + ui.accountView->selectionModel()->select(model()->index(0, 0), QItemSelectionModel::Select); + setWidgetStates(); +} + +void CoreAccountSettingsPage::save() { + SettingsPage::save(); + Client::coreAccountModel()->update(_model); + Client::coreAccountModel()->save(); + CoreAccountSettings s; +} + +QVariant CoreAccountSettingsPage::loadAutoWidgetValue(const QString &widgetName) { + if(widgetName == "autoConnectAccount") { + CoreAccountSettings s; + AccountId id = s.autoConnectAccount(); + if(id <= 0) + return QVariant(); + ui.autoConnectAccount->setCurrentIndex(model()->accountIndex(id).row()); + return id.toInt(); + } + return SettingsPage::loadAutoWidgetValue(widgetName); +} + +void CoreAccountSettingsPage::saveAutoWidgetValue(const QString &widgetName, const QVariant &v) { + CoreAccountSettings s; + if(widgetName == "autoConnectAccount") { + AccountId id = _model->index(ui.autoConnectAccount->currentIndex(), 0).data(CoreAccountModel::AccountIdRole).value(); + s.setAutoConnectAccount(id); + return; + } + SettingsPage::saveAutoWidgetValue(widgetName, v); +} + +// TODO: Qt 4.6 - replace by proper rowsMoved() semantics +void CoreAccountSettingsPage::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end) { + _lastAutoConnectId = _lastAccountId = 0; + if(index.isValid() || start != end) + return; + + // the current index is removed, so remember it in case it's reinserted immediately afterwards + AccountId id = model()->index(start, 0).data(CoreAccountModel::AccountIdRole).value(); + if(start == ui.accountView->currentIndex().row()) + _lastAccountId = id; + if(start == ui.autoConnectAccount->currentIndex()) + _lastAutoConnectId = id; +} + +void CoreAccountSettingsPage::rowsInserted(const QModelIndex &index, int start, int end) { + if(index.isValid() || start != end) + return; + + // check if the inserted index was just removed and select it in that case + AccountId id = model()->index(start, 0).data(CoreAccountModel::AccountIdRole).value(); + if(id == _lastAccountId) + ui.accountView->setCurrentIndex(model()->index(start, 0)); + if(id == _lastAutoConnectId) + ui.autoConnectAccount->setCurrentIndex(start); + _lastAccountId = _lastAutoConnectId = 0; +} + +void CoreAccountSettingsPage::on_addAccountButton_clicked() { + CoreAccountEditDlg dlg(CoreAccount(), this); + if(dlg.exec() == QDialog::Accepted) { + AccountId id =_model->createOrUpdateAccount(dlg.account()); + ui.accountView->setCurrentIndex(model()->accountIndex(id)); + widgetHasChanged(); + } +} + +void CoreAccountSettingsPage::on_editAccountButton_clicked() { + QModelIndex idx = ui.accountView->selectionModel()->currentIndex(); + if(!idx.isValid()) + return; + + CoreAccountEditDlg dlg(_model->account(idx), this); + if(dlg.exec() == QDialog::Accepted) { + AccountId id = _model->createOrUpdateAccount(dlg.account()); + ui.accountView->setCurrentIndex(model()->accountIndex(id)); + widgetHasChanged(); + } +} + +void CoreAccountSettingsPage::on_deleteAccountButton_clicked() { + if(!ui.accountView->selectionModel()->selectedIndexes().count()) + return; + AccountId id = ui.accountView->selectionModel()->selectedIndexes().at(0).data(CoreAccountModel::AccountIdRole).value(); + if(id.isValid()) { + model()->removeAccount(id); + widgetHasChanged(); + } +} + +void CoreAccountSettingsPage::setWidgetStates() { + bool selected = ui.accountView->selectionModel()->selectedIndexes().count(); + + ui.editAccountButton->setEnabled(selected); + ui.deleteAccountButton->setEnabled(selected); +} + +void CoreAccountSettingsPage::widgetHasChanged() { + setChangedState(testHasChanged()); + setWidgetStates(); +} + +bool CoreAccountSettingsPage::testHasChanged() { + if(!(*model() == *Client::coreAccountModel())) + return true; + + return false; +} + +/***************************************************************************************** + * CoreAccountEditDlg + *****************************************************************************************/ +CoreAccountEditDlg::CoreAccountEditDlg(const CoreAccount &acct, QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + + _account = acct; + + ui.hostName->setText(acct.hostName()); + ui.port->setValue(acct.port()); + ui.accountName->setText(acct.accountName()); + ui.user->setText(acct.user()); + ui.password->setText(acct.password()); + ui.rememberPassword->setChecked(acct.storePassword()); + ui.useProxy->setChecked(acct.useProxy()); + ui.proxyHostName->setText(acct.proxyHostName()); + ui.proxyPort->setValue(acct.proxyPort()); + ui.proxyType->setCurrentIndex(acct.proxyType() == QNetworkProxy::Socks5Proxy ? 0 : 1); + ui.proxyUser->setText(acct.proxyUser()); + ui.proxyPassword->setText(acct.proxyPassword()); + + if(acct.accountId().isValid()) + setWindowTitle(tr("Edit Core Account")); + else + setWindowTitle(tr("Add Core Account")); +} + +CoreAccount CoreAccountEditDlg::account() { + _account.setAccountName(ui.accountName->text().trimmed()); + _account.setHostName(ui.hostName->text().trimmed()); + _account.setPort(ui.port->value()); + _account.setUser(ui.user->text().trimmed()); + _account.setPassword(ui.password->text()); + _account.setStorePassword(ui.rememberPassword->isChecked()); + _account.setUseProxy(ui.useProxy->isChecked()); + _account.setProxyHostName(ui.proxyHostName->text().trimmed()); + _account.setProxyPort(ui.proxyPort->value()); + _account.setProxyType(ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy); + _account.setProxyUser(ui.proxyUser->text().trimmed()); + _account.setProxyPassword(ui.proxyPassword->text()); + return _account; +} + +void CoreAccountEditDlg::setWidgetStates() { + bool ok = !ui.accountName->text().trimmed().isEmpty() + && !ui.user->text().trimmed().isEmpty() + && !ui.hostName->text().isEmpty(); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); +} + +void CoreAccountEditDlg::on_hostName_textChanged(const QString &text) { + Q_UNUSED(text); + setWidgetStates(); +} + +void CoreAccountEditDlg::on_accountName_textChanged(const QString &text) { + Q_UNUSED(text); + setWidgetStates(); +} + +void CoreAccountEditDlg::on_user_textChanged(const QString &text) { + Q_UNUSED(text) + setWidgetStates(); +} diff --git a/src/qtui/settingspages/coreaccountsettingspage.h b/src/qtui/settingspages/coreaccountsettingspage.h new file mode 100644 index 00000000..e552a0b5 --- /dev/null +++ b/src/qtui/settingspages/coreaccountsettingspage.h @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright (C) 2009 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef COREACCOUNTSETTINGSPAGE_H_ +#define COREACCOUNTSETTINGSPAGE_H_ + +#include "settingspage.h" + +#include "coreaccount.h" + +#include "ui_coreaccounteditdlg.h" +#include "ui_coreaccountsettingspage.h" + +class CoreAccountModel; + +class CoreAccountSettingsPage : public SettingsPage { + Q_OBJECT + + public: + CoreAccountSettingsPage(QWidget *parent = 0); + + virtual inline bool hasDefaults() const { return false; } + + public slots: + void save(); + void load(); + + private slots: + void on_addAccountButton_clicked(); + void on_editAccountButton_clicked(); + void on_deleteAccountButton_clicked(); + + void setWidgetStates(); + + void rowsAboutToBeRemoved(const QModelIndex &index, int start, int end); + void rowsInserted(const QModelIndex &index, int start, int end); + + private: + Ui::CoreAccountSettingsPage ui; + + CoreAccountModel *_model; + inline CoreAccountModel *model() const { return _model; } + + AccountId _lastAccountId, _lastAutoConnectId; + + virtual QVariant loadAutoWidgetValue(const QString &widgetName); + virtual void saveAutoWidgetValue(const QString &widgetName, const QVariant &value); + + void widgetHasChanged(); + bool testHasChanged(); + + inline QString settingsKey() const { return QString("CoreAccounts"); } +}; + +// ======================================== +// CoreAccountEditDlg +// ======================================== +class CoreAccountEditDlg : public QDialog { + Q_OBJECT + +public: + CoreAccountEditDlg(const CoreAccount &account, QWidget *parent = 0); + + CoreAccount account(); + +private slots: + void on_hostName_textChanged(const QString &); + void on_accountName_textChanged(const QString &); + void on_user_textChanged(const QString &); + + void setWidgetStates(); + +private: + Ui::CoreAccountEditDlg ui; + CoreAccount _account; +}; + +#endif diff --git a/src/qtui/settingspages/coreaccountsettingspage.ui b/src/qtui/settingspages/coreaccountsettingspage.ui new file mode 100644 index 00000000..94d45c06 --- /dev/null +++ b/src/qtui/settingspages/coreaccountsettingspage.ui @@ -0,0 +1,238 @@ + + + CoreAccountSettingsPage + + + + 0 + 0 + 388 + 464 + + + + + 0 + 0 + + + + Connect to Quassel Core + + + + :/16x16/actions/network-disconnect:/16x16/actions/network-disconnect + + + + + + Core Accounts + + + + + + QAbstractItemView::SelectRows + + + + + + + + + Edit... + + + + :/16x16/actions/oxygen/16x16/actions/document-properties.png:/16x16/actions/oxygen/16x16/actions/document-properties.png + + + + + + + Add... + + + + :/16x16/actions/oxygen/16x16/actions/list-add.png:/16x16/actions/oxygen/16x16/actions/list-add.png + + + + + + + Delete + + + + :/16x16/actions/oxygen/16x16/actions/list-remove.png:/16x16/actions/oxygen/16x16/actions/list-remove.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Automatically connect on startup + + + true + + + AutoConnectOnStartup + + + true + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + + + + + Connect to last account used + + + true + + + + + + + + + Always connect to + + + AutoConnectToFixedAccount + + + false + + + + + + + false + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + accountView + editAccountButton + addAccountButton + deleteAccountButton + autoConnectOnStartup + autoConnectToLast + autoConnectToFixedAccount + autoConnectAccount + + + + + autoConnectOnStartup + toggled(bool) + widget + setEnabled(bool) + + + 94 + 390 + + + 391 + 450 + + + + + autoConnectToFixedAccount + toggled(bool) + autoConnectAccount + setEnabled(bool) + + + 154 + 445 + + + 256 + 449 + + + + + diff --git a/src/qtui/settingspages/settingspages.inc b/src/qtui/settingspages/settingspages.inc index d96bddce..62ab5903 100644 --- a/src/qtui/settingspages/settingspages.inc +++ b/src/qtui/settingspages/settingspages.inc @@ -1,11 +1,11 @@ # Putting $FOO in SETTINGSPAGES automatically includes # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui -set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection chatmonitor general +set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection chatmonitor coreaccount general highlight identities ignorelist inputwidget itemview networks topicwidget) # Specify additional files (e.g. for subdialogs) here! set(SP_SOURCES aliasesmodel.cpp identityeditwidget.cpp ignorelistmodel.cpp notificationssettingspage.cpp) set(SP_HEADERS aliasesmodel.h identityeditwidget.h ignorelistmodel.h notificationssettingspage.h previewbufferview.h) -set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui identityeditwidget.ui ignorelisteditdlg.ui saveidentitiesdlg.ui +set(SP_FORMS buffervieweditdlg.ui coreaccounteditdlg.ui createidentitydlg.ui identityeditwidget.ui ignorelisteditdlg.ui saveidentitiesdlg.ui networkadddlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui) -- 2.20.1