Skip to content

Commit c7ae97f

Browse files
committed
Qt: add button to remove gamepad config
1 parent d61f410 commit c7ae97f

File tree

3 files changed

+108
-32
lines changed

3 files changed

+108
-32
lines changed

rpcs3/rpcs3qt/pad_settings_dialog.cpp

Lines changed: 91 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "Emu/System.h"
1818
#include "Emu/system_utils.hpp"
19+
#include "Utilities/File.h"
1920

2021
#include "Input/pad_thread.h"
2122
#include "Input/gui_pad_thread.h"
@@ -86,21 +87,7 @@ pad_settings_dialog::pad_settings_dialog(std::shared_ptr<gui_settings> gui_setti
8687

8788
if (m_title_id.empty())
8889
{
89-
const QString input_config_dir = QString::fromStdString(rpcs3::utils::get_input_config_dir(m_title_id));
90-
QStringList config_files = gui::utils::get_dir_entries(QDir(input_config_dir), QStringList() << "*.yml");
91-
QString active_config_file = QString::fromStdString(g_cfg_input_configs.active_configs.get_value(g_cfg_input_configs.global_key));
92-
93-
if (!config_files.contains(active_config_file))
94-
{
95-
const QString default_config_file = QString::fromStdString(g_cfg_input_configs.default_config);
96-
97-
if (!config_files.contains(default_config_file) && CreateConfigFile(input_config_dir, default_config_file))
98-
{
99-
config_files.prepend(default_config_file);
100-
}
101-
102-
active_config_file = default_config_file;
103-
}
90+
const auto [config_files, active_config_file] = get_config_files();
10491

10592
for (const QString& profile : config_files)
10693
{
@@ -145,6 +132,9 @@ pad_settings_dialog::pad_settings_dialog(std::shared_ptr<gui_settings> gui_setti
145132
// Pushbutton: Add config file
146133
connect(ui->b_addConfig, &QAbstractButton::clicked, this, &pad_settings_dialog::AddConfigFile);
147134

135+
// Pushbutton: Remove config file
136+
connect(ui->b_remConfig, &QAbstractButton::clicked, this, &pad_settings_dialog::RemoveConfigFile);
137+
148138
ui->buttonBox->button(QDialogButtonBox::Reset)->setText(tr("Filter Noise"));
149139

150140
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](QAbstractButton* button)
@@ -272,6 +262,27 @@ void pad_settings_dialog::showEvent(QShowEvent* event)
272262
QDialog::showEvent(event);
273263
}
274264

265+
std::pair<QStringList, QString> pad_settings_dialog::get_config_files()
266+
{
267+
const QString input_config_dir = QString::fromStdString(rpcs3::utils::get_input_config_dir(m_title_id));
268+
QStringList config_files = gui::utils::get_dir_entries(QDir(input_config_dir), QStringList() << "*.yml");
269+
QString active_config_file = QString::fromStdString(g_cfg_input_configs.active_configs.get_value(g_cfg_input_configs.global_key));
270+
271+
if (!config_files.contains(active_config_file))
272+
{
273+
const QString default_config_file = QString::fromStdString(g_cfg_input_configs.default_config);
274+
275+
if (!config_files.contains(default_config_file) && CreateConfigFile(input_config_dir, default_config_file))
276+
{
277+
config_files.prepend(default_config_file);
278+
}
279+
280+
active_config_file = default_config_file;
281+
}
282+
283+
return std::make_pair<QStringList, QString>(std::move(config_files), std::move(active_config_file));
284+
}
285+
275286
void pad_settings_dialog::InitButtons()
276287
{
277288
m_pad_buttons = new QButtonGroup(this);
@@ -321,6 +332,7 @@ void pad_settings_dialog::InitButtons()
321332

322333
m_pad_buttons->addButton(ui->b_refresh, button_ids::id_refresh);
323334
m_pad_buttons->addButton(ui->b_addConfig, button_ids::id_add_config_file);
335+
m_pad_buttons->addButton(ui->b_remConfig, button_ids::id_remove_config_file);
324336

325337
connect(m_pad_buttons, &QButtonGroup::idClicked, this, &pad_settings_dialog::OnPadButtonClicked);
326338

@@ -1320,6 +1332,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
13201332
case button_ids::id_pad_begin:
13211333
case button_ids::id_pad_end:
13221334
case button_ids::id_add_config_file:
1335+
case button_ids::id_remove_config_file:
13231336
case button_ids::id_refresh:
13241337
return;
13251338
case button_ids::id_reset_parameters:
@@ -1636,6 +1649,8 @@ void pad_settings_dialog::ChangeConfig(const QString& config_file)
16361649

16371650
m_config_file = config_file.toStdString();
16381651

1652+
ui->b_remConfig->setEnabled(m_title_id.empty() && m_config_file != g_cfg_input_configs.default_config);
1653+
16391654
// Load in order to get the pad handlers
16401655
if (!g_cfg_input.load(m_title_id, m_config_file, true))
16411656
{
@@ -1810,6 +1825,44 @@ void pad_settings_dialog::AddConfigFile()
18101825
}
18111826
}
18121827

1828+
void pad_settings_dialog::RemoveConfigFile()
1829+
{
1830+
const std::string config_to_remove = m_config_file;
1831+
const QString q_config_to_remove = QString::fromStdString(config_to_remove);
1832+
1833+
if (config_to_remove == g_cfg_input_configs.default_config)
1834+
{
1835+
QMessageBox::warning(this, tr("Warning!"), tr("Can't remove default configuration '%0'.").arg(q_config_to_remove));
1836+
return;
1837+
}
1838+
1839+
if (QMessageBox::question(this, tr("Remove Configuration?"), tr("Do you really want to remove the configuration '%0'?").arg(q_config_to_remove)) != QMessageBox::StandardButton::Yes)
1840+
{
1841+
return;
1842+
}
1843+
1844+
const std::string filepath = fmt::format("%s%s.yml", rpcs3::utils::get_input_config_dir(m_title_id), config_to_remove);
1845+
1846+
if (!fs::remove_file(filepath))
1847+
{
1848+
QMessageBox::warning(this, tr("Warning!"), tr("Failed to remove '%0'.").arg(QString::fromStdString(filepath)));
1849+
return;
1850+
}
1851+
1852+
const auto [config_files, active_config_file] = get_config_files();
1853+
1854+
ui->chooseConfig->setCurrentText(active_config_file);
1855+
ui->chooseConfig->removeItem(ui->chooseConfig->findText(q_config_to_remove));
1856+
1857+
// Save new config if we removed the currently saved config
1858+
if (active_config_file == q_config_to_remove)
1859+
{
1860+
save(false);
1861+
}
1862+
1863+
QMessageBox::information(this, tr("Removed Configuration"), tr("Removed configuration '%0'.\nThe selected configuration is now '%1'.").arg(q_config_to_remove).arg(active_config_file));
1864+
}
1865+
18131866
void pad_settings_dialog::RefreshHandlers()
18141867
{
18151868
const u32 player_id = GetPlayerIndex();
@@ -1949,27 +2002,30 @@ void pad_settings_dialog::ApplyCurrentPlayerConfig(int new_player_id)
19492002
cfg.product_id.set(info.product_id);
19502003
}
19512004

1952-
void pad_settings_dialog::SaveExit()
2005+
void pad_settings_dialog::save(bool check_duplicates)
19532006
{
19542007
ApplyCurrentPlayerConfig(m_last_player_id);
19552008

1956-
for (const auto& [player_id, key] : m_duplicate_buttons)
2009+
if (check_duplicates)
19572010
{
1958-
if (!key.empty())
2011+
for (const auto& [player_id, key] : m_duplicate_buttons)
19592012
{
1960-
int result = QMessageBox::Yes;
1961-
m_gui_settings->ShowConfirmationBox(
1962-
tr("Warning!"),
1963-
tr("The %0 button <b>%1</b> of <b>Player %2</b> was assigned at least twice.<br>Please consider adjusting the configuration.<br><br>Continue anyway?<br>")
1964-
.arg(QString::fromStdString(g_cfg_input.player[player_id]->handler.to_string()))
1965-
.arg(QString::fromStdString(key))
1966-
.arg(player_id + 1),
1967-
gui::ib_same_buttons, &result, this);
1968-
1969-
if (result == QMessageBox::No)
1970-
return;
2013+
if (!key.empty())
2014+
{
2015+
int result = QMessageBox::Yes;
2016+
m_gui_settings->ShowConfirmationBox(
2017+
tr("Warning!"),
2018+
tr("The %0 button <b>%1</b> of <b>Player %2</b> was assigned at least twice.<br>Please consider adjusting the configuration.<br><br>Continue anyway?<br>")
2019+
.arg(QString::fromStdString(g_cfg_input.player[player_id]->handler.to_string()))
2020+
.arg(QString::fromStdString(key))
2021+
.arg(player_id + 1),
2022+
gui::ib_same_buttons, &result, this);
2023+
2024+
if (result == QMessageBox::No)
2025+
return;
19712026

1972-
break;
2027+
break;
2028+
}
19732029
}
19742030
}
19752031

@@ -1979,6 +2035,11 @@ void pad_settings_dialog::SaveExit()
19792035
g_cfg_input_configs.save();
19802036

19812037
g_cfg_input.save(m_title_id, m_config_file);
2038+
}
2039+
2040+
void pad_settings_dialog::SaveExit()
2041+
{
2042+
save(true);
19822043

19832044
QDialog::accept();
19842045
}

rpcs3/rpcs3qt/pad_settings_dialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class pad_settings_dialog : public QDialog
7474
id_reset_parameters,
7575
id_blacklist,
7676
id_refresh,
77-
id_add_config_file
77+
id_add_config_file,
78+
id_remove_config_file
7879
};
7980

8081
struct pad_button
@@ -101,6 +102,7 @@ private Q_SLOTS:
101102
void ChangeDevice(int index);
102103
void HandleDeviceClassChange(u32 class_id) const;
103104
void AddConfigFile();
105+
void RemoveConfigFile();
104106
/** Update the current player config with the GUI values. */
105107
void ApplyCurrentPlayerConfig(int new_player_id);
106108
void RefreshPads();
@@ -192,6 +194,9 @@ private Q_SLOTS:
192194
void start_input_thread();
193195
void pause_input_thread();
194196

197+
std::pair<QStringList, QString> get_config_files();
198+
199+
void save(bool check_duplicates);
195200
void SaveExit();
196201
void CancelExit();
197202

rpcs3/rpcs3qt/pad_settings_dialog.ui

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@
170170
<item>
171171
<widget class="QPushButton" name="b_addConfig">
172172
<property name="text">
173-
<string>Add Configuration</string>
173+
<string>Add New</string>
174+
</property>
175+
<property name="autoDefault">
176+
<bool>false</bool>
177+
</property>
178+
</widget>
179+
</item>
180+
<item>
181+
<widget class="QPushButton" name="b_remConfig">
182+
<property name="text">
183+
<string>Remove</string>
174184
</property>
175185
<property name="autoDefault">
176186
<bool>false</bool>

0 commit comments

Comments
 (0)