2021-09-08 20:08:43 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "DolphinQt/Settings/BroadbandAdapterSettingsDialog.h"
|
|
|
|
|
|
|
|
#include <regex>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/StringUtil.h"
|
2022-01-03 06:07:32 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2021-09-08 20:08:43 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
|
|
|
|
|
|
BroadbandAdapterSettingsDialog::BroadbandAdapterSettingsDialog(QWidget* parent, Type bba_type)
|
|
|
|
: QDialog(parent)
|
|
|
|
{
|
|
|
|
m_bba_type = bba_type;
|
|
|
|
InitControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BroadbandAdapterSettingsDialog::InitControls()
|
|
|
|
{
|
|
|
|
QLabel* address_label = nullptr;
|
|
|
|
QLabel* description = nullptr;
|
|
|
|
QString address_placeholder;
|
|
|
|
QString current_address;
|
|
|
|
QString window_title;
|
|
|
|
|
|
|
|
switch (m_bba_type)
|
|
|
|
{
|
|
|
|
case Type::Ethernet:
|
|
|
|
// i18n: MAC stands for Media Access Control. A MAC address uniquely identifies a network
|
|
|
|
// interface (physical) like a serial number. "MAC" should be kept in translations.
|
|
|
|
address_label = new QLabel(tr("Enter new Broadband Adapter MAC address:"));
|
|
|
|
address_placeholder = QString::fromStdString("aa:bb:cc:dd:ee:ff");
|
2022-01-03 06:07:32 +00:00
|
|
|
current_address = QString::fromStdString(Config::Get(Config::MAIN_BBA_MAC));
|
2021-09-08 20:08:43 +00:00
|
|
|
description = new QLabel(tr("For setup instructions, <a "
|
|
|
|
"href=\"https://wiki.dolphin-emu.org/"
|
|
|
|
"index.php?title=Broadband_Adapter\">refer to this page</a>."));
|
|
|
|
|
|
|
|
// i18n: MAC stands for Media Access Control. A MAC address uniquely identifies a network
|
|
|
|
// interface (physical) like a serial number. "MAC" should be kept in translations.
|
|
|
|
window_title = tr("Broadband Adapter MAC Address");
|
|
|
|
break;
|
|
|
|
|
2022-05-22 16:21:28 +00:00
|
|
|
case Type::BuiltIn:
|
|
|
|
address_label = new QLabel(tr("Enter the DNS server to use:"));
|
2022-07-08 14:20:18 +00:00
|
|
|
address_placeholder = QStringLiteral("8.8.8.8");
|
2022-05-22 16:21:28 +00:00
|
|
|
current_address = QString::fromStdString(Config::Get(Config::MAIN_BBA_BUILTIN_DNS));
|
|
|
|
description = new QLabel(tr("Use 8.8.8.8 for normal DNS, else enter your custom one"));
|
|
|
|
|
|
|
|
window_title = tr("Broadband Adapter DNS setting");
|
|
|
|
break;
|
|
|
|
|
2021-09-08 20:08:43 +00:00
|
|
|
case Type::XLinkKai:
|
|
|
|
address_label = new QLabel(tr("Enter IP address of device running the XLink Kai Client:"));
|
|
|
|
address_placeholder = QString::fromStdString("127.0.0.1");
|
2022-01-03 06:07:32 +00:00
|
|
|
current_address = QString::fromStdString(Config::Get(Config::MAIN_BBA_XLINK_IP));
|
2021-09-08 20:08:43 +00:00
|
|
|
description =
|
|
|
|
new QLabel(tr("For setup instructions, <a "
|
|
|
|
"href=\"https://www.teamxlink.co.uk/wiki/Dolphin\">refer to this page</a>."));
|
|
|
|
window_title = tr("XLink Kai BBA Destination Address");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(window_title);
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
m_address_input = new QLineEdit(current_address);
|
|
|
|
m_address_input->setPlaceholderText(address_placeholder);
|
|
|
|
|
|
|
|
auto buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
connect(buttonbox, &QDialogButtonBox::accepted, this,
|
|
|
|
&BroadbandAdapterSettingsDialog::SaveAddress);
|
|
|
|
connect(buttonbox, &QDialogButtonBox::rejected, this, &BroadbandAdapterSettingsDialog::reject);
|
|
|
|
|
|
|
|
description->setTextFormat(Qt::RichText);
|
|
|
|
description->setWordWrap(true);
|
|
|
|
description->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
|
|
|
description->setOpenExternalLinks(true);
|
|
|
|
|
|
|
|
auto* main_layout = new QVBoxLayout();
|
|
|
|
main_layout->addWidget(address_label);
|
|
|
|
main_layout->addWidget(m_address_input);
|
|
|
|
main_layout->addWidget(description);
|
|
|
|
main_layout->addWidget(buttonbox);
|
|
|
|
|
|
|
|
setLayout(main_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BroadbandAdapterSettingsDialog::SaveAddress()
|
|
|
|
{
|
2022-07-19 22:13:26 +00:00
|
|
|
const std::string bba_new_address(StripWhitespace(m_address_input->text().toStdString()));
|
2021-09-08 20:08:43 +00:00
|
|
|
|
|
|
|
switch (m_bba_type)
|
|
|
|
{
|
|
|
|
case Type::Ethernet:
|
2023-06-08 01:07:54 +00:00
|
|
|
{
|
|
|
|
static const std::regex re_mac_address("([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})");
|
|
|
|
if (!std::regex_match(bba_new_address, re_mac_address))
|
2021-09-08 20:08:43 +00:00
|
|
|
{
|
|
|
|
ModalMessageBox::critical(
|
|
|
|
this, tr("Broadband Adapter Error"),
|
|
|
|
// i18n: MAC stands for Media Access Control. A MAC address uniquely identifies a network
|
|
|
|
// interface (physical) like a serial number. "MAC" should be kept in translations.
|
|
|
|
tr("The entered MAC address is invalid."));
|
|
|
|
return;
|
|
|
|
}
|
2022-01-03 06:07:32 +00:00
|
|
|
Config::SetBaseOrCurrent(Config::MAIN_BBA_MAC, bba_new_address);
|
2021-09-08 20:08:43 +00:00
|
|
|
break;
|
2023-06-08 01:07:54 +00:00
|
|
|
}
|
2022-05-22 16:21:28 +00:00
|
|
|
case Type::BuiltIn:
|
|
|
|
Config::SetBaseOrCurrent(Config::MAIN_BBA_BUILTIN_DNS, bba_new_address);
|
|
|
|
break;
|
2021-09-08 20:08:43 +00:00
|
|
|
case Type::XLinkKai:
|
2022-01-03 06:07:32 +00:00
|
|
|
Config::SetBaseOrCurrent(Config::MAIN_BBA_XLINK_IP, bba_new_address);
|
2021-09-08 20:08:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
accept();
|
|
|
|
}
|