summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/webview.cpp60
-rw-r--r--src/webview.h4
2 files changed, 60 insertions, 4 deletions
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 <KStandardShortcut>
#include <KMenu>
#include <KActionMenu>
+#include <ktoolinvocation.h>
// Qt Includes
#include <QContextMenuEvent>
@@ -54,7 +55,10 @@
#include <QKeyEvent>
#include <QAction>
#include <QLayout>
-
+#include <QtDBus/QDBusConnectionInterface>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusReply>
+#include <QDir>
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<KAction*>(sender());
+
+ QList<QString> contentList;
+ contentList.append(a->data().toUrl().toString());
+ kget.call("importLinks", QVariant(contentList));
+}
+
+
+
+void WebView::downloadAllContentsWithKGet()
+{
+ QList<QString> 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 <KWebView>
// 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;