2011-09-15 11:22:10 -04:00
|
|
|
#include "UnsupportedContentHandler.h"
|
|
|
|
#include "WebPage.h"
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
|
|
|
|
m_page = page;
|
|
|
|
m_reply = reply;
|
|
|
|
connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
|
|
|
|
disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnsupportedContentHandler::handleUnsupportedContent() {
|
|
|
|
QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
|
|
|
|
if(!contentMimeType.isNull()) {
|
2011-09-23 11:00:50 -04:00
|
|
|
this->loadUnsupportedContent();
|
|
|
|
this->finish(true);
|
|
|
|
} else {
|
|
|
|
this->finish(false);
|
|
|
|
}
|
|
|
|
this->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnsupportedContentHandler::loadUnsupportedContent() {
|
2011-09-15 11:22:10 -04:00
|
|
|
QByteArray text = m_reply->readAll();
|
|
|
|
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
|
2011-09-23 11:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnsupportedContentHandler::finish(bool success) {
|
2011-09-15 11:22:10 -04:00
|
|
|
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
2011-09-23 11:00:50 -04:00
|
|
|
m_page->loadFinished(success);
|
2011-09-15 11:22:10 -04:00
|
|
|
}
|