Qt: Replace QtSettingsInterface with INISettingsInterface

This commit is contained in:
Albert Liu 2020-07-13 09:24:11 -07:00
parent 9b2740b395
commit 4e2b3189b0
19 changed files with 335 additions and 454 deletions

View file

@ -47,8 +47,6 @@ add_executable(duckstation-qt
qthostinterface.h qthostinterface.h
qtprogresscallback.cpp qtprogresscallback.cpp
qtprogresscallback.h qtprogresscallback.h
qtsettingsinterface.cpp
qtsettingsinterface.h
qtutils.cpp qtutils.cpp
qtutils.h qtutils.h
settingsdialog.cpp settingsdialog.cpp

View file

@ -9,25 +9,29 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(QtHostInterface* host_interface,
for (u32 i = 0; i < static_cast<u32>(LOGLEVEL_COUNT); i++) for (u32 i = 0; i < static_cast<u32>(LOGLEVEL_COUNT); i++)
m_ui.logLevel->addItem(tr(Settings::GetLogLevelDisplayName(static_cast<LOGLEVEL>(i)))); m_ui.logLevel->addItem(tr(Settings::GetLogLevelDisplayName(static_cast<LOGLEVEL>(i))));
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.logLevel, QStringLiteral("Logging/LogLevel"), SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.logLevel, QStringLiteral("Logging"),
&Settings::ParseLogLevelName, &Settings::GetLogLevelName, QStringLiteral("LogLevel"), &Settings::ParseLogLevelName,
Settings::DEFAULT_LOG_LEVEL); &Settings::GetLogLevelName, Settings::DEFAULT_LOG_LEVEL);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, m_ui.logFilter, QStringLiteral("Logging/LogFilter")); SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, m_ui.logFilter, QStringLiteral("Logging"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToConsole, QStringLiteral("LogFilter"));
QStringLiteral("Logging/LogToConsole")); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToConsole, QStringLiteral("Logging"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToDebug, QStringLiteral("Logging/LogToDebug")); QStringLiteral("LogToConsole"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToWindow, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToDebug, QStringLiteral("Logging"),
QStringLiteral("Logging/LogToWindow")); QStringLiteral("LogToDebug"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToFile, QStringLiteral("Logging/LogToFile")); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToWindow, QStringLiteral("Logging"),
QStringLiteral("LogToWindow"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.logToFile, QStringLiteral("Logging"),
QStringLiteral("LogToFile"));
// Tweaks/Hacks section // Tweaks/Hacks section
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.dmaMaxSliceTicks, SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.dmaMaxSliceTicks, QStringLiteral("Hacks"),
QStringLiteral("Hacks/DMAMaxSliceTicks")); QStringLiteral("DMAMaxSliceTicks"));
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.dmaHaltTicks, SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.dmaHaltTicks, QStringLiteral("Hacks"),
QStringLiteral("Hacks/DMAHaltTicks")); QStringLiteral("DMAHaltTicks"));
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.gpuFIFOSize, QStringLiteral("Hacks/GPUFIFOSize")); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.gpuFIFOSize, QStringLiteral("Hacks"),
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.gpuMaxRunAhead, QStringLiteral("GPUFIFOSize"));
QStringLiteral("Hacks/GPUMaxRunAhead")); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.gpuMaxRunAhead, QStringLiteral("Hacks"),
QStringLiteral("GPUMaxRunAhead"));
connect(m_ui.resetToDefaultButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::onResetToDefaultClicked); connect(m_ui.resetToDefaultButton, &QPushButton::clicked, this, &AdvancedSettingsWidget::onResetToDefaultClicked);
} }

View file

@ -11,14 +11,19 @@ AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidge
for (u32 i = 0; i < static_cast<u32>(AudioBackend::Count); i++) for (u32 i = 0; i < static_cast<u32>(AudioBackend::Count); i++)
m_ui.audioBackend->addItem(tr(Settings::GetAudioBackendDisplayName(static_cast<AudioBackend>(i)))); m_ui.audioBackend->addItem(tr(Settings::GetAudioBackendDisplayName(static_cast<AudioBackend>(i))));
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.audioBackend, "Audio/Backend", SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.audioBackend, QStringLiteral("Audio"),
&Settings::ParseAudioBackend, &Settings::GetAudioBackendName, QStringLiteral("Backend"), &Settings::ParseAudioBackend,
Settings::DEFAULT_AUDIO_BACKEND); &Settings::GetAudioBackendName, Settings::DEFAULT_AUDIO_BACKEND);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.syncToOutput, "Audio/Sync"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.syncToOutput, QStringLiteral("Audio"),
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.bufferSize, "Audio/BufferSize"); QStringLiteral("Sync"));
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.volume, "Audio/OutputVolume"); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.bufferSize, QStringLiteral("Audio"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.muted, "Audio/OutputMuted"); QStringLiteral("BufferSize"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startDumpingOnBoot, "Audio/DumpOnBoot"); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.volume, QStringLiteral("Audio"),
QStringLiteral("OutputVolume"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.muted, QStringLiteral("Audio"),
QStringLiteral("OutputMuted"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startDumpingOnBoot, QStringLiteral("Audio"),
QStringLiteral("DumpOnBoot"));
connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel); connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel);
connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::updateVolumeLabel); connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::updateVolumeLabel);

View file

@ -15,17 +15,22 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW
for (u32 i = 0; i < static_cast<u32>(CPUExecutionMode::Count); i++) for (u32 i = 0; i < static_cast<u32>(CPUExecutionMode::Count); i++)
m_ui.cpuExecutionMode->addItem(tr(Settings::GetCPUExecutionModeDisplayName(static_cast<CPUExecutionMode>(i)))); m_ui.cpuExecutionMode->addItem(tr(Settings::GetCPUExecutionModeDisplayName(static_cast<CPUExecutionMode>(i))));
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.region, "Console/Region", SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.region, QStringLiteral("Console"),
&Settings::ParseConsoleRegionName, &Settings::GetConsoleRegionName, QStringLiteral("Region"), &Settings::ParseConsoleRegionName,
Settings::DEFAULT_CONSOLE_REGION); &Settings::GetConsoleRegionName, Settings::DEFAULT_CONSOLE_REGION);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, m_ui.biosPath, "BIOS/Path"); SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, m_ui.biosPath, QStringLiteral("BIOS"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableTTYOutput, "BIOS/PatchTTYEnable"); QStringLiteral("Path"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.fastBoot, "BIOS/PatchFastBoot"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableTTYOutput, QStringLiteral("BIOS"),
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.cpuExecutionMode, "CPU/ExecutionMode", QStringLiteral("PatchTTYEnable"));
&Settings::ParseCPUExecutionMode, &Settings::GetCPUExecutionModeName, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.fastBoot, QStringLiteral("BIOS"),
Settings::DEFAULT_CPU_EXECUTION_MODE); QStringLiteral("PatchFastBoot"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromReadThread, "CDROM/ReadThread"); SettingWidgetBinder::BindWidgetToEnumSetting(
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromRegionCheck, "CDROM/RegionCheck"); m_host_interface, m_ui.cpuExecutionMode, QStringLiteral("CPU"), QStringLiteral("ExecutionMode"),
&Settings::ParseCPUExecutionMode, &Settings::GetCPUExecutionModeName, Settings::DEFAULT_CPU_EXECUTION_MODE);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromReadThread, QStringLiteral("CDROM"),
QStringLiteral("ReadThread"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromRegionCheck, QStringLiteral("CDROM"),
QStringLiteral("RegionCheck"));
connect(m_ui.biosPathBrowse, &QPushButton::pressed, this, &ConsoleSettingsWidget::onBrowseBIOSPathButtonClicked); connect(m_ui.biosPathBrowse, &QPushButton::pressed, this, &ConsoleSettingsWidget::onBrowseBIOSPathButtonClicked);
} }
@ -40,6 +45,6 @@ void ConsoleSettingsWidget::onBrowseBIOSPathButtonClicked()
m_ui.biosPath->setText(path); m_ui.biosPath->setText(path);
m_host_interface->putSettingValue("BIOS/Path", path); m_host_interface->putSettingValue(QStringLiteral("BIOS"), QStringLiteral("Path"), path);
m_host_interface->applySettings(); m_host_interface->applySettings();
} }

View file

