cdownloadmanager_moc.h 1.3 KB

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