From 33114df2208f08ac4dda744a2f01e3fd9f29829b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 26 Jul 2009 17:09:47 +0200 Subject: Wikipedia && Google contextual actions I started implementing them from Lionel's code but changed a bit to use KServices implementation and just a unique slot --- src/webview.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/webview.h | 3 ++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/webview.cpp b/src/webview.cpp index ec747b36..97c2f325 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -170,6 +170,20 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a->setShortcut(KStandardShortcut::paste().primary()); menu.addAction(a); + 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(slotGoogleSearch())); + 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(slotWikipediaSearch())); + menu.addAction(a); + // TODO Add translate, show translation } else if (result.isContentEditable()) @@ -191,7 +205,21 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a->setShortcut(KStandardShortcut::copy().primary()); menu.addAction(a); - // TODO Add search with google, wikipedia, show translation + 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); + + // TODO Add translate, show translation } else { @@ -283,3 +311,12 @@ void WebView::mousePressEvent(QMouseEvent *event) QWebView::mousePressEvent(event); }; } + + +void WebView::slotGooWikiSearch() +{ + KAction *a = qobject_cast(sender()); + QString search = a->data().toString() + selectedText(); + KUrl urlSearch = KUrl::fromEncoded(search.toUtf8()); + Application::instance()->loadUrl(urlSearch, Rekonq::NewTab); +} diff --git a/src/webview.h b/src/webview.h index 4efb2733..ea80ef1a 100644 --- a/src/webview.h +++ b/src/webview.h @@ -64,7 +64,8 @@ private slots: void setProgress(int progress); void loadFinished(); void setStatusBarText(const QString &string); - + void slotGooWikiSearch(); + private: WebPage *m_page; -- cgit v1.2.1