diff options
-rw-r--r-- | src/webpage.cpp | 119 | ||||
-rw-r--r-- | src/webpage.h | 3 |
2 files changed, 63 insertions, 59 deletions
diff --git a/src/webpage.cpp b/src/webpage.cpp index 160294e2..6dd3286c 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -121,49 +121,72 @@ WebPage *WebPage::newWindow(WebWindowType type) // FIXME: dear slot, you need to handle unsupported content a bit better.. void WebPage::slotHandleUnsupportedContent(QNetworkReply *reply) { - - const KUrl url(reply->request().url()); - kDebug() << "title:" << url; - kDebug() << "error:" << reply->errorString(); - - QString filename = url.fileName(); - QString mimetype = reply->header(QNetworkRequest::ContentTypeHeader).toString(); - KService::Ptr offer = KMimeTypeTrader::self()->preferredService(mimetype); - - KParts::BrowserRun::AskSaveResult res = KParts::BrowserRun::askSave( - url, - offer, - mimetype, - filename - ); - switch (res) + if (reply->error() == QNetworkReply::NoError) { - case KParts::BrowserRun::Save: - slotDownloadRequested(reply->request()); - return; - case KParts::BrowserRun::Cancel: - return; - default: // non extant case - break; - } + const KUrl url(reply->request().url()); + QString filename = url.fileName(); + QString mimetype = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + KService::Ptr offer = KMimeTypeTrader::self()->preferredService(mimetype); + + KParts::BrowserRun::AskSaveResult res = KParts::BrowserRun::askSave( + url, + offer, + mimetype, + filename + ); + switch (res) + { + case KParts::BrowserRun::Save: + slotDownloadRequested(reply->request()); + return; + case KParts::BrowserRun::Cancel: + return; + default: // non extant case + break; + } - KUrl::List list; - list.append(url); - KRun::run(*offer,url,0); + KUrl::List list; + list.append(url); + KRun::run(*offer,url,0); + } return; } void WebPage::manageNetworkErrors(QNetworkReply* reply) { - if(reply->error() == QNetworkReply::NoError) - return; - - viewErrorPage(reply); + switch (reply->error()) + { + case QNetworkReply::NoError: + return; + case QNetworkReply::ContentNotFoundError: + { + QList<QWebFrame*> frames; + frames.append(mainFrame()); + while (!frames.isEmpty()) + { + QWebFrame *firstFrame = frames.takeFirst(); + + if (firstFrame->url() == reply->url()) + { + firstFrame->setHtml(errorPage(reply), reply->url()); + return; + } + QList<QWebFrame *> children = firstFrame->childFrames(); + foreach(QWebFrame *frame, children) + { + frames.append(frame); + } + } + } + break; + default: + mainFrame()->setHtml(errorPage(reply), reply->url()); + break; + } } - -void WebPage::viewErrorPage(QNetworkReply *reply) +QString WebPage::errorPage(QNetworkReply *reply) { // display "not found" page QString notfoundFilePath = KStandardDirs::locate("data", "rekonq/htmls/notfound.html"); @@ -172,38 +195,20 @@ void WebPage::viewErrorPage(QNetworkReply *reply) if (!isOpened) { kWarning() << "Couldn't open the notfound.html file"; - return; + return QString(""); } QString title = i18n("Error loading page: ") + reply->url().toString(); QString imagePath = KIconLoader::global()->iconPath("rekonq", KIconLoader::NoGroup, false); QString html = QString(QLatin1String(file.readAll())) - .arg(title) - .arg("file://" + imagePath) - .arg(reply->errorString()) - .arg(reply->url().toString()); - - // test - QList<QWebFrame*> frames; - frames.append(mainFrame()); - while (!frames.isEmpty()) - { - QWebFrame *firstFrame = frames.takeFirst(); - if (firstFrame->url() == reply->url()) - { - firstFrame->setHtml(html, reply->url()); - return; - } - QList<QWebFrame *> children = firstFrame->childFrames(); - foreach(QWebFrame *frame, children) - { - frames.append(frame); - } - } + .arg(title) + .arg("file://" + imagePath) + .arg(reply->errorString()) + .arg(reply->url().toString()); + return html; } - void WebPage::javaScriptAlert(QWebFrame *frame, const QString &msg) { KMessageBox::error(frame->page()->view(), msg, i18n("JavaScript")); diff --git a/src/webpage.h b/src/webpage.h index d21fc44d..5adad291 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -84,8 +84,7 @@ protected Q_SLOTS: private: friend class WebView; - - void viewErrorPage(QNetworkReply *); + QString errorPage(QNetworkReply *); // keyboard/mouse modifiers Qt::KeyboardModifiers m_keyboardModifiers; |