Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #8804 from iwubcode/dsu-improvements
DolphinQt / InputCommon - Support multiple DSU servers
- Loading branch information
Showing
11 changed files
with
442 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Source/Core/DolphinQt/Config/ControllerInterface/DualShockUDPClientAddServerDialog.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2020 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #include "DolphinQt/Config/ControllerInterface/DualShockUDPClientAddServerDialog.h" | ||
|
|
||
| #include <fmt/format.h> | ||
|
|
||
| #include <QButtonGroup> | ||
| #include <QDialog> | ||
| #include <QDialogButtonBox> | ||
| #include <QGridLayout> | ||
| #include <QLabel> | ||
| #include <QLineEdit> | ||
| #include <QPushButton> | ||
| #include <QSpinBox> | ||
| #include <QString> | ||
| #include <QWidget> | ||
|
|
||
| #include "Common/Config/Config.h" | ||
| #include "DolphinQt/Config/ControllerInterface/ServerStringValidator.h" | ||
| #include "InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.h" | ||
|
|
||
| DualShockUDPClientAddServerDialog::DualShockUDPClientAddServerDialog(QWidget* parent) | ||
| : QDialog(parent) | ||
| { | ||
| CreateWidgets(); | ||
| setLayout(m_main_layout); | ||
| } | ||
|
|
||
| void DualShockUDPClientAddServerDialog::CreateWidgets() | ||
| { | ||
| setWindowTitle(tr("Add New DSU Server")); | ||
| setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | ||
|
|
||
| m_main_layout = new QGridLayout; | ||
|
|
||
| m_description = new QLineEdit(); | ||
| m_description->setPlaceholderText(tr("BetterJoy, DS4Windows, etc")); | ||
| m_description->setValidator(new ServerStringValidator(m_description)); | ||
|
|
||
| m_server_address = | ||
| new QLineEdit(QString::fromStdString(ciface::DualShockUDPClient::DEFAULT_SERVER_ADDRESS)); | ||
| m_server_address->setValidator(new ServerStringValidator(m_server_address)); | ||
|
|
||
| m_server_port = new QSpinBox(); | ||
| m_server_port->setMaximum(65535); | ||
| m_server_port->setValue(ciface::DualShockUDPClient::DEFAULT_SERVER_PORT); | ||
|
|
||
| m_main_layout->addWidget(new QLabel(tr("Description")), 1, 0); | ||
| m_main_layout->addWidget(m_description, 1, 1); | ||
| m_main_layout->addWidget(new QLabel(tr("Server IP Address")), 2, 0); | ||
| m_main_layout->addWidget(m_server_address, 2, 1); | ||
| m_main_layout->addWidget(new QLabel(tr("Server Port")), 3, 0); | ||
| m_main_layout->addWidget(m_server_port, 3, 1); | ||
|
|
||
| m_buttonbox = new QDialogButtonBox(); | ||
| auto* add_button = new QPushButton(tr("Add")); | ||
| auto* cancel_button = new QPushButton(tr("Cancel")); | ||
| m_buttonbox->addButton(add_button, QDialogButtonBox::AcceptRole); | ||
| m_buttonbox->addButton(cancel_button, QDialogButtonBox::RejectRole); | ||
| connect(add_button, &QPushButton::clicked, this, | ||
| &DualShockUDPClientAddServerDialog::OnServerAdded); | ||
| connect(cancel_button, &QPushButton::clicked, this, &DualShockUDPClientAddServerDialog::reject); | ||
| add_button->setDefault(true); | ||
|
|
||
| m_main_layout->addWidget(m_buttonbox, 4, 0, 1, 2); | ||
| } | ||
|
|
||
| void DualShockUDPClientAddServerDialog::OnServerAdded() | ||
| { | ||
| const auto& servers_setting = Config::Get(ciface::DualShockUDPClient::Settings::SERVERS); | ||
| Config::SetBaseOrCurrent(ciface::DualShockUDPClient::Settings::SERVERS, | ||
| servers_setting + fmt::format("{}:{}:{};", | ||
| m_description->text().toStdString(), | ||
| m_server_address->text().toStdString(), | ||
| m_server_port->value())); | ||
| accept(); | ||
| } |
29 changes: 29 additions & 0 deletions
29
Source/Core/DolphinQt/Config/ControllerInterface/DualShockUDPClientAddServerDialog.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2020 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QDialog> | ||
|
|
||
| class QDialogButtonBox; | ||
| class QGridLayout; | ||
| class QLineEdit; | ||
| class QSpinBox; | ||
|
|
||
| class DualShockUDPClientAddServerDialog final : public QDialog | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit DualShockUDPClientAddServerDialog(QWidget* parent); | ||
|
|
||
| private: | ||
| void CreateWidgets(); | ||
| void OnServerAdded(); | ||
|
|
||
| QDialogButtonBox* m_buttonbox; | ||
| QGridLayout* m_main_layout; | ||
| QLineEdit* m_description; | ||
| QLineEdit* m_server_address; | ||
| QSpinBox* m_server_port; | ||
| }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Source/Core/DolphinQt/Config/ControllerInterface/ServerStringValidator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2020 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #include "DolphinQt/Config/ControllerInterface/ServerStringValidator.h" | ||
|
|
||
| ServerStringValidator::ServerStringValidator(QObject* parent) : QValidator(parent) | ||
| { | ||
| } | ||
|
|
||
| QValidator::State ServerStringValidator::validate(QString& input, int& pos) const | ||
| { | ||
| if (input.isEmpty()) | ||
| return Invalid; | ||
|
|
||
| if (input.contains(QStringLiteral(":"))) | ||
| return Invalid; | ||
|
|
||
| if (input.contains(QStringLiteral(";"))) | ||
| return Invalid; | ||
|
|
||
| return Acceptable; | ||
| } |
16 changes: 16 additions & 0 deletions
16
Source/Core/DolphinQt/Config/ControllerInterface/ServerStringValidator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2020 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QValidator> | ||
|
|
||
| class ServerStringValidator : public QValidator | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit ServerStringValidator(QObject* parent); | ||
|
|
||
| State validate(QString& input, int& pos) const override; | ||
| }; |
Oops, something went wrong.