downloadmanager.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef DOWNLOADMANAGER_H
  2. #define DOWNLOADMANAGER_H
  3. #include <QFile>
  4. #include <QObject>
  5. #include <QQueue>
  6. #include <QTime>
  7. #include <QUrl>
  8. #include <QLabel>
  9. #include <QNetworkAccessManager>
  10. class DownloadManager: public QObject
  11. {
  12. Q_OBJECT
  13. private:
  14. DownloadManager(QObject *parent = 0);
  15. public:
  16. static DownloadManager* getInstance() {
  17. static DownloadManager instance;
  18. return &instance;
  19. }
  20. public:
  21. void append(const QUrl &url);
  22. void append(const QStringList &urlList);
  23. void startNextDownload();
  24. void abortDownload(QString name);
  25. signals:
  26. void finishedAllDownloads();
  27. void fileDownloadFinished(QString filename, QString msg);
  28. void updateDownloadProgress(QString msg);
  29. private slots:
  30. void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  31. void downloadFinished();
  32. void downloadReadyRead();
  33. private:
  34. QNetworkAccessManager manager;
  35. QQueue<QUrl> downloadQueue;
  36. QNetworkReply *currentDownload;
  37. QFile output;
  38. QTime downloadTime;
  39. QString download_name;
  40. int downloadedCount;
  41. int totalCount;
  42. };
  43. #endif // DOWNLOADMANAGER_H