GUIApplicationManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. explicit GUIApplicationManager(int* argc, char*** argv, QObject* parent = 0);
  44. ~GUIApplicationManager() override;
  45. ApplicationManager::BeforeRunStatus BeforeRun() override;
  46. IniConfiguration* GetIniConfiguration() const;
  47. FileServer* GetFileServer() const;
  48. bool Run() override;
  49. ////////////////////////////////////////////////////
  50. ///MessageInfoBus::Listener interface///////////////
  51. void NegotiationFailed() override;
  52. void OnAssetFailed(const AZStd::string& sourceFileName) override;
  53. void OnErrorMessage(const char* error) override;
  54. ///////////////////////////////////////////////////
  55. //! TraceMessageBus::Handler
  56. bool OnError(const char* window, const char* message) override;
  57. bool OnAssert(const char* message) override;
  58. WId GetWindowId() const override;
  59. private:
  60. bool Activate() override;
  61. bool PostActivate() override;
  62. void CreateQtApplication() override;
  63. bool InitApplicationServer() override;
  64. void InitConnectionManager() override;
  65. void InitIniConfiguration();
  66. void DestroyIniConfiguration();
  67. void InitFileServer();
  68. void DestroyFileServer();
  69. void Destroy() override;
  70. Q_SIGNALS:
  71. void ShowWindow();
  72. protected Q_SLOTS:
  73. void FileChanged(QString path);
  74. void DirectoryChanged(QString path);
  75. void ShowMessageBox(QString title, QString msg, bool isCritical);
  76. void ShowTrayIconMessage(QString msg);
  77. void ShowTrayIconErrorMessage(QString msg);
  78. void QuitRequested() override;
  79. private:
  80. bool Restart();
  81. void Reflect() override;
  82. const char* GetLogBaseName() override;
  83. ApplicationManager::RegistryCheckInstructions PopupRegistryProblemsMessage(QString warningText) override;
  84. void InitSourceControl() override;
  85. bool GetShouldExitOnIdle() const override;
  86. IniConfiguration* m_iniConfiguration = nullptr;
  87. FileServer* m_fileServer = nullptr;
  88. QFileSystemWatcher m_qtFileWatcher;
  89. AZ::UserSettingsProvider m_localUserSettings;
  90. bool m_messageBoxIsVisible = false;
  91. bool m_startedSuccessfully = true;
  92. QPointer<QSystemTrayIcon> m_trayIcon;
  93. QPointer<MainWindow> m_mainWindow;
  94. AZStd::unique_ptr<ErrorCollector> m_startupErrorCollector; // Collects errors during start up to display when startup has finished
  95. AZStd::chrono::steady_clock::time_point m_timeWhenLastWarningWasShown;
  96. };