2012-03-26 18:41:33 -04:00
|
|
|
#include "WebPageManager.h"
|
2012-03-28 23:05:24 -04:00
|
|
|
#include "WebPage.h"
|
2012-06-21 23:34:51 -04:00
|
|
|
#include "NetworkCookieJar.h"
|
2012-03-26 18:41:33 -04:00
|
|
|
|
2012-04-04 15:40:18 -04:00
|
|
|
WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
|
|
|
|
m_ignoreSslErrors = false;
|
2012-06-21 23:34:51 -04:00
|
|
|
m_cookieJar = new NetworkCookieJar(this);
|
2012-06-29 10:41:08 -04:00
|
|
|
m_success = true;
|
2012-06-29 12:14:22 -04:00
|
|
|
m_loggingEnabled = false;
|
|
|
|
m_ignoredOutput = new QString();
|
2012-04-04 18:18:17 -04:00
|
|
|
createPage(this)->setFocus();
|
2012-03-26 18:41:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPageManager::append(WebPage *value) {
|
2012-03-27 18:49:57 -04:00
|
|
|
m_pages.append(value);
|
2012-03-26 18:41:33 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 10:41:08 -04:00
|
|
|
QList<WebPage *> WebPageManager::pages() const {
|
2012-04-05 18:49:55 -04:00
|
|
|
return m_pages;
|
2012-03-26 18:41:33 -04:00
|
|
|
}
|
|
|
|
|
2012-03-28 23:05:24 -04:00
|
|
|
void WebPageManager::setCurrentPage(WebPage *page) {
|
|
|
|
m_currentPage = page;
|
|
|
|
}
|
|
|
|
|
2012-06-29 12:14:22 -04:00
|
|
|
WebPage *WebPageManager::currentPage() const {
|
2012-03-28 23:05:24 -04:00
|
|
|
return m_currentPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebPage *WebPageManager::createPage(QObject *parent) {
|
|
|
|
WebPage *page = new WebPage(this, parent);
|
2012-06-29 10:41:08 -04:00
|
|
|
connect(page, SIGNAL(loadStarted()),
|
|
|
|
this, SLOT(emitLoadStarted()));
|
|
|
|
connect(page, SIGNAL(pageFinished(bool)),
|
2012-06-29 12:14:22 -04:00
|
|
|
this, SLOT(setPageStatus(bool)));
|
2012-06-29 10:41:08 -04:00
|
|
|
connect(page, SIGNAL(requestCreated(QNetworkReply *)),
|
|
|
|
this, SLOT(requestCreated(QNetworkReply *)));
|
|
|
|
connect(page, SIGNAL(replyFinished(QNetworkReply *)),
|
|
|
|
this, SLOT(replyFinished(QNetworkReply *)));
|
2012-03-28 23:05:24 -04:00
|
|
|
append(page);
|
|
|
|
return page;
|
|
|
|
}
|
2012-04-04 15:40:18 -04:00
|
|
|
|
2012-05-14 21:59:28 -04:00
|
|
|
void WebPageManager::emitLoadStarted() {
|
2012-06-29 10:41:08 -04:00
|
|
|
if (m_started.empty()) {
|
2012-06-29 12:14:22 -04:00
|
|
|
logger() << "Load started";
|
2012-05-14 21:59:28 -04:00
|
|
|
emit loadStarted();
|
2012-06-29 10:41:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPageManager::requestCreated(QNetworkReply *reply) {
|
2012-06-29 12:14:22 -04:00
|
|
|
logger() << "Started request to" << reply->url().toString();
|
2012-06-29 10:41:08 -04:00
|
|
|
m_started += reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPageManager::replyFinished(QNetworkReply *reply) {
|
2012-06-29 12:14:22 -04:00
|
|
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
logger() << "Received" << status << "from" << reply->url().toString();
|
2012-06-29 10:41:08 -04:00
|
|
|
m_started.remove(reply);
|
2012-06-29 12:14:22 -04:00
|
|
|
logger() << m_started.size() << "requests remaining";
|
|
|
|
if (m_started.empty() && !m_success) {
|
|
|
|
emitPageFinished();
|
|
|
|
}
|
2012-06-29 10:41:08 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 12:14:22 -04:00
|
|
|
void WebPageManager::setPageStatus(bool success) {
|
|
|
|
logger() << "Page finished with" << success;
|
2012-06-29 10:41:08 -04:00
|
|
|
m_success = success && m_success;
|
|
|
|
if (m_started.empty()) {
|
2012-06-29 12:14:22 -04:00
|
|
|
emitPageFinished();
|
2012-06-29 10:41:08 -04:00
|
|
|
}
|
2012-05-14 21:59:28 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 12:14:22 -04:00
|
|
|
void WebPageManager::emitPageFinished() {
|
|
|
|
logger() << "Load finished";
|
|
|
|
emit pageFinished(m_success);
|
|
|
|
m_success = true;
|
|
|
|
}
|
|
|
|
|
2012-03-30 15:00:51 -04:00
|
|
|
void WebPageManager::setIgnoreSslErrors(bool value) {
|
|
|
|
m_ignoreSslErrors = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPageManager::ignoreSslErrors() {
|
|
|
|
return m_ignoreSslErrors;
|
|
|
|
}
|
2012-05-14 21:59:28 -04:00
|
|
|
|
|
|
|
void WebPageManager::reset() {
|
2012-06-21 23:34:51 -04:00
|
|
|
m_cookieJar->clearCookies();
|
2012-05-14 21:59:28 -04:00
|
|
|
m_pages.first()->deleteLater();
|
|
|
|
m_pages.clear();
|
|
|
|
createPage(this)->setFocus();
|
|
|
|
}
|
2012-06-21 23:34:51 -04:00
|
|
|
|
|
|
|
NetworkCookieJar *WebPageManager::cookieJar() {
|
|
|
|
return m_cookieJar;
|
|
|
|
}
|
2012-06-29 10:41:08 -04:00
|
|
|
|
|
|
|
bool WebPageManager::isLoading() const {
|
|
|
|
foreach(WebPage *page, pages()) {
|
|
|
|
if (page->isLoading()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-29 12:14:22 -04:00
|
|
|
|
|
|
|
QDebug WebPageManager::logger() const {
|
|
|
|
if (m_loggingEnabled)
|
|
|
|
return qDebug();
|
|
|
|
else
|
|
|
|
return QDebug(m_ignoredOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPageManager::enableLogging() {
|
|
|
|
m_loggingEnabled = true;
|
|
|
|
}
|