cdownloadmanager_moc.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. QString filename;
  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);
  41. // returns network reply so caller can connect to required signals
  42. void downloadFile(const QUrl & url, const QString & file);
  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. };