summaryrefslogtreecommitdiffstats
path: root/src/fbbrowser.cpp
blob: edfea361fdbaae1ff9cdb7cb465e2f94d57dd538 (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
#include "fbbrowser.h"

#include <QFile>
#include <QFileInfo>
#include <QtWebKit>
#include "jsObject.h"

void fbbrowser::httpReqFinished()
{
}

void fbbrowser::saveData()
{
}

void fbbrowser::download(const QString &file)
{
}

fbbrowser::fbbrowser(const QUrl & url)
{
	view = new QWebView(this);
 	baseUrl = url;
	// Create QNetworkAccessManager which is needed to send/receive requests.
	manager = new QNetworkAccessManager(this);
	// Create a QNetworkRequest object and set its URL.
	//* QNetworkRequest request;
	request.setUrl(url);

	// Check Internet connection
	// Let the manager send the request and receive the reply.
	// QNetworkReply *reply = manager->get(request);
    reply = manager->get(request);
	// connect(reply, SIGNAL(finished()), this, SLOT(httpReqFinished()));

	// Check if the reply is an error message.
	qDebug() << "QNetworkReply error code is: " << reply->error();

	// TODO: error differentiation
    // reply->error() returns 0 even for invalid URL.
    // A possibility to check for validity, is to listen to readyRead()
    // signal, haven't found a better way yet ...
	if(reply->error() == QNetworkReply::NoError)
	{
		qDebug() << "No error, loading given URL...";
		view->load(url);
	}
	else 
	{
		qDebug() << "Error occured, loading error page...";
		view->load(QUrl("qrc:/html/errorPage.html"));
	}
	// **** TEST ****
	DownloadManager* dm = new DownloadManager();
	dm->print();
	dm->setUrl(baseUrl);
	QString qs = "test.php";
	dm->downloadFile(qs);
	// **** TEST ****

	//remove the window decoration
	this->setWindowFlags(Qt::SplashScreen);

	//enable JavaScript access to qt objects
	QObject::connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject()));

	//set form to fullscreen
	this->showFullScreen();

	setCentralWidget(view);
}

// Destructor
fbbrowser::~fbbrowser()
{
}

//
void fbbrowser::addJSObject()
{
	jsObject *jso = new jsObject();
	view->page()->mainFrame()->addToJavaScriptWindowObject(QString("jsObject"), jso);
}

void fbbrowser::writeText(QString text)
{
	QFile file("out.txt");
	if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
		return;

	QTextStream out(&file);
	out << text << "\n";
}

// This function needed now ?
void fbbrowser::quitAll()
{
	emit signalQuitAll();
}

void fbbrowser::getSysInfo()
{
	/*
	QString time = QTime::currentTime().toString("hh:mm:ss");
	QString date = QDate::currentDate().toString("dd.MM.yyyy");
	QList<QHostAddress> ipList = QNetworkInterface::allAddresses();
	QString macAddress = QNetworkInterface::hardwareAddress()
	*/
}