From 281cea13a0d063e02f35696dbc1936973f58e79c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Wed, 20 May 2009 17:15:59 +0200
Subject: [PATCH] Implemented SettingsDatabase::remove

At the same time, fixed the order in the QuickOpen plugin to make sure
the RefreshInterval setting isn't immediately removed after saving it.

Also disabled debug output for settings database.
---
 src/plugins/coreplugin/settingsdatabase.cpp | 25 +++++++++++++++++----
 src/plugins/quickopen/quickopenplugin.cpp   |  2 +-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/plugins/coreplugin/settingsdatabase.cpp b/src/plugins/coreplugin/settingsdatabase.cpp
index 881fa2f4596..b26cb188f3a 100644
--- a/src/plugins/coreplugin/settingsdatabase.cpp
+++ b/src/plugins/coreplugin/settingsdatabase.cpp
@@ -49,7 +49,7 @@
 using namespace Core;
 using namespace Core::Internal;
 
-enum { debug_settings = 1 };
+enum { debug_settings = 0 };
 
 namespace Core {
 namespace Internal {
@@ -67,7 +67,7 @@ public:
     QString effectiveKey(const QString &key) const
     {
         QString g = effectiveGroup();
-        if (!g.isEmpty())
+        if (!g.isEmpty() && !key.isEmpty())
             g += QLatin1Char('/');
         g += key;
         return g;
@@ -181,8 +181,25 @@ bool SettingsDatabase::contains(const QString &key) const
 
 void SettingsDatabase::remove(const QString &key)
 {
-    Q_UNUSED(key);
-    // TODO: Remove key and all subkeys
+    const QString effectiveKey = d->effectiveKey(key);
+
+    // Delete keys from the database
+    QSqlQuery query(d->m_db);
+    query.prepare(QLatin1String("DELETE FROM settings WHERE key = ? OR key LIKE ?"));
+    query.addBindValue(effectiveKey);
+    query.addBindValue(effectiveKey + QLatin1String("/%"));
+    query.exec();
+
+    // Remove keys from the cache
+    foreach (const QString &k, d->m_settings.keys()) {
+        // Either it's an exact match, or it matches up to a /
+        if (k.startsWith(effectiveKey)
+            && (k.length() == effectiveKey.length()
+                || k.at(effectiveKey.length()) == QLatin1Char('/')))
+        {
+            d->m_settings.remove(k);
+        }
+    }
 }
 
 void SettingsDatabase::beginGroup(const QString &prefix)
diff --git a/src/plugins/quickopen/quickopenplugin.cpp b/src/plugins/quickopen/quickopenplugin.cpp
index 9640e8f08ec..ae64e8dfe51 100644
--- a/src/plugins/quickopen/quickopenplugin.cpp
+++ b/src/plugins/quickopen/quickopenplugin.cpp
@@ -206,8 +206,8 @@ void QuickOpenPlugin::saveSettings()
     if (core && core->settingsDatabase()) {
         Core::SettingsDatabase *s = core->settingsDatabase();
         s->beginGroup("QuickOpen");
-        s->setValue("RefreshInterval", refreshInterval());
         s->remove("");
+        s->setValue("RefreshInterval", refreshInterval());
         foreach (IQuickOpenFilter *filter, m_filters) {
             if (!m_customFilters.contains(filter))
                 s->setValue(filter->name(), filter->saveState());
-- 
GitLab