summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rekonq.kcfg6
-rw-r--r--src/settings/settings_general.ui23
-rw-r--r--src/webpage.cpp75
-rw-r--r--src/webpage.h3
-rw-r--r--src/webview.cpp58
-rw-r--r--src/webview.h2
6 files changed, 113 insertions, 54 deletions
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg
index 6b926552..14b727d3 100644
--- a/src/rekonq.kcfg
+++ b/src/rekonq.kcfg
@@ -38,6 +38,12 @@
<entry name="showBookmarksPanel" type="Bool">
<default>false</default>
</entry>
+ <entry name="kgetDownload" type="Bool">
+ <default>false</default>
+ </entry>
+ <entry name="kgetList" type="Bool">
+ <default>false</default>
+ </entry>
</group>
<!-- Tabs Settings -->
diff --git a/src/settings/settings_general.ui b/src/settings/settings_general.ui
index 57d293e6..9662ec3c 100644
--- a/src/settings/settings_general.ui
+++ b/src/settings/settings_general.ui
@@ -210,6 +210,29 @@
</widget>
</item>
<item>
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="title">
+ <string>Download Manager</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <item>
+ <widget class="QCheckBox" name="kcfg_kgetDownload">
+ <property name="text">
+ <string>Download with KGet</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_kgetList">
+ <property name="text">
+ <string>List links with KGet</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/src/webpage.cpp b/src/webpage.cpp
index cdb72caa..14a96543 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -53,6 +53,8 @@
#include <kparts/browseropenorsavequestion.h>
+#include <kio/renamedialog.h>
+
#include <KDE/KMimeTypeTrader>
#include <KDE/KRun>
#include <KDE/KFileDialog>
@@ -250,3 +252,76 @@ QString WebPage::errorPage(QNetworkReply *reply)
;
return html;
}
+
+
+void WebPage::downloadRequest(const QNetworkRequest &request)
+{
+ if (ReKonfig::kgetDownload())
+ {
+ //*Copy of kwebpage code (Shouldn't be done in kwepage ?)
+
+ KUrl destUrl;
+ KUrl srcUrl (request.url());
+ int result = KIO::R_OVERWRITE;
+
+ do
+ {
+ destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view());
+
+ if (destUrl.isLocalFile())
+ {
+ QFileInfo finfo (destUrl.toLocalFile());
+ if (finfo.exists())
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ KIO::RenameDialog dlg (view(), i18n("Overwrite File?"), srcUrl, destUrl,
+ KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
+ -1, finfo.size(),
+ now.toTime_t(), finfo.created().toTime_t(),
+ now.toTime_t(), finfo.lastModified().toTime_t());
+ result = dlg.exec();
+ }
+ }
+ }
+ while (result == KIO::R_CANCEL && destUrl.isValid());
+
+ if (result == KIO::R_OVERWRITE && destUrl.isValid())
+ {
+ //*End of copy code
+
+ //KGet integration:
+ if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget"))
+ {
+ KToolInvocation::kdeinitExecWait("kget");
+ }
+ QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main");
+ kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true);
+ }
+ }
+ else KWebPage::downloadRequest(request);
+}
+
+
+void WebPage::downloadAllContentsWithKGet()
+{
+ QList<QString> contentList;
+
+ QWebElementCollection images = mainFrame()->documentElement().findAll("img");
+ foreach(QWebElement img, images)
+ {
+ contentList.append(img.attribute("src"));
+ }
+
+ QWebElementCollection links = 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/webpage.h b/src/webpage.h
index c76eaea3..9169ad60 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -56,7 +56,8 @@ public:
public slots:
void manageNetworkErrors(QNetworkReply *reply);
-
+ virtual void downloadRequest(const QNetworkRequest &request);
+ void downloadAllContentsWithKGet();
protected:
WebPage *createWindow(WebWindowType type);
diff --git a/src/webview.cpp b/src/webview.cpp
index a6ebd08d..462adc08 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -101,13 +101,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewWindow()));
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::DownloadLinkToDisk));
menu.addAction(pageAction(KWebPage::CopyLinkToClipboard));
menu.addSeparator();
}
@@ -270,9 +264,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
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);
+ if (ReKonfig::kgetList())
+ {
+ a = new KAction(KIcon("kget"), i18n("List all links"), this);
+ connect(a, SIGNAL(triggered(bool)), page(), SLOT(downloadAllContentsWithKGet()));
+ menu.addAction(a);
+ }
menu.addAction(mainwindow->actionByName("page_source"));
@@ -390,44 +387,3 @@ 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());
-
- QString url = a->data().toUrl().toString(QUrl::RemoveFragment);
- QString filename = QDir::homePath()+"/"+url.remove(0,url.lastIndexOf("/")+1);
- kDebug() << filename;
- kget.call("addTransfer", a->data().toUrl().toString(), filename, true);
-}
-
-
-
-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 56b273fc..ef520a15 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -59,8 +59,6 @@ private slots:
void openLinkInNewWindow();
void openLinkInNewTab();
void viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
- void downloadLinkWithKGet();
- void downloadAllContentsWithKGet();
private:
WebPage *const m_page;