DownloadController.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <QString>
  11. #include <QThread>
  12. #include <AzCore/std/containers/deque.h>
  13. #endif
  14. QT_FORWARD_DECLARE_CLASS(QProcess)
  15. namespace O3DE::ProjectManager
  16. {
  17. QT_FORWARD_DECLARE_CLASS(DownloadWorker)
  18. class DownloadController : public QObject
  19. {
  20. Q_OBJECT
  21. public:
  22. enum DownloadObjectType
  23. {
  24. Gem = 1 << 0,
  25. Project = 1 << 1,
  26. Template = 1 << 2
  27. };
  28. struct DownloadableObject
  29. {
  30. QString m_objectName;
  31. QString m_destinationPath;
  32. DownloadObjectType m_objectType;
  33. };
  34. explicit DownloadController(QWidget* parent = nullptr);
  35. ~DownloadController();
  36. void AddObjectDownload(const QString& objectName, const QString& destinationPath, DownloadObjectType objectType);
  37. void CancelObjectDownload(const QString& objectName, DownloadObjectType objectType);
  38. bool IsDownloadingObject(const QString& objectName, DownloadObjectType objectType);
  39. bool IsDownloadQueueEmpty()
  40. {
  41. return m_objects.empty();
  42. }
  43. const AZStd::deque<DownloadableObject>& GetDownloadQueue() const
  44. {
  45. return m_objects;
  46. }
  47. const QString& GetCurrentDownloadingGem() const
  48. {
  49. if (!m_objects.empty())
  50. {
  51. return m_objects[0].m_objectName;
  52. }
  53. else
  54. {
  55. static const QString emptyString;
  56. return emptyString;
  57. }
  58. }
  59. public slots:
  60. void UpdateUIProgress(int bytesDownloaded, int totalBytes);
  61. void HandleResults(const QString& result, const QString& detailedError);
  62. signals:
  63. void StartObjectDownload(const QString& objectName, const QString& destinationPath, DownloadObjectType objectType, bool downloadNow);
  64. void Done(const QString& objectName, bool success = true);
  65. void ObjectDownloadAdded(const QString& objectName, DownloadObjectType objectType);
  66. void ObjectDownloadRemoved(const QString& objectName, DownloadObjectType objectType);
  67. void ObjectDownloadProgress(const QString& objectName, DownloadObjectType objectType, int bytesDownloaded, int totalBytes);
  68. private:
  69. DownloadWorker* m_worker;
  70. QThread m_workerThread;
  71. AZStd::deque<DownloadableObject> m_objects;
  72. };
  73. } // namespace O3DE::ProjectManager