diff options
Diffstat (limited to 'src/search')
-rw-r--r-- | src/search/searchengine.cpp | 110 | ||||
-rw-r--r-- | src/search/searchengine.h | 10 |
2 files changed, 51 insertions, 69 deletions
diff --git a/src/search/searchengine.cpp b/src/search/searchengine.cpp index 0a66bb64..7065d55f 100644 --- a/src/search/searchengine.cpp +++ b/src/search/searchengine.cpp @@ -36,40 +36,70 @@ #include <KServiceTypeTrader> +bool SearchEngine::m_loaded = false; QString SearchEngine::m_delimiter = ""; +KService::List SearchEngine::m_favorites; +KService::Ptr SearchEngine::m_defaultEngine; -QString SearchEngine::delimiter() -{ - if (m_delimiter == "") loadDelimiter(); - return m_delimiter; -} - - -void SearchEngine::loadDelimiter() +void SearchEngine::reload() { - KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfig config("kuriikwsfilterrc"); //Shared with konqueror KConfigGroup cg = config.group("General"); + + //load delimiter m_delimiter = cg.readEntry("KeywordDelimiter", ":"); + + //load favorite engines + QStringList favoriteEngines; + favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); + KService::List favorites; + KService::Ptr service; + foreach(const QString &engine, favoriteEngines) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + if (service) + favorites << service; + } + m_favorites = favorites; + + //load default engine + QString d = cg.readEntry("DefaultSearchEngine"); + m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); + if (!m_defaultEngine) + { + d = QL1S("google"); + m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); + } + + m_loaded = true; } -KService::Ptr SearchEngine::m_defaultWS; +QString SearchEngine::delimiter() +{ + if (!m_loaded) + reload(); + + return m_delimiter; +} -KService::Ptr SearchEngine::defaultWS() +KService::List SearchEngine::favorites() { - if (!m_defaultWS) loadDefaultWS(); - return m_defaultWS; + if (!m_loaded) + reload(); + + return m_favorites; } -void SearchEngine::loadDefaultWS() +KService::Ptr SearchEngine::defaultEngine() { - KConfig config("kuriikwsfilterrc"); //Share with konqueror - KConfigGroup cg = config.group("General"); - QString d = cg.readEntry("DefaultSearchEngine", "google"); - m_defaultWS = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); + if (!m_loaded) + reload(); + + return m_defaultEngine; } @@ -106,48 +136,4 @@ QString SearchEngine::buildQuery(KService::Ptr engine, QString text) } -KService::List SearchEngine::m_favorites; - - -KService::List SearchEngine::favorites() -{ - if (m_favorites.isEmpty()) loadFavorites(); - return m_favorites; -} - -void SearchEngine::loadFavorites() -{ - KConfig config("kuriikwsfilterrc"); //Share with konqueror - KConfigGroup cg = config.group("General"); - QStringList favoriteEngines; - favoriteEngines << "google"; //defaults - favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); - - KService::List favorites; - KService::Ptr service; - foreach(const QString &engine, favoriteEngines) - { - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); - if (service) - favorites << service; - } - - m_favorites = favorites; -} - -KService::Ptr SearchEngine::defaultEngine() -{ - KConfig config("kuriikwsfilterrc"); //Share with konqueror - KConfigGroup cg = config.group("General"); - QString d = cg.readEntry("DefaultSearchEngine"); - KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); - if (!service) - { - d = QL1S("google"); - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); - } - - return service; - -} diff --git a/src/search/searchengine.h b/src/search/searchengine.h index 2e30e056..e57b1a5c 100644 --- a/src/search/searchengine.h +++ b/src/search/searchengine.h @@ -41,22 +41,18 @@ class SearchEngine { public: - + static void reload(); static QString delimiter(); static KService::Ptr defaultEngine(); static KService::List favorites(); static KService::Ptr fromString(QString text); static QString buildQuery(KService::Ptr engine, QString text); - static KService::Ptr defaultWS(); - - static void loadDelimiter(); - static void loadFavorites(); - static void loadDefaultWS(); private: + static bool m_loaded; static QString m_delimiter; static KService::List m_favorites; - static KService::Ptr m_defaultWS; + static KService::Ptr m_defaultEngine; }; #endif |