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/JSObject.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/JSObject.cpp (limited to 'src/JSObject.cpp') 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(){} -- cgit v1.2.3-55-g7522