From 412855ae3d967ff81a383688397c4d9448a4ee15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 30 Oct 2016 02:37:38 +0100 Subject: NOISSUE refactor window management and launch, make MultiMC a single instance application. --- application/MultiMC.h | 57 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'application/MultiMC.h') diff --git a/application/MultiMC.h b/application/MultiMC.h index 070447fc..663da1a1 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -7,8 +7,14 @@ #include #include #include -class FolderInstanceProvider; +#include + +class LaunchController; +class LocalPeer; +class InstanceWindow; +class MainWindow; +class FolderInstanceProvider; class GenericPageProvider; class QFile; class MinecraftVersionList; @@ -36,8 +42,6 @@ class ITheme; class MultiMC : public QApplication { // friends for the purpose of limiting access to deprecated stuff - friend class MultiMCPage; - friend class MainWindow; Q_OBJECT public: enum Status @@ -51,13 +55,12 @@ public: MultiMC(int &argc, char **argv); virtual ~MultiMC(); - // InstanceList, IconList, OneSixFTBInstance, LegacyUpdate, LegacyInstance, MCEditTool, JVisualVM, MinecraftInstance, JProfiler, BaseInstance - std::shared_ptr settings() + std::shared_ptr settings() const { return m_settings; } - std::shared_ptr globalSettingsPages() + std::shared_ptr globalSettingsPages() const { return m_globalSettingsProvider; } @@ -72,6 +75,7 @@ public: void setIconTheme(const QString& name); std::vector getValidApplicationThemes(); + void setApplicationTheme(const QString& name); // DownloadUpdateTask @@ -86,7 +90,6 @@ public: std::shared_ptr liteloaderlist(); std::shared_ptr javalist(); - // APPLICATION ONLY std::shared_ptr instances() const { return m_instances; @@ -102,46 +105,44 @@ public: return m_icons; } - // APPLICATION ONLY std::shared_ptr accounts() const { return m_accounts; } - // APPLICATION ONLY Status status() const { return m_status; } - // APPLICATION ONLY const QMap> &profilers() const { return m_profilers; } - // APPLICATION ONLY const QMap> &tools() const { return m_tools; } - // APPLICATION ONLY + /// this is the root of the 'installation'. Used for automatic updates + const QString &root() + { + return m_rootPath; + } + + // install updates now. void installUpdates(const QString updateFilesDir, GoUpdate::OperationList operations); /*! - * Opens a json file using either a system default editor, or, if note empty, the editor + * Opens a json file using either a system default editor, or, if not empty, the editor * specified in the settings */ bool openJsonEditor(const QString &filename); -protected: /* to be removed! */ - // FIXME: remove. used by MainWindow to create application update tasks - /// this is the root of the 'installation'. Used for automatic updates - const QString &root() - { - return rootPath; - } + InstanceWindow *showInstanceWindow(InstancePtr instance, QString page = QString()); + MainWindow *showMainWindow(); + void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr); private slots: /** @@ -149,6 +150,10 @@ private slots: */ void onExit(); + void on_windowClose(); + + void messageReceived(const QString & message); + private: void initLogger(); void initIcons(); @@ -160,6 +165,7 @@ private: private: QDateTime startTime; + unique_qobject_ptr m_launchController; std::shared_ptr m_qt_translator; std::shared_ptr m_mmc_translator; std::shared_ptr m_settings; @@ -180,12 +186,19 @@ private: QMap> m_profilers; QMap> m_tools; - QString rootPath; + QString m_rootPath; Status m_status = MultiMC::Failed; + // used on Windows to attach the standard IO streams bool consoleAttached = false; + + // map from instance ID to its window + QMap m_instanceWindows; + // main window, if any + MainWindow * m_mainWindow = nullptr; + LocalPeer * m_peerInstance = nullptr; public: - QString instanceIdToLaunch; + QString m_instanceIdToLaunch; std::unique_ptr logFile; }; -- cgit v1.2.3