@ -45,9 +45,9 @@ void ControllerSettingsWidget::onProfileLoaded()
for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++) for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++)
{ {
ControllerType ctype = Settings::ParseControllerTypeName( ControllerType ctype = Settings::ParseControllerTypeName(
m_host_interface->getSettingValue(QStringLiteral("Controller%1/Type").arg(i + 1)) m_host_interface
.toString() ->GetSettingValue(QStringLiteral("Controller%1").arg(i + 1).toStdString().c_str(),
.toStdString() QStringLiteral("Type").toStdString().c_str())
.c_str()) .c_str())
.value_or(ControllerType::None); .value_or(ControllerType::None);
@ -88,9 +88,9 @@ void ControllerSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* u
QString::fromUtf8(Settings::GetControllerTypeDisplayName(static_cast<ControllerType>(i)))); QString::fromUtf8(Settings::GetControllerTypeDisplayName(static_cast<ControllerType>(i))));
} }
ControllerType ctype = Settings::ParseControllerTypeName( ControllerType ctype = Settings::ParseControllerTypeName(
m_host_interface->getSettingValue(QStringLiteral("Controller%1/Type").arg(index + 1)) m_host_interface
.toString() ->GetSettingValue(QStringLiteral("Controller%1").arg(index + 1).toStdString().c_str(),
.toStdString() QStringLiteral("Type").toStdString().c_str())
.c_str()) .c_str())
.value_or(ControllerType::None); .value_or(ControllerType::None);
ui->controller_type->setCurrentIndex(static_cast<int>(ctype)); ui->controller_type->setCurrentIndex(static_cast<int>(ctype));
@ -195,10 +195,11 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
} }
const QString button_name_q = QString::fromStdString(button_name); const QString button_name_q = QString::fromStdString(button_name);
const QString setting_name = QStringLiteral("Controller%1/Button%2").arg(index + 1).arg(button_name_q); const QString section_name = QStringLiteral("Controller%1").arg(index + 1);
const QString key_name = QStringLiteral("Button%1").arg(button_name_q);
QLabel* label = new QLabel(button_name_q, ui->bindings_container); QLabel* label = new QLabel(button_name_q, ui->bindings_container);
InputButtonBindingWidget* button = InputButtonBindingWidget* button =
new InputButtonBindingWidget(m_host_interface, setting_name, ui->bindings_container); new InputButtonBindingWidget(m_host_interface, section_name, key_name, ui->bindings_container);
layout->addWidget(label, start_row + current_row, current_column); layout->addWidget(label, start_row + current_row, current_column);
layout->addWidget(button, start_row + current_row, current_column + 1); layout->addWidget(button, start_row + current_row, current_column + 1);
@ -232,10 +233,11 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
} }
const QString axis_name_q = QString::fromStdString(axis_name); const QString axis_name_q = QString::fromStdString(axis_name);
const QString setting_name = QStringLiteral("Controller%1/Axis%2").arg(index + 1).arg(axis_name_q); const QString section_name = QStringLiteral("Controller%1").arg(index + 1);
const QString key_name = QStringLiteral("Axis%1").arg(axis_name_q);
QLabel* label = new QLabel(axis_name_q, ui->bindings_container); QLabel* label = new QLabel(axis_name_q, ui->bindings_container);
InputAxisBindingWidget* button = InputAxisBindingWidget* button =
new InputAxisBindingWidget(m_host_interface, setting_name, ui->bindings_container); new InputAxisBindingWidget(m_host_interface, section_name, key_name, ui->bindings_container);
layout->addWidget(label, start_row + current_row, current_column); layout->addWidget(label, start_row + current_row, current_column);
layout->addWidget(button, start_row + current_row, current_column + 1); layout->addWidget(button, start_row + current_row, current_column + 1);
@ -256,10 +258,11 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
{ {
layout->addWidget(QtUtils::CreateHorizontalLine(ui->widget), start_row++, 0, 1, 4); layout->addWidget(QtUtils::CreateHorizontalLine(ui->widget), start_row++, 0, 1, 4);
const QString setting_name = QStringLiteral("Controller%1/Rumble").arg(index + 1); const QString section_name = QStringLiteral("Controller%1").arg(index + 1);
const QString key_name = QStringLiteral("Rumble");
QLabel* label = new QLabel(tr("Rumble"), ui->bindings_container); QLabel* label = new QLabel(tr("Rumble"), ui->bindings_container);
InputRumbleBindingWidget* button = InputRumbleBindingWidget* button =
new InputRumbleBindingWidget(m_host_interface, setting_name, ui->bindings_container); new InputRumbleBindingWidget(m_host_interface, section_name, key_name, ui->bindings_container);
layout->addWidget(label, start_row, 0); layout->addWidget(label, start_row, 0);
layout->addWidget(button, start_row, 1); layout->addWidget(button, start_row, 1);
@ -280,7 +283,8 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
for (const SettingInfo& si : settings) for (const SettingInfo& si : settings)
{ {
const QString setting_name = QStringLiteral("Controller%1/%2").arg(index + 1).arg(si.key); const QString section_name = QStringLiteral("Controller%1").arg(index + 1);
const QString key_name = QStringLiteral("%1").arg(si.key);
const QString setting_tooltip = si.description ? QString::fromUtf8(si.description) : ""; const QString setting_tooltip = si.description ? QString::fromUtf8(si.description) : "";
switch (si.type) switch (si.type)
@ -289,7 +293,8 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
{ {
QCheckBox* cb = new QCheckBox(tr(si.visible_name), ui->bindings_container); QCheckBox* cb = new QCheckBox(tr(si.visible_name), ui->bindings_container);
cb->setToolTip(setting_tooltip); cb->setToolTip(setting_tooltip);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, cb, setting_name, si.BooleanDefaultValue()); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, cb, section_name, key_name,
si.BooleanDefaultValue());
layout->addWidget(cb, start_row, 0, 1, 4); layout->addWidget(cb, start_row, 0, 1, 4);
start_row++; start_row++;
} }
@ -302,7 +307,8 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
sb->setMinimum(si.IntegerMinValue()); sb->setMinimum(si.IntegerMinValue());
sb->setMaximum(si.IntegerMaxValue()); sb->setMaximum(si.IntegerMaxValue());
sb->setSingleStep(si.IntegerStepValue()); sb->setSingleStep(si.IntegerStepValue());
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, sb, setting_name, si.IntegerDefaultValue()); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, sb, section_name, key_name,
si.IntegerDefaultValue());
layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0); layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0);
layout->addWidget(sb, start_row, 1, 1, 3); layout->addWidget(sb, start_row, 1, 1, 3);
start_row++; start_row++;
@ -316,7 +322,8 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
sb->setMinimum(si.FloatMinValue()); sb->setMinimum(si.FloatMinValue());
sb->setMaximum(si.FloatMaxValue()); sb->setMaximum(si.FloatMaxValue());
sb->setSingleStep(si.FloatStepValue()); sb->setSingleStep(si.FloatStepValue());
SettingWidgetBinder::BindWidgetToFloatSetting(m_host_interface, sb, setting_name, si.FloatDefaultValue()); SettingWidgetBinder::BindWidgetToFloatSetting(m_host_interface, sb, section_name, key_name,
si.FloatDefaultValue());
layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0); layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0);
layout->addWidget(sb, start_row, 1, 1, 3); layout->addWidget(sb, start_row, 1, 1, 3);
start_row++; start_row++;
@ -327,7 +334,7 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
{ {
QLineEdit* le = new QLineEdit(ui->bindings_container); QLineEdit* le = new QLineEdit(ui->bindings_container);
le->setToolTip(setting_tooltip); le->setToolTip(setting_tooltip);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, le, setting_name, SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, le, section_name, key_name,
QString::fromUtf8(si.StringDefaultValue())); QString::fromUtf8(si.StringDefaultValue()));
layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0); layout->addWidget(new QLabel(tr(si.visible_name), ui->bindings_container), start_row, 0);
layout->addWidget(le, start_row, 1, 1, 3); layout->addWidget(le, start_row, 1, 1, 3);
@ -340,9 +347,9 @@ void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettin
QLineEdit* le = new QLineEdit(ui->bindings_container); QLineEdit* le = new QLineEdit(ui->bindings_container);
le->setToolTip(setting_tooltip); le->setToolTip(setting_tooltip);
QPushButton* browse_button = new QPushButton(tr("Browse..."), ui->bindings_container); QPushButton* browse_button = new QPushButton(tr("Browse..."), ui->bindings_container);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, le, setting_name, SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, le, section_name, key_name,
QString::fromUtf8(si.StringDefaultValue())); QString::fromUtf8(si.StringDefaultValue()));
connect(browse_button, &QPushButton::clicked, [this, index, le, setting_name]() { connect(browse_button, &QPushButton::clicked, [this, le]() {
QString path = QFileDialog::getOpenFileName(this, tr("Select File")); QString path = QFileDialog::getOpenFileName(this, tr("Select File"));
if (!path.isEmpty()) if (!path.isEmpty())
le->setText(path); le->setText(path);
@ -376,8 +383,9 @@ void ControllerSettingsWidget::onControllerTypeChanged(int index)
return; return;
m_host_interface->putSettingValue( m_host_interface->putSettingValue(
QStringLiteral("Controller%1/Type").arg(index + 1), QStringLiteral("Controller%1").arg(index + 1), QStringLiteral("Type"),
QString::fromStdString(Settings::GetControllerTypeName(static_cast<ControllerType>(type_index)))); QString::fromStdString(Settings::GetControllerTypeName(static_cast<ControllerType>(type_index))));
m_host_interface->applySettings(); m_host_interface->applySettings();
createPortBindingSettingsUi(index, &m_port_ui[index], static_cast<ControllerType>(type_index)); createPortBindingSettingsUi(index, &m_port_ui[index], static_cast<ControllerType>(type_index));
} }

View file

@ -154,13 +154,13 @@ public:
void loadFromSettings() void loadFromSettings()
{ {
QStringList path_list = m_host_interface->getSettingValue(QStringLiteral("GameList/Paths")).toStringList(); std::vector<std::string> path_list = m_host_interface->GetStringList("GameList", "Paths");
for (QString& entry : path_list) for (std::string& entry : path_list)
m_entries.push_back({std::move(entry), false}); m_entries.push_back({QString::fromStdString(entry), false});
path_list = m_host_interface->getSettingValue(QStringLiteral("GameList/RecursivePaths")).toStringList(); path_list = m_host_interface->GetStringList("GameList", "RecursivePaths");
for (QString& entry : path_list) for (std::string& entry : path_list)
m_entries.push_back({std::move(entry), true}); m_entries.push_back({QString::fromStdString(entry), true});
} }
void saveToSettings() void saveToSettings()
@ -177,14 +177,14 @@ public:
} }
if (paths.empty()) if (paths.empty())
m_host_interface->removeSettingValue(QStringLiteral("GameList/Paths")); m_host_interface->removeSettingValue("GameList", "Paths");
else else
m_host_interface->putSettingValue(QStringLiteral("GameList/Paths"), paths); m_host_interface->putSettingValue(QStringLiteral("GameList"), QStringLiteral("Paths"), paths);
if (recursive_paths.empty()) if (recursive_paths.empty())
m_host_interface->removeSettingValue(QStringLiteral("GameList/RecursivePaths")); m_host_interface->removeSettingValue("GameList", "RecursivePaths");
else else
m_host_interface->putSettingValue(QStringLiteral("GameList/RecursivePaths"), recursive_paths); m_host_interface->putSettingValue(QStringLiteral("GameList"), QStringLiteral("RecursivePaths"), recursive_paths);
} }
private: private:

