From 512bdf9c60038024a1afb435aae71ce9178c55cf Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 22 Feb 2021 23:55:02 -0800 Subject: [PATCH] Qt: Dolphin cleanup --- src/platform/qt/DolphinConnector.cpp | 21 +++++++++++++++++---- src/platform/qt/DolphinConnector.h | 4 ++++ src/platform/qt/Window.cpp | 14 +++++++++++++- src/platform/qt/Window.h | 3 +++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/platform/qt/DolphinConnector.cpp b/src/platform/qt/DolphinConnector.cpp index fb026ea24..cd311b13d 100644 --- a/src/platform/qt/DolphinConnector.cpp +++ b/src/platform/qt/DolphinConnector.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "DolphinConnector.h" +#include + #include "CoreController.h" #include "Window.h" #include "utils.h" @@ -43,15 +45,26 @@ void DolphinConnector::attach() { } convertAddress(&qaddress, &address); - CoreController::Interrupter interrupter(m_window->controller()); - m_window->controller()->attachDolphin(address); + m_controller = m_window->controller(); + CoreController::Interrupter interrupter(m_controller); + m_controller->attachDolphin(address); + connect(m_controller.get(), &CoreController::stopping, this, &DolphinConnector::detach); + + if (!m_controller->isDolphinConnected()) { + QMessageBox* fail = new QMessageBox(QMessageBox::Warning, tr("Couldn't Connect"), + tr("Could not connect to Dolphin."), + QMessageBox::Ok); + fail->setAttribute(Qt::WA_DeleteOnClose); + fail->show(); + } updateAttached(); } void DolphinConnector::detach() { - if (m_window->controller()) { - m_window->controller()->detachDolphin(); + if (m_controller) { + m_controller->detachDolphin(); + m_controller.reset(); } updateAttached(); } diff --git a/src/platform/qt/DolphinConnector.h b/src/platform/qt/DolphinConnector.h index 9b4c00132..796b496ee 100644 --- a/src/platform/qt/DolphinConnector.h +++ b/src/platform/qt/DolphinConnector.h @@ -7,8 +7,11 @@ #include "ui_DolphinConnector.h" +#include + namespace QGBA { +class CoreController; class Window; class DolphinConnector : public QDialog { @@ -27,6 +30,7 @@ private slots: private: Ui::DolphinConnector m_ui; + std::shared_ptr m_controller; Window* m_window; }; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 52a47041f..58fc4a56d 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -499,6 +499,18 @@ std::function Window::openControllerTView(A... arg) { }; } +template +std::function Window::openNamedTView(std::unique_ptr* name, A... arg) { + return [=]() { + if (!*name) { + *name = std::make_unique(arg...); + connect(this, &Window::shutdown, name->get(), &QWidget::close); + } + (*name)->show(); + (*name)->setFocus(Qt::PopupFocusReason); + }; +} + template std::function Window::openNamedControllerTView(std::unique_ptr* name, A... arg) { return [=]() { @@ -1196,7 +1208,7 @@ void Window::setupMenu(QMenuBar* menubar) { }, "file"); #ifdef M_CORE_GBA - Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openTView(this), "file"); + Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView(&m_dolphinView, this), "file"); m_platformActions.insert(mPLATFORM_GBA, dolphin); #endif diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 90f9dbab5..a5cca0657 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -34,6 +34,7 @@ class CoreController; class CoreManager; class DebuggerConsoleController; class Display; +class DolphinConnector; class FrameView; class GDBController; class GIFView; @@ -164,6 +165,7 @@ private: template std::function openTView(A... arg); template std::function openControllerTView(A... arg); + template std::function openNamedTView(std::unique_ptr*, A... arg); template std::function openNamedControllerTView(std::unique_ptr*, A... arg); Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {}); @@ -225,6 +227,7 @@ private: std::unique_ptr m_overrideView; std::unique_ptr m_sensorView; + std::unique_ptr m_dolphinView; FrameView* m_frameView = nullptr; #ifdef USE_FFMPEG