summaryrefslogtreecommitdiffstats
path: root/src/filedownloader.h
blob: ec49c23f1849e6df4d3163a428fd67d46d4868c5 (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
/*
 * filedownloader.h
 *
 *  Created on: Mar 7, 2014
 *      Author: nils
 */

#ifndef FILEDOWNLOADER_H_
#define FILEDOWNLOADER_H_

#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

class FileDownloader : public QObject
{
    Q_OBJECT

public:

    explicit FileDownloader(const QUrl& fileUrl, QObject *parent = nullptr);

    virtual ~FileDownloader();

    bool downloadFile();

signals:

    /**
     * Triggered when the download has finished.
     * On error, downloadedData will be empty.
     */
    void downloaded(const QUrl& url, const QByteArray& downloadedData);

private slots:

    void fileDownloaded();
    void downloadFailed(QNetworkReply::NetworkError code);
    void downloadProgress(qint64 received, qint64 totalSize);

private:

    void killReply(QNetworkReply *reply);

    bool started;
    QUrl url;

};

#endif /* FILEDOWNLOADER_H_ */