#ifndef INCLUDEILEDOWNLOADER_H
#define INCLUDEILEDOWNLOADER_H

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

class Downloader : public QObject
{
    Q_OBJECT

public:
    explicit Downloader(QObject *parent = 0);
    virtual ~Downloader();

    QUrl getUrl();
    void setUrl(const QUrl& _url);
    void waitForDownloaded();

signals:
    void downloadFinished();
    void progressChanged(qint64 bytesReceived, qint64 bytesTotal);

public slots:
    void start();
    void updateDownloadSpeedLimit(int bytes_per_sec);
    void stop();

private slots:
    void onDownloadFinished(QNetworkReply* pReply);
    void onReadyRead();

public:
    QFile* targetFile {nullptr};
    QByteArray* targetBytearray {nullptr};

private:
    bool busy;
    QUrl url;
    QNetworkReply* m_CurrentReply {nullptr};
    QNetworkAccessManager m_WebCtrl;

    unsigned download_speed_limit {0};
};

#endif // INCLUDEILEDOWNLOADER_H
