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
|
#include "fbbrowser.h"
#include "JSObject.h"
#include "DownloadManager.h"
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QNetworkInterface>
#include <QtWebKit>
// -------------------------------------------------------------------------------------------
void fbbrowser::forwardDownloadRequest(QString& filename)
{
// Forge URL for filename from baseUrl
QUrl fileUrl;
fileUrl = baseUrl.resolved(QUrl(filename));
emit downloadFile(fileUrl);
}
// -------------------------------------------------------------------------------------------
void fbbrowser::forwardUpdateProgress(int progress)
{
emit updateProgress(progress);
}
// -------------------------------------------------------------------------------------------
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();
}
// -------------------------------------------------------------------------------------------
fbbrowser::fbbrowser()
{
// Initialise Browser Window.
mw = new QMainWindow(this);
view = new QWebView(mw);
// Prepare loading of baseUrl.
// Maybe possible to let DM take care of these steps?
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);
}
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.
qwf = view->page()->mainFrame();
jso = new JSObject(qwf);
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(requestFile(QString&)), this, SLOT(forwardDownloadRequest(QString&)));
QObject::connect(this, SIGNAL(updateProgress(int)), jso, SLOT(updateProgress(int)));
QObject::connect(jso, SIGNAL(signalQuitAll()), this, SLOT(quit()));
// Initialize Download Manager.
dm = new DownloadManager();
QObject::connect(this, SIGNAL(downloadFile(QUrl&)), dm, SLOT(downloadFile(QUrl&)));
QObject::connect(dm, SIGNAL(updateProgress(int)), this, SLOT(forwardUpdateProgress(int)));
// Remove the window decoration, form to fullscreen, central view?
mw->setWindowFlags(Qt::SplashScreen);
mw->showFullScreen();
mw->setCentralWidget(view);
}
// -------------------------------------------------------------------------------------------
fbbrowser::~fbbrowser()
{
delete mw;
delete view;
delete manager;
delete dm;
delete jso;
}
|