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
|
#include "fbbrowser.h"
#include "JSObject.h"
#include "DownloadManager.h"
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QNetworkInterface>
#include <QtWebKit>
// -------------------------------------------------------------------------------------------
void fbbrowser::processAction(QString action){
// Do stuff
}
// -------------------------------------------------------------------------------------------
fbbrowser::fbbrowser()
{
// Initialise Browser Window.
QWebView* view = new QWebView(this);
QNetworkRequest request;
QNetworkReply *reply;
QNetworkAccessManager *manager;
manager = new QNetworkAccessManager(this);
request.setUrl(baseURL);
reply = manager->get(request);
// TODO: error differentiation
if(reply->error() == QNetworkReply::NoError)
{
qDebug() << "Loading: " << baseURL.toString();
view->load(baseURL);
qDebug() << "Loaded.";
}
else
{
qDebug() << "QNetworkReply error code is: " << reply->error();
qDebug() << "Error occured, loading error page...";
view->load(QUrl("qrc:/html/errorPage.html"));
}
// Enable Javascript through JSObject.
QWebFrame* qwf = view->page()->mainFrame();
JSObject* jso = new JSObject(qwf);
/* ACTION TESTING */
QObject::connect(jso, SIGNAL(processAction(QString)), this, SLOT(processAction(QString)));
QObject::connect(qwf, SIGNAL(javaScriptWindowObjectCleared()),
jso, SLOT(attachToDOM()));
QObject::connect(jso, SIGNAL(getMAC()), this, SLOT(getMAC()));
QObject::connect(this, SIGNAL(printMAC(QString&)), jso, SLOT(printMAC(QString&)));
QObject::connect(jso, SIGNAL(getTime()), this, SLOT(getTime()));
QObject::connect(this, SIGNAL(printTime(QString&)), jso, SLOT(printTime(QString&)));
QObject::connect(jso, SIGNAL(signalQuitAll()), this, SLOT(quit()));
// Initialize Download Manager.
DownloadManager* dm = new DownloadManager();
QObject::connect(jso, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&)));
QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgressBar(int)));
}
// -------------------------------------------------------------------------------------------
void fbbrowser::getMAC()
{
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;
}
emit printMAC(macAddress);
}
// -------------------------------------------------------------------------------------------
void fbbrowser::getTime()
{
qDebug() << "---- call: showTime_Slot";
QString time = QTime::currentTime().toString("hh:mm:ss");
emit printTime(time);
}
// -------------------------------------------------------------------------------------------
void fbbrowser::quit()
{
emit killApp();
}
|