From fb3662682c75b9490c91ffa0f585807c941e0c60 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Mon, 27 Jul 2009 17:23:44 +0200 Subject: copy paste from khtml_ext.cpp: favorite search providers (webshortcuts) in context menu instead of google and wikipedia --- src/webview.cpp | 67 ++++++++++++++++++++++++++++++++++++--------------------- src/webview.h | 2 +- 2 files changed, 44 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/webview.cpp b/src/webview.cpp index e39cdacb..fec96edc 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include // Qt Includes #include @@ -172,17 +174,26 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); - a = new KAction(i18n("Google Search"), this); - a->setIcon(Application::icon(KUrl("http://www.google.com"))); - a->setData("gg:"); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); - menu.addAction(a); - - a = new KAction(i18n("Wikipedia Search"), this); - a->setIcon(Application::icon(KUrl("http://wikipedia.org"))); - a->setData("wk:"); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); - menu.addAction(a); + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QStringList favoriteEngines; + favoriteEngines << "wikipedia" << "google"; //defaults + favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); + const char keywordDelimiter = cg.readEntry("KeywordDelimiter", static_cast(':')); + KService::Ptr service; + KUriFilterData data; + foreach (QString engine, favoriteEngines) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; + data.setData(searchProviderPrefix + "some keyword"); + a = new KAction(i18n("Search with ")+service->name(), this); + a->setIcon(Application::icon(KUrl(data.uri()))); + a->setData(searchProviderPrefix); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotSearch())); + menu.addAction(a); + } + // TODO Add translate, show translation } @@ -207,18 +218,26 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); - a = new KAction(i18n("Google Search"), this); - a->setIcon(Application::icon(KUrl("http://www.google.com"))); - a->setData("gg:"); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); - menu.addAction(a); - - a = new KAction(i18n("Wikipedia Search"), this); - a->setIcon(Application::icon(KUrl("http://wikipedia.org"))); - a->setData("wk:"); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); - menu.addAction(a); - + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QStringList favoriteEngines; + favoriteEngines << "wikipedia" << "google"; //defaults + favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); + const char keywordDelimiter = cg.readEntry("KeywordDelimiter", static_cast(':')); + KService::Ptr service; + KUriFilterData data; + foreach (QString engine, favoriteEngines) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; + data.setData(searchProviderPrefix + "some keyword"); + a = new KAction(i18n("Search with ")+service->name(), this); + a->setIcon(Application::icon(KUrl(data.uri()))); + a->setData(searchProviderPrefix); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotSearch())); + menu.addAction(a); + } + // TODO Add translate, show translation } else if (!result.pixmap().isNull()) @@ -329,7 +348,7 @@ void WebView::wheelEvent(QWheelEvent *event) } -void WebView::slotGooWikiSearch() +void WebView::slotSearch() { KAction *a = qobject_cast(sender()); QString search = a->data().toString() + selectedText(); diff --git a/src/webview.h b/src/webview.h index ffdc874c..08d597db 100644 --- a/src/webview.h +++ b/src/webview.h @@ -64,7 +64,7 @@ private slots: void setProgress(int progress); void loadFinished(); void setStatusBarText(const QString &string); - void slotGooWikiSearch(); + void slotSearch(); private: WebPage *m_page; -- cgit v1.2.1