2012-03-23 16:34:39 -04:00
|
|
|
#include "PageLoadingCommand.h"
|
2012-07-08 15:04:30 -04:00
|
|
|
#include "SocketCommand.h"
|
2012-03-23 16:34:39 -04:00
|
|
|
#include "WebPage.h"
|
2012-05-14 21:59:28 -04:00
|
|
|
#include "WebPageManager.h"
|
2013-02-02 17:32:54 -05:00
|
|
|
#include "ErrorMessage.h"
|
2012-03-23 16:34:39 -04:00
|
|
|
|
2012-07-08 15:05:50 -04:00
|
|
|
PageLoadingCommand::PageLoadingCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
|
2012-05-14 21:59:28 -04:00
|
|
|
m_manager = manager;
|
2012-03-23 16:34:39 -04:00
|
|
|
m_command = command;
|
|
|
|
m_pageLoadingFromCommand = false;
|
|
|
|
m_pageSuccess = true;
|
|
|
|
m_pendingResponse = NULL;
|
2012-12-12 01:47:54 -05:00
|
|
|
m_command->setParent(this);
|
2012-03-23 16:34:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageLoadingCommand::start() {
|
2012-06-29 12:14:22 -04:00
|
|
|
m_manager->logger() << "Started" << m_command->toString();
|
2012-03-23 16:34:39 -04:00
|
|
|
connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
|
2012-12-05 19:38:03 -05:00
|
|
|
connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
|
|
|
connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
2012-03-23 16:34:39 -04:00
|
|
|
m_command->start();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PageLoadingCommand::pendingLoadFinished(bool success) {
|
|
|
|
m_pageSuccess = success;
|
|
|
|
if (m_pageLoadingFromCommand) {
|
|
|
|
m_pageLoadingFromCommand = false;
|
|
|
|
if (m_pendingResponse) {
|
2012-06-29 12:14:22 -04:00
|
|
|
m_manager->logger() << "Page load from command finished";
|
2012-03-23 16:34:39 -04:00
|
|
|
if (m_pageSuccess) {
|
|
|
|
emit finished(m_pendingResponse);
|
|
|
|
} else {
|
2012-05-14 21:59:28 -04:00
|
|
|
QString message = m_manager->currentPage()->failureString();
|
2013-02-11 18:31:41 -05:00
|
|
|
finish(false, new ErrorMessage(message));
|
2012-03-23 16:34:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageLoadingCommand::pageLoadingFromCommand() {
|
2012-06-29 12:14:22 -04:00
|
|
|
m_manager->logger() << m_command->toString() << "started page load";
|
2012-03-23 16:34:39 -04:00
|
|
|
m_pageLoadingFromCommand = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageLoadingCommand::commandFinished(Response *response) {
|
2012-05-14 21:59:28 -04:00
|
|
|
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
2012-07-11 23:36:22 -04:00
|
|
|
m_manager->logger() << "Finished" << m_command->toString() << "with response" << response->toString();
|
2012-12-12 01:47:54 -05:00
|
|
|
|
2012-03-23 16:34:39 -04:00
|
|
|
if (m_pageLoadingFromCommand)
|
|
|
|
m_pendingResponse = response;
|
|
|
|
else
|
|
|
|
emit finished(response);
|
|
|
|
}
|