From 0d711f2fc464eb05866cd9c329b57ec279a98971 Mon Sep 17 00:00:00 2001
From: Jonathan Bauer
Date: Fri, 4 Mar 2011 23:51:45 +0100
Subject: Code cleanup, JSO class continued, added webkitTest.html for
reference
---
src/.cproject | 243 -----------------------------------------------
src/DownloadManager.cpp | 1 -
src/JSObject.cpp | 118 +++++++++++++++++++++++
src/JSObject.h | 102 ++++++++++++++++++++
src/fbbrowser.cpp | 167 +++++---------------------------
src/fbbrowser.h | 46 ++-------
src/fbgui.cpp | 3 +-
src/fbgui.pro | 4 +-
src/html/webkitTest.html | 90 ++++++++++++++++++
src/jsObject.cpp | 18 ----
src/jsObject.h | 74 ---------------
11 files changed, 343 insertions(+), 523 deletions(-)
delete mode 100644 src/.cproject
create mode 100644 src/JSObject.cpp
create mode 100644 src/JSObject.h
create mode 100644 src/html/webkitTest.html
delete mode 100644 src/jsObject.cpp
delete mode 100644 src/jsObject.h
(limited to 'src')
diff --git a/src/.cproject b/src/.cproject
deleted file mode 100644
index c852b37..0000000
--- a/src/.cproject
+++ /dev/null
@@ -1,243 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- make
- release
- false
- false
- true
-
-
-
-
-
-
-
-
-
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp
index b61b171..3314055 100644
--- a/src/DownloadManager.cpp
+++ b/src/DownloadManager.cpp
@@ -112,7 +112,6 @@ void DownloadManager::downloadFinished()
// Constructor.
DownloadManager::DownloadManager(const QUrl& baseUrl)
{
- qDebug() << endl << "Initialising Download Manager...";
this->qnam = new QNetworkAccessManager();
this->baseUrl = baseUrl;
dip = false;
diff --git a/src/JSObject.cpp b/src/JSObject.cpp
new file mode 100644
index 0000000..110f200
--- /dev/null
+++ b/src/JSObject.cpp
@@ -0,0 +1,118 @@
+/*
+ * jsObject.cpp
+ *
+ * Created on: Feb 1, 2011
+ * Author: niklas
+ */
+
+#include "JSObject.h"
+#include
+#include
+//-------------------------------------------------------------------------------------------------------
+JSObject::JSObject(QWebFrame* qwf) {
+ target = qwf;
+}
+//-------------------------------------------------------------------------------------------------------
+JSObject::~JSObject() {}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::enableJavascriptAccess()
+{
+ // Attaches itself to the DOM
+ target->addToJavaScriptWindowObject(QString("jsObject"), this);
+
+ // connect the signals of the jsObject to the slots of the fbbrowser
+ QObject::connect(this, SIGNAL(closeBrowser()), this, SLOT(quitAll()));
+ QObject::connect(this, SIGNAL(startDownload(QString)), this, SLOT(startDownload_Slot(QString)));
+ QObject::connect(this, SIGNAL(getMacAddress()), this, SLOT(getMacAddress_Slot()));
+ QObject::connect(this, SIGNAL(showTime()), this, SLOT(showTime_Slot()));
+ QObject::connect(this, SIGNAL(showHelloWorld()), this, SLOT(showHelloWorld_Slot()));
+
+ // for testing reasons
+ QObject::connect(this, SIGNAL(showDate()), this, SLOT(showDate_Slot()));
+
+ // TODO: Implement this?
+ QObject::connect(this, SIGNAL(getIpAddress()), this, SLOT(getIpAddress_Slot()));
+ QObject::connect(this, SIGNAL(getIntegratedHardwareDevices()),
+ this, SLOT(getIntegratedHardwareDevices_Slot()));
+ QObject::connect(this, SIGNAL(getUsbDevices()), this, SLOT(getUsbDevices_Slot()));
+ QObject::connect(this, SIGNAL(getHardDrives()), this, SLOT(getHardDrives_Slot()));
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::startDownload_Slot(QString filename)
+{
+ qDebug() << "Returned from JS: " << filename;
+ emit downloadFile(filename);
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::updateProgressSlot(int i)
+{
+ QString code = QString("updateProgress(\%1)").arg(i);
+ target->evaluateJavaScript(code);
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getMacAddress_Slot()
+{
+ QNetworkInterface *qNetI = new QNetworkInterface();
+ QList list;
+ list=qNetI->allInterfaces();
+ QString str;
+ QString macAddress;
+ for (int i = 0; i < list.size(); ++i) {
+ str = list.at(i).name();
+ macAddress = list.at(i).hardwareAddress();
+ qDebug() << str;
+ qDebug() << macAddress;
+ }
+
+ //TODO:: edit jsFunction name
+ QString code;
+ code = QString("printMacAddress(\"%1\")").arg(macAddress);
+ target->evaluateJavaScript(code);
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::showTime_Slot()
+{
+ qDebug() << "---- call: showTime_Slot";
+ QString time = QTime::currentTime().toString("hh:mm:ss");
+
+ //TODO:: edit jsFunction name
+ QString code;
+ code = QString("printTime(\"%1\")").arg(time);
+ target->evaluateJavaScript(code);
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::showDate_Slot()
+{
+ QString date = QDate::currentDate().toString("dd.MM.yyyy");
+ //TODO:: edit jsFunction name
+ target->evaluateJavaScript("");
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::showHelloWorld_Slot()
+{
+ target->evaluateJavaScript("alert(\"Hello World\")");
+}
+
+//-------------------------------------------------------------------------------------------------------
+void JSObject::quitAll()
+{
+ emit signalQuitAll();
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getSysInfo(){
+
+ /*
+ QString time = QTime::currentTime().toString("hh:mm:ss");
+ QString date = QDate::currentDate().toString("dd.MM.yyyy");
+ QList ipList = QNetworkInterface::allAddresses();
+ QString macAddress = QNetworkInterface::hardwareAddress();
+ */
+}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getIpAddress_Slot(){}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getIntegratedHardwareDevices_Slot(){}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getUsbDevices_Slot(){}
+//-------------------------------------------------------------------------------------------------------
+void JSObject::getHardDrives_Slot(){}
diff --git a/src/JSObject.h b/src/JSObject.h
new file mode 100644
index 0000000..58ce633
--- /dev/null
+++ b/src/JSObject.h
@@ -0,0 +1,102 @@
+/*
+ * jsObject.h
+ *
+ * Created on: Feb 1, 2011
+ * Author: niklas
+ * The purpose of the jsObject class is to provide signals which will be emited in the javascript functions.
+ * Those javascript functions are writen in a seperate file: jsFunktions.js
+ */
+
+#ifndef JSOBJECT_H_
+#define JSOBJECT_H_
+
+#include "fbbrowser.h"
+#include
+
+typedef enum
+{
+ QUIT,
+ SHOW_USB_DEVICES,
+ SHOW_HARDDRIVES,
+ SHOW_MAC_ADDRESS,
+ SHOW_IP_ADDRESS,
+ SHOW_TIME,
+ SHOW_DATE
+} jsAction;
+
+class fbbrowser;
+class QWebFrame;
+class JSObject : public QObject
+{
+ Q_OBJECT
+private:
+ QWebFrame* target;
+ fbbrowser* browser;
+public:
+ JSObject(QWebFrame* qwf);
+ virtual ~JSObject();
+
+//private:
+// fbbrowser browser;
+
+// no slots needed. class provides only signals
+// private slots:
+// void performAction(jsAction a);
+
+// define all the needed signals.
+// every action gets its own signal. (the former enum is not needed anymore)
+// the signals will be connected in the fbbrowser class with slots of the fbbrowser class
+signals:
+ // should be the last signal to be emited.
+ // Will close the browser and continues the boot sequenze
+ void closeBrowser();
+ void signalQuitAll();
+ // will start the download of all needed files for the following boot sequence
+ void startDownload(QString filename);
+ void downloadFile(QString filename);
+ // starts the slot which is responsible for extracting the MAC address of the machine
+ // the MAC Address will be the parameter of a javascript function which will present it on the webpage
+ void getMacAddress();
+ // starts the slot which is responsible for extracting the IP address of the machine
+ // the IP address will be the parameter of a javascript function which will present it on the webpage
+ void getIpAddress();
+ // starts the slot which is responsible for extracting the integrated hardware devices of the machine
+ // the array of integrated hardware devices will be the parameter of a javascript function which will present // it on the webpage
+ void getIntegratedHardwareDevices();
+ // starts the slot which is responsible for extracting the usb devices of the machine
+ // the array of usb devices will be the parameter of a javascript function which will present it on the webpag
+ void getUsbDevices();
+ // starts the slot which is responsible for extracting the hard drive devices of the machine
+ // the array of hard rive devices will be the parameter of a javascript function which will present it on the // webpag
+ void getHardDrives();
+
+ // for testing
+ void showTime();
+ void showDate();
+ void showHelloWorld();
+
+public slots:
+
+ void enableJavascriptAccess();
+ // slots which are emited by the jsObject signals
+
+ void quitAll();
+ void startDownload_Slot(QString filename);
+ void updateProgressSlot(int i);
+
+ // System info stuff
+ void getSysInfo();
+ void getMacAddress_Slot();
+ void getIpAddress_Slot();
+ void getIntegratedHardwareDevices_Slot();
+ void getUsbDevices_Slot();
+ void getHardDrives_Slot();
+
+ // for testing reasons
+ void showTime_Slot();
+ void showDate_Slot();
+ void showHelloWorld_Slot();
+
+};
+
+#endif /* JSOBJECT_H_ */
diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp
index 4deca61..535907e 100644
--- a/src/fbbrowser.cpp
+++ b/src/fbbrowser.cpp
@@ -1,11 +1,17 @@
#include "fbbrowser.h"
+#include "JSObject.h"
#include "DownloadManager.h"
#include
#include
#include
-#include "jsObject.h"
+// -------------------------------------------------------------------------------------------
+void fbbrowser::quit()
+{
+ emit killApp();
+}
+// -------------------------------------------------------------------------------------------
fbbrowser::fbbrowser(const QUrl & url)
{
view = new QWebView(this);
@@ -14,10 +20,8 @@ fbbrowser::fbbrowser(const QUrl & url)
manager = new QNetworkAccessManager(this);
// Create a QNetworkRequest object and set its URL.
request.setUrl(url);
-
// Let the manager send the request and receive the reply.
- reply = manager->get(request);
-
+ reply = manager->get(request);
// TODO: error differentiation
// reply->error() returns 0 even for invalid URL.
// A possibility to check for validity, is to listen to readyRead()
@@ -34,156 +38,29 @@ fbbrowser::fbbrowser(const QUrl & url)
view->load(QUrl("qrc:/html/errorPage.html"));
}
+ // Enable Javascript through JSObject.
+ qwf = view->page()->mainFrame();
+ jso = new JSObject(qwf);
+ QObject::connect(qwf, SIGNAL(javaScriptWindowObjectCleared()),
+ jso, SLOT(enableJavascriptAccess()));
+ QObject::connect(jso, SIGNAL(signalQuitAll()), this, SLOT(quit()));
+
// Initialize Download Manager.
dm = new DownloadManager(baseUrl);
- QObject::connect(this, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString)));
+ QObject::connect(jso, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString)));
+ QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgressSlot(int)));
//remove the window decoration
this->setWindowFlags(Qt::SplashScreen);
-
- //enable JavaScript access to qt objects
- QObject::connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject()));
-
//set form to fullscreen
this->showFullScreen();
-
setCentralWidget(view);
}
-
-// Destructor
+// -------------------------------------------------------------------------------------------
fbbrowser::~fbbrowser()
{
-}
-
-//
-void fbbrowser::addJSObject()
-{
- jso = new jsObject();
- view->page()->mainFrame()->addToJavaScriptWindowObject(QString("jsObject"), jso);
-
- // connect the signals of the jsObject to the slots of the fbbrowser
- connectJsSignalsToSlots();
-}
-
-void fbbrowser::connectJsSignalsToSlots()
-{
- QObject::connect(jso, SIGNAL(closeBrowser()), this, SLOT(quitAll()));
- QObject::connect(jso, SIGNAL(startDownload(QString)), this, SLOT(startDownload_Slot(QString)));
- QObject::connect(jso, SIGNAL(getMacAddress()), this, SLOT(getMacAddress_Slot()));
- QObject::connect(jso, SIGNAL(getIpAddress()), this, SLOT(getIpAddress_Slot()));
- QObject::connect(jso, SIGNAL(getIntegratedHardwareDevices()), this, SLOT(getIntegratedHardwareDevices_Slot()));
- QObject::connect(jso, SIGNAL(getUsbDevices()), this, SLOT(getUsbDevices_Slot()));
- QObject::connect(jso, SIGNAL(getHardDrives()), this, SLOT(getHardDrives_Slot()));
-
- // for testing reasons
- QObject::connect(jso, SIGNAL(showTime()), this, SLOT(showTime_Slot()));
- QObject::connect(jso, SIGNAL(showDate()), this, SLOT(showDate_Slot()));
- QObject::connect(jso, SIGNAL(showHelloWorld()), this, SLOT(showHelloWorld_Slot()));
- // further tests
- QObject::connect(dm, SIGNAL(updateProgress(int)), this, SLOT(updateProgressSlot(int)));
-}
-//
-void fbbrowser::updateProgressSlot(int i)
-{
- QString code = QString("updateProgress(\%1\)").arg(i);
- view->page()->mainFrame()->evaluateJavaScript(code);
-}
-void fbbrowser::writeText(QString text)
-{
- QFile file("out.txt");
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
- return;
-
- QTextStream out(&file);
- out << text << "\n";
-}
-
-// This function needed now ?
-void fbbrowser::quitAll()
-{
- emit signalQuitAll();
-}
-
-
-void fbbrowser::startDownload_Slot(QString filename)
-{
-
- qDebug() << "Returned from JS: " << filename;
- // Start download.
- emit downloadFile(filename);
-
-}
-
-void fbbrowser::getMacAddress_Slot()
-{
-
- QNetworkInterface *qNetI = new QNetworkInterface();
- QList list;
- list=qNetI->allInterfaces();
- QString str;
- QString macAddress;
- for (int i = 0; i < list.size(); ++i) {
- str = list.at(i).name();
- macAddress = list.at(i).hardwareAddress();
- qDebug() << str;
- qDebug() << macAddress;
- }
-
- //TODO:: edit jsFunction name
- QString code;
- code = QString("printMacAddress(\"%1\")").arg(macAddress);
- view->page()->mainFrame()->evaluateJavaScript(code);
-}
-
-void fbbrowser::getIpAddress_Slot()
-{
-
-}
-
-void fbbrowser::getIntegratedHardwareDevices_Slot()
-{
-
-}
-
-void fbbrowser::getUsbDevices_Slot()
-{
-
-}
-
-void fbbrowser::getHardDrives_Slot()
-{
-
-}
-
-// for testing reasons
-void fbbrowser::showTime_Slot()
-{
- qDebug() << "---- call: showTime_Slot";
- QString time = QTime::currentTime().toString("hh:mm:ss");
-
- //TODO:: edit jsFunction name
- QString code;
- code = QString("printTime(\"%1\")").arg(time);
- view->page()->mainFrame()->evaluateJavaScript(code);
-}
-
-void fbbrowser::showDate_Slot()
-{
- QString date = QDate::currentDate().toString("dd.MM.yyyy");
- //TODO:: edit jsFunction name
- //view->page()->mainFrame()->evaluateJavaScript("");
-}
-
-void fbbrowser::showHelloWorld_Slot()
-{
- view->page()->mainFrame()->evaluateJavaScript("alert(\"Hello World\")");
-}
-
-void fbbrowser::getSysInfo(){
-/*
- QString time = QTime::currentTime().toString("hh:mm:ss");
- QString date = QDate::currentDate().toString("dd.MM.yyyy");
- QList ipList = QNetworkInterface::allAddresses();
- QString macAddress = QNetworkInterface::hardwareAddress();
- */
+ delete view;
+ delete manager;
+ delete dm;
+ delete jso;
}
diff --git a/src/fbbrowser.h b/src/fbbrowser.h
index e349b98..7c09cef 100644
--- a/src/fbbrowser.h
+++ b/src/fbbrowser.h
@@ -1,18 +1,14 @@
#ifndef FBBROWSER_H
#define FBBROWSER_H
+#include "JSObject.h"
#include "DownloadManager.h"
-
-#include "jsObject.h"
#include
#include
#include
class QWebView;
-//QT_BEGIN_NAMESPACE
-//class QLineEdit;
-//QT_END_NAMESPACE
-
+class JSObject;
class DownloadManager;
class fbbrowser : public QMainWindow
@@ -22,51 +18,25 @@ class fbbrowser : public QMainWindow
public:
fbbrowser(const QUrl& url);
~fbbrowser();
- void printusage();
- Q_INVOKABLE void writeText(QString text); //used for writing web content into a file
private:
QUrl baseUrl;
QNetworkRequest request;
QNetworkReply *reply;
QWebView *view;
+ QWebFrame* qwf;
QNetworkAccessManager *manager;
- // Temporal stuff for the download function...
- // Private download function.
-
//the jsObject. connection to the webpage for emiting signals
- jsObject *jso;
+ JSObject *jso;
DownloadManager* dm;
- // connects all jsObject signals with fbbrowser slots
- void connectJsSignalsToSlots();
-
-
-public slots:
- void updateProgressSlot(int i);
-
-private slots:
- void addJSObject();
- void getSysInfo();
-
- // slots which are emited by the jsObject signals
-
- void quitAll();
- void startDownload_Slot(QString filename);
- void getMacAddress_Slot();
- void getIpAddress_Slot();
- void getIntegratedHardwareDevices_Slot();
- void getUsbDevices_Slot();
- void getHardDrives_Slot();
-
- // for testing reasons
- void showTime_Slot();
- void showDate_Slot();
- void showHelloWorld_Slot();
signals:
void downloadFile(QString filename);
- void signalQuitAll();
+ void killApp();
+
+public slots:
+ void quit();
};
#endif // FBBROWSER_H
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index f3a77c1..8cd58bc 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -1,7 +1,6 @@
#include "fbgui.h"
#include "fbbrowser.h"
#include "DownloadManager.h"
-#include "DMThread.h"
#include
#include
#include
@@ -66,7 +65,7 @@ int main(int argc, char *argv[])
fbbrowser* fbb = new fbbrowser(url);
// Listen to the signalQuitAll() Signal to kill the app from within the browser.
- QObject::connect(fbb, SIGNAL(signalQuitAll()), &a, SLOT(quit()));
+ QObject::connect(fbb, SIGNAL(killApp()), &a, SLOT(quit()));
// Display the browser.
fbb->show();
diff --git a/src/fbgui.pro b/src/fbgui.pro
index 895b709..ab75949 100644
--- a/src/fbgui.pro
+++ b/src/fbgui.pro
@@ -6,10 +6,10 @@ QT += core \
gui \
webkit \
network
-HEADERS += jsObject.h \
+HEADERS += JSObject.h \
DownloadManager.h \
fbbrowser.h
-SOURCES += jsObject.cpp \
+SOURCES += JSObject.cpp \
fbgui.cpp \
DownloadManager.cpp \
fbbrowser.cpp
diff --git a/src/html/webkitTest.html b/src/html/webkitTest.html
new file mode 100644
index 0000000..37fc963
--- /dev/null
+++ b/src/html/webkitTest.html
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+WebkitTest
+
+
+