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

void DownloadManager::downloadFile(QString& filename)
{
	QUrl u = this->baseUrl.resolved(filename);
	this->request.setUrl(u);
	this->filename = filename;
	qDebug() << "Downloading file: " << u.toString();
	this->reply = this->qnam->get(this->request);
	QObject::connect(this->reply, SIGNAL(finished()), this, SLOT(saveData()));
}

void DownloadManager::saveData()
{
	QFile outfile(this->filename);
	if (!outfile.open(QIODevice::WriteOnly))
	{
		qDebug() << "Couldnt open file! exiting...";
		exit(1);
	}
	outfile.write(this->reply->readAll());
	outfile.close();
	qDebug() << "Download done.";
}

void DownloadManager::print()
{
	qDebug() << "The download manager is still working";
}

DownloadManager::DownloadManager(const QUrl& baseUrl)
{
	this->qnam = new QNetworkAccessManager();
	this->baseUrl = baseUrl;
}

DownloadManager::~DownloadManager()
{
}