View file

@ -380,7 +380,7 @@ void GameListWidget::resizeTableViewColumnsToFit()
static QString getColumnVisibilitySettingsKeyName(int column) static QString getColumnVisibilitySettingsKeyName(int column)
{ {
return QStringLiteral("GameListTableView/Show%1").arg(GameListModel::s_column_names[column]); return QStringLiteral("Show%1").arg(GameListModel::s_column_names[column]);
} }
void GameListWidget::loadTableViewColumnVisibilitySettings() void GameListWidget::loadTableViewColumnVisibilitySettings()
@ -390,9 +390,9 @@ void GameListWidget::loadTableViewColumnVisibilitySettings()
for (int column = 0; column < GameListModel::Column_Count; column++) for (int column = 0; column < GameListModel::Column_Count; column++)
{ {
const bool visible = const bool visible = m_host_interface->GetBooleanSettingValue(
m_host_interface->getSettingValue(getColumnVisibilitySettingsKeyName(column), DEFAULT_VISIBILITY[column]) "GameListTableView", getColumnVisibilitySettingsKeyName(column).toStdString().c_str(),
.toBool(); DEFAULT_VISIBILITY[column]);
m_table_view->setColumnHidden(column, !visible); m_table_view->setColumnHidden(column, !visible);
} }
} }
@ -402,14 +402,14 @@ void GameListWidget::saveTableViewColumnVisibilitySettings()
for (int column = 0; column < GameListModel::Column_Count; column++) for (int column = 0; column < GameListModel::Column_Count; column++)
{ {
const bool visible = !m_table_view->isColumnHidden(column); const bool visible = !m_table_view->isColumnHidden(column);
m_host_interface->putSettingValue(getColumnVisibilitySettingsKeyName(column), visible); m_host_interface->putSettingValue(QStringLiteral("GameListTableView"), getColumnVisibilitySettingsKeyName(column), visible);
} }
} }
void GameListWidget::saveTableViewColumnVisibilitySettings(int column) void GameListWidget::saveTableViewColumnVisibilitySettings(int column)
{ {
const bool visible = !m_table_view->isColumnHidden(column); const bool visible = !m_table_view->isColumnHidden(column);
m_host_interface->putSettingValue(getColumnVisibilitySettingsKeyName(column), visible); m_host_interface->putSettingValue(QStringLiteral("GameListTableView"), getColumnVisibilitySettingsKeyName(column), visible);
} }
void GameListWidget::loadTableViewColumnSortSettings() void GameListWidget::loadTableViewColumnSortSettings()
@ -418,12 +418,10 @@ void GameListWidget::loadTableViewColumnSortSettings()
const bool DEFAULT_SORT_DESCENDING = false; const bool DEFAULT_SORT_DESCENDING = false;
const GameListModel::Column sort_column = const GameListModel::Column sort_column =
GameListModel::getColumnIdForName( GameListModel::getColumnIdForName(m_host_interface->GetSettingValue("GameListTableView", "SortColumn"))
m_host_interface->getSettingValue(QStringLiteral("GameListTableView/SortColumn")).toString().toStdString())
.value_or(DEFAULT_SORT_COLUMN); .value_or(DEFAULT_SORT_COLUMN);
const bool sort_descending = const bool sort_descending =
m_host_interface->getSettingValue(QStringLiteral("GameListTableView/SortDescending"), DEFAULT_SORT_DESCENDING) m_host_interface->GetBooleanSettingValue("GameListTableView", "SortDescending", DEFAULT_SORT_DESCENDING);
.toBool();
m_table_sort_model->sort(sort_column, sort_descending ? Qt::DescendingOrder : Qt::AscendingOrder); m_table_sort_model->sort(sort_column, sort_descending ? Qt::DescendingOrder : Qt::AscendingOrder);
} }
@ -434,11 +432,11 @@ void GameListWidget::saveTableViewColumnSortSettings()
if (sort_column >= 0 && sort_column < GameListModel::Column_Count) if (sort_column >= 0 && sort_column < GameListModel::Column_Count)
{ {
m_host_interface->putSettingValue(QStringLiteral("GameListTableView/SortColumn"), m_host_interface->putSettingValue(QStringLiteral("GameListTableView"), QStringLiteral("SortColumn"),
QString::fromUtf8(GameListModel::s_column_names[sort_column])); QString::fromUtf8(GameListModel::s_column_names[sort_column]));
} }
m_host_interface->putSettingValue(QStringLiteral("GameListTableView/SortDescending"), sort_descending); m_host_interface->putSettingValue(QStringLiteral("GameListTableView"), QStringLiteral("SortDescending"), sort_descending);
} }
const GameListEntry* GameListWidget::getSelectedEntry() const const GameListEntry* GameListWidget::getSelectedEntry() const

View file

