summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Hartmetz <ahartmetz@gmail.com>2010-11-29 22:05:39 +0100
committerAndreas Hartmetz <ahartmetz@gmail.com>2010-11-29 22:05:39 +0100
commit4ba011f9465ad0067c93c39c19638a80807b5183 (patch)
tree30dfafcf0c951ffc92b193d6c50692d9a4e7e2f3
parentMy kuriikwsfilterrc contains no default search engine, so (diff)
downloadrekonq-4ba011f9465ad0067c93c39c19638a80807b5183.tar.xz
Port SearchEngine from somewhat unsafe "naked" static variables to
K_GLOBAL_STATIC(), which is Perfectly Safe ;) Acked-by Jon.
-rw-r--r--src/opensearch/searchengine.cpp40
-rw-r--r--src/opensearch/searchengine.h23
2 files changed, 30 insertions, 33 deletions
diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp
index 4378a26c..92b3293e 100644
--- a/src/opensearch/searchengine.cpp
+++ b/src/opensearch/searchengine.cpp
@@ -37,12 +37,16 @@
#include <KConfigGroup>
#include <KServiceTypeTrader>
+struct SearchEnginePrivate
+{
+ SearchEnginePrivate() : isLoaded(false) {}
+ bool isLoaded;
+ QString delimiter;
+ KService::List favorites;
+ KService::Ptr defaultEngine;
+};
-bool SearchEngine::m_loaded = false;
-QString SearchEngine::m_delimiter = "";
-KService::List SearchEngine::m_favorites;
-KService::Ptr SearchEngine::m_defaultEngine;
-
+K_GLOBAL_STATIC(SearchEnginePrivate, d)
void SearchEngine::reload()
{
@@ -50,7 +54,7 @@ void SearchEngine::reload()
KConfigGroup cg = config.group("General");
//load delimiter
- m_delimiter = cg.readEntry("KeywordDelimiter", ":");
+ d->delimiter = cg.readEntry("KeywordDelimiter", ":");
//load favorite engines
QStringList favoriteEngines;
@@ -65,44 +69,44 @@ void SearchEngine::reload()
QUrl url = service->property("Query").toUrl();
kDebug() << "ENGINE URL: " << url;
Application::iconManager()->downloadIconFromUrl(url);
-
+
favorites << service;
}
}
- m_favorites = favorites;
+ d->favorites = favorites;
//load default engine
- QString d = cg.readEntry("DefaultSearchEngine");
- m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d));
-
- m_loaded = true;
+ QString dse = cg.readEntry("DefaultSearchEngine");
+ d->defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(dse));
+
+ d->isLoaded = true;
}
QString SearchEngine::delimiter()
{
- if (!m_loaded)
+ if (!d->isLoaded)
reload();
- return m_delimiter;
+ return d->delimiter;
}
KService::List SearchEngine::favorites()
{
- if (!m_loaded)
+ if (!d->isLoaded)
reload();
- return m_favorites;
+ return d->favorites;
}
KService::Ptr SearchEngine::defaultEngine()
{
- if (!m_loaded)
+ if (!d->isLoaded)
reload();
- return m_defaultEngine;
+ return d->defaultEngine;
}
diff --git a/src/opensearch/searchengine.h b/src/opensearch/searchengine.h
index d813666b..45077f03 100644
--- a/src/opensearch/searchengine.h
+++ b/src/opensearch/searchengine.h
@@ -38,22 +38,15 @@
#include <QString>
-class SearchEngine
+namespace SearchEngine
{
-public:
- static void reload();
- static QString delimiter();
- static KService::Ptr defaultEngine();
- static KService::List favorites();
- static KService::Ptr fromString(const QString &text);
- static QString buildQuery(KService::Ptr engine, const QString &text);
- static QString extractQuery(const QString &text);
-
-private:
- static bool m_loaded;
- static QString m_delimiter;
- static KService::List m_favorites;
- static KService::Ptr m_defaultEngine;
+void reload();
+QString delimiter();
+KService::Ptr defaultEngine();
+KService::List favorites();
+KService::Ptr fromString(const QString &text);
+QString buildQuery(KService::Ptr engine, const QString &text);
+QString extractQuery(const QString &text);
};
#endif