[kad-general] [PATCH] RS_Settings-ported-to-KConfig-little-API-change

[ Thread Index | Date Index | More lists.tuxfamily.org/kad-general Archives ]


From 0caddf0342039a99ffebb0e9c87ffa83a84e9640 Mon Sep 17 00:00:00 2001
From: Riccardo Gori <goric@xxxxxxxxxxx>
Date: Sun, 6 Apr 2008 17:40:02 +0200
Subject: [PATCH] RS_Settings ported to KConfig; little API change

---
 kad/src/main.cpp                   |   10 ++--
 qcadlib/src/engine/rs_color.h      |    2 +-
 qcadlib/src/engine/rs_insert.cpp   |    2 +-
 qcadlib/src/engine/rs_settings.cpp |   72 ++++++++++-------------------------
 qcadlib/src/engine/rs_settings.h   |   47 +++++++----------------
 5 files changed, 42 insertions(+), 91 deletions(-)

diff --git a/kad/src/main.cpp b/kad/src/main.cpp
index 680c03e..6e45c5e 100644
--- a/kad/src/main.cpp
+++ b/kad/src/main.cpp
@@ -117,23 +117,23 @@ int main(int argc, char** argv)
 	KApplication::addCmdLineOptions();
     	KApplication app;
 	QDir dir(app.applicationDirPath());
-	dir.cdUp()
+	dir.cdUp();
 	KGlobal::dirs()->addPrefix(dir.absPath());
 	RS_DEBUG->setLevel(RS_Debug::D_WARNING);
 	RS_DEBUG->print("param 0: %s", argv[0]);
 
 	QFileInfo prgInfo( QFile::decodeName(argv[0]) );
 	dir.cd("share");
-    RS_SYSTEM->init("KAD", VERSION, "qcad", dir.absPath());
+	RS_SYSTEM->init("KAD", VERSION, "qcad", dir.absPath());
 	
 	RS_FILEIO->registerFilter(new RS_FilterCXF());
 	RS_FILEIO->registerFilter(new RS_FilterDXF());
 	RS_FILEIO->registerFilter(new RS_FilterDXF1());
 
 	// parse command line arguments that might not need a launched program:
-	RS_String lang;
-	RS_String langCmd;
-	RS_String unit;
+	QString lang;
+	QString langCmd;
+	QString unit;
 	
 	RS_SETTINGS->beginGroup("/Defaults");
 #ifndef QC_PREDEFINED_UNIT
diff --git a/qcadlib/src/engine/rs_color.h b/qcadlib/src/engine/rs_color.h
index 7e943ad..1f11897 100644
--- a/qcadlib/src/engine/rs_color.h
+++ b/qcadlib/src/engine/rs_color.h
@@ -28,7 +28,7 @@
 #ifndef RS_COLOR_H
 #define RS_COLOR_H
 
-#include <qcolor.h>
+#include <QColor>
 
 #include "rs_flags.h"
 
