/* * 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(){}