From fa037e4187b0c9ada1d9d72a772efa88c373aa2b Mon Sep 17 00:00:00 2001 From: Michael Dominic K Date: Wed, 16 Sep 2009 15:13:59 +0200 Subject: Proper implementation of ContextPropertyInfo exists stuff. --- libcontextsubscriber/src/contextpropertyinfo.cpp | 21 ++++++++------------- libcontextsubscriber/src/contextpropertyinfo.h | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/contextpropertyinfo.cpp b/libcontextsubscriber/src/contextpropertyinfo.cpp index 30cfd8b7..9a19baad 100644 --- a/libcontextsubscriber/src/contextpropertyinfo.cpp +++ b/libcontextsubscriber/src/contextpropertyinfo.cpp @@ -211,6 +211,7 @@ ContextPropertyInfo::ContextPropertyInfo(const QString &key, QObject *parent) cachedDoc = infoBackend->docForKey(keyName); cachedPlugin = infoBackend->pluginForKey(keyName); cachedConstructionString = infoBackend->constructionStringForKey(keyName); + cachedExists = infoBackend->keyExists(keyName); } } @@ -239,11 +240,7 @@ QString ContextPropertyInfo::type() const bool ContextPropertyInfo::exists() const { QMutexLocker lock(&cacheLock); - // A key is assumed to exist if it's type != "". - if (cachedType != "") - return true; - else - return false; + return cachedExists; } /// Returns the name of the plugin supplying this property @@ -312,10 +309,13 @@ void ContextPropertyInfo::onKeyDataChanged(const QString& key) QString oldPlugin = cachedPlugin; QString oldConstructionString = cachedConstructionString; + bool oldExists = cachedExists; + QString newPlugin = InfoBackend::instance()->pluginForKey(keyName); QString newConstructionString = InfoBackend::instance()->constructionStringForKey(keyName); cachedPlugin = newPlugin; cachedConstructionString = newConstructionString; + cachedExists = InfoBackend::instance()->keyExists(keyName); // Release the lock before emitting the signals; otherwise // listeners trying to access cached values would create a @@ -323,15 +323,10 @@ void ContextPropertyInfo::onKeyDataChanged(const QString& key) lock.unlock(); // Emit the needed signals - if (oldType != newType) { - - if (oldType == "") - emit existsChanged(true); - if (newType == "") - emit existsChanged(false); - + if (oldType != newType) emit typeChanged(cachedType); - } + if (oldExists != cachedExists) + emit existsChanged(cachedExists); // TBD: obsolete the providerChanged & providerDBusTypeChanged signals? if (oldPlugin != newPlugin || oldConstructionString != newConstructionString) { diff --git a/libcontextsubscriber/src/contextpropertyinfo.h b/libcontextsubscriber/src/contextpropertyinfo.h index e83aebb9..15bf6ddb 100644 --- a/libcontextsubscriber/src/contextpropertyinfo.h +++ b/libcontextsubscriber/src/contextpropertyinfo.h @@ -55,6 +55,7 @@ private: QString cachedType; ///< Cached (stored) type of the key. QString cachedPlugin; ///< Cached name of the plugin providing the key QString cachedConstructionString; ///< Cached construction string for the Provider + bool cachedExists; ///< Cached state of the key (existance). mutable QMutex cacheLock; ///< Lock for the cache. private slots: -- cgit v1.2.3