downloadmanager.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. //#include "textprogressbar.h"
  11. class DownloadManager: public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. DownloadManager(QObject *parent = 0);
  16. void append(const QUrl &url);
  17. void append(const QStringList &urlList);
  18. void abortDownload(QString name);
  19. int getDownloadedCount();
  20. void resetDownloadedCount();
  21. void startDownloads();
  22. signals:
  23. void changePatchStatus(QString name, QString status);
  24. void changeHint(QString title, QString hint);
  25. void finished();
  26. void cancelDownload();
  27. void allDownloadsFinished(QStringList downloads);
  28. private slots:
  29. void startNextDownload();
  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. QString elapsed_time;
  41. QStringList downloaded_list;
  42. int bytesReceivedBeforeSecond; // Нужны для подсчёта текущей скорости скачивания, а не
  43. int timeElapsedBeforeSecond; // средней за всё время.
  44. QString current_speed;
  45. int downloadedCount;
  46. int totalCount;
  47. bool busy;
  48. };
  49. #endif // DOWNLOADMANAGER_H