#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

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

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

public:
    static DownloadManager* getInstance() {
        static DownloadManager instance;
        return &instance;
    }

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

signals:
    void finishedAllDownloads();
    void fileDownloadFinished(QString filename, QString msg);
    void updateDownloadProgress(QString msg);

private slots:
    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;

    int downloadedCount;
    int totalCount;
};

#endif // DOWNLOADMANAGER_H
