summaryrefslogtreecommitdiffstats
path: root/src/JSObject.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-04 23:51:45 +0100
committerJonathan Bauer2011-03-04 23:51:45 +0100
commit0d711f2fc464eb05866cd9c329b57ec279a98971 (patch)
tree80e76c58f4336f61be40cef18435626e270b822f /src/JSObject.cpp
parentdefault url for testApp.sh (diff)
downloadfbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.tar.gz
fbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.tar.xz
fbgui-0d711f2fc464eb05866cd9c329b57ec279a98971.zip
Code cleanup, JSO class continued, added webkitTest.html for reference
Diffstat (limited to 'src/JSObject.cpp')
-rw-r--r--src/JSObject.cpp118
1 files changed, 118 insertions, 0 deletions
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(){}