From: Manuel Nickschas Date: Mon, 7 Dec 2009 21:35:38 +0000 (+0100) Subject: Introduce CoreConnectionSettings and a settingspage for configuring it X-Git-Tag: 0.6-beta1~118 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=b099603e2e1297ec41a354dc949729e4f77d7bbd Introduce CoreConnectionSettings and a settingspage for configuring it You can now configure your client/core connection via Configure -> Remote Cores -> Connection. Also introduced Settings::initAndNotify() that does the same as notify(), but also reads and notifies on connect, thus saving an extra line. --- diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 0af9c6ec..0b779037 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -175,6 +175,48 @@ void CoreAccountSettings::clearAccounts() { removeLocalKey(key); } +/***********************************************************************************************/ +// CoreConnectionSettings: + +CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {} + +void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) { + setLocalValue("NetworkDetectionMode", mode); +} + +CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() { +#ifdef HAVE_KDE + NetworkDetectionMode def = UseSolid; +#else + NetworkDetectionMode def = UsePingTimeout; +#endif + return (NetworkDetectionMode)localValue("NetworkDetectionMode", def).toInt(); +} + +void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) { + setLocalValue("AutoReconnect", autoReconnect); +} + +bool CoreConnectionSettings::autoReconnect() { + return localValue("AutoReconnect", true).toBool(); +} + +void CoreConnectionSettings::setPingTimeoutInterval(int interval) { + setLocalValue("PingTimeoutInterval", interval); +} + +int CoreConnectionSettings::pingTimeoutInterval() { + return localValue("PingTimeoutInterval", 60).toInt(); +} + +void CoreConnectionSettings::setReconnectInterval(int interval) { + setLocalValue("ReconnectInterval", interval); +} + +int CoreConnectionSettings::reconnectInterval() { + return localValue("ReconnectInterval", 60).toInt(); +} + /***********************************************************************************************/ // NotificationSettings: diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h index 5d16f278..3ae5ae43 100644 --- a/src/client/clientsettings.h +++ b/src/client/clientsettings.h @@ -107,6 +107,33 @@ public: bool nicksCaseSensitive(); }; +// ======================================== +// CoreConnectionSettings +// ======================================== + +class CoreConnectionSettings : public ClientSettings { +public: + enum NetworkDetectionMode { + UseSolid, + UsePingTimeout, + NoActiveDetection + }; + + CoreConnectionSettings(); + + void setNetworkDetectionMode(NetworkDetectionMode mode); + NetworkDetectionMode networkDetectionMode(); + + void setAutoReconnect(bool autoReconnect); + bool autoReconnect(); + + void setPingTimeoutInterval(int interval); + int pingTimeoutInterval(); + + void setReconnectInterval(int interval); + int reconnectInterval(); +}; + // ======================================== // TabCompletionSettings // ======================================== diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 2731da26..24ddd5fc 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -60,7 +60,12 @@ QHash Settings::settingsChangeNotifier; void Settings::notify(const QString &key, QObject *receiver, const char *slot) { QObject::connect(notifier(normalizedKey(group, key)), SIGNAL(valueChanged(const QVariant &)), - receiver, slot); + receiver, slot); +} + +void Settings::initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue) { + notify(key, receiver, slot); + emit notifier(normalizedKey(group, key))->valueChanged(localValue(key, defaultValue)); } uint Settings::version() { diff --git a/src/common/settings.h b/src/common/settings.h index 64743538..e2920c24 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -44,7 +44,12 @@ public: enum Mode { Default, Custom }; public: + //! Call the given slot on change of the given key virtual void notify(const QString &key, QObject *receiver, const char *slot); + + //! Sets up notification and calls the given slot to set the initial value + void initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue = QVariant()); + virtual uint version(); protected: diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 2e1ae409..2a5b379d 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -112,6 +112,7 @@ #include "settingspages/chatviewsettingspage.h" #include "settingspages/connectionsettingspage.h" #include "settingspages/coreaccountsettingspage.h" +#include "settingspages/coreconnectionsettingspage.h" #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" #include "settingspages/ignorelistsettingspage.h" @@ -956,6 +957,7 @@ void MainWin::showSettingsDlg() { // Category: Remote Cores if(Quassel::runMode() != Quassel::Monolithic) { dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg)); + dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg)); } dlg->show(); diff --git a/src/qtui/settingspages/coreconnectionsettingspage.cpp b/src/qtui/settingspages/coreconnectionsettingspage.cpp new file mode 100644 index 00000000..c3b78059 --- /dev/null +++ b/src/qtui/settingspages/coreconnectionsettingspage.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * 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) any later version. * + * * + * 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 "coreconnectionsettingspage.h" + +CoreConnectionSettingsPage::CoreConnectionSettingsPage(QWidget *parent) + : SettingsPage(tr("Remote Cores"), tr("Connection"), parent) { + ui.setupUi(this); +#ifndef HAVE_KDE + ui.useSolid->hide(); +#endif + + initAutoWidgets(); + + connect(ui.useSolid, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); + connect(ui.usePingTimeout, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); + connect(ui.useNoTimeout, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); +} + +void CoreConnectionSettingsPage::widgetHasChanged() { + bool hasChanged = false; + CoreConnectionSettings::NetworkDetectionMode mode = modeFromRadioButtons(); + if(mode != _detectionMode) + hasChanged = true; + + setChangedState(hasChanged); +} + +void CoreConnectionSettingsPage::defaults() { +#ifdef HAVE_KDE + setRadioButtons(CoreConnectionSettings::UseSolid); +#else + setRadioButtons(CoreConnectionSettings::UsePingTimeout); +#endif + + SettingsPage::defaults(); +} + +void CoreConnectionSettingsPage::load() { + CoreConnectionSettings s; + _detectionMode = s.networkDetectionMode(); + setRadioButtons(_detectionMode); + SettingsPage::load(); +} + +void CoreConnectionSettingsPage::save() { + _detectionMode = modeFromRadioButtons(); + CoreConnectionSettings s; + s.setNetworkDetectionMode(_detectionMode); + SettingsPage::save(); +} + +void CoreConnectionSettingsPage::setRadioButtons(CoreConnectionSettings::NetworkDetectionMode mode) { + switch(mode) { +#ifdef HAVE_KDE + case CoreConnectionSettings::UseSolid: + ui.useSolid->setChecked(true); + break; +#endif + case CoreConnectionSettings::UsePingTimeout: + ui.usePingTimeout->setChecked(true); + break; + default: + ui.useNoTimeout->setChecked(true); + } +} + +CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettingsPage::modeFromRadioButtons() const { +#ifdef HAVE_KDE + if(ui.useSolid->isChecked()) + return CoreConnectionSettings::UseSolid; +#endif + if(ui.usePingTimeout->isChecked()) + return CoreConnectionSettings::UsePingTimeout; + + return CoreConnectionSettings::NoActiveDetection; +} diff --git a/src/qtui/settingspages/coreconnectionsettingspage.h b/src/qtui/settingspages/coreconnectionsettingspage.h new file mode 100644 index 00000000..58d2966d --- /dev/null +++ b/src/qtui/settingspages/coreconnectionsettingspage.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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) any later version. * + * * + * 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 "clientsettings.h" +#include "settingspage.h" + +#include "ui_coreconnectionsettingspage.h" + +class CoreConnectionSettingsPage : public SettingsPage { + Q_OBJECT + +public: + CoreConnectionSettingsPage(QWidget *parent = 0); + + inline bool hasDefaults() const { return true; } + +public slots: + void save(); + void load(); + void defaults(); + +signals: + +private slots: + void widgetHasChanged(); + +private: + Ui::CoreConnectionSettingsPage ui; + CoreConnectionSettings::NetworkDetectionMode _detectionMode; + + void setRadioButtons(CoreConnectionSettings::NetworkDetectionMode mode); + CoreConnectionSettings::NetworkDetectionMode modeFromRadioButtons() const; + + inline QString settingsKey() const { return QString("CoreConnection"); } +}; + +#endif diff --git a/src/qtui/settingspages/coreconnectionsettingspage.ui b/src/qtui/settingspages/coreconnectionsettingspage.ui new file mode 100644 index 00000000..84df5fd9 --- /dev/null +++ b/src/qtui/settingspages/coreconnectionsettingspage.ui @@ -0,0 +1,260 @@ + + + CoreConnectionSettingsPage + + + + 0 + 0 + 446 + 465 + + + + Form + + + + + + Network Status Detection + + + + + + Rely on KDE's hardware layer to detect if we're online. Recommended for most KDE users + + + Use KDE's network status detection (via Solid) + + + false + + + + + + + + + Actively ping the remote core and disconnect if we didn't get a reply after a certain time + + + Ping timeout after + + + true + + + false + + + + + + + Actively ping the remote core and disconnect if we didn't get a reply after a certain time + + + seconds + + + 30 + + + 3600 + + + 30 + + + 60 + + + PingTimeoutInterval + + + 60 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Only disconnect if the network socket gets closed by the operating system. This may take a long time after actually losing connectivity + + + Never time out actively + + + + + + + + + + Automatically reconnect on network failures + + + true + + + AutoReconnect + + + true + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Retry every + + + + + + + Actively ping the remote core and disconnect if we didn't get a reply after a certain time + + + seconds + + + 30 + + + 3600 + + + 30 + + + 60 + + + ReconnectInterval + + + 60 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + usePingTimeout + toggled(bool) + pingTimeout + setEnabled(bool) + + + 134 + 79 + + + 208 + 81 + + + + + autoReconnect + toggled(bool) + reconnectLabel + setEnabled(bool) + + + 75 + 141 + + + 72 + 178 + + + + + autoReconnect + toggled(bool) + reconnectInterval + setEnabled(bool) + + + 136 + 142 + + + 134 + 178 + + + + + diff --git a/src/qtui/settingspages/settingspages.inc b/src/qtui/settingspages/settingspages.inc index 48966bf2..1efe3e29 100644 --- a/src/qtui/settingspages/settingspages.inc +++ b/src/qtui/settingspages/settingspages.inc @@ -1,7 +1,7 @@ # Putting $FOO in SETTINGSPAGES automatically includes # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui -set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection chatmonitor coreaccount +set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection coreconnection chatmonitor coreaccount highlight identities ignorelist inputwidget itemview networks topicwidget) # Specify additional files (e.g. for subdialogs) here!