@ -7,23 +7,33 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pauseOnStart, "Main/StartPaused"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pauseOnStart, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startFullscreen, "Main/StartFullscreen"); QStringLiteral("StartPaused"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.renderToMain, "Main/RenderToMainWindow"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startFullscreen, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.saveStateOnExit, "Main/SaveStateOnExit"); QStringLiteral("StartFullscreen"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.confirmPowerOff, "Main/ConfirmPowerOff"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.renderToMain, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.loadDevicesFromSaveStates, QStringLiteral("RenderToMainWindow"));
"Main/LoadDevicesFromSaveStates"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.saveStateOnExit, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showOSDMessages, "Display/ShowOSDMessages"); QStringLiteral("SaveStateOnExit"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display/ShowFPS"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.confirmPowerOff, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, "Display/ShowVPS"); QStringLiteral("ConfirmPowerOff"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showSpeed, "Display/ShowSpeed"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.loadDevicesFromSaveStates, QStringLiteral("Main"),
QStringLiteral("LoadDevicesFromSaveStates"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showOSDMessages, QStringLiteral("Display"),
QStringLiteral("ShowOSDMessages"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, QStringLiteral("Display"),
QStringLiteral("ShowFPS"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, QStringLiteral("Display"),
QStringLiteral("ShowVPS"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showSpeed, QStringLiteral("Display"),
QStringLiteral("ShowSpeed"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableSpeedLimiter, "Main/SpeedLimiterEnabled"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableSpeedLimiter, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.increaseTimerResolution, QStringLiteral("SpeedLimiterEnabled"));
"Main/IncreaseTimerResolution"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.increaseTimerResolution, QStringLiteral("Main"),
SettingWidgetBinder::BindWidgetToNormalizedSetting(m_host_interface, m_ui.emulationSpeed, "Main/EmulationSpeed", QStringLiteral("IncreaseTimerResolution"));
100.0f); SettingWidgetBinder::BindWidgetToNormalizedSetting(m_host_interface, m_ui.emulationSpeed, QStringLiteral("Main"),
QStringLiteral("EmulationSpeed"), 100.0f);
connect(m_ui.enableSpeedLimiter, &QCheckBox::stateChanged, this, connect(m_ui.enableSpeedLimiter, &QCheckBox::stateChanged, this,
&GeneralSettingsWidget::onEnableSpeedLimiterStateChanged); &GeneralSettingsWidget::onEnableSpeedLimiterStateChanged);
@ -75,8 +85,8 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
#ifdef WITH_DISCORD_PRESENCE #ifdef WITH_DISCORD_PRESENCE
{ {
QCheckBox* enableDiscordPresence = new QCheckBox(tr("Enable Discord Presence"), m_ui.groupBox_4); QCheckBox* enableDiscordPresence = new QCheckBox(tr("Enable Discord Presence"), m_ui.groupBox_4);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, enableDiscordPresence, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, enableDiscordPresence, QStringLiteral("Main"),
QStringLiteral("Main/EnableDiscordPresence")); QStringLiteral("EnableDiscordPresence"));
m_ui.formLayout_4->addWidget(enableDiscordPresence, m_ui.formLayout_4->rowCount(), 0); m_ui.formLayout_4->addWidget(enableDiscordPresence, m_ui.formLayout_4->rowCount(), 0);
dialog->registerWidgetHelp(enableDiscordPresence, "Enable Discord Presence", "Unchecked", dialog->registerWidgetHelp(enableDiscordPresence, "Enable Discord Presence", "Unchecked",
"Shows the game you are currently playing as part of your profile in Discord."); "Shows the game you are currently playing as part of your profile in Discord.");

View file

@ -16,33 +16,35 @@ GPUSettingsWidget::GPUSettingsWidget(QtHostInterface* host_interface, QWidget* p
m_ui.setupUi(this); m_ui.setupUi(this);
setupAdditionalUi(); setupAdditionalUi();
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.renderer, QStringLiteral("GPU/Renderer"), SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.renderer, QStringLiteral("GPU"),
&Settings::ParseRendererName, &Settings::GetRendererName, QStringLiteral("Renderer"), &Settings::ParseRendererName,
Settings::DEFAULT_GPU_RENDERER); &Settings::GetRendererName, Settings::DEFAULT_GPU_RENDERER);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.useDebugDevice, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.useDebugDevice, QStringLiteral("GPU"),
QStringLiteral("GPU/UseDebugDevice")); QStringLiteral("UseDebugDevice"));
SettingWidgetBinder::BindWidgetToEnumSetting( SettingWidgetBinder::BindWidgetToEnumSetting(
m_host_interface, m_ui.displayAspectRatio, QStringLiteral("Display/AspectRatio"), m_host_interface, m_ui.displayAspectRatio, QStringLiteral("Display"), QStringLiteral("AspectRatio"),
&Settings::ParseDisplayAspectRatio, &Settings::GetDisplayAspectRatioName, Settings::DEFAULT_DISPLAY_ASPECT_RATIO); &Settings::ParseDisplayAspectRatio, &Settings::GetDisplayAspectRatioName, Settings::DEFAULT_DISPLAY_ASPECT_RATIO);
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.displayCropMode, SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.displayCropMode, QStringLiteral("Display"),
QStringLiteral("Display/CropMode"), &Settings::ParseDisplayCropMode, QStringLiteral("CropMode"), &Settings::ParseDisplayCropMode,
&Settings::GetDisplayCropModeName, Settings::DEFAULT_DISPLAY_CROP_MODE); &Settings::GetDisplayCropModeName, Settings::DEFAULT_DISPLAY_CROP_MODE);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.displayLinearFiltering, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.displayLinearFiltering, QStringLiteral("Display"),
QStringLiteral("Display/LinearFiltering")); QStringLiteral("LinearFiltering"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.displayIntegerScaling, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.displayIntegerScaling, QStringLiteral("Display"),
QStringLiteral("Display/IntegerScaling")); QStringLiteral("IntegerScaling"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.vsync, QStringLiteral("Display/VSync")); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.vsync, QStringLiteral("Display"),
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.resolutionScale, QStringLiteral("VSync"));
QStringLiteral("GPU/ResolutionScale")); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.resolutionScale, QStringLiteral("GPU"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.trueColor, QStringLiteral("GPU/TrueColor")); QStringLiteral("ResolutionScale"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.scaledDithering, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.trueColor, QStringLiteral("GPU"),
QStringLiteral("GPU/ScaledDithering")); QStringLiteral("TrueColor"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.disableInterlacing, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.scaledDithering, QStringLiteral("GPU"),
QStringLiteral("GPU/DisableInterlacing")); QStringLiteral("ScaledDithering"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.forceNTSCTimings, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.disableInterlacing, QStringLiteral("GPU"),
QStringLiteral("GPU/ForceNTSCTimings")); QStringLiteral("DisableInterlacing"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.linearTextureFiltering, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.forceNTSCTimings, QStringLiteral("GPU"),
QStringLiteral("GPU/TextureFiltering")); QStringLiteral("ForceNTSCTimings"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.linearTextureFiltering, QStringLiteral("GPU"),
QStringLiteral("TextureFiltering"));
connect(m_ui.resolutionScale, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(m_ui.resolutionScale, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&GPUSettingsWidget::updateScaledDitheringEnabled); &GPUSettingsWidget::updateScaledDitheringEnabled);
@ -166,7 +168,8 @@ void GPUSettingsWidget::populateGPUAdapters()
break; break;
} }
QString current_value = m_host_interface->getSettingValue(QStringLiteral("GPU/Adapter")).toString(); QString current_value = QString::fromStdString(m_host_interface->GetSettingValue("GPU", "Adapter"));
QSignalBlocker blocker(m_ui.adapter); QSignalBlocker blocker(m_ui.adapter);
// add the default entry - we'll fall back to this if the GPU no longer exists, or there's no options // add the default entry - we'll fall back to this if the GPU no longer exists, or there's no options
@ -192,9 +195,9 @@ void GPUSettingsWidget::onGPUAdapterIndexChanged()
if (m_ui.adapter->currentIndex() == 0) if (m_ui.adapter->currentIndex() == 0)
{ {
// default // default
m_host_interface->removeSettingValue(QStringLiteral("GPU/Adapter")); m_host_interface->removeSettingValue("GPU", "Adapter");
return; return;
} }
m_host_interface->putSettingValue(QStringLiteral("GPU/Adapter"), m_ui.adapter->currentText()); m_host_interface->putSettingValue(QStringLiteral("GPU"), QStringLiteral("Adapter"), m_ui.adapter->currentText());
} }

View file

@ -61,8 +61,9 @@ void HotkeySettingsWidget::createButtons()
QGridLayout* layout = iter->layout; QGridLayout* layout = iter->layout;
const int target_row = layout->count() / 2; const int target_row = layout->count() / 2;
const QString setting_name = QStringLiteral("Hotkeys/%1").arg(hi.name.GetCharArray()); const QString section_name = QStringLiteral("Hotkeys");
const QString key_name = QStringLiteral("%1").arg(hi.name.GetCharArray());
layout->addWidget(new QLabel(QString::fromUtf8(hi.display_name), container), target_row, 0); layout->addWidget(new QLabel(QString::fromUtf8(hi.display_name), container), target_row, 0);
layout->addWidget(new InputButtonBindingWidget(m_host_interface, setting_name, container), target_row, 1); layout->addWidget(new InputButtonBindingWidget(m_host_interface, section_name, key_name, container), target_row, 1);
} }
} }

View file

@ -9,10 +9,13 @@
#include <QtGui/QMouseEvent> #include <QtGui/QMouseEvent>
#include <cmath> #include <cmath>
InputBindingWidget::InputBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent) InputBindingWidget::InputBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name,
: QPushButton(parent), m_host_interface(host_interface), m_setting_name(std::move(setting_name)) QWidget* parent)
: QPushButton(parent), m_host_interface(host_interface),
m_section_name(std::move(section_name)), m_key_name(std::move(key_name))
{ {
m_current_binding_value = m_host_interface->getSettingValue(m_setting_name).toString(); m_current_binding_value = QString::fromStdString(
m_host_interface->GetSettingValue(m_section_name.toStdString().c_str(), m_key_name.toStdString().c_str()));
setText(m_current_binding_value); setText(m_current_binding_value);
setMinimumWidth(150); setMinimumWidth(150);
setMaximumWidth(150); setMaximumWidth(150);
@ -63,7 +66,7 @@ void InputBindingWidget::setNewBinding()
if (m_new_binding_value.isEmpty()) if (m_new_binding_value.isEmpty())
return; return;
m_host_interface->putSettingValue(m_setting_name, m_new_binding_value); m_host_interface->putSettingValue(m_section_name, m_key_name, m_new_binding_value);
m_host_interface->updateInputMap(); m_host_interface->updateInputMap();
m_current_binding_value = std::move(m_new_binding_value); m_current_binding_value = std::move(m_new_binding_value);
@ -73,14 +76,15 @@ void InputBindingWidget::setNewBinding()
void InputBindingWidget::clearBinding() void InputBindingWidget::clearBinding()
{ {
m_current_binding_value.clear(); m_current_binding_value.clear();
m_host_interface->removeSettingValue(m_setting_name); m_host_interface->removeSettingValue(m_section_name.toStdString().c_str(), m_key_name.toStdString().c_str());
m_host_interface->updateInputMap(); m_host_interface->updateInputMap();
setText(m_current_binding_value); setText(m_current_binding_value);
} }
void InputBindingWidget::reloadBinding() void InputBindingWidget::reloadBinding()
{ {
m_current_binding_value = m_host_interface->getSettingValue(m_setting_name).toString(); m_current_binding_value = QString::fromStdString(m_host_interface->GetSettingValue(m_section_name.toStdString().c_str(),
m_key_name.toStdString().c_str()));
setText(m_current_binding_value); setText(m_current_binding_value);
} }
@ -135,9 +139,9 @@ void InputBindingWidget::stopListeningForInput()
m_is_binding_all = false; m_is_binding_all = false;
} }
InputButtonBindingWidget::InputButtonBindingWidget(QtHostInterface* host_interface, QString setting_name, InputButtonBindingWidget::InputButtonBindingWidget(QtHostInterface* host_interface, QString section_name,
QWidget* parent) QString key_name, QWidget* parent)
: InputBindingWidget(host_interface, setting_name, parent) : InputBindingWidget(host_interface, section_name, key_name, parent)
{ {
} }
@ -244,8 +248,9 @@ void InputButtonBindingWidget::stopListeningForInput()
InputBindingWidget::stopListeningForInput(); InputBindingWidget::stopListeningForInput();
} }
InputAxisBindingWidget::InputAxisBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent) InputAxisBindingWidget::InputAxisBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name,
: InputBindingWidget(host_interface, setting_name, parent) QWidget* parent)
: InputBindingWidget(host_interface, section_name, key_name, parent)
{ {
} }
@ -305,9 +310,9 @@ void InputAxisBindingWidget::stopListeningForInput()
InputBindingWidget::stopListeningForInput(); InputBindingWidget::stopListeningForInput();
} }
InputRumbleBindingWidget::InputRumbleBindingWidget(QtHostInterface* host_interface, QString setting_name, InputRumbleBindingWidget::InputRumbleBindingWidget(QtHostInterface* host_interface, QString section_name,
QWidget* parent) QString key_name, QWidget* parent)
: InputBindingWidget(host_interface, setting_name, parent) : InputBindingWidget(host_interface, section_name, key_name, parent)
{ {
} }

