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