#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

#include <QFile>
#include <QObject>
#include <QQueue>
#include <QTime>
#include <QUrl>
#include <QLabel>
#include <QNetworkAccessManager>


//#include "textprogressbar.h"

class DownloadManager: public QObject
{
    Q_OBJECT
public:
    DownloadManager(QObject *parent = 0);

    void append(const QUrl &url);
    void append(const QStringList &urlList);
    void abortDownload(QString name);

    int getDownloadedCount();
    void resetDownloadedCount();
    void startDownloads();

signals:
    void changePatchStatus(QString name, QString status);
    void changeHint(QString title, QString hint);
    void finished();
    void cancelDownload();
    void allDownloadsFinished(QStringList downloads);

private slots:
    void startNextDownload();
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void downloadFinished();
    void downloadReadyRead();

private:
    QNetworkAccessManager manager;
    QQueue<QUrl> downloadQueue;
    QNetworkReply *currentDownload;
    QFile output;

    QTime downloadTime;
    QString download_name;
    QString elapsed_time;
    QStringList downloaded_list;

    int bytesReceivedBeforeSecond; // Нужны для подсчёта текущей скорости скачивания, а не
    int timeElapsedBeforeSecond;   // средней за всё время.
    QString current_speed;

    int downloadedCount;
    int totalCount;
    bool busy;
};

#endif // DOWNLOADMANAGER_H