View file

@ -11,7 +11,7 @@ class InputBindingWidget : public QPushButton
Q_OBJECT Q_OBJECT
public: public:
InputBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent); InputBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name, QWidget* parent);
~InputBindingWidget(); ~InputBindingWidget();
ALWAYS_INLINE InputBindingWidget* getNextWidget() const { return m_next_widget; } ALWAYS_INLINE InputBindingWidget* getNextWidget() const { return m_next_widget; }
@ -43,7 +43,8 @@ protected:
void setNewBinding(); void setNewBinding();
QtHostInterface* m_host_interface; QtHostInterface* m_host_interface;
QString m_setting_name; QString m_section_name;
QString m_key_name;
QString m_current_binding_value; QString m_current_binding_value;
QString m_new_binding_value; QString m_new_binding_value;
QTimer* m_input_listen_timer = nullptr; QTimer* m_input_listen_timer = nullptr;
@ -58,7 +59,7 @@ class InputButtonBindingWidget : public InputBindingWidget
Q_OBJECT Q_OBJECT
public: public:
InputButtonBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent); InputButtonBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name, QWidget* parent);
~InputButtonBindingWidget(); ~InputButtonBindingWidget();
protected: protected:
@ -80,7 +81,7 @@ class InputAxisBindingWidget : public InputBindingWidget
Q_OBJECT Q_OBJECT
public: public:
InputAxisBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent); InputAxisBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name, QWidget* parent);
~InputAxisBindingWidget(); ~InputAxisBindingWidget();
private Q_SLOTS: private Q_SLOTS:
@ -98,7 +99,7 @@ class InputRumbleBindingWidget : public InputBindingWidget
Q_OBJECT Q_OBJECT
public: public:
InputRumbleBindingWidget(QtHostInterface* host_interface, QString setting_name, QWidget* parent); InputRumbleBindingWidget(QtHostInterface* host_interface, QString section_name, QString key_name, QWidget* parent);
~InputRumbleBindingWidget(); ~InputRumbleBindingWidget();
private Q_SLOTS: private Q_SLOTS:

View file

