yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #2504 from lioncash/config

yuzu/configuration/config: Specify string conversions explicitly
This commit is contained in:
bunnei 2019-05-24 18:23:58 -04:00 committed by GitHub
commit 59f110ef31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 33 deletions

View File

@ -11,6 +11,7 @@
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "input_common/main.h" #include "input_common/main.h"
#include "yuzu/configuration/config.h" #include "yuzu/configuration/config.h"
#include "yuzu/ui_settings.h"
Config::Config() { Config::Config() {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files. // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
@ -206,25 +207,28 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default
}; };
// This shouldn't have anything except static initializers (no functions). So // This shouldn't have anything except static initializers (no functions). So
// QKeySequnce(...).toString() is NOT ALLOWED HERE. // QKeySequence(...).toString() is NOT ALLOWED HERE.
// This must be in alphabetical order according to action name as it must have the same order as // This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered. // UISetting::values.shortcuts, which is alphabetically ordered.
const std::array<UISettings::Shortcut, 15> Config::default_hotkeys{ // clang-format off
{{"Capture Screenshot", "Main Window", {"Ctrl+P", Qt::ApplicationShortcut}}, const std::array<UISettings::Shortcut, 15> default_hotkeys{{
{"Continue/Pause Emulation", "Main Window", {"F4", Qt::WindowShortcut}}, {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}},
{"Decrease Speed Limit", "Main Window", {"-", Qt::ApplicationShortcut}}, {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}},
{"Exit yuzu", "Main Window", {"Ctrl+Q", Qt::WindowShortcut}}, {QStringLiteral("Decrease Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}},
{"Exit Fullscreen", "Main Window", {"Esc", Qt::WindowShortcut}}, {QStringLiteral("Exit yuzu"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"), Qt::WindowShortcut}},
{"Fullscreen", "Main Window", {"F11", Qt::WindowShortcut}}, {QStringLiteral("Exit Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}},
{"Increase Speed Limit", "Main Window", {"+", Qt::ApplicationShortcut}}, {QStringLiteral("Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}},
{"Load Amiibo", "Main Window", {"F2", Qt::ApplicationShortcut}}, {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}},
{"Load File", "Main Window", {"Ctrl+O", Qt::WindowShortcut}}, {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}},
{"Restart Emulation", "Main Window", {"F6", Qt::WindowShortcut}}, {QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WindowShortcut}},
{"Stop Emulation", "Main Window", {"F5", Qt::WindowShortcut}}, {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}},
{"Toggle Filter Bar", "Main Window", {"Ctrl+F", Qt::WindowShortcut}}, {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}},
{"Toggle Speed Limit", "Main Window", {"Ctrl+Z", Qt::ApplicationShortcut}}, {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}},
{"Toggle Status Bar", "Main Window", {"Ctrl+S", Qt::WindowShortcut}}, {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}},
{"Change Docked Mode", "Main Window", {"F10", Qt::ApplicationShortcut}}}}; {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}},
{QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}},
}};
// clang-format on
void Config::ReadPlayerValues() { void Config::ReadPlayerValues() {
for (std::size_t p = 0; p < Settings::values.players.size(); ++p) { for (std::size_t p = 0; p < Settings::values.players.size(); ++p) {
@ -370,14 +374,21 @@ void Config::ReadMouseValues() {
} }
void Config::ReadTouchscreenValues() { void Config::ReadTouchscreenValues() {
Settings::values.touchscreen.enabled = ReadSetting("touchscreen_enabled", true).toBool(); Settings::values.touchscreen.enabled =
ReadSetting(QStringLiteral("touchscreen_enabled"), true).toBool();
Settings::values.touchscreen.device = Settings::values.touchscreen.device =
ReadSetting("touchscreen_device", "engine:emu_window").toString().toStdString(); ReadSetting(QStringLiteral("touchscreen_device"), QStringLiteral("engine:emu_window"))
.toString()
.toStdString();
Settings::values.touchscreen.finger = ReadSetting("touchscreen_finger", 0).toUInt(); Settings::values.touchscreen.finger =
Settings::values.touchscreen.rotation_angle = ReadSetting("touchscreen_angle", 0).toUInt(); ReadSetting(QStringLiteral("touchscreen_finger"), 0).toUInt();
Settings::values.touchscreen.diameter_x = ReadSetting("touchscreen_diameter_x", 15).toUInt(); Settings::values.touchscreen.rotation_angle =
Settings::values.touchscreen.diameter_y = ReadSetting("touchscreen_diameter_y", 15).toUInt(); ReadSetting(QStringLiteral("touchscreen_angle"), 0).toUInt();
Settings::values.touchscreen.diameter_x =
ReadSetting(QStringLiteral("touchscreen_diameter_x"), 15).toUInt();
Settings::values.touchscreen.diameter_y =
ReadSetting(QStringLiteral("touchscreen_diameter_y"), 15).toUInt();
} }
void Config::ApplyDefaultProfileIfInputInvalid() { void Config::ApplyDefaultProfileIfInputInvalid() {
@ -541,8 +552,8 @@ void Config::ReadRendererValues() {
void Config::ReadShortcutValues() { void Config::ReadShortcutValues() {
qt_config->beginGroup(QStringLiteral("Shortcuts")); qt_config->beginGroup(QStringLiteral("Shortcuts"));
for (auto [name, group, shortcut] : default_hotkeys) { for (const auto& [name, group, shortcut] : default_hotkeys) {
auto [keyseq, context] = shortcut; const auto& [keyseq, context] = shortcut;
qt_config->beginGroup(group); qt_config->beginGroup(group);
qt_config->beginGroup(name); qt_config->beginGroup(name);
UISettings::values.shortcuts.push_back( UISettings::values.shortcuts.push_back(
@ -591,7 +602,8 @@ void Config::ReadUIValues() {
qt_config->beginGroup(QStringLiteral("UI")); qt_config->beginGroup(QStringLiteral("UI"));
UISettings::values.theme = UISettings::values.theme =
ReadSetting(QStringLiteral("theme"), UISettings::themes[0].second).toString(); ReadSetting(QStringLiteral("theme"), QString::fromUtf8(UISettings::themes[0].second))
.toString();
UISettings::values.enable_discord_presence = UISettings::values.enable_discord_presence =
ReadSetting(QStringLiteral("enable_discord_presence"), true).toBool(); ReadSetting(QStringLiteral("enable_discord_presence"), true).toBool();
UISettings::values.screenshot_resolution_factor = UISettings::values.screenshot_resolution_factor =
@ -626,7 +638,7 @@ void Config::ReadUIValues() {
} }
void Config::ReadUIGamelistValues() { void Config::ReadUIGamelistValues() {
qt_config->beginGroup("UIGameList"); qt_config->beginGroup(QStringLiteral("UIGameList"));
UISettings::values.show_unknown = ReadSetting(QStringLiteral("show_unknown"), true).toBool(); UISettings::values.show_unknown = ReadSetting(QStringLiteral("show_unknown"), true).toBool();
UISettings::values.show_add_ons = ReadSetting(QStringLiteral("show_add_ons"), true).toBool(); UISettings::values.show_add_ons = ReadSetting(QStringLiteral("show_add_ons"), true).toBool();
@ -723,7 +735,7 @@ void Config::SavePlayerValues() {
} }
void Config::SaveDebugValues() { void Config::SaveDebugValues() {
WriteSetting("debug_pad_enabled", Settings::values.debug_pad_enabled, false); WriteSetting(QStringLiteral("debug_pad_enabled"), Settings::values.debug_pad_enabled, false);
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); const std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
WriteSetting(QStringLiteral("debug_pad_") + WriteSetting(QStringLiteral("debug_pad_") +
@ -924,7 +936,7 @@ void Config::SaveShortcutValues() {
// Lengths of UISettings::values.shortcuts & default_hotkeys are same. // Lengths of UISettings::values.shortcuts & default_hotkeys are same.
// However, their ordering must also be the same. // However, their ordering must also be the same.
for (std::size_t i = 0; i < default_hotkeys.size(); i++) { for (std::size_t i = 0; i < default_hotkeys.size(); i++) {
const auto [name, group, shortcut] = UISettings::values.shortcuts[i]; const auto& [name, group, shortcut] = UISettings::values.shortcuts[i];
const auto& default_hotkey = default_hotkeys[i].shortcut; const auto& default_hotkey = default_hotkeys[i].shortcut;
qt_config->beginGroup(group); qt_config->beginGroup(group);
@ -961,7 +973,8 @@ void Config::SaveSystemValues() {
void Config::SaveUIValues() { void Config::SaveUIValues() {
qt_config->beginGroup(QStringLiteral("UI")); qt_config->beginGroup(QStringLiteral("UI"));
WriteSetting(QStringLiteral("theme"), UISettings::values.theme, UISettings::themes[0].second); WriteSetting(QStringLiteral("theme"), UISettings::values.theme,
QString::fromUtf8(UISettings::themes[0].second));
WriteSetting(QStringLiteral("enable_discord_presence"), WriteSetting(QStringLiteral("enable_discord_presence"),
UISettings::values.enable_discord_presence, true); UISettings::values.enable_discord_presence, true);
WriteSetting(QStringLiteral("screenshot_resolution_factor"), WriteSetting(QStringLiteral("screenshot_resolution_factor"),

View File

@ -9,7 +9,6 @@
#include <string> #include <string>
#include <QVariant> #include <QVariant>
#include "core/settings.h" #include "core/settings.h"
#include "yuzu/ui_settings.h"
class QSettings; class QSettings;
@ -82,8 +81,6 @@ private:
void WriteSetting(const QString& name, const QVariant& value); void WriteSetting(const QString& name, const QVariant& value);
void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value); void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value);
static const std::array<UISettings::Shortcut, 15> default_hotkeys;
std::unique_ptr<QSettings> qt_config; std::unique_ptr<QSettings> qt_config;
std::string qt_config_loc; std::string qt_config_loc;
}; };