Skip to content
Browse files

Emit loadStarted and pageFinished on WebPage state change

Instead of emitting loadStarted when a reply is created and pageFinished
when all pending replies have finished, emit these signals when the
corresponding WebPage events fire.
  • Loading branch information...
1 parent 5bef336 commit b28452e8ac417993d461de78d0c78559aa2354c0 @mhoran mhoran committed Dec 5, 2012
Showing with 5 additions and 9 deletions.
  1. +2 −2 src/PageLoadingCommand.cpp
  2. +2 −6 src/WebPageManager.cpp
  3. +1 −1 src/WebPageManager.h
View
4 src/PageLoadingCommand.cpp
@@ -9,13 +9,13 @@ PageLoadingCommand::PageLoadingCommand(Command *command, WebPageManager *manager
m_pageLoadingFromCommand = false;
m_pageSuccess = true;
m_pendingResponse = NULL;
- connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
- connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
void PageLoadingCommand::start() {
m_manager->logger() << "Started" << m_command->toString();
connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
+ connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
m_command->start();
};
View
8 src/WebPageManager.cpp
@@ -45,6 +45,7 @@ void WebPageManager::emitLoadStarted() {
logger() << "Load started";
emit loadStarted();
}
+ m_started += qobject_cast<WebPage *>(sender());
}
void WebPageManager::requestCreated(QByteArray &url, QNetworkReply *reply) {
@@ -53,7 +54,6 @@ void WebPageManager::requestCreated(QByteArray &url, QNetworkReply *reply) {
replyFinished(reply);
else {
connect(reply, SIGNAL(finished()), SLOT(handleReplyFinished()));
- m_started += reply;
}
}
@@ -66,15 +66,11 @@ void WebPageManager::handleReplyFinished() {
void WebPageManager::replyFinished(QNetworkReply *reply) {
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
logger() << "Received" << status << "from" << reply->url().toString();
- m_started.remove(reply);
- logger() << m_started.size() << "requests remaining";
- if (m_started.empty() && !m_success) {
- emitPageFinished();
- }
}
void WebPageManager::setPageStatus(bool success) {
logger() << "Page finished with" << success;
+ m_started.remove(qobject_cast<WebPage *>(sender()));
m_success = success && m_success;
if (m_started.empty()) {
emitPageFinished();
View
2 src/WebPageManager.h
@@ -49,7 +49,7 @@ class WebPageManager : public QObject {
WebPage *m_currentPage;
bool m_ignoreSslErrors;
NetworkCookieJar *m_cookieJar;
- QSet<QNetworkReply*> m_started;
+ QSet<WebPage *> m_started;
bool m_success;
bool m_loggingEnabled;
QString *m_ignoredOutput;

0 comments on commit b28452e

Please sign in to comment.
Something went wrong with that request. Please try again.