Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 33 lines (28 sloc) 1.135 kb
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
1 #include "UnsupportedContentHandler.h"
2 #include "WebPage.h"
3 #include <QNetworkReply>
4
5 UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
6 m_page = page;
7 m_reply = reply;
8 connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
9 disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
10 }
11
12 void UnsupportedContentHandler::handleUnsupportedContent() {
13 QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
ff0a6e7 @halogenandtoast Reversed if clause
halogenandtoast authored
14 if(contentMimeType.isNull()) {
15 this->finish(false);
16 } else {
9257fe3 @halogenandtoast Cleanup
halogenandtoast authored
17 this->loadUnsupportedContent();
18 this->finish(true);
19 }
20 this->deleteLater();
21 }
22
23 void UnsupportedContentHandler::loadUnsupportedContent() {
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
24 QByteArray text = m_reply->readAll();
25 m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
9257fe3 @halogenandtoast Cleanup
halogenandtoast authored
26 }
27
28 void UnsupportedContentHandler::finish(bool success) {
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
29 connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
784b9b7 @halogenandtoast Setup multi-window sync.
halogenandtoast authored
30 m_page->networkAccessManagerFinishedReply(m_reply);
9257fe3 @halogenandtoast Cleanup
halogenandtoast authored
31 m_page->loadFinished(success);
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
32 }
Something went wrong with that request. Please try again.