cdownloadmanager_moc.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. Status status;
  28. qint64 bytesReceived;
  29. qint64 totalSize;
  30. };
  31. QStringList encounteredErrors;
  32. QNetworkAccessManager manager;
  33. QList<FileEntry> currentDownloads;
  34. FileEntry & getEntry(QNetworkReply * reply);
  35. public:
  36. CDownloadManager();
  37. // returns true if download with such URL is in progress/queued
  38. // FIXME: not sure what's right place for "mod download in progress" check
  39. bool downloadInProgress(const QUrl & url);
  40. // returns network reply so caller can connect to required signals
  41. void downloadFile(const QUrl & url, const QString & file);
  42. public slots:
  43. void downloadFinished(QNetworkReply * reply);
  44. void downloadProgressChanged(qint64 bytesReceived, qint64 bytesTotal);
  45. signals:
  46. // for status bar updates. Merges all queued downloads into one
  47. void downloadProgress(qint64 currentAmount, qint64 maxAmount);
  48. // called when all files were downloaded and manager goes to idle state
  49. // Lists contains files that were successfully downloaded / failed to download
  50. void finished(QStringList savedFiles, QStringList failedFiles, QStringList errors);
  51. };