From 5b57eee8c589634c9f3f9d081c42ec8a9a77c0ec Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Fri, 16 Mar 2012 17:53:36 -0400 Subject: [PATCH] Simplify Visit --- src/Connection.cpp | 18 +++++++++++++----- src/Connection.h | 1 + src/Visit.cpp | 11 +---------- src/Visit.h | 3 --- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Connection.cpp b/src/Connection.cpp index c798f6d..7b00016 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -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(); } } @@ -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(); @@ -96,5 +103,6 @@ void Connection::writeResponse(Response *response) { m_socket->write(messageLength.toAscii()); m_socket->write(messageUtf8); delete response; + m_pendingResponse = NULL; } diff --git a/src/Connection.h b/src/Connection.h index e6682e0..458e868 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -23,6 +23,7 @@ class Connection : public QObject { private: void startCommand(); void writeResponse(Response *response); + void pageLoadFailed(); QTcpSocket *m_socket; QString m_commandName; diff --git a/src/Visit.cpp b/src/Visit.cpp index 2e819f3..3c88b47 100644 --- a/src/Visit.cpp +++ b/src/Visit.cpp @@ -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)); } diff --git a/src/Visit.h b/src/Visit.h index 5e6d148..c9c4e14 100644 --- a/src/Visit.h +++ b/src/Visit.h @@ -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); };