summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlionelc <lionelc@lionelc.(none)>2010-08-17 15:19:33 +0200
committerlionelc <lionelc@lionelc.(none)>2010-08-17 15:19:33 +0200
commitae36abefdc165a5a7365eb7af79f67da05f15ed5 (patch)
tree145426cef690aa8afecc181404ebe109f3636eb2 /src
parentMerge commit 'refs/merge-requests/172' of git://gitorious.org/rekonq/mainline... (diff)
downloadrekonq-ae36abefdc165a5a7365eb7af79f67da05f15ed5.tar.xz
search engine review
Diffstat (limited to 'src')
-rw-r--r--src/searchengine.cpp110
-rw-r--r--src/searchengine.h10
-rw-r--r--src/settings/settingsdialog.cpp4
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");