config.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <memory>
  7. #include <string>
  8. #include <QMetaType>
  9. #include <QVariant>
  10. #include "common/settings.h"
  11. #include "yuzu/uisettings.h"
  12. class QSettings;
  13. class Config {
  14. public:
  15. enum class ConfigType {
  16. GlobalConfig,
  17. PerGameConfig,
  18. InputProfile,
  19. };
  20. explicit Config(std::string_view config_name = "qt-config",
  21. ConfigType config_type = ConfigType::GlobalConfig);
  22. ~Config();
  23. void Reload();
  24. void Save();
  25. void ReadControlPlayerValue(std::size_t player_index);
  26. void SaveControlPlayerValue(std::size_t player_index);
  27. const std::string& GetConfigFilePath() const;
  28. static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
  29. static const std::array<int, Settings::NativeMotion::NumMotions> default_motions;
  30. static const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> default_analogs;
  31. static const std::array<int, 2> default_stick_mod;
  32. static const std::array<int, Settings::NativeMouseButton::NumMouseButtons>
  33. default_mouse_buttons;
  34. static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys;
  35. static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods;
  36. static const std::array<UISettings::Shortcut, 17> default_hotkeys;
  37. private:
  38. void Initialize(std::string_view config_name);
  39. void ReadValues();
  40. void ReadPlayerValue(std::size_t player_index);
  41. void ReadDebugValues();
  42. void ReadKeyboardValues();
  43. void ReadMouseValues();
  44. void ReadTouchscreenValues();
  45. void ReadMotionTouchValues();
  46. // Read functions bases off the respective config section names.
  47. void ReadAudioValues();
  48. void ReadControlValues();
  49. void ReadCoreValues();
  50. void ReadDataStorageValues();
  51. void ReadDebuggingValues();
  52. void ReadServiceValues();
  53. void ReadDisabledAddOnValues();
  54. void ReadMiscellaneousValues();
  55. void ReadPathValues();
  56. void ReadCpuValues();
  57. void ReadRendererValues();
  58. void ReadScreenshotValues();
  59. void ReadShortcutValues();
  60. void ReadSystemValues();
  61. void ReadUIValues();
  62. void ReadUIGamelistValues();
  63. void ReadUILayoutValues();
  64. void ReadWebServiceValues();
  65. void SaveValues();
  66. void SavePlayerValue(std::size_t player_index);
  67. void SaveDebugValues();
  68. void SaveMouseValues();
  69. void SaveTouchscreenValues();
  70. void SaveMotionTouchValues();
  71. // Save functions based off the respective config section names.
  72. void SaveAudioValues();
  73. void SaveControlValues();
  74. void SaveCoreValues();
  75. void SaveDataStorageValues();
  76. void SaveDebuggingValues();
  77. void SaveServiceValues();
  78. void SaveDisabledAddOnValues();
  79. void SaveMiscellaneousValues();
  80. void SavePathValues();
  81. void SaveCpuValues();
  82. void SaveRendererValues();
  83. void SaveScreenshotValues();
  84. void SaveShortcutValues();
  85. void SaveSystemValues();
  86. void SaveUIValues();
  87. void SaveUIGamelistValues();
  88. void SaveUILayoutValues();
  89. void SaveWebServiceValues();
  90. QVariant ReadSetting(const QString& name) const;
  91. QVariant ReadSetting(const QString& name, const QVariant& default_value) const;
  92. // Templated ReadSettingGlobal functions will also look for the use_global setting and set
  93. // both the value and the global state properly
  94. template <typename Type>
  95. void ReadSettingGlobal(Settings::Setting<Type>& setting, const QString& name);
  96. template <typename Type>
  97. void ReadSettingGlobal(Settings::Setting<Type>& setting, const QString& name,
  98. const QVariant& default_value);
  99. template <typename Type>
  100. void ReadSettingGlobal(Type& setting, const QString& name, const QVariant& default_value) const;
  101. // Templated WriteSettingGlobal functions will also write the global state if needed and will
  102. // skip writing the actual setting if it defers to the global value
  103. void WriteSetting(const QString& name, const QVariant& value);
  104. void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value);
  105. template <typename Type>
  106. void WriteSettingGlobal(const QString& name, const Settings::Setting<Type>& setting);
  107. template <typename Type>
  108. void WriteSettingGlobal(const QString& name, const Settings::Setting<Type>& setting,
  109. const QVariant& default_value);
  110. void WriteSettingGlobal(const QString& name, const QVariant& value, bool use_global,
  111. const QVariant& default_value);
  112. ConfigType type;
  113. std::unique_ptr<QSettings> qt_config;
  114. std::string qt_config_loc;
  115. bool global;
  116. };
  117. // These metatype declarations cannot be in common/settings.h because core is devoid of QT
  118. Q_DECLARE_METATYPE(Settings::CPUAccuracy);
  119. Q_DECLARE_METATYPE(Settings::RendererBackend);
  120. Q_DECLARE_METATYPE(Settings::GPUAccuracy);