Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (50 sloc) 1.571 kb
da93136 Sean Geoghegan Add configurable timeouts to commands.
seangeo authored
1 #include "TimeoutCommand.h"
2 #include "Command.h"
3 #include "WebPageManager.h"
4 #include "WebPage.h"
af26bab Vokhmin Alexey V #362: Include QTimer library has been updated.
avokhmin authored
5 #include <QTimer>
da93136 Sean Geoghegan Add configurable timeouts to commands.
seangeo authored
6
7 TimeoutCommand::TimeoutCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
8 m_command = command;
9 m_manager = manager;
10 m_timer = new QTimer(this);
11 m_timer->setSingleShot(true);
12 connect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
13 connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
14 }
15
16 void TimeoutCommand::start() {
17 if (m_manager->isLoading()) {
18 connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
19 startTimeout();
20 } else {
21 startCommand();
22 }
23 }
24
25 void TimeoutCommand::startCommand() {
26 connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
27 m_command->start();
28 }
29
30 void TimeoutCommand::startTimeout() {
31 int timeout = m_manager->getTimeout();
32 if (timeout > 0) {
33 m_timer->start(timeout * 1000);
34 }
35 }
36
37 void TimeoutCommand::pendingLoadFinished(bool success) {
38 if (success) {
39 startCommand();
40 } else {
41 emit finished(new Response(false, m_manager->currentPage()->failureString()));
42 }
43 }
44
45 void TimeoutCommand::pageLoadingFromCommand() {
46 startTimeout();
47 }
48
49 void TimeoutCommand::commandTimeout() {
50 m_manager->currentPage()->triggerAction(QWebPage::Stop);
51 m_command->deleteLater();
52 emit finished(new Response(false, QString("timeout")));
53 }
54
55 void TimeoutCommand::commandFinished(Response *response) {
56 m_command->deleteLater();
57 emit finished(response);
58 }
59
Something went wrong with that request. Please try again.