@ -10,7 +10,6 @@
#include "gamepropertiesdialog.h" #include "gamepropertiesdialog.h"
#include "qtdisplaywidget.h" #include "qtdisplaywidget.h"
#include "qthostinterface.h" #include "qthostinterface.h"
#include "qtsettingsinterface.h"
#include "qtutils.h" #include "qtutils.h"
#include "scmversion/scmversion.h" #include "scmversion/scmversion.h"
#include "settingsdialog.h" #include "settingsdialog.h"
@ -338,7 +337,7 @@ void MainWindow::onGameListEntryDoubleClicked(const GameListEntry* entry)
QString path = QString::fromStdString(entry->path); QString path = QString::fromStdString(entry->path);
if (!m_emulation_running) if (!m_emulation_running)
{ {
if (!entry->code.empty() && m_host_interface->getSettingValue("General/SaveStateOnExit", true).toBool()) if (!entry->code.empty() && m_host_interface->GetBooleanSettingValue("General", "SaveStateOnExit", true))
{ {
m_host_interface->resumeSystemFromState(path, true); m_host_interface->resumeSystemFromState(path, true);
} }
@ -434,7 +433,7 @@ void MainWindow::setupAdditionalUi()
QAction* action = m_ui.menuCPUExecutionMode->addAction(tr(Settings::GetCPUExecutionModeDisplayName(mode))); QAction* action = m_ui.menuCPUExecutionMode->addAction(tr(Settings::GetCPUExecutionModeDisplayName(mode)));
action->setCheckable(true); action->setCheckable(true);
connect(action, &QAction::triggered, [this, mode]() { connect(action, &QAction::triggered, [this, mode]() {
m_host_interface->putSettingValue(QStringLiteral("CPU/ExecutionMode"), m_host_interface->putSettingValue(QStringLiteral("CPU"), QStringLiteral("ExecutionMode"),
QString(Settings::GetCPUExecutionModeName(mode))); QString(Settings::GetCPUExecutionModeName(mode)));
m_host_interface->applySettings(); m_host_interface->applySettings();
updateDebugMenuCPUExecutionMode(); updateDebugMenuCPUExecutionMode();
@ -448,7 +447,8 @@ void MainWindow::setupAdditionalUi()
QAction* action = m_ui.menuRenderer->addAction(tr(Settings::GetRendererDisplayName(renderer))); QAction* action = m_ui.menuRenderer->addAction(tr(Settings::GetRendererDisplayName(renderer)));
action->setCheckable(true); action->setCheckable(true);
connect(action, &QAction::triggered, [this, renderer]() { connect(action, &QAction::triggered, [this, renderer]() {
m_host_interface->putSettingValue(QStringLiteral("GPU/Renderer"), QString(Settings::GetRendererName(renderer))); m_host_interface->putSettingValue(QStringLiteral("GPU"), QStringLiteral("Renderer"),
QString(Settings::GetRendererName(renderer)));
m_host_interface->applySettings(); m_host_interface->applySettings();
updateDebugMenuGPURenderer(); updateDebugMenuGPURenderer();
}); });
@ -608,23 +608,27 @@ void MainWindow::connectSignals()
m_host_interface->populateSaveStateMenus(nullptr, m_ui.menuLoadState, m_ui.menuSaveState); m_host_interface->populateSaveStateMenus(nullptr, m_ui.menuLoadState, m_ui.menuSaveState);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugDumpCPUtoVRAMCopies, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugDumpCPUtoVRAMCopies,
"Debug/DumpCPUToVRAMCopies"); QStringLiteral("Debug"), QStringLiteral("DumpCPUToVRAMCopies"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugDumpVRAMtoCPUCopies, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugDumpVRAMtoCPUCopies,
"Debug/DumpVRAMToCPUCopies"); QStringLiteral("Debug"), QStringLiteral("DumpVRAMToCPUCopies"));
connect(m_ui.actionDumpAudio, &QAction::toggled, [this](bool checked) { connect(m_ui.actionDumpAudio, &QAction::toggled, [this](bool checked) {
if (checked) if (checked)
m_host_interface->startDumpingAudio(); m_host_interface->startDumpingAudio();
else else
m_host_interface->stopDumpingAudio(); m_host_interface->stopDumpingAudio();
}); });
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowVRAM, "Debug/ShowVRAM"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowVRAM, QStringLiteral("Debug"),
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowGPUState, "Debug/ShowGPUState"); QStringLiteral("ShowVRAM"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowGPUState, QStringLiteral("Debug"),
QStringLiteral("ShowGPUState"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowCDROMState, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowCDROMState,
"Debug/ShowCDROMState"); QStringLiteral("Debug"), QStringLiteral("ShowCDROMState"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowSPUState, "Debug/ShowSPUState"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowSPUState, QStringLiteral("Debug"),
QStringLiteral("ShowSPUState"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowTimersState, SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowTimersState,
"Debug/ShowTimersState"); QStringLiteral("Debug"), QStringLiteral("ShowTimersState"));
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowMDECState, "Debug/ShowMDECState"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowMDECState, QStringLiteral("Debug"),
QStringLiteral("ShowMDECState"));
addThemeToMenu(tr("Default"), QStringLiteral("default")); addThemeToMenu(tr("Default"), QStringLiteral("default"));
addThemeToMenu(tr("DarkFusion"), QStringLiteral("darkfusion")); addThemeToMenu(tr("DarkFusion"), QStringLiteral("darkfusion"));
@ -641,13 +645,13 @@ void MainWindow::addThemeToMenu(const QString& name, const QString& key)
void MainWindow::setTheme(const QString& theme) void MainWindow::setTheme(const QString& theme)
{ {
m_host_interface->putSettingValue(QStringLiteral("UI/Theme"), theme); m_host_interface->putSettingValue(QStringLiteral("UI"), QStringLiteral("Theme"), theme);
updateTheme(); updateTheme();
} }
void MainWindow::updateTheme() void MainWindow::updateTheme()
{ {
QString theme = m_host_interface->getSettingValue(QStringLiteral("UI/Theme"), QStringLiteral("default")).toString(); QString theme = QString::fromStdString(m_host_interface->GetSettingValue("UI", "Theme", "default"));
if (theme == QStringLiteral("qdarkstyle")) if (theme == QStringLiteral("qdarkstyle"))
{ {
qApp->setStyle(m_unthemed_style_name); qApp->setStyle(m_unthemed_style_name);
@ -737,8 +741,8 @@ void MainWindow::doSettings(SettingsDialog::Category category)
void MainWindow::updateDebugMenuCPUExecutionMode() void MainWindow::updateDebugMenuCPUExecutionMode()
{ {
std::optional<CPUExecutionMode> current_mode = Settings::ParseCPUExecutionMode( std::optional<CPUExecutionMode> current_mode =
m_host_interface->getSettingValue(QStringLiteral("CPU/ExecutionMode")).toString().toStdString().c_str()); Settings::ParseCPUExecutionMode(m_host_interface->GetSettingValue("CPU", "ExecutionMode").c_str());
if (!current_mode.has_value()) if (!current_mode.has_value())
return; return;
@ -754,8 +758,8 @@ void MainWindow::updateDebugMenuCPUExecutionMode()
void MainWindow::updateDebugMenuGPURenderer() void MainWindow::updateDebugMenuGPURenderer()
{ {
// update the menu with the new selected renderer // update the menu with the new selected renderer
std::optional<GPURenderer> current_renderer = Settings::ParseRendererName( std::optional<GPURenderer> current_renderer =
m_host_interface->getSettingValue(QStringLiteral("GPU/Renderer")).toString().toStdString().c_str()); Settings::ParseRendererName(m_host_interface->GetSettingValue("GPU", "Renderer").c_str());
if (!current_renderer.has_value()) if (!current_renderer.has_value())
return; return;

View file

@ -65,7 +65,7 @@ void MemoryCardSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* u
const MemoryCardType default_value = (index == 0) ? MemoryCardType::PerGameTitle : MemoryCardType::None; const MemoryCardType default_value = (index == 0) ? MemoryCardType::PerGameTitle : MemoryCardType::None;
SettingWidgetBinder::BindWidgetToEnumSetting( SettingWidgetBinder::BindWidgetToEnumSetting(
m_host_interface, ui->memory_card_type, QStringLiteral("MemoryCards/Card%1Type").arg(index + 1), m_host_interface, ui->memory_card_type, QStringLiteral("MemoryCards"), QStringLiteral("Card%1Type").arg(index + 1),
&Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName, default_value); &Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName, default_value);
ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container)); ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container));
ui->layout->addWidget(ui->memory_card_type); ui->layout->addWidget(ui->memory_card_type);
@ -73,7 +73,7 @@ void MemoryCardSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* u
QHBoxLayout* memory_card_layout = new QHBoxLayout(); QHBoxLayout* memory_card_layout = new QHBoxLayout();
ui->memory_card_path = new QLineEdit(ui->container); ui->memory_card_path = new QLineEdit(ui->container);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, ui->memory_card_path, SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, ui->memory_card_path,
QStringLiteral("MemoryCards/Card%1Path").arg(index + 1)); QStringLiteral("MemoryCards"), QStringLiteral("Card%1Path").arg(index + 1));
memory_card_layout->addWidget(ui->memory_card_path); memory_card_layout->addWidget(ui->memory_card_path);
QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container); QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container);

View file

@ -9,6 +9,7 @@
#include "core/gpu.h" #include "core/gpu.h"
#include "core/system.h" #include "core/system.h"
#include "frontend-common/imgui_styles.h" #include "frontend-common/imgui_styles.h"
#include "frontend-common/ini_settings_interface.h"
#include "frontend-common/opengl_host_display.h" #include "frontend-common/opengl_host_display.h"
#include "frontend-common/sdl_audio_stream.h" #include "frontend-common/sdl_audio_stream.h"
#include "frontend-common/sdl_controller_interface.h" #include "frontend-common/sdl_controller_interface.h"
@ -17,7 +18,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "qtdisplaywidget.h" #include "qtdisplaywidget.h"
#include "qtprogresscallback.h" #include "qtprogresscallback.h"
#include "qtsettingsinterface.h"
#include "qtutils.h" #include "qtutils.h"
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
@ -26,6 +26,7 @@
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtWidgets/QMenu> #include <QtWidgets/QMenu>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
#include <algorithm>
#include <memory> #include <memory>
Log_SetChannel(QtHostInterface); Log_SetChannel(QtHostInterface);
@ -122,29 +123,62 @@ bool QtHostInterface::parseCommandLineParameters(int argc, char* argv[],
return CommonHostInterface::ParseCommandLineParameters(argc, argv, out_boot_params); return CommonHostInterface::ParseCommandLineParameters(argc, argv, out_boot_params);
} }
std::string QtHostInterface::GetSettingValue(const char* section, const char* key, const char* default_value) std::string QtHostInterface::GetSettingValue(const char* section, const char* key, const char* default_value /*= ""*/)
{ {
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
QVariant value = m_qsettings->value(QStringLiteral("%1/%2").arg(section).arg(key), QString(default_value)); return m_settings_interface->GetStringValue(section, key, default_value);
return value.toString().toStdString();
} }
QVariant QtHostInterface::getSettingValue(const QString& name, const QVariant& default_value) std::vector<std::string> QtHostInterface::GetStringList(const char* section, const char* key)
{ {
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
return m_qsettings->value(name, default_value); return m_settings_interface->GetStringList(section, key);
} }
void QtHostInterface::putSettingValue(const QString& name, const QVariant& value) void QtHostInterface::putSettingValue(const QString& section, const QString& key, const bool& value)
{ {
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
m_qsettings->setValue(name, value); m_settings_interface->SetBoolValue(section.toStdString().c_str(), key.toStdString().c_str(), value);
} }
void QtHostInterface::removeSettingValue(const QString& name) void QtHostInterface::putSettingValue(const QString& section, const QString& key, const int& value)
{ {
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
m_qsettings->remove(name); m_settings_interface->SetIntValue(section.toStdString().c_str(), key.toStdString().c_str(), value);
}
void QtHostInterface::putSettingValue(const QString& section, const QString& key, const float& value)
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
m_settings_interface->SetFloatValue(section.toStdString().c_str(), key.toStdString().c_str(), value);
}
void QtHostInterface::putSettingValue(const QString& section, const QString& key, const QString& value)
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
m_settings_interface->SetStringValue(section.toStdString().c_str(), key.toStdString().c_str(),
value.toStdString().c_str());
}
void QtHostInterface::putSettingValue(const QString& section, const QString& key, const QStringList& list)
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
std::vector<std::string> str_list;
for (const QString& qstr : list)
str_list.push_back(qstr.toStdString());
std::vector<std::string_view> strview_list;
for (const std::string& str : str_list)
strview_list.push_back(str);
m_settings_interface->SetStringList(section.toStdString().c_str(), key.toStdString().c_str(), strview_list);
}
void QtHostInterface::removeSettingValue(const char* section, const char* key)
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
m_settings_interface->DeleteValue(section, key);
} }
void QtHostInterface::setDefaultSettings() void QtHostInterface::setDefaultSettings()
@ -157,10 +191,9 @@ void QtHostInterface::setDefaultSettings()
Settings old_settings(std::move(m_settings)); Settings old_settings(std::move(m_settings));
{ {
QtSettingsInterface si(m_qsettings.get()); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); SetDefaultSettings(*m_settings_interface.get());
SetDefaultSettings(si); CommonHostInterface::LoadSettings(*m_settings_interface.get());
CommonHostInterface::LoadSettings(si);
} }
CheckForSettingsChanges(old_settings); CheckForSettingsChanges(old_settings);
@ -176,9 +209,8 @@ void QtHostInterface::applySettings()
Settings old_settings(std::move(m_settings)); Settings old_settings(std::move(m_settings));
{ {
QtSettingsInterface si(m_qsettings.get()); std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex); CommonHostInterface::LoadSettings(*m_settings_interface.get());
CommonHostInterface::LoadSettings(si);
} }
CheckForSettingsChanges(old_settings); CheckForSettingsChanges(old_settings);
@ -186,7 +218,7 @@ void QtHostInterface::applySettings()
// detect when render-to-main flag changes // detect when render-to-main flag changes
if (m_system) if (m_system)
{ {
const bool render_to_main = getSettingValue("Main/RenderToMainWindow", true).toBool(); const bool render_to_main = m_settings_interface->GetBoolValue("Main", "RenderToMainWindow", true);
if (m_display && !m_is_fullscreen && render_to_main != m_is_rendering_to_main) if (m_display && !m_is_fullscreen && render_to_main != m_is_rendering_to_main)
{ {
m_is_rendering_to_main = render_to_main; m_is_rendering_to_main = render_to_main;
@ -203,9 +235,8 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool
{ {
Assert(!isOnWorkerThread()); Assert(!isOnWorkerThread());
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> lock(m_settings_mutex);
QtSettingsInterface si(m_qsettings.get()); m_game_list->SetSearchDirectoriesFromSettings(*m_settings_interface.get());
m_game_list->SetSearchDirectoriesFromSettings(si);
QtProgressCallback progress(m_main_window); QtProgressCallback progress(m_main_window);
m_game_list->Refresh(invalidate_cache, invalidate_database, &progress); m_game_list->Refresh(invalidate_cache, invalidate_database, &progress);
@ -342,7 +373,7 @@ bool QtHostInterface::AcquireHostDisplay()
{ {
Assert(!m_display); Assert(!m_display);
m_is_rendering_to_main = getSettingValue("Main/RenderToMainWindow", true).toBool(); m_is_rendering_to_main = m_settings_interface->GetBoolValue("Main", "RenderToMainWindow", true);
QtDisplayWidget* display_widget = QtDisplayWidget* display_widget =
createDisplayRequested(m_worker_thread, QString::fromStdString(m_settings.gpu_adapter), createDisplayRequested(m_worker_thread, QString::fromStdString(m_settings.gpu_adapter),
@ -542,21 +573,10 @@ void QtHostInterface::OnSystemStateSaved(bool global, s32 slot)
void QtHostInterface::LoadSettings() void QtHostInterface::LoadSettings()
{ {
// no need to lock here because the main thread is waiting for us m_settings_interface = std::make_unique<INISettingsInterface>(CommonHostInterface::GetSettingsFileName());
m_qsettings = std::make_unique<QSettings>(QString::fromStdString(GetSettingsFileName()), QSettings::IniFormat);
QtSettingsInterface si(m_qsettings.get());
// check settings validity CommonHostInterface::CheckSettings(*m_settings_interface.get());
const QSettings::Status settings_status = m_qsettings->status(); CommonHostInterface::LoadSettings(*m_settings_interface.get());
if (settings_status != QSettings::NoError)
{
m_qsettings->clear();
SetDefaultSettings(si);
}
// load in settings
CommonHostInterface::CheckSettings(si);
CommonHostInterface::LoadSettings(si);
} }
void QtHostInterface::SetDefaultSettings(SettingsInterface& si) void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
@ -579,9 +599,8 @@ void QtHostInterface::updateInputMap()
return; return;
} }
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> lock(m_settings_mutex);
QtSettingsInterface si(m_qsettings.get()); CommonHostInterface::UpdateInputMap(*m_settings_interface.get());
CommonHostInterface::UpdateInputMap(si);
} }
void QtHostInterface::applyInputProfile(const QString& profile_path) void QtHostInterface::applyInputProfile(const QString& profile_path)
@ -592,17 +611,15 @@ void QtHostInterface::applyInputProfile(const QString& profile_path)
return; return;
} }
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> lock(m_settings_mutex);
QtSettingsInterface si(m_qsettings.get()); ApplyInputProfile(profile_path.toUtf8().data(), *m_settings_interface.get());
ApplyInputProfile(profile_path.toUtf8().data(), si);
emit inputProfileLoaded(); emit inputProfileLoaded();
} }
void QtHostInterface::saveInputProfile(const QString& profile_name) void QtHostInterface::saveInputProfile(const QString& profile_name)
{ {
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex); std::lock_guard<std::recursive_mutex> lock(m_settings_mutex);
QtSettingsInterface si(m_qsettings.get()); SaveInputProfile(profile_name.toUtf8().data(), *m_settings_interface.get());
SaveInputProfile(profile_name.toUtf8().data(), si);
} }
QString QtHostInterface::getUserDirectoryRelativePath(const QString& arg) const QString QtHostInterface::getUserDirectoryRelativePath(const QString& arg) const

View file

@ -24,13 +24,14 @@ class QWidget;
class QTimer; class QTimer;
class GameList; class GameList;
class INISettingsInterface;
class MainWindow; class MainWindow;
class QtDisplayWidget; class QtDisplayWidget;
Q_DECLARE_METATYPE(SystemBootParameters); Q_DECLARE_METATYPE(SystemBootParameters);
class QtHostInterface final : public QObject, private CommonHostInterface class QtHostInterface final : public QObject, public CommonHostInterface
{ {
Q_OBJECT Q_OBJECT
@ -49,11 +50,15 @@ public:
bool parseCommandLineParameters(int argc, char* argv[], std::unique_ptr<SystemBootParameters>* out_boot_params); bool parseCommandLineParameters(int argc, char* argv[], std::unique_ptr<SystemBootParameters>* out_boot_params);
/// Thread-safe QSettings access. /// Thread-safe settings access.
std::string GetSettingValue(const char* section, const char* key, const char* default_value = "") override; std::string GetSettingValue(const char* section, const char* key, const char* default_value = "") override;
QVariant getSettingValue(const QString& name, const QVariant& default_value = QVariant()); std::vector<std::string> GetStringList(const char* section, const char* key);
void putSettingValue(const QString& name, const QVariant& value); void putSettingValue(const QString& section, const QString& key, const bool& value);
void removeSettingValue(const QString& name); void putSettingValue(const QString& section, const QString& key, const int& value);
void putSettingValue(const QString& section, const QString& key, const float& value);
void putSettingValue(const QString& section, const QString& key, const QString& value);
void putSettingValue(const QString& section, const QString& key, const QStringList& list);
void removeSettingValue(const char* section, const char* key);
ALWAYS_INLINE const GameList* getGameList() const { return m_game_list.get(); } ALWAYS_INLINE const GameList* getGameList() const { return m_game_list.get(); }
ALWAYS_INLINE GameList* getGameList() { return m_game_list.get(); } ALWAYS_INLINE GameList* getGameList() { return m_game_list.get(); }
@ -205,8 +210,8 @@ private:
void updateDisplayState(); void updateDisplayState();
void wakeThread(); void wakeThread();
std::unique_ptr<QSettings> m_qsettings; std::unique_ptr<INISettingsInterface> m_settings_interface;
std::recursive_mutex m_qsettings_mutex; std::recursive_mutex m_settings_mutex;
MainWindow* m_main_window = nullptr; MainWindow* m_main_window = nullptr;
QThread* m_original_thread = nullptr; QThread* m_original_thread = nullptr;

View file

@ -1,147 +0,0 @@
#include "qtsettingsinterface.h"
#include <QtCore/QSettings>
#include <algorithm>
static QString GetFullKey(const char* section, const char* key)
{
return QStringLiteral("%1/%2").arg(section, key);
}
QtSettingsInterface::QtSettingsInterface(QSettings* settings) : m_settings(settings) {}
QtSettingsInterface::~QtSettingsInterface() = default;
void QtSettingsInterface::Clear()
{
m_settings->clear();
}
int QtSettingsInterface::GetIntValue(const char* section, const char* key, int default_value /*= 0*/)
{
QVariant value = m_settings->value(GetFullKey(section, key));
if (!value.isValid())
return default_value;
bool converted_value_okay;
int converted_value = value.toInt(&converted_value_okay);
if (!converted_value_okay)
return default_value;
else
return converted_value;
}
float QtSettingsInterface::GetFloatValue(const char* section, const char* key, float default_value /*= 0.0f*/)
{
QVariant value = m_settings->value(GetFullKey(section, key));
if (!value.isValid())
return default_value;
bool converted_value_okay;
float converted_value = value.toFloat(&converted_value_okay);
if (!converted_value_okay)
return default_value;
else
return converted_value;
}
bool QtSettingsInterface::GetBoolValue(const char* section, const char* key, bool default_value /*= false*/)
{
QVariant value = m_settings->value(GetFullKey(section, key));
return value.isValid() ? value.toBool() : default_value;
}
std::string QtSettingsInterface::GetStringValue(const char* section, const char* key,
const char* default_value /*= ""*/)
{
QVariant value = m_settings->value(GetFullKey(section, key));
return value.isValid() ? value.toString().toStdString() : std::string(default_value);
}
void QtSettingsInterface::SetIntValue(const char* section, const char* key, int value)
{
m_settings->setValue(GetFullKey(section, key), QVariant(value));
}
void QtSettingsInterface::SetFloatValue(const char* section, const char* key, float value)
{
m_settings->setValue(GetFullKey(section, key), QString::number(value));
}
void QtSettingsInterface::SetBoolValue(const char* section, const char* key, bool value)
{
m_settings->setValue(GetFullKey(section, key), QVariant(value));
}
void QtSettingsInterface::SetStringValue(const char* section, const char* key, const char* value)
{
m_settings->setValue(GetFullKey(section, key), QVariant(value));
}
std::vector<std::string> QtSettingsInterface::GetStringList(const char* section, const char* key)
{
QVariant value = m_settings->value(GetFullKey(section, key));
if (value.type() == QVariant::String)
return {value.toString().toStdString()};
else if (value.type() != QVariant::StringList)
return {};
QStringList value_sl = value.toStringList();
std::vector<std::string> results;
results.reserve(static_cast<unsigned>(value_sl.size()));
std::transform(value_sl.begin(), value_sl.end(), std::back_inserter(results),
[](const QString& str) { return str.toStdString(); });
return results;
}
void QtSettingsInterface::SetStringList(const char* section, const char* key,
const std::vector<std::string_view>& items)
{
QString full_key = GetFullKey(section, key);
if (items.empty())
{
m_settings->remove(full_key);
return;
}
QStringList sl;
sl.reserve(static_cast<int>(items.size()));
std::transform(items.begin(), items.end(), std::back_inserter(sl), [](const std::string_view& sv) {
return QString::fromLocal8Bit(sv.data(), static_cast<int>(sv.size()));
});
m_settings->setValue(full_key, sl);
}
bool QtSettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
{
QString full_key = GetFullKey(section, key);
QVariant var = m_settings->value(full_key);
QStringList sl = var.toStringList();
if (sl.removeAll(item) == 0)
return false;
if (sl.isEmpty())
m_settings->remove(full_key);
else
m_settings->setValue(full_key, sl);
return true;
}
bool QtSettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
{
QString full_key = GetFullKey(section, key);
QVariant var = m_settings->value(full_key);
QStringList sl = (var.type() == QVariant::StringList) ? var.toStringList() : QStringList();
QString qitem(item);
if (sl.contains(qitem))
return false;
sl.push_back(qitem);
m_settings->setValue(full_key, sl);
return true;
}
void QtSettingsInterface::DeleteValue(const char* section, const char* key)
{
m_settings->remove(GetFullKey(section, key));
}

View file

@ -1,33 +0,0 @@
#pragma once
#include "core/settings.h"
class QSettings;
class QtSettingsInterface : public SettingsInterface
{
public:
QtSettingsInterface(QSettings* settings);
~QtSettingsInterface();
void Clear() override;
int GetIntValue(const char* section, const char* key, int default_value = 0) override;
float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) override;
bool GetBoolValue(const char* section, const char* key, bool default_value = false) override;
std::string GetStringValue(const char* section, const char* key, const char* default_value = "") override;
void SetIntValue(const char* section, const char* key, int value) override;
void SetFloatValue(const char* section, const char* key, float value) override;
void SetBoolValue(const char* section, const char* key, bool value) override;
void SetStringValue(const char* section, const char* key, const char* value) override;
std::vector<std::string> GetStringList(const char* section, const char* key) override;
void SetStringList(const char* section, const char* key, const std::vector<std::string_view>& items) override;
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
bool AddToStringList(const char* section, const char* key, const char* item) override;
void DeleteValue(const char* section, const char* key) override;
private:
QSettings* m_settings;
};

View file

@ -200,119 +200,116 @@ struct SettingAccessor<QAction>
/// Binds a widget's value to a setting, updating it when the value changes. /// Binds a widget's value to a setting, updating it when the value changes.
template<typename WidgetType> template<typename WidgetType>
void BindWidgetToBoolSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, void BindWidgetToBoolSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
bool default_value = false) const QString& key_name, bool default_value = false)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
QVariant value = hi->getSettingValue(setting_name); bool value =
if (value.isValid()) hi->GetBooleanSettingValue(section_name.toStdString().c_str(), key_name.toStdString().c_str(), default_value);
Accessor::setBoolValue(widget, value.toBool());
else
Accessor::setBoolValue(widget, default_value);
Accessor::connectValueChanged(widget, [hi, widget, setting_name]() { Accessor::setBoolValue(widget, value);
Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name]() {
const bool new_value = Accessor::getBoolValue(widget); const bool new_value = Accessor::getBoolValue(widget);
hi->putSettingValue(setting_name, new_value); hi->putSettingValue(section_name, key_name, new_value);
hi->applySettings(); hi->applySettings();
}); });
} }
template<typename WidgetType> template<typename WidgetType>
void BindWidgetToIntSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, int default_value = 0) void BindWidgetToIntSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
const QString& key_name, int default_value = 0)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
QVariant value = hi->getSettingValue(setting_name); s32 value = hi->GetIntegerSettingValue(section_name.toStdString().c_str(), key_name.toStdString().c_str(),
if (value.isValid()) static_cast<s32>(default_value));
Accessor::setIntValue(widget, value.toInt());
else
Accessor::setIntValue(widget, default_value);
Accessor::connectValueChanged(widget, [hi, widget, setting_name]() { Accessor::setIntValue(widget, static_cast<int>(value));
Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name]() {
const int new_value = Accessor::getIntValue(widget); const int new_value = Accessor::getIntValue(widget);
hi->putSettingValue(setting_name, new_value); hi->putSettingValue(section_name, key_name, new_value);
hi->applySettings(); hi->applySettings();
}); });
} }
template<typename WidgetType> template<typename WidgetType>
void BindWidgetToFloatSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, void BindWidgetToFloatSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
float default_value = 0.0f) const QString& key_name, float default_value = 0.0f)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
QVariant value = hi->getSettingValue(setting_name); float value =
if (value.isValid()) hi->GetFloatSettingValue(section_name.toStdString().c_str(), key_name.toStdString().c_str(), default_value);
Accessor::setFloatValue(widget, value.toFloat());
else
Accessor::setFloatValue(widget, default_value);
Accessor::connectValueChanged(widget, [hi, widget, setting_name]() { Accessor::setFloatValue(widget, value);
Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name]() {
const float new_value = Accessor::getFloatValue(widget); const float new_value = Accessor::getFloatValue(widget);
hi->putSettingValue(setting_name, new_value); hi->putSettingValue(section_name, key_name, new_value);
hi->applySettings(); hi->applySettings();
}); });
} }
template<typename WidgetType> template<typename WidgetType>
void BindWidgetToNormalizedSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, float range, void BindWidgetToNormalizedSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
float default_value = 0.0f) const QString& key_name, float range, float default_value = 0.0f)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
QVariant value = hi->getSettingValue(setting_name); float value =
if (value.isValid()) hi->GetFloatSettingValue(section_name.toStdString().c_str(), key_name.toStdString().c_str(), default_value);
Accessor::setIntValue(widget, static_cast<int>(value.toFloat() * range));
else
Accessor::setIntValue(widget, static_cast<int>(default_value * range));
Accessor::connectValueChanged(widget, [hi, widget, setting_name, range]() { Accessor::setIntValue(widget, static_cast<int>(value * range));
Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name, range]() {
const float new_value = (static_cast<float>(Accessor::getIntValue(widget)) / range); const float new_value = (static_cast<float>(Accessor::getIntValue(widget)) / range);
hi->putSettingValue(setting_name, QString::number(new_value)); hi->putSettingValue(section_name, key_name, new_value);
hi->applySettings(); hi->applySettings();
}); });
} }
template<typename WidgetType> template<typename WidgetType>
void BindWidgetToStringSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, void BindWidgetToStringSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
const QString& default_value = QString()) const QString& key_name, const QString& default_value = QString())
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
QVariant value = hi->getSettingValue(setting_name); std::string value = hi->GetSettingValue(section_name.toStdString().c_str(), key_name.toStdString().c_str(),
if (value.isValid()) default_value.toStdString().c_str());
Accessor::setStringValue(widget, value.toString());
else
Accessor::setStringValue(widget, default_value);
Accessor::connectValueChanged(widget, [hi, widget, setting_name]() { Accessor::setStringValue(widget, QString::fromStdString(value));
Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name]() {
const QString new_value = Accessor::getStringValue(widget); const QString new_value = Accessor::getStringValue(widget);
hi->putSettingValue(setting_name, new_value); hi->putSettingValue(section_name, key_name, new_value);
hi->applySettings(); hi->applySettings();
}); });
} }
template<typename WidgetType, typename DataType> template<typename WidgetType, typename DataType>
void BindWidgetToEnumSetting(QtHostInterface* hi, WidgetType* widget, const QString& setting_name, void BindWidgetToEnumSetting(QtHostInterface* hi, WidgetType* widget, const QString& section_name,
std::optional<DataType> (*from_string_function)(const char* str), const QString& key_name, std::optional<DataType> (*from_string_function)(const char* str),
const char* (*to_string_function)(DataType value), DataType default_value) const char* (*to_string_function)(DataType value), DataType default_value)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
using UnderlyingType = std::underlying_type_t<DataType>; using UnderlyingType = std::underlying_type_t<DataType>;
const QString old_setting_string_value = hi->getSettingValue(setting_name).toString(); // TODO: Clean this up?
const std::optional<DataType> old_setting_value = const std::string old_setting_string_value = hi->GetSettingValue(
from_string_function(old_setting_string_value.toStdString().c_str()); section_name.toStdString().c_str(), key_name.toStdString().c_str(), to_string_function(default_value));
const std::optional<DataType> old_setting_value = from_string_function(old_setting_string_value.c_str());
if (old_setting_value.has_value()) if (old_setting_value.has_value())
Accessor::setIntValue(widget, static_cast<int>(static_cast<UnderlyingType>(old_setting_value.value()))); Accessor::setIntValue(widget, static_cast<int>(static_cast<UnderlyingType>(old_setting_value.value())));
else else
Accessor::setIntValue(widget, static_cast<int>(static_cast<UnderlyingType>(default_value))); Accessor::setIntValue(widget, static_cast<int>(static_cast<UnderlyingType>(default_value)));
Accessor::connectValueChanged(widget, [hi, widget, setting_name, to_string_function]() { Accessor::connectValueChanged(widget, [hi, widget, section_name, key_name, to_string_function]() {
const DataType value = static_cast<DataType>(static_cast<UnderlyingType>(Accessor::getIntValue(widget))); const DataType value = static_cast<DataType>(static_cast<UnderlyingType>(Accessor::getIntValue(widget)));
const char* string_value = to_string_function(value); const char* string_value = to_string_function(value);
hi->putSettingValue(setting_name, QString::fromLocal8Bit(string_value)); hi->putSettingValue(section_name, key_name, QString::fromLocal8Bit(string_value));
hi->applySettings(); hi->applySettings();
}); });
} }