cdownloadmanager_moc.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * cdownloadmanager_moc.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <QSharedPointer>
  12. #include <QtNetwork/QNetworkReply>
  13. class QFile;
  14. class CDownloadManager : public QObject
  15. {
  16. Q_OBJECT
  17. struct FileEntry
  18. {
  19. enum Status
  20. {
  21. IN_PROGRESS,
  22. FINISHED,
  23. FAILED
  24. };
  25. QNetworkReply * reply;
  26. QSharedPointer<QFile> file;
  27. QString filename;
  28. Status status;
  29. qint64 bytesReceived;
  30. qint64 totalSize;
  31. };
  32. QStringList encounteredErrors;
  33. QNetworkAccessManager manager;
  34. QList<FileEntry> currentDownloads;
  35. FileEntry & getEntry(QNetworkReply * reply);
  36. public:
  37. CDownloadManager();
  38. // returns true if download with such URL is in progress/queued
  39. // FIXME: not sure what's right place for "mod download in progress" check
  40. bool downloadInProgress(const QUrl & url) const;
  41. // returns network reply so caller can connect to required signals
  42. void downloadFile(const QUrl & url, const QString & file, qint64 bytesTotal = 0);
  43. public slots:
  44. void downloadFinished(QNetworkReply * reply);
  45. void downloadProgressChanged(qint64 bytesReceived, qint64 bytesTotal);
  46. signals:
  47. // for status bar updates. Merges all queued downloads into one
  48. void downloadProgress(qint64 currentAmount, qint64 maxAmount);
  49. // called when all files were downloaded and manager goes to idle state
  50. // Lists contains files that were successfully downloaded / failed to download
  51. void finished(QStringList savedFiles, QStringList failedFiles, QStringList errors);
  52. };