summaryrefslogblamecommitdiffstats
path: root/src/DownloadManager.cpp
blob: b5087231840ef20e071fe5162345350f2b4cd37f (plain) (tree)
1
2
3
4
5
6
7
8
9
                            
 
                                                     
 

                                                  
                                  
                                                     
                           










                                                                                  
                                             

                        













                                                            
                                                 




                                   
#include "DownloadManager.h"

void DownloadManager::downloadFile(QString& filename)
{
	QUrl u = this->baseUrl.resolved(filename);
	this->request.setUrl(u);
	this->filename = filename;
	this->reply = this->qnam->get(this->request);
	this->qiod = reply;
	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->qiod->readAll());
	outfile.close();

}

void DownloadManager::setUrl(QUrl& qurl)
{
	this->baseUrl = qurl;
}

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

DownloadManager::DownloadManager()
{
	this->qnam = new QNetworkAccessManager();
}

DownloadManager::~DownloadManager()
{
}