From 04a0850cb6f7750859a10ea3fe3c7a48e94728dc Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 11 Nov 2009 02:14:26 +0100 Subject: Moving to kdewebkit. First step --- src/webpage.cpp | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'src/webpage.cpp') diff --git a/src/webpage.cpp b/src/webpage.cpp index 56865eb7..e75e898c 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -39,8 +39,6 @@ #include "application.h" #include "mainwindow.h" #include "mainview.h" -#include "cookiejar.h" -#include "networkaccessmanager.h" #include "webview.h" #include "webpluginfactory.h" @@ -66,8 +64,8 @@ #include -WebPage::WebPage(QObject *parent) - : QWebPage(parent) +WebPage::WebPage(QObject *parent, qlonglong windowId) + : KWebPage(parent, windowId) , m_keyboardModifiers(Qt::NoModifier) , m_pressedButtons(Qt::NoButton) { @@ -75,8 +73,7 @@ WebPage::WebPage(QObject *parent) setForwardUnsupportedContent(true); - setNetworkAccessManager(Application::networkAccessManager()); - connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); + connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); connect(this, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &))); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); @@ -122,7 +119,7 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r m_requestedUrl = request.url(); - return QWebPage::acceptNavigationRequest(frame, request, type); + return KWebPage::acceptNavigationRequest(frame, request, type); } @@ -258,30 +255,3 @@ QString WebPage::errorPage(QNetworkReply *reply) ; return html; } - - -// TODO FIXME: sometimes url.fileName() fails to retrieve url file name -void WebPage::downloadRequested(const QNetworkRequest &request) -{ - const KUrl url(request.url()); - - const QString destUrl = KFileDialog::getSaveFileName(url.fileName(), QString(), view()); - if (destUrl.isEmpty()) return; - KIO::Job *job = KIO::file_copy(url, KUrl(destUrl), -1, KIO::Overwrite); - //job->setMetaData(metadata); //TODO: add metadata from request - job->addMetaData( QLatin1String("MaxCacheSize"), QLatin1String("0") ); // Don't store in http cache. - job->addMetaData( QLatin1String("cache"), QLatin1String("cache") ); // Use entry from cache if available. - job->uiDelegate()->setAutoErrorHandlingEnabled(true); -} - - -QString WebPage::userAgentForUrl(const QUrl& _url) const -{ - const KUrl url(_url); - QString userAgent = KProtocolManager::userAgentForHost((url.isLocalFile() ? "localhost" : url.host())); - - if (userAgent == KProtocolManager::defaultUserAgent()) - return QWebPage::userAgentForUrl(_url); - - return userAgent; -} -- cgit v1.2.1 From 06d7bc99ae16724d9b23bf0a589a6583dfdb0b46 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 12 Nov 2009 02:50:14 +0100 Subject: Fixes and improvements in rekonq web classes --- src/webpage.cpp | 61 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'src/webpage.cpp') diff --git a/src/webpage.cpp b/src/webpage.cpp index e75e898c..b19b1ff2 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -49,7 +49,8 @@ #include #include -#include +#include + #include #include #include @@ -73,9 +74,9 @@ WebPage::WebPage(QObject *parent, qlonglong windowId) setForwardUnsupportedContent(true); - connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); + connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); - connect(this, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &))); + connect(this, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequest(const QNetworkRequest &))); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); } @@ -126,12 +127,7 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r WebPage *WebPage::createWindow(QWebPage::WebWindowType type) { kDebug() << "WebPage createWindow slot"; - return newWindow(type); -} - -WebPage *WebPage::newWindow(WebWindowType type) -{ // added to manage web modal dialogs if (type == QWebPage::WebModalDialog) kDebug() << "Modal Dialog"; @@ -154,34 +150,32 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) if (reply->error() == QNetworkReply::NoError) { const KUrl url(reply->request().url()); - QString filename = url.fileName(); - QString mimetype = reply->header(QNetworkRequest::ContentTypeHeader).toString(); - KService::Ptr offer = KMimeTypeTrader::self()->preferredService(mimetype); + + QString mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + KService::Ptr offer = KMimeTypeTrader::self()->preferredService(mimeType); if( offer.isNull() ) // no service can handle this. We can just download it.. { - downloadRequested(reply->request()); + downloadRequest(reply->request()); + return; } - else + + KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), url, mimeType); + switch ( dlg.askEmbedOrSave() ) { - // WARNING switch to BrowserOpenOrSaveQuestion for 4.4 - switch ( KParts::BrowserRun::askSave( url, offer, mimetype, filename ) ) - { - case KParts::BrowserRun::Save: - downloadRequested(reply->request()); - return; - case KParts::BrowserRun::Cancel: - return; - default: // non extant case - break; - } - // case KParts::BrowserRun::Open - KUrl::List list; - list.append(url); - KRun::run(*offer,url,0); + case KParts::BrowserOpenOrSaveQuestion::Save: + downloadRequested(reply->request()); + return; + case KParts::BrowserOpenOrSaveQuestion::Cancel: + return; + default: // non extant case + break; } + // case KParts::BrowserRun::Embed + KUrl::List list; + list.append(url); + KRun::run(*offer,url,0); } - return; } @@ -255,3 +249,12 @@ QString WebPage::errorPage(QNetworkReply *reply) ; return html; } + + +bool WebPage::authorizedRequest(const QUrl &url) const +{ + Q_UNUSED(url) + // TODO implement ad-block here + return true; +} + -- cgit v1.2.1 From c50290e8fdbce0e7736a717cf44c8ab8b062fe77 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 12 Nov 2009 15:35:05 +0100 Subject: KIO download system ported to kdewebkit signals and functions --- src/webpage.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/webpage.cpp') diff --git a/src/webpage.cpp b/src/webpage.cpp index b19b1ff2..94ecbe09 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -76,7 +76,6 @@ WebPage::WebPage(QObject *parent, qlonglong windowId) connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); - connect(this, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequest(const QNetworkRequest &))); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); } @@ -257,4 +256,3 @@ bool WebPage::authorizedRequest(const QUrl &url) const // TODO implement ad-block here return true; } - -- cgit v1.2.1