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

#include <QFile>
#include <QFileInfo>
#include <QtWebKit>

// -------------------------------------------------------------------------------------------
void fbbrowser::quit()
{
	emit killApp();
}
// -------------------------------------------------------------------------------------------
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.
	request.setUrl(url);
	// Let the manager send the request and receive the reply.
    reply = manager->get(request);
	// TODO: error differentiation
	if(reply->error() == QNetworkReply::NoError)
	{
		view->load(url);
	}
	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(signalQuitAll()), this, SLOT(quit()));

	// Initialize Download Manager.
	dm = new DownloadManager();
	QObject::connect(jso, SIGNAL(downloadFile(QUrl&)), dm, SLOT(downloadFile(QUrl&)));
	QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgress(int)));

	// Remove the window decoration, form to fullscreen, central view?
	this->setWindowFlags(Qt::SplashScreen);
	this->showFullScreen();
	setCentralWidget(view);
}
// -------------------------------------------------------------------------------------------
fbbrowser::~fbbrowser()
{
	delete view;
	delete manager;
	delete dm;
	delete jso;
}