all repos — mgba @ 8ad2e89cfce6f46f4dd630e6c43ee91afb7feada

mGBA Game Boy Advance Emulator

src/platform/qt/DolphinConnector.cpp (view raw)

 1/* Copyright (c) 2013-2021 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "DolphinConnector.h"
 7
 8#include "CoreController.h"
 9#include "Window.h"
10#include "utils.h"
11
12using namespace QGBA;
13
14DolphinConnector::DolphinConnector(Window* window, QWidget* parent)
15	: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
16	, m_window(window)
17{
18	m_ui.setupUi(this);
19
20	connect(window, &QObject::destroyed, this, &QWidget::close);
21	connect(m_ui.connect, &QAbstractButton::clicked, this, &DolphinConnector::attach);
22	connect(m_ui.disconnect, &QAbstractButton::clicked, this, &DolphinConnector::detach);
23
24	updateAttached();
25}
26
27void DolphinConnector::attach() {
28	QHostAddress qaddress;
29	Address address;
30	if (m_ui.specLocal->isChecked()) {
31		qaddress.setAddress("127.0.0.1");
32	} else if (m_ui.specIPAddr->isChecked()) {
33		if (!qaddress.setAddress(m_ui.ipAddr->text())) {
34			return;
35		}
36
37	}
38	if (!m_window->controller()) {
39		m_window->bootBIOS();
40		if (!m_window->controller() || m_window->controller()->platform() != mPLATFORM_GBA) {
41			return;
42		}
43	}
44
45	convertAddress(&qaddress, &address);
46	CoreController::Interrupter interrupter(m_window->controller());
47	m_window->controller()->attachDolphin(address);
48
49	updateAttached();
50}
51
52void DolphinConnector::detach() {
53	if (m_window->controller()) {
54		m_window->controller()->detachDolphin();
55	}
56	updateAttached();
57}
58
59void DolphinConnector::updateAttached() {
60	bool attached = m_window->controller() && m_window->controller()->isDolphinConnected();
61	m_ui.connect->setDisabled(attached);
62	m_ui.disconnect->setEnabled(attached);
63	m_ui.specLocal->setDisabled(attached);
64	m_ui.specIPAddr->setDisabled(attached);
65}