Qt: Dolphin cleanup
Vicki Pfau vi@endrift.com
Mon, 22 Feb 2021 23:55:02 -0800
4 files changed,
37 insertions(+),
5 deletions(-)
M
src/platform/qt/DolphinConnector.cpp
→
src/platform/qt/DolphinConnector.cpp
@@ -5,6 +5,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "DolphinConnector.h" +#include <QMessageBox> + #include "CoreController.h" #include "Window.h" #include "utils.h"@@ -43,15 +45,26 @@ }
} 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(); }
M
src/platform/qt/DolphinConnector.h
→
src/platform/qt/DolphinConnector.h
@@ -7,8 +7,11 @@ #pragma once
#include "ui_DolphinConnector.h" +#include <memory> + namespace QGBA { +class CoreController; class Window; class DolphinConnector : public QDialog {@@ -27,6 +30,7 @@
private: Ui::DolphinConnector m_ui; + std::shared_ptr<CoreController> m_controller; Window* m_window; };
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -500,6 +500,18 @@ };
} template <typename T, typename... A> +std::function<void()> Window::openNamedTView(std::unique_ptr<T>* name, A... arg) { + return [=]() { + if (!*name) { + *name = std::make_unique<T>(arg...); + connect(this, &Window::shutdown, name->get(), &QWidget::close); + } + (*name)->show(); + (*name)->setFocus(Qt::PopupFocusReason); + }; +} + +template <typename T, typename... A> std::function<void()> Window::openNamedControllerTView(std::unique_ptr<T>* name, A... arg) { return [=]() { if (!*name) {@@ -1196,7 +1208,7 @@ GBAApp::app()->newWindow();
}, "file"); #ifdef M_CORE_GBA - Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openTView<DolphinConnector>(this), "file"); + Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView<DolphinConnector>(&m_dolphinView, this), "file"); m_platformActions.insert(mPLATFORM_GBA, dolphin); #endif
M
src/platform/qt/Window.h
→
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 @@ void openView(QWidget* widget);
template <typename T, typename... A> std::function<void()> openTView(A... arg); template <typename T, typename... A> std::function<void()> openControllerTView(A... arg); + template <typename T, typename... A> std::function<void()> openNamedTView(std::unique_ptr<T>*, A... arg); template <typename T, typename... A> std::function<void()> openNamedControllerTView(std::unique_ptr<T>*, A... arg); Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});@@ -225,6 +227,7 @@ bool m_hitUnimplementedBiosCall;
std::unique_ptr<OverrideView> m_overrideView; std::unique_ptr<SensorView> m_sensorView; + std::unique_ptr<DolphinConnector> m_dolphinView; FrameView* m_frameView = nullptr; #ifdef USE_FFMPEG