diff options
| author | Jonathan Bauer | 2011-03-04 23:51:45 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-04 23:51:45 +0100 |
| commit | 0d711f2fc464eb05866cd9c329b57ec279a98971 (patch) | |
| tree | 80e76c58f4336f61be40cef18435626e270b822f | |
| parent | default url for testApp.sh (diff) | |
| download | fbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.tar.gz fbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.tar.xz fbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.zip | |
Code cleanup, JSO class continued, added webkitTest.html for reference
| -rw-r--r-- | src/.cproject | 243 | ||||
| -rw-r--r-- | src/DownloadManager.cpp | 1 | ||||
| -rw-r--r-- | src/JSObject.cpp | 118 | ||||
| -rw-r--r-- | src/JSObject.h (renamed from src/jsObject.h) | 40 | ||||
| -rw-r--r-- | src/fbbrowser.cpp | 167 | ||||
| -rw-r--r-- | src/fbbrowser.h | 46 | ||||
| -rw-r--r-- | src/fbgui.cpp | 3 | ||||
| -rw-r--r-- | src/fbgui.pro | 4 | ||||
| -rw-r--r-- | src/html/webkitTest.html | 90 | ||||
| -rw-r--r-- | src/jsObject.cpp | 18 |
10 files changed, 275 insertions, 455 deletions
diff --git a/src/.cproject b/src/.cproject deleted file mode 100644 index c852b37..0000000 --- a/src/.cproject +++ /dev/null @@ -1,243 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<?fileVersion 4.0.0?> - -<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> - <storageModule moduleId="org.eclipse.cdt.core.settings"> - <cconfiguration id="0.1719944755"> - <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1719944755" moduleId="org.eclipse.cdt.core.settings" name="Default"> - <externalSettings/> - <extensions> - <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> - <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> - <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> - <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> - <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> - <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> - <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> - </extensions> - </storageModule> - <storageModule moduleId="org.eclipse.cdt.core.pathentry"> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtNetwork" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtCore" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtXml" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtTest" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtDBus" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtSql" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtDeclarative" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtGui" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtScript" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtSvg" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtScriptTools" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtMultimedia" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtUiTools" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="Qt" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtWebKit" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtDesigner" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="Qt3Support" kind="inc" path="" system="true"/> - <pathentry base-path="/usr/local/Trolltech/QtEmbedded-4.7.1/include" include="QtHelp" kind="inc" path="" system="true"/> - </storageModule> - <storageModule moduleId="cdtBuildSystem" version="4.0.0"> - <configuration buildProperties="" description="" id="0.1719944755" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg"> - <folderInfo id="0.1719944755." name="/" resourcePath=""> - <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1953817660" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain"> - <targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.eclipse.cdt.build.core.prefbase.toolchain.1953817660.1039381753" name=""/> - <builder id="org.eclipse.cdt.build.core.settings.default.builder.1891129888" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/> - <tool id="org.eclipse.cdt.build.core.settings.holder.libs.1062620040" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/> - <tool id="org.eclipse.cdt.build.core.settings.holder.640273578" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder"> - <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1373462247" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> - </tool> - <tool id="org.eclipse.cdt.build.core.settings.holder.2017625377" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder"> - <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1294540575" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> - </tool> - <tool id="org.eclipse.cdt.build.core.settings.holder.1775845390" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder"> - <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.35744408" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> - </tool> - </toolChain> - </folderInfo> - </configuration> - </storageModule> - <storageModule moduleId="scannerConfiguration"> - <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> - <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="makefileGenerator"> - <runAction arguments="-E -P -v -dD" command="" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <scannerConfigBuildInfo instanceId="0.1719944755"> - <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> - <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="makefileGenerator"> - <runAction arguments="-E -P -v -dD" command="" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/${specs_file}"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'g++ -E -P -v -dD "${plugin_state_location}/specs.cpp"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"> - <buildOutputProvider> - <openAction enabled="true" filePath=""/> - <parser enabled="true"/> - </buildOutputProvider> - <scannerInfoProvider id="specsFile"> - <runAction arguments="-c 'gcc -E -P -v -dD "${plugin_state_location}/specs.c"'" command="sh" useDefault="true"/> - <parser enabled="true"/> - </scannerInfoProvider> - </profile> - </scannerConfigBuildInfo> - </storageModule> - <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> - <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> - <buildTargets> - <target name="Qt Release Build" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> - <buildCommand>make</buildCommand> - <buildTarget>release</buildTarget> - <stopOnError>false</stopOnError> - <useDefaultCommand>false</useDefaultCommand> - <runAllBuilders>true</runAllBuilders> - </target> - </buildTargets> - </storageModule> - </cconfiguration> - </storageModule> - <storageModule moduleId="cdtBuildSystem" version="4.0.0"> - <project id="src.null.2069411115" name="src"/> - </storageModule> -</cproject> 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 <QTime> +#include <QNetworkInterface> +//------------------------------------------------------------------------------------------------------- +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<QNetworkInterface> 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<QHostAddress> 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 index a58594f..58ce633 100644 --- a/src/jsObject.h +++ b/src/JSObject.h @@ -10,6 +10,7 @@ #ifndef JSOBJECT_H_ #define JSOBJECT_H_ +#include "fbbrowser.h" #include <QObject> typedef enum @@ -23,13 +24,17 @@ typedef enum SHOW_DATE } jsAction; -class jsObject : public QObject +class fbbrowser; +class QWebFrame; +class JSObject : public QObject { Q_OBJECT - +private: + QWebFrame* target; + fbbrowser* browser; public: - jsObject(); - virtual ~jsObject(); + JSObject(QWebFrame* qwf); + virtual ~JSObject(); //private: // fbbrowser browser; @@ -44,10 +49,11 @@ public: signals: // should be the last signal to be emited. // Will close the browser and continues the boot sequenze - void closeBrowser(); + 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(); @@ -69,6 +75,28 @@ signals: 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 <QFile> #include <QFileInfo> #include <QtWebKit> -#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<QNetworkInterface> 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<QHostAddress> 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 <QString> #include <QtGui> #include <QtNetwork> 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 <getopt.h> #include <limits.h> #include <unistd.h> @@ -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 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" + "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> + + <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> +<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> + +<script type="text/javascript"> +var progress; +function showHelloWorld(){ + jsObject.showHelloWorld(); +} + +function showTime(){ + jsObject.showTime(); +} + +function printTime(time){ + document.formular.textfieldTime.value=time; +} + +function getMacAddress(){ + jsObject.getMacAddress(); +} + +function printMacAddress(macAddress){ + document.formular.textfieldMac.value=macAddress; +} + +function quitProgramm(){ + jsObject.closeBrowser(); +} + +function downloadFile(){ + var tmp=document.formular.downloadFilename.value; + jsObject.startDownload(tmp); +} +function updateProgress(i){ + $("#progressbar").progressbar({ value: i }); +} + +</script> + +</head> +<body onload="Fenster()";> + +<p><center> +WebkitTest +</center></p> + +<form name="formular"> + <p> + <input type="button" name="quitProgramm_Button" value="quit programm" + onclick="quitProgramm()"> + <input type="button" name="showHelloWorld_Button" value="Hello World" + onclick="showHelloWorld()"> + </p> + <p> + Die Zeit des Host: + <input type="text" name="textfieldTime"> + <input type="button" name="showTime_Button" value="Show Time" + onclick="showTime()"> + </p> + <p> + Mac Adresse des Host: + <input type="text" name="textfieldMac"> + <input type="button" name="getMacAddress_Button" value="Get Mac Address" + onclick="getMacAddress()"> + </p> + <p> + Download File: + <input type="text" name="downloadFilename"> + <input type="button" name="downloadButton" value="Download File" + onclick="downloadFile()"> + </p> + + <script> + $(document).ready(function() { + $("#progressbar").progressbar({ value: 0 }); + }); + </script> + + +<div id="progressbar"></div> + +</body> +</html> + diff --git a/src/jsObject.cpp b/src/jsObject.cpp deleted file mode 100644 index f41187c..0000000 --- a/src/jsObject.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * jsObject.cpp - * - * Created on: Feb 1, 2011 - * Author: niklas - */ - -#include "jsObject.h" - -jsObject::jsObject() { - -} - -jsObject::~jsObject() { - // TODO Auto-generated destructor stub -} - - |
