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.
This commit is contained in:
Thorbjørn Lindeijer
2009-05-20 17:15:59 +02:00
parent 93e61533aa
commit 281cea13a0
2 changed files with 22 additions and 5 deletions

View File

@@ -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)

View File

@@ -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());