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) {
m_queuedCommand = command;
m_manager->logger() << "Received" << command->toString();
startCommand();
startCommand(command);
}
void Connection::startCommand() {
void Connection::startCommand(Command *command) {
if (m_pageSuccess) {
m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this);
m_runningCommand = new TimeoutCommand(m_runningCommand, m_manager, this);
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
m_runningCommand->start();
command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
command->start();
} else {
writePageLoadFailure();
}
@ -50,7 +48,7 @@ void Connection::writePageLoadFailure() {
void Connection::finishCommand(Response *response) {
m_pageSuccess = true;
m_runningCommand->deleteLater();
sender()->deleteLater();
writeResponse(response);
}

View File

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

View File

@ -39,6 +39,9 @@ void TimeoutCommand::pendingLoadFinished(bool success) {
if (success) {
startCommand();
} 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()));
}
}
@ -48,12 +51,18 @@ void TimeoutCommand::pageLoadingFromCommand() {
}
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_command->deleteLater();
emit finished(new Response(false, QString("timeout")));
}
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();
emit finished(response);
}