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

Commit

Permalink
Move window change handling into WebPageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed May 30, 2012
1 parent baf21c9 commit bfbda84
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/Command.h
Expand Up @@ -16,7 +16,6 @@ class Command : public QObject {

signals:
void finished(Response *response);
void windowChanged(WebPage *);

protected:
WebPage *page();
Expand Down
9 changes: 1 addition & 8 deletions src/Connection.cpp
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion src/Connection.h
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Expand Up @@ -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);
}
6 changes: 4 additions & 2 deletions src/WebPage.cpp
Expand Up @@ -10,6 +10,8 @@
#include <QUuid>

WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
m_manager = manager;

setForwardUnsupportedContent(true);
loadJavascript();
setUserStylesheet();
Expand All @@ -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() {
Expand Down
9 changes: 8 additions & 1 deletion src/WebPageManager.cpp
Expand Up @@ -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) {
Expand All @@ -26,3 +28,8 @@ WebPage *WebPageManager::createPage(QObject *parent) {
append(page);
return page;
}

void WebPageManager::emitPageFinished(bool success) {
if (currentPage() == sender())
emit pageFinished(success);
}
13 changes: 11 additions & 2 deletions src/WebPageManager.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/WindowFocus.cpp
Expand Up @@ -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));
}

Expand Down

0 comments on commit bfbda84

Please sign in to comment.