From bfbda84141cf5318e94af10ca999526b4a1fe58f Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Wed, 4 Apr 2012 15:40:18 -0400 Subject: [PATCH] Move window change handling into WebPageManager --- src/Command.h | 1 - src/Connection.cpp | 9 +-------- src/Connection.h | 1 - src/Server.cpp | 2 +- src/WebPage.cpp | 6 ++++-- src/WebPageManager.cpp | 9 ++++++++- src/WebPageManager.h | 13 +++++++++++-- src/WindowFocus.cpp | 2 +- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Command.h b/src/Command.h index 4e3c296..3c81295 100644 --- a/src/Command.h +++ b/src/Command.h @@ -16,7 +16,6 @@ class Command : public QObject { signals: void finished(Response *response); - void windowChanged(WebPage *); protected: WebPage *page(); diff --git a/src/Connection.cpp b/src/Connection.cpp index b3f6298..374161a 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -19,7 +19,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par m_commandWaiting = false; connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext())); connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *))); - connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); + connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); } void Connection::commandReady(Command *command) { @@ -35,7 +35,6 @@ void Connection::startCommand() { if (m_pageSuccess) { m_runningCommand = new PageLoadingCommand(m_queuedCommand, currentPage(), this); connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); - connect(m_queuedCommand, SIGNAL(windowChanged(WebPage *)), this, SLOT(changeWindow(WebPage *))); m_runningCommand->start(); } else { writePageLoadFailure(); @@ -72,12 +71,6 @@ void Connection::writeResponse(Response *response) { delete response; } -void Connection::changeWindow(WebPage *page) { - disconnect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); - m_manager->setCurrentPage(page); - connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); -} - WebPage *Connection::currentPage() { return m_manager->currentPage(); } diff --git a/src/Connection.h b/src/Connection.h index da24f03..244ddb6 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -20,7 +20,6 @@ class Connection : public QObject { void commandReady(Command *command); void finishCommand(Response *response); void pendingLoadFinished(bool success); - void changeWindow(WebPage *); private: void startCommand(); diff --git a/src/Server.cpp b/src/Server.cpp index 6f5c2ff..9dc1536 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -19,5 +19,5 @@ quint16 Server::server_port() const { void Server::handleConnection() { QTcpSocket *socket = m_tcp_server->nextPendingConnection(); - new Connection(socket, new WebPageManager(), this); + new Connection(socket, new WebPageManager(this), this); } diff --git a/src/WebPage.cpp b/src/WebPage.cpp index 1a08ad7..89768be 100644 --- a/src/WebPage.cpp +++ b/src/WebPage.cpp @@ -10,6 +10,8 @@ #include WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) { + m_manager = manager; + setForwardUnsupportedContent(true); loadJavascript(); setUserStylesheet(); @@ -24,13 +26,13 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) { this, SLOT(frameCreated(QWebFrame *))); connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*))); + connect(this, SIGNAL(pageFinished(bool)), + m_manager, SLOT(emitPageFinished(bool))); resetWindowSize(); settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); m_uuid = QUuid::createUuid().toString(); - - m_manager = manager; } void WebPage::resetWindowSize() { diff --git a/src/WebPageManager.cpp b/src/WebPageManager.cpp index 2b8725b..3391768 100644 --- a/src/WebPageManager.cpp +++ b/src/WebPageManager.cpp @@ -2,7 +2,9 @@ #include "WebPage.h" #include -WebPageManager::WebPageManager() { +WebPageManager::WebPageManager(QObject *parent) : QObject(parent) { + m_currentPage = NULL; + m_ignoreSslErrors = false; } void WebPageManager::append(WebPage *value) { @@ -26,3 +28,8 @@ WebPage *WebPageManager::createPage(QObject *parent) { append(page); return page; } + +void WebPageManager::emitPageFinished(bool success) { + if (currentPage() == sender()) + emit pageFinished(success); +} diff --git a/src/WebPageManager.h b/src/WebPageManager.h index 61d8cef..d510387 100644 --- a/src/WebPageManager.h +++ b/src/WebPageManager.h @@ -5,18 +5,27 @@ class WebPage; -class WebPageManager { +class WebPageManager : public QObject { + Q_OBJECT + public: - WebPageManager(); + WebPageManager(QObject *parent = 0); void append(WebPage *value); QListIterator iterator(); void setCurrentPage(WebPage *); WebPage *currentPage(); WebPage *createPage(QObject *); + public slots: + void emitPageFinished(bool); + + signals: + void pageFinished(bool); + private: QList m_pages; WebPage *m_currentPage; + bool m_ignoreSslErrors; }; #endif // _WEBPAGEMANAGER_H diff --git a/src/WindowFocus.cpp b/src/WindowFocus.cpp index 9181341..f8dfcff 100644 --- a/src/WindowFocus.cpp +++ b/src/WindowFocus.cpp @@ -16,7 +16,7 @@ void WindowFocus::windowNotFound() { } void WindowFocus::success(WebPage *page) { - emit windowChanged(page); + ((CommandFactory *) parent())->m_manager->setCurrentPage(page); emit finished(new Response(true)); }