diff options
| author | megabigbug <megabigbug@arrakis.(none)> | 2009-07-27 17:23:44 +0200 | 
|---|---|---|
| committer | megabigbug <megabigbug@arrakis.(none)> | 2009-07-27 17:23:44 +0200 | 
| commit | fb3662682c75b9490c91ffa0f585807c941e0c60 (patch) | |
| tree | 1a2fcf8e221a64c645ea5c4cfd00e9f2afc6f29c /src | |
| parent | Updated TODO (diff) | |
| download | rekonq-fb3662682c75b9490c91ffa0f585807c941e0c60.tar.xz | |
copy paste from khtml_ext.cpp:
favorite search providers (webshortcuts) in context menu
instead of google and wikipedia
Diffstat (limited to 'src')
| -rw-r--r-- | src/webview.cpp | 67 | ||||
| -rw-r--r-- | src/webview.h | 2 | 
2 files changed, 44 insertions, 25 deletions
| 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 <KActionCollection>  #include <KDebug>  #include <KToolInvocation> +#include <KService> +#include <KUriFilterData>  // Qt Includes  #include <QtGui/QContextMenuEvent> @@ -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<int>(':')); +        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<int>(':')); +        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<KAction*>(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; | 
