Disconnect signals from TimeoutCommand after fired

This commit is contained in:
Matthew Horan 2012-10-25 23:45:39 -04:00
parent f20d32df10
commit 7289a8e77a
3 changed files with 16 additions and 11 deletions

View File

@ -22,17 +22,15 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
} }
void Connection::commandReady(Command *command) { void Connection::commandReady(Command *command) {
m_queuedCommand = command;
m_manager->logger() << "Received" << command->toString(); m_manager->logger() << "Received" << command->toString();
startCommand(); startCommand(command);
} }
void Connection::startCommand() { void Connection::startCommand(Command *command) {
if (m_pageSuccess) { if (m_pageSuccess) {
m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this); command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
m_runningCommand = new TimeoutCommand(m_runningCommand, m_manager, this); connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); command->start();
m_runningCommand->start();
} else { } else {
writePageLoadFailure(); writePageLoadFailure();
} }
@ -50,7 +48,7 @@ void Connection::writePageLoadFailure() {
void Connection::finishCommand(Response *response) { void Connection::finishCommand(Response *response) {
m_pageSuccess = true; m_pageSuccess = true;
m_runningCommand->deleteLater(); sender()->deleteLater();
writeResponse(response); writeResponse(response);
} }

View File

@ -22,16 +22,14 @@ class Connection : public QObject {
void pendingLoadFinished(bool success); void pendingLoadFinished(bool success);
private: private:
void startCommand(); void startCommand(Command *);
void writeResponse(Response *response); void writeResponse(Response *response);
void writePageLoadFailure(); void writePageLoadFailure();
QTcpSocket *m_socket; QTcpSocket *m_socket;
Command *m_queuedCommand;
WebPageManager *m_manager; WebPageManager *m_manager;
CommandParser *m_commandParser; CommandParser *m_commandParser;
CommandFactory *m_commandFactory; CommandFactory *m_commandFactory;
Command *m_runningCommand;
bool m_pageSuccess; bool m_pageSuccess;
WebPage *currentPage(); WebPage *currentPage();
}; };

View File

@ -39,6 +39,9 @@ void TimeoutCommand::pendingLoadFinished(bool success) {
if (success) { if (success) {
startCommand(); startCommand();
} else { } else {
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
emit finished(new Response(false, m_manager->currentPage()->failureString())); emit finished(new Response(false, m_manager->currentPage()->failureString()));
} }
} }
@ -48,12 +51,18 @@ void TimeoutCommand::pageLoadingFromCommand() {
} }
void TimeoutCommand::commandTimeout() { void TimeoutCommand::commandTimeout() {
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
m_manager->currentPage()->triggerAction(QWebPage::Stop); m_manager->currentPage()->triggerAction(QWebPage::Stop);
m_command->deleteLater(); m_command->deleteLater();
emit finished(new Response(false, QString("timeout"))); emit finished(new Response(false, QString("timeout")));
} }
void TimeoutCommand::commandFinished(Response *response) { void TimeoutCommand::commandFinished(Response *response) {
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
m_command->deleteLater(); m_command->deleteLater();
emit finished(response); emit finished(response);
} }