Revamped a lot of the settings stuff. This should fix the Q_ASSERT that would appear
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 5 Jan 2008 23:47:38 +0000 (23:47 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 5 Jan 2008 23:47:38 +0000 (23:47 +0000)
when the quasselcore was quit, due to gui types stored in the config...

I took the opportunity to change the organization name to "Quassel Project", which affects
the location of the QSettings files. Also, we now use two separate files for client and core.
Old core settings and some client settings are automatically migrated. Some UI settings are lost,
however. :(

Further reduced the usage of QSettings where it doesn't belong.

15 files changed:
Quassel.kdevelop.filelist
src/client/clientsettings.cpp
src/common/global.h
src/common/main.cpp
src/common/settings.cpp
src/common/settings.h
src/core/core.cpp
src/core/core.pri
src/core/coresession.cpp
src/core/coresettings.cpp
src/core/coresettings.h
src/core/sessionsettings.cpp [new file with mode: 0644]
src/core/sessionsettings.h [new file with mode: 0644]
src/qtui/mainwin.cpp
src/qtui/serverlist.cpp

index 4691796..08acd95 100644 (file)
@@ -89,6 +89,8 @@ src/core/ircserverhandler.cpp
 src/core/ircserverhandler.h
 src/core/server.cpp
 src/core/server.h
+src/core/sessionsettings.cpp
+src/core/sessionsettings.h
 src/core/sqlitestorage.cpp
 src/core/sqlitestorage.h
 src/core/storage.cpp
index 83dd812..0a82306 100644 (file)
 
 #include "client.h"
 #include "clientsettings.h"
+#include "global.h"
 
 #include <QStringList>
 
-ClientSettings::ClientSettings(QString g) : Settings(g) {
+ClientSettings::ClientSettings(QString g) : Settings(g, Global::clientApplicationName) {
 
 
 }
index e8db8bb..a2d8c84 100644 (file)
@@ -39,8 +39,8 @@
 namespace Global {
   // We need different config (QSettings) files for client and gui, since the core cannot work with GUI types
   // Set these here. They're used in ClientSettings and CoreSettings.
-  const QString coreApplicationName = "Quassel IRC Core";
-  const QString clientApplicationName = "Quassel IRC Client";
+  const QString coreApplicationName = "Quassel Core";
+  const QString clientApplicationName = "Quassel Client";
 
   enum RunMode { Monolithic, ClientOnly, CoreOnly };
   extern RunMode runMode;
index f715192..102c9d4 100644 (file)
@@ -85,7 +85,7 @@ int main(int argc, char **argv) {
 
   QCoreApplication::setOrganizationDomain("quassel-irc.org");
   QCoreApplication::setApplicationName("Quassel IRC");
-  QCoreApplication::setOrganizationName("Quassel IRC Development Team");  // FIXME
+  QCoreApplication::setOrganizationName("Quassel Project");
 
   // Check if a non-standard core port is requested
   QStringList args = QCoreApplication::arguments();  // TODO Build a CLI parser
index 0563ff7..5224560 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <QCoreApplication>
 #include <QSettings>
 #include <QStringList>
 #include <QDebug>
 
 #ifdef Q_WS_QWS
 #include <Qtopia>
-#include <QCoreApplication>
 #endif
 
 #include "settings.h"
 
-Settings::Settings(QString g) : group(g) {
+Settings::Settings(QString g, QString applicationName) : QSettings(QCoreApplication::organizationName(), applicationName), group(g) {
 
+/* we need to call the constructor immediately in order to set the path...
 #ifndef Q_WS_QWS
-  QSettings();
+  QSettings(QCoreApplication::organizationName(), applicationName);
 #else
   // FIXME sandboxDir() is not currently working correctly...
   //if(Qtopia::sandboxDir().isEmpty()) QSettings();
@@ -44,9 +45,10 @@ Settings::Settings(QString g) : group(g) {
     QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
     qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
   } else {
-    QSettings();
+    QSettings(QCoreApplication::organizationName(), applicationName);
   }
 #endif
+*/
 }
 
 Settings::~Settings() {
index 7142e72..0f71644 100644 (file)
@@ -36,22 +36,17 @@ class Settings : private QSettings {
     enum Mode { Default, Custom };
 
   protected:
-    Settings(QString group = "General");
+    Settings(QString group, QString applicationName);
 
     void setGroup(QString group);
 
     virtual QStringList allLocalKeys();
     virtual QStringList localChildKeys(const QString &rootkey = QString());
     virtual QStringList localChildGroups(const QString &rootkey = QString());
-    //virtual QStringList allSessionKeys() = 0;
-    virtual QStringList sessionKeys() = 0;
 
     virtual void setLocalValue(const QString &key, const QVariant &data);
     virtual QVariant localValue(const QString &key, const QVariant &def = QVariant());
 
-    virtual void setSessionValue(const QString &key, const QVariant &data) = 0;
-    virtual QVariant sessionValue(const QString &key, const QVariant &def = QVariant()) = 0;
-
     virtual void removeLocalKey(const QString &key);
 
     QString group;
index d03ca6b..e3c5555 100644 (file)
@@ -42,10 +42,55 @@ void Core::destroy() {
 }
 
 Core::Core() {
-  storage = NULL;
+  storage = 0;
 }
 
 void Core::init() {
+
+  // TODO: Remove this again at some point
+  // Check if old core settings need to be migrated in order to make the switch to the
+  // new location less painful.
+  CoreSettings cs;
+  QVariant foo = cs.databaseSettings();
+  if(!foo.isValid()) {
+    // ok, no settings stored yet. check for old ones.
+    QSettings os("Quassel IRC Development Team", "Quassel IRC");
+    QVariant bar = os.value("Core/DatabaseSettings");
+    if(bar.isValid()) {
+      // old settings available -- migrate!
+      qWarning() << "\n\nOld settings detected. Will migrate core settings to the new location...\nNOTE: GUI style settings won't be migrated!\n";
+      QSettings ncs("Quassel Project", "Quassel Core");
+      ncs.setValue("Core/CoreState", os.value("Core/CoreState"));
+      ncs.setValue("Core/DatabaseSettings", os.value("Core/DatabaseSettings"));
+      os.beginGroup("SessionData");
+      foreach(QString group, os.childGroups()) {
+        ncs.setValue(QString("SessionData/%1/Identities").arg(group), os.value(QString("%1/Identities").arg(group)));
+        ncs.setValue(QString("SessionData/%1/Networks").arg(group), os.value(QString("%1/Networks").arg(group)));
+      }
+      os.endGroup();
+
+      QSettings ngs("Quassel Project", "Quassel Client");
+      os.beginGroup("Accounts");
+      foreach(QString key, os.childKeys()) {
+        ngs.setValue(QString("Accounts/%1").arg(key), os.value(key));
+      }
+      foreach(QString group, os.childGroups()) {
+        ngs.setValue(QString("Accounts/%1/AccountData").arg(group), os.value(QString("%1/AccountData").arg(group)));
+      }
+      os.endGroup();
+      os.beginGroup("Geometry");
+      foreach(QString key, os.childKeys()) {
+        ngs.setValue(QString("UI/%1").arg(key), os.value(key));
+      }
+      os.endGroup();
+
+      ncs.sync();
+      ngs.sync();
+      qWarning() << "Migration successfully finished. You may now delete $HOME/.config/Quassel IRC Development Team/ (on Linux).\n\n";
+    }
+  }
+  // END
+
   CoreSettings s;
   configured = false;
 
index 4f020b9..6664e2d 100644 (file)
@@ -1,4 +1,6 @@
 DEPMOD = common
 QT_MOD = core network sql script
-SRCS = core.cpp coresession.cpp coresettings.cpp server.cpp sqlitestorage.cpp storage.cpp basichandler.cpp ircserverhandler.cpp userinputhandler.cpp ctcphandler.cpp 
-HDRS = core.h coresession.h coresettings.h server.h sqlitestorage.h storage.h basichandler.h ircserverhandler.h userinputhandler.h ctcphandler.h 
+SRCS = core.cpp coresession.cpp coresettings.cpp server.cpp sqlitestorage.cpp storage.cpp basichandler.cpp \
+       ircserverhandler.cpp userinputhandler.cpp ctcphandler.cpp sessionsettings.cpp 
+HDRS = core.h coresession.h coresettings.h server.h sqlitestorage.h storage.h basichandler.h \
+       ircserverhandler.h userinputhandler.h ctcphandler.h sessionsettings.h
index bb24c7a..874de76 100644 (file)
@@ -30,6 +30,7 @@
 #include "identity.h"
 
 #include "util.h"
+#include "sessionsettings.h"
 
 #include <QtScript>
 
@@ -43,14 +44,18 @@ CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent)
 
   SignalProxy *p = signalProxy();
 
+  SessionSettings s(user);
+  sessionData = s.sessionData(); qDebug() << sessionData;
+  /*
   QSettings s;  // FIXME don't use QSettings anymore
   mutex.lock();
   s.beginGroup(QString("SessionData/%1").arg(user));
-  foreach(QString key, s.allKeys()) {
+  foreach(QString key, s.allKeys()) { qDebug() << key;
     sessionData[key] = s.value(key);
   }
   s.endGroup();
   mutex.unlock(); // FIXME remove
+  */
   /* temporarily disabled
   s.beginGroup(QString("Identities/%1").arg(user));
   foreach(QString id, s.childKeys()) {
@@ -137,13 +142,11 @@ void CoreSession::restoreState(const QVariant &previousState) {
 
 
 void CoreSession::storeSessionData(const QString &key, const QVariant &data) {
-  QSettings s;
-  s.beginGroup(QString("SessionData/%1").arg(user));
+  SessionSettings s(user);
   mutex.lock();
+  s.setSessionValue(key, data);
   sessionData[key] = data;
-  s.setValue(key, data);
   mutex.unlock();
-  s.endGroup();
   emit sessionDataChanged(key, data);
   emit sessionDataChanged(key);
 }
@@ -317,6 +320,7 @@ void CoreSession::createOrUpdateIdentity(const Identity &id) {
     // update
     _identities[id.id()]->update(id);
   }
+  Q_ASSERT(false); // FIX QSettings first!
   QSettings s;  // FIXME don't use QSettings
   s.beginGroup(QString("Identities/%1").arg(user));
   s.setValue(QString::number(id.id()), QVariant::fromValue<Identity>(*_identities[id.id()]));
index 3c38b23..435f056 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <QStringList>
 
-CoreSettings::CoreSettings() : Settings("Core") {
+CoreSettings::CoreSettings(const QString group) : Settings(group, Global::coreApplicationName) {
 }
 
 CoreSettings::~CoreSettings() {
@@ -51,17 +51,3 @@ void CoreSettings::setCoreState(const QVariant &data) {
 QVariant CoreSettings::coreState(const QVariant &def) {
   return localValue("CoreState", def);
 }
-
-QStringList CoreSettings::sessionKeys() {
-  Q_ASSERT(false);
-  return QStringList();
-}
-
-void CoreSettings::setSessionValue(const QString &key, const QVariant &data) {
-  Q_ASSERT(false);
-}
-
-QVariant CoreSettings::sessionValue(const QString &key, const QVariant &def) {
-  Q_ASSERT(false);
-  return QVariant();
-}
index 7b958b9..cf2cb45 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef CORESETTINGS_H_
-#define CORESETTINGS_H_
+#ifndef _CORESETTINGS_H_
+#define _CORESETTINGS_H_
 
 #include "global.h"
 #include "settings.h"
@@ -28,7 +28,7 @@ class CoreSettings : public Settings {
 
   public:
     virtual ~CoreSettings();
-    CoreSettings();
+    CoreSettings(const QString group = "Core");
 
     void setDatabaseSettings(const QVariant &data);
     QVariant databaseSettings(const QVariant &def = QVariant());
@@ -39,12 +39,6 @@ class CoreSettings : public Settings {
     void setCoreState(const QVariant &data);
     QVariant coreState(const QVariant &def = QVariant());
 
-  private:
-    //virtual QStringList allSessionKeys() = 0;
-    virtual QStringList sessionKeys();
-
-    virtual void setSessionValue(const QString &key, const QVariant &data);
-    virtual QVariant sessionValue(const QString &key, const QVariant &def = QVariant());
 };
 
 #endif /*CORESETTINGS_H_*/
diff --git a/src/core/sessionsettings.cpp b/src/core/sessionsettings.cpp
new file mode 100644 (file)
index 0000000..3f804ab
--- /dev/null
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+ *   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>
+#include <QDebug>
+
+SessionSettings::SessionSettings(UserId uid) : CoreSettings("SessionData"), user(uid) {
+
+}
+
+QVariantMap SessionSettings::sessionData() {
+  QVariantMap res;
+  foreach(QString key, localChildKeys(QString("%1").arg(user))) {
+    res[key] = localValue(QString("%1/%2").arg(user).arg(key));
+  }
+  return res;
+}
+
+void SessionSettings::setSessionValue(const QString &key, const QVariant &data) {
+  setLocalValue(QString("%1/%2").arg(user).arg(key), data);
+}
+
+QVariant SessionSettings::sessionValue(const QString &key, const QVariant &def) {
+  return localValue(QString("%1/%2").arg(user).arg(key), def);
+}
+
diff --git a/src/core/sessionsettings.h b/src/core/sessionsettings.h
new file mode 100644 (file)
index 0000000..a5df112
--- /dev/null
@@ -0,0 +1,47 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+ *   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 "coresettings.h"
+#include "types.h"
+
+#include <QVariantMap>
+
+// this class should only be used from CoreSession!
+//! This class stores and retrieves data from permanent storage for the use in SessionData.
+/** \Note Data stored here is not propagated into the actual SessionData!
+ */
+class SessionSettings : public CoreSettings {
+
+  private:
+    explicit SessionSettings(UserId user);
+
+    QVariantMap sessionData();
+    QVariant sessionValue(const QString &key, const QVariant &def = QVariant());
+    void setSessionValue(const QString &key, const QVariant &value);
+
+    UserId user;
+
+    friend class CoreSession;
+};
+
+#endif
index fee617d..d244dc8 100644 (file)
@@ -29,8 +29,8 @@
 #include "serverlist.h"
 #include "settingsdlg.h"
 #include "signalproxy.h"
-
 #include "topicwidget.h"
+#include "uisettings.h"
 
 #include "selectionmodelsynchronizer.h"
 #include "mappedselectionmodel.h"
@@ -87,17 +87,8 @@ void MainWin::init() {
   ui.menuViews->addAction(nickDock->toggleViewAction());
 
   // restore mainwin state
-  QSettings s;
-  s.beginGroup("Geometry");
-  //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
-  //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
-  if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
-  s.endGroup();
-
-  //s.beginGroup("Buffers");
-  //QString net = s.value("CurrentNetwork", "").toString();
-  //QString buf = s.value("CurrentBuffer", "").toString();
-  //s.endGroup();
+  UiSettings s;
+  restoreState(s.value("MainWinState").toByteArray());
 
   disconnectedFromCore();  // Disable menus and stuff
   showCoreConnectionDlg(true); // autoconnect if appropriate
@@ -266,16 +257,10 @@ void MainWin::closeEvent(QCloseEvent *event)
 {
   //if (userReallyWantsToQuit()) {
     ui.bufferWidget->saveState();
-    QSettings s;
-    s.beginGroup("Geometry");
+    UiSettings s;
     s.setValue("MainWinSize", size());
     s.setValue("MainWinPos", pos());
     s.setValue("MainWinState", saveState());
-    s.endGroup();
-    s.beginGroup("Buffers");
-    //s.setValue("CurrentNetwork", currentNetwork);
-    s.setValue("CurrentBuffer", currentBuffer);
-    s.endGroup();
     delete systray;
     event->accept();
   //} else {
index 2f99f05..f13ef1b 100644 (file)
@@ -33,7 +33,7 @@ ServerListDlg::ServerListDlg(QWidget *parent) : QDialog(parent) {
 
   QSettings settings;
   settings.beginGroup("GUI");
-  ui.showOnStartup->setChecked(settings.value("ShowServerListOnStartup", true).toBool());
+  ui.showOnStartup->setChecked(settings.value("ShowServerListOnStartup", false).toBool());
 
   updateNetworkTree();
   connect(ui.networkTree, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
@@ -163,8 +163,8 @@ void ServerListDlg::editIdentities(bool end) {
 }
 
 void ServerListDlg::on_showOnStartup_stateChanged(int) {
-  QSettings s;
-  s.setValue("GUI/ShowServerListOnStartup", ui.showOnStartup->isChecked());
+  //QSettings s;
+  //s.setValue("GUI/ShowServerListOnStartup", ui.showOnStartup->isChecked());
 }
 
 void ServerListDlg::accept() {