summaryrefslogtreecommitdiffstats
path: root/src/javascriptInterface.cpp
blob: d57ce44dd3f996d1b619385f89936c59f56e75e7 (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
#include "fbgui.h"
#include "javascriptInterface.h"
#include "sysInfo.h"

//-------------------------------------------------------------------------------------------------------
javascriptInterface::javascriptInterface(QWebFrame *parent)
{
	//TODO: check for better way to use evaluateJavaScript()
	_parent = parent;
}
//-------------------------------------------------------------------------------------------------------
javascriptInterface::~javascriptInterface() {}
//-------------------------------------------------------------------------------------------------------
QString javascriptInterface::getSysInfo(QString info)
{
	sysInfo si;
	if (debug) qDebug() << "Requested info: " << info << endl;
	return si.getInfo(info);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::attachToDOM()
{
	_parent->addToJavaScriptWindowObject(QString("fbgui"), this);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::startDownload(QString filename)
{
	/* ignore if empty filename */
	if (filename.isEmpty()){
		_parent->evaluateJavaScript("alert(\"No filename!\")");
		return;
	}
	emit requestFile(filename);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::updateProgressBar(QString current, int i)
{
	if (i == 0) return;
	QString code = QString("updateProgress('\%1', \%2)").arg(current).arg(i);
	if (debug) qDebug() << "To JS:  " << code;
	_parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::setCallbackOnDlQueueFinished(QString jsFunction)
{
	callBackOnDownloadsFinished = jsFunction;
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::callbackOnDlQueueFinished()
{
	QString code = QString("\%1").arg(callBackOnDownloadsFinished);
	_parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::quit()
{
	if (debug) qDebug() << "Quit signal.";
	emit quitFbgui();
}