1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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(){}
|