Introduce CoreConnectionSettings and a settingspage for configuring it
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 7 Dec 2009 21:35:38 +0000 (22:35 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 7 Dec 2009 21:42:54 +0000 (22:42 +0100)
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.

src/client/clientsettings.cpp
src/client/clientsettings.h
src/common/settings.cpp
src/common/settings.h
src/qtui/mainwin.cpp
src/qtui/settingspages/coreconnectionsettingspage.cpp [new file with mode: 0644]
src/qtui/settingspages/coreconnectionsettingspage.h [new file with mode: 0644]
src/qtui/settingspages/coreconnectionsettingspage.ui [new file with mode: 0644]
src/qtui/settingspages/settingspages.inc

index 0af9c6e..0b77903 100644 (file)
@@ -175,6 +175,48 @@ void CoreAccountSettings::clearAccounts() {
     removeLocalKey(key);
 }
 
     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:
 
 /***********************************************************************************************/
 // NotificationSettings:
 
index 5d16f27..3ae5ae4 100644 (file)
@@ -107,6 +107,33 @@ public:
   bool nicksCaseSensitive();
 };
 
   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
 // ========================================
 // ========================================
 // TabCompletionSettings
 // ========================================
index 2731da2..24ddd5f 100644 (file)
@@ -60,7 +60,12 @@ QHash<QString, SettingsChangeNotifier *> Settings::settingsChangeNotifier;
 
 void Settings::notify(const QString &key, QObject *receiver, const char *slot) {
   QObject::connect(notifier(normalizedKey(group, key)), SIGNAL(valueChanged(const QVariant &)),
 
 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() {
 }
 
 uint Settings::version() {
index 6474353..e2920c2 100644 (file)
@@ -44,7 +44,12 @@ public:
   enum Mode { Default, Custom };
 
 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);
   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:
   virtual uint version();
 
 protected:
index 2e1ae40..2a5b379 100644 (file)
 #include "settingspages/chatviewsettingspage.h"
 #include "settingspages/connectionsettingspage.h"
 #include "settingspages/coreaccountsettingspage.h"
 #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"
 #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));
   // Category: Remote Cores
   if(Quassel::runMode() != Quassel::Monolithic) {
     dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
+    dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
   }
 
   dlg->show();
   }
 
   dlg->show();
diff --git a/src/qtui/settingspages/coreconnectionsettingspage.cpp b/src/qtui/settingspages/coreconnectionsettingspage.cpp
new file mode 100644 (file)
index 0000000..c3b7805
--- /dev/null
@@ -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 (file)
index 0000000..58d2966
--- /dev/null
@@ -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 (file)
index 0000000..84df5fd
--- /dev/null
@@ -0,0 +1,260 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CoreConnectionSettingsPage</class>
+ <widget class="QWidget" name="CoreConnectionSettingsPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>446</width>
+    <height>465</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Network Status Detection</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <item>
+       <widget class="QRadioButton" name="useSolid">
+        <property name="toolTip">
+         <string>Rely on KDE's hardware layer to detect if we're online. Recommended for most KDE users</string>
+        </property>
+        <property name="text">
+         <string>Use KDE's network status detection (via Solid)</string>
+        </property>
+        <property name="checked">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QRadioButton" name="usePingTimeout">
+          <property name="toolTip">
+           <string>Actively ping the remote core and disconnect if we didn't get a reply after a certain time</string>
+          </property>
+          <property name="text">
+           <string>Ping timeout after</string>
+          </property>
+          <property name="checkable">
+           <bool>true</bool>
+          </property>
+          <property name="checked">
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QSpinBox" name="pingTimeout">
+          <property name="toolTip">
+           <string>Actively ping the remote core and disconnect if we didn't get a reply after a certain time</string>
+          </property>
+          <property name="suffix">
+           <string> seconds</string>
+          </property>
+          <property name="minimum">
+           <number>30</number>
+          </property>
+          <property name="maximum">
+           <number>3600</number>
+          </property>
+          <property name="singleStep">
+           <number>30</number>
+          </property>
+          <property name="value">
+           <number>60</number>
+          </property>
+          <property name="settingsKey" stdset="0">
+           <string notr="true">PingTimeoutInterval</string>
+          </property>
+          <property name="defaultValue" stdset="0">
+           <UInt>60</UInt>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="useNoTimeout">
+        <property name="toolTip">
+         <string>Only disconnect if the network socket gets closed by the operating system. This may take a long time after actually losing connectivity</string>
+        </property>
+        <property name="text">
+         <string>Never time out actively</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QCheckBox" name="autoReconnect">
+     <property name="text">
+      <string>Automatically reconnect on network failures</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string notr="true">AutoReconnect</string>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="reconnectLabel">
+       <property name="text">
+        <string>Retry every</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="reconnectInterval">
+       <property name="toolTip">
+        <string>Actively ping the remote core and disconnect if we didn't get a reply after a certain time</string>
+       </property>
+       <property name="suffix">
+        <string> seconds</string>
+       </property>
+       <property name="minimum">
+        <number>30</number>
+       </property>
+       <property name="maximum">
+        <number>3600</number>
+       </property>
+       <property name="singleStep">
+        <number>30</number>
+       </property>
+       <property name="value">
+        <number>60</number>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string notr="true">ReconnectInterval</string>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <UInt>60</UInt>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>usePingTimeout</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>pingTimeout</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>134</x>
+     <y>79</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>208</x>
+     <y>81</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>autoReconnect</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>reconnectLabel</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>75</x>
+     <y>141</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>72</x>
+     <y>178</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>autoReconnect</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>reconnectInterval</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>136</x>
+     <y>142</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>134</x>
+     <y>178</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
index 48966bf..1efe3e2 100644 (file)
@@ -1,7 +1,7 @@
 # Putting $FOO in SETTINGSPAGES automatically includes
 # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui
 
 # 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!
                   highlight identities ignorelist inputwidget itemview networks topicwidget)
 
 # Specify additional files (e.g. for subdialogs) here!