summaryrefslogtreecommitdiffstats
path: root/src/JSObject.cpp
blob: 11f91c6823c91a50ac83e7ca7e08770d0e74230c (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
/*
 * jsObject.cpp
 *
 *  Created on: Feb 1, 2011
 *      Author: niklas
 */
#include "fbgui.h"
#include "JSObject.h"
#include "sysInfo.h"


//-------------------------------------------------------------------------------------------------------
JSObject::JSObject(QWebFrame *parent) {
	// check for better way to use evaluateJavaScript()
	_parent = parent;
}
//-------------------------------------------------------------------------------------------------------
JSObject::~JSObject() {}
//-------------------------------------------------------------------------------------------------------
/* TEST */
QString JSObject::getSysInfo(QString info)
{
	sysInfo si;
	if (debug) qDebug() << "Requested info: " << info;
	if (debug) qDebug() << "sysInfo output: " << si.getInfo(info);
	if (info == QString("time")){
		return si.getInfo(info);
	}
	if (info == QString("mac")){
		return si.getInfo(info);
		//return "MAC_ADDRESS";
	}
	else
		return "no value";
}
//-------------------------------------------------------------------------------------------------------
void JSObject::attachToDOM()
{
	// Attaches itself to the DOM
	_parent->addToJavaScriptWindowObject(QString("jsObject"), this);
}
//-------------------------------------------------------------------------------------------------------
void JSObject::startDownload(QString filename)
{
	/* return if no filename in input field */
	if (filename.isEmpty())
	{
		_parent->evaluateJavaScript("alert(\"No filename!\")");
		return;
	}
	if (debug) qDebug() << "Request download: " << baseURL.resolved(QUrl(filename)).toString();
	emit requestFile(filename);

}
//-------------------------------------------------------------------------------------------------------
void JSObject::updateProgressBar(int i)
{
	if (i == 0)
		return;
	QString code = QString("updateProgress(\%1)").arg(i);
	_parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------

void JSObject::quitAll()
{
	if (debug) qDebug() << "Quit signal.";
	emit signalQuitAll();
}