2021-12-10 02:10:24 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2019-10-26 16:05:16 +00:00
|
|
|
#include "DolphinQt/Config/ControllerInterface/DualShockUDPClientWidget.h"
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2020-05-09 20:44:45 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
2019-10-22 23:49:48 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLabel>
|
2020-05-09 20:44:45 +00:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2019-10-22 23:49:48 +00:00
|
|
|
|
|
|
|
#include "Common/Config/Config.h"
|
2020-05-09 20:44:45 +00:00
|
|
|
#include "DolphinQt/Config/ControllerInterface/DualShockUDPClientAddServerDialog.h"
|
2022-03-08 07:51:29 +00:00
|
|
|
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
2019-10-26 16:05:16 +00:00
|
|
|
#include "InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.h"
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2019-10-26 16:05:16 +00:00
|
|
|
DualShockUDPClientWidget::DualShockUDPClientWidget()
|
2019-10-22 23:49:48 +00:00
|
|
|
{
|
|
|
|
CreateWidgets();
|
|
|
|
ConnectWidgets();
|
|
|
|
}
|
|
|
|
|
2019-10-26 16:05:16 +00:00
|
|
|
void DualShockUDPClientWidget::CreateWidgets()
|
2019-10-22 23:49:48 +00:00
|
|
|
{
|
2020-05-09 20:44:45 +00:00
|
|
|
auto* main_layout = new QVBoxLayout;
|
|
|
|
|
|
|
|
m_servers_enabled = new QCheckBox(tr("Enable"));
|
|
|
|
m_servers_enabled->setChecked(Config::Get(ciface::DualShockUDPClient::Settings::SERVERS_ENABLED));
|
2020-08-22 01:09:04 +00:00
|
|
|
main_layout->addWidget(m_servers_enabled, 0, {});
|
2020-05-09 20:44:45 +00:00
|
|
|
|
|
|
|
m_server_list = new QListWidget();
|
|
|
|
main_layout->addWidget(m_server_list);
|
|
|
|
|
2022-03-08 07:51:29 +00:00
|
|
|
m_add_server = new NonDefaultQPushButton(tr("Add..."));
|
2020-05-09 20:44:45 +00:00
|
|
|
m_add_server->setEnabled(m_servers_enabled->isChecked());
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2022-03-08 07:51:29 +00:00
|
|
|
m_remove_server = new NonDefaultQPushButton(tr("Remove"));
|
2020-05-09 20:44:45 +00:00
|
|
|
m_remove_server->setEnabled(m_servers_enabled->isChecked());
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2020-05-09 20:44:45 +00:00
|
|
|
QHBoxLayout* hlayout = new QHBoxLayout;
|
|
|
|
hlayout->addStretch();
|
|
|
|
hlayout->addWidget(m_add_server);
|
|
|
|
hlayout->addWidget(m_remove_server);
|
2019-10-22 23:49:48 +00:00
|
|
|
|
2020-05-09 20:44:45 +00:00
|
|
|
main_layout->addItem(hlayout);
|
2019-10-22 23:49:48 +00:00
|
|
|
|
|
|
|
auto* description =
|
2019-10-26 16:05:16 +00:00
|
|
|
new QLabel(tr("DSU protocol enables the use of input and motion data from compatible "
|
2019-10-22 23:49:48 +00:00
|
|
|
"sources, like PlayStation, Nintendo Switch and Steam controllers.<br><br>"
|
|
|
|
"For setup instructions, "
|
2019-10-26 16:05:16 +00:00
|
|
|
"<a href=\"https://wiki.dolphin-emu.org/index.php?title=DSU_Client\">"
|
2019-10-22 23:49:48 +00:00
|
|
|
"refer to this page</a>."));
|
|
|
|
description->setTextFormat(Qt::RichText);
|
|
|
|
description->setWordWrap(true);
|
|
|
|
description->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
|
|
|
description->setOpenExternalLinks(true);
|
2020-05-09 20:44:45 +00:00
|
|
|
main_layout->addWidget(description);
|
2019-10-22 23:49:48 +00:00
|
|
|
|
|
|
|
setLayout(main_layout);
|
2020-05-09 20:44:45 +00:00
|
|
|
|
|
|
|
RefreshServerList();
|
2019-10-22 23:49:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 16:05:16 +00:00
|
|
|
void DualShockUDPClientWidget::ConnectWidgets()
|
2019-10-22 23:49:48 +00:00
|
|
|
{
|
2020-05-09 20:44:45 +00:00
|
|
|
connect(m_servers_enabled, &QCheckBox::clicked, this,
|
|
|
|
&DualShockUDPClientWidget::OnServersToggled);
|
|
|
|
connect(m_add_server, &QPushButton::clicked, this, &DualShockUDPClientWidget::OnServerAdded);
|
|
|
|
connect(m_remove_server, &QPushButton::clicked, this, &DualShockUDPClientWidget::OnServerRemoved);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DualShockUDPClientWidget::RefreshServerList()
|
|
|
|
{
|
|
|
|
m_server_list->clear();
|
|
|
|
|
2020-07-13 05:26:43 +00:00
|
|
|
const auto server_address_setting =
|
|
|
|
Config::Get(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS);
|
|
|
|
const auto server_port_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVER_PORT);
|
|
|
|
|
|
|
|
// Update our servers setting if the user is using old configuration
|
|
|
|
if (!server_address_setting.empty() && server_port_setting != 0)
|
|
|
|
{
|
|
|
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
|
|
|
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS,
|
|
|
|
servers_setting + fmt::format("{}:{}:{};", "DS4",
|
|
|
|
server_address_setting,
|
|
|
|
server_port_setting));
|
|
|
|
Config::SetBase(ciface::DualShockUDPClient::Settings::SERVER_ADDRESS, "");
|
|
|
|
Config::SetBase(ciface::DualShockUDPClient::Settings::SERVER_PORT, 0);
|
|
|
|
}
|
|
|
|
|
2020-05-09 20:44:45 +00:00
|
|
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
|
|
|
const auto server_details = SplitString(servers_setting, ';');
|
|
|
|
for (const std::string& server_detail : server_details)
|
|
|
|
{
|
|
|
|
const auto server_info = SplitString(server_detail, ':');
|
|
|
|
if (server_info.size() < 3)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QListWidgetItem* list_item = new QListWidgetItem(QString::fromStdString(
|
|
|
|
fmt::format("{}:{} - {}", server_info[1], server_info[2], server_info[0])));
|
|
|
|
m_server_list->addItem(list_item);
|
|
|
|
}
|
|
|
|
emit ConfigChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DualShockUDPClientWidget::OnServerAdded()
|
|
|
|
{
|
|
|
|
DualShockUDPClientAddServerDialog add_server_dialog(this);
|
|
|
|
connect(&add_server_dialog, &DualShockUDPClientAddServerDialog::accepted, this,
|
|
|
|
&DualShockUDPClientWidget::RefreshServerList);
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(&add_server_dialog);
|
2020-05-09 20:44:45 +00:00
|
|
|
add_server_dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DualShockUDPClientWidget::OnServerRemoved()
|
|
|
|
{
|
|
|
|
const int row_to_remove = m_server_list->currentRow();
|
|
|
|
|
|
|
|
const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS);
|
|
|
|
const auto server_details = SplitString(servers_setting, ';');
|
|
|
|
|
|
|
|
std::string new_server_setting;
|
|
|
|
for (int i = 0; i < m_server_list->count(); i++)
|
|
|
|
{
|
|
|
|
if (i == row_to_remove)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_server_setting += server_details[i] + ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS, new_server_setting);
|
|
|
|
|
|
|
|
RefreshServerList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DualShockUDPClientWidget::OnServersToggled()
|
|
|
|
{
|
|
|
|
bool checked = m_servers_enabled->isChecked();
|
|
|
|
Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS_ENABLED, checked);
|
|
|
|
m_add_server->setEnabled(checked);
|
|
|
|
m_remove_server->setEnabled(checked);
|
2019-10-22 23:49:48 +00:00
|
|
|
}
|