blob: d9ff22550f20f0a435d005242ca73598baa7a870 (
plain) (
blame)
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
|
/*
* javascriptinterfacefbgui.cpp
*
* Created on: Feb 21, 2012
* Author: joe
*/
#include "javascriptinterfacefbgui.h"
#include "sysinfo.h"
JavascriptInterfaceFBGUI::JavascriptInterfaceFBGUI(QWebFrame* parent)
: JavascriptInterface(parent){
}
JavascriptInterfaceFBGUI::~JavascriptInterfaceFBGUI() {
}
//-------------------------------------------------------------------------------------------------------
// Javascript functions for webpage
//-------------------------------------------------------------------------------------------------------
/**
* This method start a download.
*
* This method start a download.
* Can be called from inside a JavaScript function of the HTML page.
* Emits the JavascriptInterface::requestFile(const QString) signal.
*/
void JavascriptInterfaceFBGUI::startDownload(const QString& filename) {
// ignore if empty filename
if (filename.isEmpty()) {
_targetFrame->evaluateJavaScript("alert(\"No filename!\")");
return;
}
emit requestFile(filename);
}
//-------------------------------------------------------------------------------------------------------
/**
* This method start a download.
*
* This method start a download.
* Can be called from inside a JavaScript function of the HTML page.
*
* @todo add some more informations
*/
void JavascriptInterfaceFBGUI::setCallbackOnFinished(const QString& function) {
//LOG4CXX_DEBUG(jsiLogger, "Callback set: " << function);
_callbackOnDownloadsFinished = QString(function);
}
//-------------------------------------------------------------------------------------------------------
/**
* This method delivers system informations.
*
* This method delivers system informations. Type of informations, are defined by
* the parameter. The output of this method depends on the parameter.
* Can be called from inside a JavaScript function of the HTML page.
*
* @param infoName
* Is of type QString. Defines which method will be called. Possible values are:
* - mac
* - ip
* - mbserial
* - usb
*
* @return QString
* the output of the called method or "info_error" if an error occurred
* (e. g. invalid parameter).
*
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString JavascriptInterfaceFBGUI::getSysInfo(const QString& info) {
SysInfo si;
return si.getInfo(info);
}
//-------------------------------------------------------------------------------------------------------
// Download Manager information exchange
//-------------------------------------------------------------------------------------------------------
/**
* This method delivers some informations about the downloading file.
*
* This method delivers some informations about the downloading file.
*
* @todo add some more informations
*/
void JavascriptInterfaceFBGUI::downloadInfo(const QString& filename,
const double& filesize) {
QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(
filesize);
_targetFrame->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
/**
* This method updates the progress bar.
*
* This method calls a Javascript function to update the progress bar of the download.
* Javascript must have a function called "updateProgress" to receive this information.
*
* @todo add some more informations
*/
void JavascriptInterfaceFBGUI::updateProgressBar(const int& percent,
const double& speed, const QString& unit) {
if (percent == 0)
return;
QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(
speed).arg(unit);
_targetFrame->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
/**
* Sets a callback function for when downloads are finished (will be called when the queue is empty).
*/
void JavascriptInterfaceFBGUI::callbackOnFinished() {
QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
_targetFrame->evaluateJavaScript(code);
}
|