diff --git a/qcadlib/src/engine/rs_insert.cpp b/qcadlib/src/engine/rs_insert.cpp
index 5a7e0d7..c81eade 100644
--- a/qcadlib/src/engine/rs_insert.cpp
+++ b/qcadlib/src/engine/rs_insert.cpp
@@ -105,7 +105,7 @@ void RS_Insert::update() {
             for (int r=0; r<data.rows; ++r) {
                 RS_DEBUG->print("RS_Insert::update: row %d", r);
 
-                if (e->rtti()==RS2::EntityInsert && 
+                if (typeid(e) == typeid(RS_Insert) && 
                     data.updateMode!=RS2::PreviewUpdate) {
 
 					RS_DEBUG->print("RS_Insert::update: updating sub-insert");
diff --git a/qcadlib/src/engine/rs_settings.cpp b/qcadlib/src/engine/rs_settings.cpp
index 1b1825f..46c502f 100644
--- a/qcadlib/src/engine/rs_settings.cpp
+++ b/qcadlib/src/engine/rs_settings.cpp
@@ -26,85 +26,55 @@
 
 
 #include "rs_settings.h"
-#include <iostream>
 
 RS_Settings* RS_Settings::uniqueInstance = NULL;
 
 
 RS_Settings::RS_Settings() {
-    initialized = false;
-    companyKey = "";
-    appKey = "";
-    group = "";
+    group_ = "";
 }
 
 /**
- * Initialisation.
- *
- * @param companyKey String that identifies the company. Must start
- *        with a "/". E.g. "/RibbonSoft"
- * @param appKey String that identifies the application. Must start
- *        with a "/". E.g. "/QCad2"
- */
-void RS_Settings::init(const QString& companyKey,
-                       const QString& appKey) {
-
-    group = "";
-    this->appKey = appKey;
-    this->companyKey = companyKey;
-
-    //insertSearchPath(QSettings::Windows, companyKey + appKey);
-    //insertSearchPath(QSettings::Unix, "/usr/share/");
-    initialized = true;
-}
-
-
-/**
  * Destructor
  */
 RS_Settings::~RS_Settings() {}
 
 
-
 void RS_Settings::beginGroup(const QString& group) {
-    this->group = group;
+    group_ = group;
 }
 
 void RS_Settings::endGroup() {
-    this->group = "";
+    group_ = "";
 }
 
-bool RS_Settings::writeEntry(const QString& key, int value) {
+void RS_Settings::writeEntry(const QString& key, int value) {
     QString s = QString("%1").arg(value);
-    return writeEntry(key, s);
+    writeEntry(key, s);
 }
 
-bool RS_Settings::writeEntry(const QString& key, double value) {
+/*
+void RS_Settings::writeEntry(const QString& key, double value) {
     QString s = QString("%1").arg(value);
-    return writeEntry(key, s);
+    writeEntry(key, s);
 }
+*/
 
-bool RS_Settings::writeEntry(const QString& key, const QString& value) {
-    return true;
+void RS_Settings::writeEntry(const QString& key, const QString& value) {
+    KConfig config;
+    KConfigGroup group( &config, group_ );
+    group.writeEntry(key, value);
 }
 
 QString RS_Settings::readEntry(const QString& key,
-                                 const QString& def,
-                                 bool* ok) {
-
-    return def;
-
-}
-
-int RS_Settings::readNumEntry(const QString& key, int def, bool* ok) {
-    return def;
+                                 const QString& def) {
+    KConfig config;
+    KConfigGroup group( &config, group_ );
+    return group.readEntry(key, def);
 }
 
-
-QString RS_Settings::readEntryCache(const QString& key) {
-		return QString::null;
-}
-
-
-void RS_Settings::addToCache(const QString& key, const QString& value) {
+int RS_Settings::readNumEntry(const QString& key, int def) {
+    KConfig config;
+    KConfigGroup group( &config, group_ );
+    return group.readEntry( key, def );
 }
diff --git a/qcadlib/src/engine/rs_settings.h b/qcadlib/src/engine/rs_settings.h
index 4370030..aa32cba 100644
--- a/qcadlib/src/engine/rs_settings.h
+++ b/qcadlib/src/engine/rs_settings.h
@@ -28,21 +28,15 @@
 #ifndef RS_SETTINGS_H
 #define RS_SETTINGS_H
 
-#include <iostream>
-#include <qglobal.h>
-
-#if QT_VERSION>=0x030000
-#include <qsettings.h>
-#endif
+#include <KConfig>
+#include <KConfigGroup>
 
 #define RS_SETTINGS RS_Settings::instance()
 
 /**
  * This class can store and reload settings from a 
  * configuration file or the windoze registry.
- * Please note that the Qt default implementation doesn't
- * work as one would expect. That's why this class overwrites
- * most of the default behaviour.
+ * It is a singleton and it uses KConfig
  * 
  */
 class RS_Settings {
@@ -60,40 +54,27 @@ public:
         return uniqueInstance;
     }
 
-    /**
-     * Initialize the system.
-     *
-     * @param appName Application name
-     * @param appDirName Application directory name used for 
-     *     subdirectories in /usr, /etc ~/.
-     */
-    void init(const QString& companyKey, const QString& appKey);
-
     void beginGroup(const QString& group);
     void endGroup();
 
-    bool writeEntry(const QString& key, int value);
-    bool writeEntry(const QString& key, double value);
-    bool writeEntry(const QString& key, const QString& value);
+    void writeEntry(const QString& key, int value);
+    
+    //void writeEntry(const QString& key, double value);
+    //	Commented out because there was no method to read a double
+    //	in the original library.
+    
+    void writeEntry(const QString& key, const QString& value);
     QString readEntry(const QString& key,
-                        const QString& def = QString::null,
-                        bool* ok = 0);
-    int readNumEntry(const QString& key, int def=0, bool* ok=0);
-	
-    QString readEntryCache(const QString& key);
-	void addToCache(const QString& key, const QString& value);
+                        const QString& def = QString::null);
+    int readNumEntry(const QString& key, int def=0);
 
 public:
     ~RS_Settings();
 
 protected:
     static RS_Settings* uniqueInstance;
-
-    QMap<QString, QString> cache;
-    QString companyKey;
-    QString appKey;
-    QString group;
-    bool initialized;
+    
+    QString group_;
 };
 
 #endif
-- 
1.5.3.7



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/