Make SessionSettings derive from UiSettings
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 12 May 2009 06:59:47 +0000 (08:59 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 May 2009 21:20:29 +0000 (23:20 +0200)
In order to avoid code duplication, we'll want to be able to put mainwin state
saving/restoring into methods taking an UiSettings object. Hence, we'll let SessionSettings
inherit from UiSettings rather than ClientSettings, and virtualize the accessors.

Also kill the separate sessionsettings.* files, as we want to centralize the various settings
objects into common files.

src/qtui/CMakeLists.txt
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/qtuiapplication.cpp
src/qtui/qtuiapplication.h
src/qtui/sessionsettings.cpp [deleted file]
src/qtui/sessionsettings.h [deleted file]
src/uisupport/uisettings.cpp
src/uisupport/uisettings.h

index f70e465..8ec3ad2 100644 (file)
@@ -41,7 +41,6 @@ set(SOURCES
     qtuimessageprocessor.cpp
     qtuisettings.cpp
     qtuistyle.cpp
-    sessionsettings.cpp
     settingsdlg.cpp
     settingspagedlg.cpp
     simplenetworkeditor.cpp
index 6867d06..a4be85d 100644 (file)
@@ -66,7 +66,6 @@
 #include "qtuiapplication.h"
 #include "qtuimessageprocessor.h"
 #include "qtuisettings.h"
-#include "sessionsettings.h"
 #include "settingsdlg.h"
 #include "settingspagedlg.h"
 #include "systemtray.h"
index 845d378..c6d746a 100644 (file)
@@ -34,8 +34,8 @@
 #include <QSystemTrayIcon>
 
 #include "qtui.h"
-#include "sessionsettings.h"
 #include "titlesetter.h"
+#include "uisettings.h"
 
 class ActionCollection;
 class BufferView;
index de9844f..047b1f5 100644 (file)
@@ -30,7 +30,6 @@
 #include "cliparser.h"
 #include "qtui.h"
 #include "qtuisettings.h"
-#include "sessionsettings.h"
 
 QtUiApplication::QtUiApplication(int &argc, char **argv)
 #ifdef HAVE_KDE
index 69a9086..fad3ea8 100644 (file)
@@ -30,7 +30,7 @@
 #include <QSessionManager>
 
 #include "quassel.h"
-#include "sessionsettings.h"
+#include "uisettings.h"
 
 class QtUi;
 
diff --git a/src/qtui/sessionsettings.cpp b/src/qtui/sessionsettings.cpp
deleted file mode 100644 (file)
index f74dba5..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2005-09 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 "sessionsettings.h"
-
-#include <QStringList>
-
-void SessionSettings::setValue(const QString &key, const QVariant &data) {
-  setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
-}
-
-QVariant SessionSettings::value(const QString &key, const QVariant &def) {
-  return localValue(QString("%1/%2").arg(_sessionId, key), def);
-}
-
-void SessionSettings::removeKey(const QString &key) {
-  removeLocalKey(QString("%1/%2").arg(_sessionId, key));
-}
-
-void SessionSettings::cleanup() {
-  QStringList sessions = localChildGroups();
-  QString str;
-  SessionSettings s(sessionId());
-  foreach(str, sessions) {
-    // load session and check age
-    s.setSessionId(str);
-    if(s.sessionAge() > 3) {
-      s.removeSession();
-    }
-  }
-}
-
-int SessionSettings::sessionAge() {
-  QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
-  bool b = false;
-  int i = val.toInt(&b);
-  if(b) {
-    return i;
-  } else {
-    // no int saved, delete session
-    //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
-    removeSession();
-  }
-  return 10;
-}
-
-void SessionSettings::removeSession() {
-  QStringList keys = localChildKeys(sessionId());
-  foreach(QString k, keys) {
-    removeKey(k);
-  }
-}
-
-
-SessionSettings::SessionSettings(const QString & sessionId, const QString & group)  : ClientSettings(group), _sessionId(sessionId) {
-}
-
-void SessionSettings::setSessionAge(int age) {
-  setValue(QString("_sessionAge"),age);
-}
-
-void SessionSettings::sessionAging() {
-  QStringList sessions = localChildGroups();
-  QString str;
-  SessionSettings s(sessionId());
-  foreach(str, sessions) {
-    // load session and check age
-    s.setSessionId(str);
-    s.setSessionAge(s.sessionAge()+1);
-  }
-}
-
diff --git a/src/qtui/sessionsettings.h b/src/qtui/sessionsettings.h
deleted file mode 100644 (file)
index 9e98453..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2005-09 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 _SESSIONSETTINGS_H_
-#define _SESSIONSETTINGS_H_
-
-#include <QVariant>
-
-#include "clientsettings.h"
-
-class SessionSettings : public ClientSettings {
-
-  public: 
-    SessionSettings(const QString &sessionId, const QString &group = "Session");
-   
-    void setValue(const QString &key, const QVariant &data);
-    QVariant value(const QString &key, const QVariant &def = QVariant());
-    
-    void removeKey(const QString &key);
-    void removeSession();
-    
-    void cleanup();
-    void sessionAging();
-    
-    int sessionAge();
-    void setSessionAge(int age);
-    inline const QString sessionId() { return _sessionId; };
-    inline void setSessionId(const QString &sessionId) { _sessionId = sessionId; }
-  private:
-    QString _sessionId;
-}; 
-
-#endif
index d443ffe..e3574c8 100644 (file)
@@ -52,3 +52,75 @@ QList<UiStyle::FormatType> UiStyleSettings::availableFormats() {
   }
   return formats;
 }
+
+/**************************************************************************
+ * SessionSettings
+ **************************************************************************/
+
+SessionSettings::SessionSettings(const QString & sessionId, const QString & group)
+: UiSettings(group), _sessionId(sessionId)
+{
+
+}
+
+void SessionSettings::setValue(const QString &key, const QVariant &data) {
+  setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
+}
+
+QVariant SessionSettings::value(const QString &key, const QVariant &def) {
+  return localValue(QString("%1/%2").arg(_sessionId, key), def);
+}
+
+void SessionSettings::removeKey(const QString &key) {
+  removeLocalKey(QString("%1/%2").arg(_sessionId, key));
+}
+
+void SessionSettings::cleanup() {
+  QStringList sessions = localChildGroups();
+  QString str;
+  SessionSettings s(sessionId());
+  foreach(str, sessions) {
+    // load session and check age
+    s.setSessionId(str);
+    if(s.sessionAge() > 3) {
+      s.removeSession();
+    }
+  }
+}
+
+int SessionSettings::sessionAge() {
+  QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
+  bool b = false;
+  int i = val.toInt(&b);
+  if(b) {
+    return i;
+  } else {
+    // no int saved, delete session
+    //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
+    removeSession();
+  }
+  return 10;
+}
+
+void SessionSettings::removeSession() {
+  QStringList keys = localChildKeys(sessionId());
+  foreach(QString k, keys) {
+    removeKey(k);
+  }
+}
+
+void SessionSettings::setSessionAge(int age) {
+  setValue(QString("_sessionAge"),age);
+}
+
+void SessionSettings::sessionAging() {
+  QStringList sessions = localChildGroups();
+  QString str;
+  SessionSettings s(sessionId());
+  foreach(str, sessions) {
+    // load session and check age
+    s.setSessionId(str);
+    s.setSessionAge(s.sessionAge()+1);
+  }
+}
+
index 704a1d5..d8560c0 100644 (file)
@@ -28,8 +28,9 @@ class UiSettings : public ClientSettings {
 public:
   UiSettings(const QString &group = "Ui");
 
-  inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
-  inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
+  virtual inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
+  virtual inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
+
   inline void remove(const QString &key) { removeLocalKey(key); }
 };
 
@@ -49,4 +50,26 @@ public:
   QList<UiStyle::FormatType> availableFormats();
 };
 
+class SessionSettings : public UiSettings {
+public:
+  SessionSettings(const QString &sessionId, const QString &group = "Session");
+
+  virtual void setValue(const QString &key, const QVariant &data);
+  virtual QVariant value(const QString &key, const QVariant &def = QVariant());
+
+  void removeKey(const QString &key);
+  void removeSession();
+
+  void cleanup();
+  void sessionAging();
+
+  int sessionAge();
+  void setSessionAge(int age);
+  inline const QString sessionId() { return _sessionId; };
+  inline void setSessionId(const QString &sessionId) { _sessionId = sessionId; }
+
+private:
+  QString _sessionId;
+};
+
 #endif