GUIApplicationManager.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "native/utilities/ApplicationManagerBase.h"
  11. #include "native/utilities/AssetUtilEBusHelper.h"
  12. #include "native/FileWatcher/FileWatcher.h"
  13. #include <QMap>
  14. #include <QAtomicInt>
  15. #include <QFileSystemWatcher>
  16. #include <AzCore/UserSettings/UserSettingsProvider.h>
  17. #include <native/ui/MainWindow.h>
  18. #include <QSystemTrayIcon>
  19. #endif
  20. class ConnectionManager;
  21. class IniConfiguration;
  22. class ApplicationServer;
  23. class FileServer;
  24. namespace AssetProcessor
  25. {
  26. class AssetRequestHandler;
  27. }
  28. class GUIApplicationManager;
  29. struct ErrorCollector
  30. {
  31. explicit ErrorCollector(QWidget* parent = nullptr) : m_parent(parent){}
  32. ~ErrorCollector();
  33. void AddError(AZStd::string message);
  34. QWidget* m_parent{};
  35. QStringList m_errorMessages;
  36. };
  37. //! This class is the Application manager for the GUI Mode
  38. class GUIApplicationManager
  39. : public ApplicationManagerBase
  40. {
  41. Q_OBJECT
  42. public:
  43. GUIApplicationManager(int* argc, char*** argv, QObject* parent = nullptr);
  44. GUIApplicationManager(int* argc, char*** argv, AZ::ComponentApplicationSettings componentAppSettings);
  45. GUIApplicationManager(int* argc, char*** argv, QObject* parent, AZ::ComponentApplicationSettings componentAppSettings);
  46. ~GUIApplicationManager() override;
  47. ApplicationManager::BeforeRunStatus BeforeRun() override;
  48. IniConfiguration* GetIniConfiguration() const;
  49. FileServer* GetFileServer() const;
  50. bool Run() override;
  51. ////////////////////////////////////////////////////
  52. ///MessageInfoBus::Listener interface///////////////
  53. void NegotiationFailed() override;
  54. void OnAssetFailed(const AZStd::string& sourceFileName) override;
  55. void OnErrorMessage(const char* error) override;
  56. ///////////////////////////////////////////////////
  57. //! TraceMessageBus::Handler
  58. bool OnError(const char* window, const char* message) override;
  59. bool OnAssert(const char* message) override;
  60. WId GetWindowId() const override;
  61. private:
  62. bool Activate() override;
  63. bool PostActivate() override;
  64. void CreateQtApplication() override;
  65. bool InitApplicationServer() override;
  66. void InitConnectionManager() override;
  67. void InitIniConfiguration();
  68. void DestroyIniConfiguration();
  69. void InitFileServer();
  70. void DestroyFileServer();
  71. void Destroy() override;
  72. Q_SIGNALS:
  73. void ShowWindow();
  74. protected Q_SLOTS:
  75. void FileChanged(QString path);
  76. void DirectoryChanged(QString path);
  77. void ShowMessageBox(QString title, QString msg, bool isCritical);
  78. void ShowTrayIconMessage(QString msg);
  79. void ShowTrayIconErrorMessage(QString msg);
  80. void QuitRequested() override;
  81. private:
  82. bool Restart();
  83. void Reflect() override;
  84. const char* GetLogBaseName() override;
  85. ApplicationManager::RegistryCheckInstructions PopupRegistryProblemsMessage(QString warningText) override;
  86. void InitSourceControl() override;
  87. bool GetShouldExitOnIdle() const override;
  88. IniConfiguration* m_iniConfiguration = nullptr;
  89. FileServer* m_fileServer = nullptr;
  90. QFileSystemWatcher m_qtFileWatcher;
  91. AZ::UserSettingsProvider m_localUserSettings;
  92. bool m_messageBoxIsVisible = false;
  93. bool m_startedSuccessfully = true;
  94. QPointer<QSystemTrayIcon> m_trayIcon;
  95. QPointer<MainWindow> m_mainWindow;
  96. AZStd::unique_ptr<ErrorCollector> m_startupErrorCollector; // Collects errors during start up to display when startup has finished
  97. AZStd::chrono::steady_clock::time_point m_timeWhenLastWarningWasShown;
  98. };