diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-08-18 10:53:20 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-08-18 10:53:20 +0200 |
commit | dbd2062b71fd59472d32a3497992e1feadfa7e3c (patch) | |
tree | bac6a5550028fd9fe2ae570ac4f349fb29576f75 | |
parent | Merge commit 'refs/merge-requests/2290' of git://gitorious.org/rekonq/mainlin... (diff) | |
parent | search engine review (diff) | |
download | rekonq-dbd2062b71fd59472d32a3497992e1feadfa7e3c.tar.xz |
Merge commit 'refs/merge-requests/175' of git://gitorious.org/rekonq/mainline into m175
-rw-r--r-- | src/searchengine.cpp | 110 | ||||
-rw-r--r-- | src/searchengine.h | 10 | ||||
-rw-r--r-- | src/settings/settingsdialog.cpp | 4 |
3 files changed, 52 insertions, 72 deletions
diff --git a/src/searchengine.cpp b/src/searchengine.cpp index 0a66bb64..7065d55f 100644 --- a/src/searchengine.cpp +++ b/src/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/searchengine.h b/src/searchengine.h index 2e30e056..e57b1a5c 100644 --- a/src/searchengine.h +++ b/src/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 diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp index cd64f434..eee2a4e1 100644 --- a/src/settings/settingsdialog.cpp +++ b/src/settings/settingsdialog.cpp @@ -197,9 +197,7 @@ void SettingsDialog::saveSettings() d->shortcutsEditor->save(); d->ebrowsingModule->save(); - SearchEngine::loadDefaultWS(); - SearchEngine::loadDelimiter(); - SearchEngine::loadFavorites(); + SearchEngine::reload(); updateButtons(); emit settingsChanged("ReKonfig"); |