aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber
diff options
context:
space:
mode:
authorMichael Dominic K <mdk@codethink.co.uk>2009-09-16 15:07:24 +0200
committerMichael Dominic K <mdk@codethink.co.uk>2009-09-16 15:07:24 +0200
commitd0743f7a89525cf3f30b606e0349149124172362 (patch)
tree480562ae955b537355eb776ed727910e8b66d32f /libcontextsubscriber
parent3b6abe1576cc24652d91179161f0960ffb2c6ff3 (diff)
New backend functionality for .exsists().
+ implementation for xml/cdb.
Diffstat (limited to 'libcontextsubscriber')
-rw-r--r--libcontextsubscriber/src/infobackend.h3
-rw-r--r--libcontextsubscriber/src/infocdbbackend.cpp10
-rw-r--r--libcontextsubscriber/src/infocdbbackend.h1
-rw-r--r--libcontextsubscriber/src/infoxmlbackend.cpp14
-rw-r--r--libcontextsubscriber/src/infoxmlbackend.h1
5 files changed, 25 insertions, 4 deletions
diff --git a/libcontextsubscriber/src/infobackend.h b/libcontextsubscriber/src/infobackend.h
index 5e8d04fc..87fb865a 100644
--- a/libcontextsubscriber/src/infobackend.h
+++ b/libcontextsubscriber/src/infobackend.h
@@ -59,6 +59,9 @@ public:
/// Returns the constructor plugin parameter for the given \a key name.
virtual QString constructionStringForKey(QString key) const = 0;
+ /// Returns true if the given key exists.
+ virtual bool keyExists(QString key) const = 0;
+
signals:
/// Emitted when key list changes. ContextRegistryInfo listens on that.
void keysChanged(const QStringList& currentKeys);
diff --git a/libcontextsubscriber/src/infocdbbackend.cpp b/libcontextsubscriber/src/infocdbbackend.cpp
index b390b83f..5b8871a7 100644
--- a/libcontextsubscriber/src/infocdbbackend.cpp
+++ b/libcontextsubscriber/src/infocdbbackend.cpp
@@ -46,7 +46,7 @@ InfoCdbBackend::InfoCdbBackend(QObject *parent)
: InfoBackend(parent), reader(InfoCdbBackend::databasePath())
{
contextDebug() << F_CDB << "Initializing cdb backend with database:" << InfoCdbBackend::databasePath();
-
+
sconnect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(onDatabaseFileChanged(QString)));
sconnect(&watcher, SIGNAL(directoryChanged(QString)), this, SLOT(onDatabaseDirectoryChanged(QString)));
@@ -96,6 +96,14 @@ QString InfoCdbBackend::constructionStringForKey(QString key) const
return reader.valueForKey(key + ":KEYCONSTRUCTIONSTRING");
}
+bool InfoCdbBackend::keyExists(QString key) const
+{
+ if (reader.valuesForKey("KEYS").contains(key))
+ return true;
+ else
+ return false;
+}
+
/// Returns true if the database file is present.
bool InfoCdbBackend::databaseExists()
{
diff --git a/libcontextsubscriber/src/infocdbbackend.h b/libcontextsubscriber/src/infocdbbackend.h
index 1ea223a9..936c0028 100644
--- a/libcontextsubscriber/src/infocdbbackend.h
+++ b/libcontextsubscriber/src/infocdbbackend.h
@@ -44,6 +44,7 @@ public:
virtual QString docForKey(QString key) const;
virtual QString pluginForKey(QString key) const;
virtual QString constructionStringForKey(QString key) const;
+ virtual bool keyExists(QString key) const;
static QString databaseDirectory();
static QString databasePath();
diff --git a/libcontextsubscriber/src/infoxmlbackend.cpp b/libcontextsubscriber/src/infoxmlbackend.cpp
index 435b35bc..5fa40fc6 100644
--- a/libcontextsubscriber/src/infoxmlbackend.cpp
+++ b/libcontextsubscriber/src/infoxmlbackend.cpp
@@ -54,7 +54,7 @@ InfoXmlBackend::InfoXmlBackend(QObject *parent)
QDir dir = QDir(InfoXmlBackend::registryPath());
if (! dir.exists() || ! dir.isReadable()) {
- contextWarning() << "Registry path" << InfoXmlBackend::registryPath()
+ contextWarning() << "Registry path" << InfoXmlBackend::registryPath()
<< "is not a directory or is not readable!";
return;
}
@@ -146,6 +146,14 @@ QString InfoXmlBackend::constructionStringForKey(QString key) const
return keyDataHash.value(key).constructionString;
}
+bool InfoXmlBackend::keyExists(QString key) const
+{
+ if (keyDataHash.contains(key))
+ return true;
+ else
+ return false;
+}
+
/// Returns the full path to the registry directory. Takes the
/// \c CONTEXT_PROVIDERS env variable into account.
QString InfoXmlBackend::registryPath()
@@ -178,7 +186,7 @@ void InfoXmlBackend::onFileChanged(const QString &path)
// an unconditional reload message for us.
contextDebug() << F_XML << path << "changed.";
-
+
QStringList oldKeys = listKeys();
regenerateKeyDataList();
QStringList currentKeys = listKeys();
@@ -213,7 +221,7 @@ void InfoXmlBackend::onDirectoryChanged(const QString &path)
return;
contextDebug() << F_XML << registryPath() << "directory changed.";
-
+
QStringList oldKeys = listKeys();
regenerateKeyDataList();
QStringList currentKeys = listKeys();
diff --git a/libcontextsubscriber/src/infoxmlbackend.h b/libcontextsubscriber/src/infoxmlbackend.h
index 061e702a..dd928bc8 100644
--- a/libcontextsubscriber/src/infoxmlbackend.h
+++ b/libcontextsubscriber/src/infoxmlbackend.h
@@ -46,6 +46,7 @@ public:
virtual QString docForKey(QString key) const;
virtual QString pluginForKey(QString key) const;
virtual QString constructionStringForKey(QString key) const;
+ virtual bool keyExists(QString key) const;
static QString registryPath();
static QString coreDeclPath();