From 9bb0eb375fbca2a6f792c13ed3dd063104d66947 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Fri, 18 Dec 2009 20:15:45 +0100 Subject: first kget integration --- src/webview.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/webview.h | 4 ++-- 2 files changed, 60 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/webview.cpp b/src/webview.cpp index 0b589ec0..f766ab58 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -45,6 +45,7 @@ #include #include #include +#include // Qt Includes #include @@ -54,7 +55,10 @@ #include #include #include - +#include +#include +#include +#include WebView::WebView(QWidget* parent) : KWebView(parent, false) @@ -98,6 +102,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addAction(a); menu.addAction(pageAction(KWebPage::DownloadLinkToDisk)); + + a = new KAction(KIcon("kget"), i18n("Download with KGet"), this); + a->setData(result.linkUrl()); + connect(a, SIGNAL(triggered(bool)), this, SLOT(downloadLinkWithKGet())); + menu.addAction(a); + menu.addAction(pageAction(KWebPage::CopyLinkToClipboard)); menu.addSeparator(); } @@ -254,11 +264,16 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addAction(frameMenu); menu.addSeparator(); - + // Page Actions menu.addAction(pageAction(KWebPage::SelectAll)); menu.addAction(mainwindow->actionByName(KStandardAction::name(KStandardAction::SaveAs))); + + a = new KAction(KIcon("kget"), i18n("Download All with KGet"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(downloadAllContentsWithKGet())); + menu.addAction(a); + menu.addAction(mainwindow->actionByName("page_source")); QAction *addBookmarkAction = Application::bookmarkProvider()->actionByName("rekonq_add_bookmark"); @@ -374,3 +389,44 @@ void WebView::keyPressEvent(QKeyEvent *event) KWebView::keyPressEvent(event); } + + +void WebView::downloadLinkWithKGet() +{ + if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) + { + KToolInvocation::kdeinitExecWait("kget"); + } + QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); + KAction *a = qobject_cast(sender()); + + QList contentList; + contentList.append(a->data().toUrl().toString()); + kget.call("importLinks", QVariant(contentList)); +} + + + +void WebView::downloadAllContentsWithKGet() +{ + QList contentList; + + QWebElementCollection images = page()->mainFrame()->documentElement().findAll("img"); + foreach(QWebElement img, images) + { + contentList.append(img.attribute("src")); + } + + QWebElementCollection links = page()->mainFrame()->documentElement().findAll("a"); + foreach(QWebElement link, links) + { + contentList.append(link.attribute("href")); + } + + if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) + { + KToolInvocation::kdeinitExecWait("kget"); + } + QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); + kget.call("importLinks", QVariant(contentList)); +} diff --git a/src/webview.h b/src/webview.h index 60c8c9fc..56b273fc 100644 --- a/src/webview.h +++ b/src/webview.h @@ -28,14 +28,12 @@ #ifndef WEBVIEW_H #define WEBVIEW_H - // KDE Includes #include // Forward Declarations class WebPage; - class WebView : public KWebView { Q_OBJECT @@ -61,6 +59,8 @@ private slots: void openLinkInNewWindow(); void openLinkInNewTab(); void viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); + void downloadLinkWithKGet(); + void downloadAllContentsWithKGet(); private: WebPage *const m_page; -- cgit v1.2.1