all repos — mgba @ 844cee07e8a16130d1f2df8886ab342df68923de

mGBA Game Boy Advance Emulator

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

 1#include "GDBWindow.h"
 2
 3#include <QGridLayout>
 4#include <QGroupBox>
 5#include <QLabel>
 6#include <QLineEdit>
 7#include <QPushButton>
 8#include <QVBoxLayout>
 9
10#include "GDBController.h"
11
12using namespace QGBA;
13
14GDBWindow::GDBWindow(GDBController* controller, QWidget* parent)
15	: QWidget(parent)
16	, m_gdbController(controller)
17{
18	setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint);
19	QVBoxLayout* mainSegment = new QVBoxLayout;
20	setLayout(mainSegment);
21	QGroupBox* settings = new QGroupBox(tr("Server settings"));
22	mainSegment->addWidget(settings);
23
24	QGridLayout* settingsGrid = new QGridLayout;
25	settings->setLayout(settingsGrid);
26
27	QLabel* portLabel = new QLabel(tr("Local port"));
28	settingsGrid->addWidget(portLabel, 0, 0, Qt::AlignRight);
29	QLabel* bindAddressLabel = new QLabel(tr("Bind address"));
30	settingsGrid->addWidget(bindAddressLabel, 1, 0, Qt::AlignRight);
31
32	m_portEdit = new QLineEdit("2345");
33	m_portEdit->setMaxLength(5);
34	connect(m_portEdit, SIGNAL(textChanged(const QString&)), this, SLOT(portChanged(const QString&)));
35	settingsGrid->addWidget(m_portEdit, 0, 1, Qt::AlignLeft);
36
37	m_bindAddressEdit = new QLineEdit("0.0.0.0");
38	m_bindAddressEdit->setMaxLength(15);
39	connect(m_bindAddressEdit, SIGNAL(textChanged(const QString&)), this, SLOT(bindAddressChanged(const QString&)));
40	settingsGrid->addWidget(m_bindAddressEdit, 1, 1, Qt::AlignLeft);
41
42	m_startStopButton = new QPushButton;
43	mainSegment->addWidget(m_startStopButton);
44	if (m_gdbController->isAttached()) {
45		started();
46	} else {
47		stopped();
48	}
49}
50
51void GDBWindow::portChanged(const QString& portString) {
52	bool ok = false;
53	ushort port = portString.toUShort(&ok);
54	if (ok) {
55		m_gdbController->setPort(port);
56	}
57}
58
59void GDBWindow::bindAddressChanged(const QString& bindAddressString) {
60	bool ok = false;
61	QStringList parts = bindAddressString.split('.');
62	if (parts.length() != 4) {
63		return;
64	}
65	int i;
66	uint32_t address = 0;
67	for (i = 0; i < 4; ++i) {
68		ushort octet = parts[i].toUShort(&ok);
69		if (!ok) {
70			return;
71		}
72		if (octet > 0xFF) {
73			return;
74		}
75		address <<= 8;
76		address += octet;
77	}
78	m_gdbController->setBindAddress(address);
79}
80
81void GDBWindow::started() {
82	m_portEdit->setEnabled(false);
83	m_bindAddressEdit->setEnabled(false);
84	m_startStopButton->setText(tr("Stop"));
85	disconnect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(listen()));
86	disconnect(m_startStopButton, SIGNAL(clicked()), this, SLOT(started()));
87	connect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(detach()));
88	connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(stopped()));
89}
90
91void GDBWindow::stopped() {
92	m_portEdit->setEnabled(true);
93	m_bindAddressEdit->setEnabled(true);
94	m_startStopButton->setText(tr("Start"));
95	disconnect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(detach()));
96	disconnect(m_startStopButton, SIGNAL(clicked()), this, SLOT(stopped()));
97	connect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(listen()));
98	connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(started()));
99}