Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Simplify Visit
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Mar 16, 2012
1 parent fc5cba3 commit 5b57eee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
18 changes: 13 additions & 5 deletions src/Connection.cpp
Expand Up @@ -52,9 +52,7 @@ void Connection::startCommand() {
}
m_commandName = QString();
} else {
m_pageSuccess = true;
QString message = m_page->failureString();
writeResponse(new Response(false, message));
pageLoadFailed();
}
}

Expand All @@ -69,12 +67,21 @@ void Connection::pendingLoadFinished(bool success) {
if (m_pageLoadingFromCommand) {
m_pageLoadingFromCommand = false;
if (m_pendingResponse) {
writeResponse(m_pendingResponse);
m_pendingResponse = NULL;
if (m_pageSuccess) {
writeResponse(m_pendingResponse);
} else {
pageLoadFailed();
}
}
}
}

void Connection::pageLoadFailed() {
m_pageSuccess = true;
QString message = m_page->failureString();
writeResponse(new Response(false, message));
}

void Connection::finishCommand(Response *response) {
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
m_command->deleteLater();
Expand All @@ -96,5 +103,6 @@ void Connection::writeResponse(Response *response) {
m_socket->write(messageLength.toAscii());
m_socket->write(messageUtf8);
delete response;
m_pendingResponse = NULL;
}

1 change: 1 addition & 0 deletions src/Connection.h
Expand Up @@ -23,6 +23,7 @@ class Connection : public QObject {
private:
void startCommand();
void writeResponse(Response *response);
void pageLoadFailed();

QTcpSocket *m_socket;
QString m_commandName;
Expand Down
11 changes: 1 addition & 10 deletions src/Visit.cpp
Expand Up @@ -3,19 +3,10 @@
#include "WebPage.h"

Visit::Visit(WebPage *page, QObject *parent) : Command(page, parent) {
connect(page, SIGNAL(pageFinished(bool)), this, SLOT(loadFinished(bool)));
}

void Visit::start(QStringList &arguments) {
QUrl requestedUrl = QUrl::fromEncoded(arguments[0].toUtf8(), QUrl::StrictMode);
page()->currentFrame()->load(QUrl(requestedUrl));
}

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));
emit finished(new Response(true));
}
3 changes: 0 additions & 3 deletions src/Visit.h
Expand Up @@ -8,8 +8,5 @@ class Visit : public Command {
public:
Visit(WebPage *page, QObject *parent = 0);
virtual void start(QStringList &arguments);

private slots:
void loadFinished(bool success);
};

0 comments on commit 5b57eee

Please sign in to comment.