Simplify Visit
This commit is contained in:
parent
fc5cba3ee0
commit
5b57eee8c5
|
@ -52,9 +52,7 @@ void Connection::startCommand() {
|
||||||
}
|
}
|
||||||
m_commandName = QString();
|
m_commandName = QString();
|
||||||
} else {
|
} else {
|
||||||
m_pageSuccess = true;
|
pageLoadFailed();
|
||||||
QString message = m_page->failureString();
|
|
||||||
writeResponse(new Response(false, message));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +67,20 @@ void Connection::pendingLoadFinished(bool success) {
|
||||||
if (m_pageLoadingFromCommand) {
|
if (m_pageLoadingFromCommand) {
|
||||||
m_pageLoadingFromCommand = false;
|
m_pageLoadingFromCommand = false;
|
||||||
if (m_pendingResponse) {
|
if (m_pendingResponse) {
|
||||||
|
if (m_pageSuccess) {
|
||||||
writeResponse(m_pendingResponse);
|
writeResponse(m_pendingResponse);
|
||||||
m_pendingResponse = NULL;
|
} else {
|
||||||
|
pageLoadFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connection::pageLoadFailed() {
|
||||||
|
m_pageSuccess = true;
|
||||||
|
QString message = m_page->failureString();
|
||||||
|
writeResponse(new Response(false, message));
|
||||||
|
}
|
||||||
|
|
||||||
void Connection::finishCommand(Response *response) {
|
void Connection::finishCommand(Response *response) {
|
||||||
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
||||||
|
@ -96,5 +103,6 @@ void Connection::writeResponse(Response *response) {
|
||||||
m_socket->write(messageLength.toAscii());
|
m_socket->write(messageLength.toAscii());
|
||||||
m_socket->write(messageUtf8);
|
m_socket->write(messageUtf8);
|
||||||
delete response;
|
delete response;
|
||||||
|
m_pendingResponse = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Connection : public QObject {
|
||||||
private:
|
private:
|
||||||
void startCommand();
|
void startCommand();
|
||||||
void writeResponse(Response *response);
|
void writeResponse(Response *response);
|
||||||
|
void pageLoadFailed();
|
||||||
|
|
||||||
QTcpSocket *m_socket;
|
QTcpSocket *m_socket;
|
||||||
QString m_commandName;
|
QString m_commandName;
|
||||||
|
|
|
@ -3,19 +3,10 @@
|
||||||
#include "WebPage.h"
|
#include "WebPage.h"
|
||||||
|
|
||||||
Visit::Visit(WebPage *page, QObject *parent) : Command(page, parent) {
|
Visit::Visit(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||||
connect(page, SIGNAL(pageFinished(bool)), this, SLOT(loadFinished(bool)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visit::start(QStringList &arguments) {
|
void Visit::start(QStringList &arguments) {
|
||||||
QUrl requestedUrl = QUrl::fromEncoded(arguments[0].toUtf8(), QUrl::StrictMode);
|
QUrl requestedUrl = QUrl::fromEncoded(arguments[0].toUtf8(), QUrl::StrictMode);
|
||||||
page()->currentFrame()->load(QUrl(requestedUrl));
|
page()->currentFrame()->load(QUrl(requestedUrl));
|
||||||
}
|
emit finished(new Response(true));
|
||||||
|
|
||||||
void Visit::loadFinished(bool success) {
|
|
||||||
QString message;
|
|
||||||
if (!success)
|
|
||||||
message = page()->failureString();
|
|
||||||
|
|
||||||
disconnect(page(), SIGNAL(pageFinished(bool)), this, SLOT(loadFinished(bool)));
|
|
||||||
emit finished(new Response(success, message));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,5 @@ class Visit : public Command {
|
||||||
public:
|
public:
|
||||||
Visit(WebPage *page, QObject *parent = 0);
|
Visit(WebPage *page, QObject *parent = 0);
|
||||||
virtual void start(QStringList &arguments);
|
virtual void start(QStringList &arguments);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void loadFinished(bool success);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue