diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-11-01 01:25:04 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-11-01 01:25:04 +0100 |
commit | fe68d5946073d92bc585b2b5372c420218807c91 (patch) | |
tree | d85c710d4f3844e8ab04e94575f6244c151f4bd5 /application | |
parent | 4b03dfcbd77f50d1f8fa3eb9d661ebcba764b9ba (diff) | |
download | MultiMC-fe68d5946073d92bc585b2b5372c420218807c91.tar MultiMC-fe68d5946073d92bc585b2b5372c420218807c91.tar.gz MultiMC-fe68d5946073d92bc585b2b5372c420218807c91.tar.lz MultiMC-fe68d5946073d92bc585b2b5372c420218807c91.tar.xz MultiMC-fe68d5946073d92bc585b2b5372c420218807c91.zip |
GH-1645 reimplement open/close instance window based on settings
Diffstat (limited to 'application')
-rw-r--r-- | application/InstanceWindow.cpp | 49 | ||||
-rw-r--r-- | application/InstanceWindow.h | 4 | ||||
-rw-r--r-- | application/LaunchController.cpp | 26 | ||||
-rw-r--r-- | application/LaunchController.h | 17 | ||||
-rw-r--r-- | application/MultiMC.cpp | 84 | ||||
-rw-r--r-- | application/MultiMC.h | 18 | ||||
-rw-r--r-- | application/widgets/PageContainer.cpp | 2 |
7 files changed, 122 insertions, 78 deletions
diff --git a/application/InstanceWindow.cpp b/application/InstanceWindow.cpp index 1c7731bd..f76ae18d 100644 --- a/application/InstanceWindow.cpp +++ b/application/InstanceWindow.cpp @@ -90,10 +90,8 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent) { auto launchTask = m_instance->getLaunchTask(); on_InstanceLaunchTask_changed(launchTask); - connect(m_instance.get(), &BaseInstance::launchTaskChanged, - this, &InstanceWindow::on_InstanceLaunchTask_changed); - connect(m_instance.get(), &BaseInstance::runningStatusChanged, - this, &InstanceWindow::on_RunningState_changed); + connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &InstanceWindow::on_InstanceLaunchTask_changed); + connect(m_instance.get(), &BaseInstance::runningStatusChanged, this, &InstanceWindow::on_RunningState_changed); } // set up instance destruction detection @@ -128,22 +126,7 @@ void InstanceWindow::setKillButton(bool kill) void InstanceWindow::on_InstanceLaunchTask_changed(std::shared_ptr<LaunchTask> proc) { - if(m_proc) - { - disconnect(m_proc.get(), &LaunchTask::succeeded, this, &InstanceWindow::onSucceeded); - disconnect(m_proc.get(), &LaunchTask::failed, this, &InstanceWindow::onFailed); - disconnect(m_proc.get(), &LaunchTask::requestProgress, this, &InstanceWindow::onProgressRequested); - } - m_proc = proc; - - if(m_proc) - { - // Set up signal connections - connect(m_proc.get(), &LaunchTask::succeeded, this, &InstanceWindow::onSucceeded); - connect(m_proc.get(), &LaunchTask::failed, this, &InstanceWindow::onFailed); - connect(m_proc.get(), &LaunchTask::requestProgress, this, &InstanceWindow::onProgressRequested); - } } void InstanceWindow::on_RunningState_changed(bool running) @@ -202,34 +185,6 @@ void InstanceWindow::on_btnKillMinecraft_clicked() } } -void InstanceWindow::onSucceeded() -{ - if (m_instance->settings()->get("AutoCloseConsole").toBool() && m_container->prepareToClose()) - { - this->close(); - return; - } - // Raise Window - if (MMC->settings()->get("RaiseConsole").toBool()) - { - show(); - raise(); - activateWindow(); - } -} - -void InstanceWindow::onFailed(QString reason) -{ -} - -void InstanceWindow::onProgressRequested(Task* task) -{ - ProgressDialog progDialog(this); - progDialog.setSkipButton(true, tr("Abort")); - m_proc->proceed(); - progDialog.execWithTask(task); -} - QString InstanceWindow::instanceId() { return m_instance->id(); diff --git a/application/InstanceWindow.h b/application/InstanceWindow.h index 5cbced03..a02a3dc6 100644 --- a/application/InstanceWindow.h +++ b/application/InstanceWindow.h @@ -47,10 +47,6 @@ slots: void on_closeButton_clicked(); void on_btnKillMinecraft_clicked(); - void onSucceeded(); - void onFailed(QString reason); - void onProgressRequested(Task *task); - void on_InstanceLaunchTask_changed(std::shared_ptr<LaunchTask> proc); void on_RunningState_changed(bool running); void on_instanceStatusChanged(BaseInstance::Status, BaseInstance::Status newStatus); diff --git a/application/LaunchController.cpp b/application/LaunchController.cpp index 4dce6708..13f453ef 100644 --- a/application/LaunchController.cpp +++ b/application/LaunchController.cpp @@ -206,11 +206,15 @@ void LaunchController::launchInstance() } auto console = qobject_cast<InstanceWindow *>(m_parentWidget); - if(!console) + if(!console && m_showConsole) { MMC->showInstanceWindow(m_instance); } connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch); + connect(m_launcher.get(), &LaunchTask::succeeded, this, &LaunchController::onSucceeded); + connect(m_launcher.get(), &LaunchTask::failed, this, &LaunchController::onFailed); + connect(m_launcher.get(), &LaunchTask::requestProgress, this, &LaunchController::onProgressRequested); + m_launcher->prependStep(std::make_shared<TextPrint>(m_launcher.get(), "MultiMC version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::MultiMC)); m_launcher->start(); @@ -221,7 +225,6 @@ void LaunchController::readyForLaunch() if (!m_profiler) { m_launcher->proceed(); - emitSucceeded(); return; } @@ -247,7 +250,6 @@ void LaunchController::readyForLaunch() msg.setModal(true); msg.exec(); m_launcher->proceed(); - emitSucceeded(); }); connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message) { @@ -263,3 +265,21 @@ void LaunchController::readyForLaunch() }); profilerInstance->beginProfiling(m_launcher); } + +void LaunchController::onSucceeded() +{ + emitSucceeded(); +} + +void LaunchController::onFailed(QString reason) +{ + emitFailed(reason); +} + +void LaunchController::onProgressRequested(Task* task) +{ + ProgressDialog progDialog(m_parentWidget); + progDialog.setSkipButton(true, tr("Abort")); + m_launcher->proceed(); + progDialog.execWithTask(task); +} diff --git a/application/LaunchController.h b/application/LaunchController.h index 55cb1e58..4cc240e8 100644 --- a/application/LaunchController.h +++ b/application/LaunchController.h @@ -17,6 +17,10 @@ public: { m_instance = instance; } + InstancePtr instance() + { + return m_instance; + } void setOnline(bool online) { m_online = online; @@ -29,6 +33,14 @@ public: { m_parentWidget = widget; } + void setShowConsole(bool showConsole) + { + m_showConsole = showConsole; + } + QString id() + { + return m_instance->id(); + } private: void login(); @@ -37,9 +49,14 @@ private: private slots: void readyForLaunch(); + void onSucceeded(); + void onFailed(QString reason); + void onProgressRequested(Task *task); + private: BaseProfilerFactory *m_profiler = nullptr; bool m_online = true; + bool m_showConsole = false; InstancePtr m_instance; QWidget * m_parentWidget = nullptr; InstanceWindow *m_console = nullptr; diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 95cf57b9..a20666ca 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -547,7 +547,6 @@ void MultiMC::initGlobalSettings() // Console m_settings->registerSetting("ShowConsole", true); - m_settings->registerSetting("RaiseConsole", true); m_settings->registerSetting("AutoCloseConsole", true); m_settings->registerSetting("LogPrePostOutput", true); @@ -1072,25 +1071,32 @@ void MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro { if(instance->canLaunch()) { - m_launchController.reset(new LaunchController()); - m_launchController->setInstance(instance); - m_launchController->setOnline(online); - m_launchController->setProfiler(profiler); - auto windowIter = m_instanceWindows.find(instance->id()); - if(windowIter != m_instanceWindows.end()) + auto & extras = m_instanceExtras[instance->id()]; + auto & window = extras.window; + if(window) { - auto window = *windowIter; if(!window->saveAll()) { return; } - m_launchController->setParentWidget(window); } - if(m_mainWindow) + auto & controller = extras.controller; + controller.reset(new LaunchController()); + controller->setInstance(instance); + controller->setOnline(online); + controller->setProfiler(profiler); + controller->setShowConsole(instance->settings()->get("ShowConsole").toBool()); + if(window) { - m_launchController->setParentWidget(m_mainWindow); + controller->setParentWidget(window); } - m_launchController->start(); + else if(m_mainWindow) + { + controller->setParentWidget(m_mainWindow); + } + connect(controller.get(), &LaunchController::succeeded, this, &MultiMC::controllerSucceeded); + connect(controller.get(), &LaunchController::failed, this, &MultiMC::controllerFailed); + controller->start(); } else if (instance->isRunning()) { @@ -1098,6 +1104,37 @@ void MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro } } +void MultiMC::controllerSucceeded() +{ + auto controller = qobject_cast<LaunchController *>(QObject::sender()); + if(!controller) + return; + auto id = controller->id(); + auto & extras = m_instanceExtras[id]; + // on success, do... + if (controller->instance()->settings()->get("AutoCloseConsole").toBool()) + { + if(extras.window) + { + extras.window->close(); + } + } + extras.controller.reset(); +} + +void MultiMC::controllerFailed(const QString& error) +{ + Q_UNUSED(error); + auto controller = qobject_cast<LaunchController *>(QObject::sender()); + if(!controller) + return; + auto id = controller->id(); + auto & extras = m_instanceExtras[id]; + + // on failure, do... nothing + extras.controller.reset(); +} + MainWindow * MultiMC::showMainWindow() { if(m_mainWindow) @@ -1123,34 +1160,43 @@ InstanceWindow *MultiMC::showInstanceWindow(InstancePtr instance, QString page) if(!instance) return nullptr; auto id = instance->id(); - InstanceWindow * window = nullptr; + auto & extras = m_instanceExtras[id]; + auto & window = extras.window; - auto iter = m_instanceWindows.find(id); - if(iter != m_instanceWindows.end()) + if(window) { - window = *iter; window->raise(); window->activateWindow(); } else { window = new InstanceWindow(instance); - m_instanceWindows[id] = window; connect(window, &InstanceWindow::isClosing, this, &MultiMC::on_windowClose); } if(!page.isEmpty()) { window->selectPage(page); } + m_openWindows ++; + if(extras.controller) + { + extras.controller->setParentWidget(window); + } return window; } void MultiMC::on_windowClose() { + m_openWindows--; auto instWindow = qobject_cast<InstanceWindow *>(QObject::sender()); if(instWindow) { - m_instanceWindows.remove(instWindow->instanceId()); + auto & extras = m_instanceExtras[instWindow->instanceId()]; + extras.window = nullptr; + if(extras.controller) + { + extras.controller->setParentWidget(m_mainWindow); + } return; } auto mainWindow = qobject_cast<MainWindow *>(QObject::sender()); @@ -1159,7 +1205,7 @@ void MultiMC::on_windowClose() m_mainWindow = nullptr; } // quit when there are no more windows. - if(m_instanceWindows.isEmpty() && !m_mainWindow) + if(m_openWindows == 0) { quit(); } diff --git a/application/MultiMC.h b/application/MultiMC.h index bb4b544a..e7f41f18 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -154,6 +154,9 @@ private slots: void messageReceived(const QString & message); + void controllerSucceeded(); + void controllerFailed(const QString & error); + private: void initLogger(); void initIcons(); @@ -167,7 +170,6 @@ private: private: QDateTime startTime; - unique_qobject_ptr<LaunchController> m_launchController; std::shared_ptr<QTranslator> m_qt_translator; std::shared_ptr<QTranslator> m_mmc_translator; std::shared_ptr<SettingsObject> m_settings; @@ -189,16 +191,24 @@ private: QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> m_tools; 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<QString, InstanceWindow *> m_instanceWindows; + // FIXME: attach to instances instead. + struct InstanceXtras + { + InstanceWindow * window = nullptr; + unique_qobject_ptr<LaunchController> controller; + }; + std::map<QString, InstanceXtras> m_instanceExtras; + size_t m_openWindows = 0; + // main window, if any MainWindow * m_mainWindow = nullptr; + + // peer MultiMC instance connector - used to implement single instance MultiMC and signalling LocalPeer * m_peerInstance = nullptr; public: QString m_instanceIdToLaunch; diff --git a/application/widgets/PageContainer.cpp b/application/widgets/PageContainer.cpp index 840b39d4..1f46ddfc 100644 --- a/application/widgets/PageContainer.cpp +++ b/application/widgets/PageContainer.cpp @@ -94,7 +94,7 @@ bool PageContainer::selectPage(QString pageId) { index = m_proxyModel->mapFromSource(m_model->index(page->listIndex)); } - else + if(!index.isValid()) { index = m_proxyModel->index(0, 0); } |