From f02d3a7ecd4e53af215bcec14ef1480cba9840ed Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 21 Feb 2010 12:24:19 +0100 Subject: handle relative urls (needs test with particular encoding) --- src/webpage.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/webpage.cpp b/src/webpage.cpp index ce2d5e40..872766ff 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -335,17 +335,21 @@ void WebPage::downloadRequest(const QNetworkRequest &request) void WebPage::downloadAllContentsWithKGet() { QList contentList; + KUrl baseUrl(m_requestedUrl); + KUrl relativeUrl; QWebElementCollection images = mainFrame()->documentElement().findAll("img"); foreach(QWebElement img, images) { - contentList.append(img.attribute("src")); + relativeUrl.setEncodedUrl(img.attribute("src").toUtf8(),KUrl::TolerantMode); + contentList.append(QString(baseUrl.resolved(relativeUrl).toEncoded())); } QWebElementCollection links = mainFrame()->documentElement().findAll("a"); foreach(QWebElement link, links) { - contentList.append(link.attribute("href")); + relativeUrl.setEncodedUrl(link.attribute("href").toUtf8(),KUrl::TolerantMode); + contentList.append(QString(baseUrl.resolved(relativeUrl).toEncoded())); } if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) -- cgit v1.2.1 From 28c51f343c210d012b2b5932d78e5f92601d7328 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 21 Feb 2010 12:49:40 +0100 Subject: add an url with japanese chars for test kget download --- src/tests/link_test.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tests/link_test.html b/src/tests/link_test.html index 7dd1470d..5ca3cd41 100644 --- a/src/tests/link_test.html +++ b/src/tests/link_test.html @@ -135,6 +135,13 @@ link + + +http://ja.wikipedia.org/wiki/特別:最近の更新 +KGet import links with particular encoding +link + + -- cgit v1.2.1 From 49a6031c6bd03fee2c4130fa05e5ae52d9f826e3 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 21 Feb 2010 13:10:36 +0100 Subject: remove duplicate links --- src/webpage.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/webpage.cpp b/src/webpage.cpp index 872766ff..252a9e93 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -334,22 +334,22 @@ void WebPage::downloadRequest(const QNetworkRequest &request) void WebPage::downloadAllContentsWithKGet() { - QList contentList; + QSet contents; KUrl baseUrl(m_requestedUrl); KUrl relativeUrl; QWebElementCollection images = mainFrame()->documentElement().findAll("img"); foreach(QWebElement img, images) { - relativeUrl.setEncodedUrl(img.attribute("src").toUtf8(),KUrl::TolerantMode); - contentList.append(QString(baseUrl.resolved(relativeUrl).toEncoded())); + relativeUrl.setEncodedUrl(img.attribute("src").toUtf8(),KUrl::TolerantMode); + contents << baseUrl.resolved(relativeUrl).toString(); } QWebElementCollection links = mainFrame()->documentElement().findAll("a"); foreach(QWebElement link, links) { relativeUrl.setEncodedUrl(link.attribute("href").toUtf8(),KUrl::TolerantMode); - contentList.append(QString(baseUrl.resolved(relativeUrl).toEncoded())); + contents << baseUrl.resolved(relativeUrl).toString(); } if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) @@ -357,5 +357,5 @@ void WebPage::downloadAllContentsWithKGet() KToolInvocation::kdeinitExecWait("kget"); } QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); - kget.call("importLinks", QVariant(contentList)); + kget.call("importLinks", QVariant(contents.toList())); } -- cgit v1.2.1