Permalink
Browse files

Move window change handling into WebPageManager

  • Loading branch information...
1 parent baf21c9 commit bfbda84141cf5318e94af10ca999526b4a1fe58f @mhoran mhoran committed Apr 4, 2012
Showing with 26 additions and 17 deletions.
  1. +0 −1 src/Command.h
  2. +1 −8 src/Connection.cpp
  3. +0 −1 src/Connection.h
  4. +1 −1 src/Server.cpp
  5. +4 −2 src/WebPage.cpp
  6. +8 −1 src/WebPageManager.cpp
  7. +11 −2 src/WebPageManager.h
  8. +1 −1 src/WindowFocus.cpp
View
@@ -16,7 +16,6 @@ class Command : public QObject {
signals:
void finished(Response *response);
- void windowChanged(WebPage *);
protected:
WebPage *page();
View
@@ -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();
}
View
@@ -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();
View
@@ -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);
}
View
@@ -10,6 +10,8 @@
#include <QUuid>
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() {
View
@@ -2,7 +2,9 @@
#include "WebPage.h"
#include <stdio.h>
-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);
+}
View
@@ -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<WebPage *> iterator();
void setCurrentPage(WebPage *);
WebPage *currentPage();
WebPage *createPage(QObject *);
+ public slots:
+ void emitPageFinished(bool);
+
+ signals:
+ void pageFinished(bool);
+
private:
QList<WebPage *> m_pages;
WebPage *m_currentPage;
+ bool m_ignoreSslErrors;
};
#endif // _WEBPAGEMANAGER_H
View
@@ -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));
}

0 comments on commit bfbda84

Please sign in to comment.