From cff49382daa8debd632d9f892848dbc5b5a92287 Mon Sep 17 00:00:00 2001
From: Daniel Albers <daniel@lbers.com>
Date: Tue, 14 Oct 2008 00:51:27 +0200
Subject: [PATCH] allow usage of .ini config files with compile time switch -DENABLE_INI=1

---
 CMakeLists.txt          |    6 ++++++
 src/common/settings.cpp |   12 ++++++------
 src/common/settings.h   |    8 ++++++++
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ac2d30..5f9bdfa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,8 @@ option(WANT_CORE     "Build the core (server) binary"           ON)
 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
 option(WANT_MONO     "Build the monolithic (all-in-one) binary" OFF)
 
+option(ENABLE_INI    "Use .ini files for settings. Useful on windows"	OFF)
+
 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"	ON)
 option(WITH_DBUS     "Enable D-Bus support if present on the system"	ON)
 option(WITH_WEBKIT   "Enable WebKit support if present on the system"	ON)
@@ -205,6 +207,10 @@ if(WANT_QTCLIENT OR WANT_MONO)
   endif(OXYGEN_ICONS MATCHES "External")
 endif(WANT_QTCLIENT OR WANT_MONO)
 
+if(ENABLE_INI)
+  add_definitions(-DCFG_INI)
+endif(ENABLE_INI)
+
 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
 
 set(COMMON_DEPS ${RC_WIN32})
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 83fb8fb..9f0481a 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -62,7 +62,7 @@ void Settings::notify(const QString &key, QObject *receiver, const char *slot) {
 }
 
 QStringList Settings::allLocalKeys() {
-  QSettings s(org(), appName);
+  QSettings s(cfgformat, QSettings::UserScope, org(), appName);
   s.beginGroup(group);
   QStringList res = s.allKeys();
   s.endGroup();
@@ -76,7 +76,7 @@ QStringList Settings::localChildKeys(const QString &rootkey) {
   else
     g = QString("%1/%2").arg(group, rootkey);
 
-  QSettings s(org(), appName);
+  QSettings s(cfgformat, QSettings::UserScope, org(), appName);
   s.beginGroup(g);
   QStringList res = s.childKeys();
   s.endGroup();
@@ -90,7 +90,7 @@ QStringList Settings::localChildGroups(const QString &rootkey) {
   else
     g = QString("%1/%2").arg(group, rootkey);
 
-  QSettings s(org(), appName);
+  QSettings s(cfgformat, QSettings::UserScope, org(), appName);
   s.beginGroup(g);
   QStringList res = s.childGroups();
   s.endGroup();
@@ -98,7 +98,7 @@ QStringList Settings::localChildGroups(const QString &rootkey) {
 }
 
 void Settings::setLocalValue(const QString &key, const QVariant &data) {
-  QSettings s(org(), appName);
+  QSettings s(cfgformat, QSettings::UserScope, org(), appName);
   s.beginGroup(group);
   s.setValue(key, data);
   s.endGroup();
@@ -110,7 +110,7 @@ void Settings::setLocalValue(const QString &key, const QVariant &data) {
 
 const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
   if(!isCached(group, key)) {
-    QSettings s(org(), appName);
+    QSettings s(cfgformat, QSettings::UserScope, org(), appName);
     s.beginGroup(group);
     setCacheValue(group, key, s.value(key, def));
     s.endGroup();
@@ -119,7 +119,7 @@ const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
 }
 
 void Settings::removeLocalKey(const QString &key) {
-  QSettings s(org(), appName);
+  QSettings s(cfgformat, QSettings::UserScope, org(), appName);
   s.beginGroup(group);
   s.remove(key);
   s.endGroup();
diff --git a/src/common/settings.h b/src/common/settings.h
index 08db0cd..7c15fb7 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -25,6 +25,7 @@
 #include <QHash>
 #include <QString>
 #include <QVariant>
+#include <QSettings>
 
 class SettingsChangeNotifier : public QObject {
   Q_OBJECT
@@ -61,6 +62,7 @@ protected:
   QString group;
   QString appName;
 
+
 private:
   inline QString org() {
 #ifdef Q_WS_MAC
@@ -70,6 +72,12 @@ private:
 #endif
   }
 
+#ifdef CFG_INI
+  static const QSettings::Format cfgformat = QSettings::IniFormat;
+#else
+  static const QSettings::Format cfgformat = QSettings::NativeFormat;
+#endif
+
   static QHash<QString, QHash<QString, QVariant> > settingsCache;
   static QHash<QString, QHash<QString, SettingsChangeNotifier *> > settingsChangeNotifier;
 
-- 
1.5.6.3

