-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffiledownloader.cpp
58 lines (47 loc) · 1.34 KB
/
ffiledownloader.cpp
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
#include <QDir>
#include <QFileInfo>
#include "ffiledownloader.h"
FFileDownloader::FFileDownloader(QUrl fileUrl, QObject *parent) :
QObject(parent)
{
connect(&m_WebCtrl, SIGNAL (finished(QNetworkReply*)),this, SLOT (fileDownloaded(QNetworkReply*)));
QNetworkRequest request(fileUrl);
m_WebCtrl.get(request);
src = fileUrl.path();
}
FFileDownloader::FFileDownloader(QUrl fileUrl, QString t, QObject *parent) :
QObject(parent)
{
connect( &m_WebCtrl, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*))
);
target = t;
src = fileUrl.path();
QNetworkRequest request(fileUrl);
m_WebCtrl.get(request);
}
FFileDownloader::~FFileDownloader() { }
void FFileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
//emit a signal
pReply->deleteLater();
if (target != NULL)
{
QFile file(target);
QFileInfo fileInfo(file);
if (!fileInfo.absoluteDir().exists())
fileInfo.absoluteDir().mkpath(fileInfo.absoluteDir().absolutePath());
file.open(QIODevice::WriteOnly);
file.write(m_DownloadedData);
file.close();
emit srcDownloaded(target);
}
else
{
emit downloaded();
}
}
QByteArray FFileDownloader::downloadedData() const
{
return m_DownloadedData;
}