config.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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(const std::string& 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, 18> default_hotkeys;
  37. private:
  38. void Initialize(const std::string& 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. /**
  91. * Reads a setting from the qt_config.
  92. *
  93. * @param name The setting's identifier
  94. * @param default_value The value to use when the setting is not already present in the config
  95. */
  96. QVariant ReadSetting(const QString& name) const;
  97. QVariant ReadSetting(const QString& name, const QVariant& default_value) const;
  98. /**
  99. * Only reads a setting from the qt_config if the current config is a global config, or if the
  100. * current config is a custom config and the setting is overriding the global setting. Otherwise
  101. * it does nothing.
  102. *
  103. * @param setting The variable to be modified
  104. * @param name The setting's identifier
  105. * @param default_value The value to use when the setting is not already present in the config
  106. */
  107. template <typename Type>
  108. void ReadSettingGlobal(Type& setting, const QString& name, const QVariant& default_value) const;
  109. /**
  110. * Writes a setting to the qt_config.
  111. *
  112. * @param name The setting's idetentifier
  113. * @param value Value of the setting
  114. * @param default_value Default of the setting if not present in qt_config
  115. * @param use_global Specifies if the custom or global config should be in use, for custom
  116. * configs
  117. */
  118. void WriteSetting(const QString& name, const QVariant& value);
  119. void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value);
  120. void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value,
  121. bool use_global);
  122. /**
  123. * Reads a value from the qt_config and applies it to the setting, using its label and default
  124. * value. If the config is a custom config, this will also read the global state of the setting
  125. * and apply that information to it.
  126. *
  127. * @param The setting
  128. */
  129. template <typename Type>
  130. void ReadGlobalSetting(Settings::Setting<Type>& setting);
  131. /**
  132. * Sets a value to the qt_config using the setting's label and default value. If the config is a
  133. * custom config, it will apply the global state, and the custom value if needed.
  134. *
  135. * @param The setting
  136. */
  137. template <typename Type>
  138. void WriteGlobalSetting(const Settings::Setting<Type>& setting);
  139. /**
  140. * Reads a value from the qt_config using the setting's label and default value and applies the
  141. * value to the setting.
  142. *
  143. * @param The setting
  144. */
  145. template <typename Type>
  146. void ReadBasicSetting(Settings::BasicSetting<Type>& setting);
  147. /** Sets a value from the setting in the qt_config using the setting's label and default value.
  148. *
  149. * @param The setting
  150. */
  151. template <typename Type>
  152. void WriteBasicSetting(const Settings::BasicSetting<Type>& setting);
  153. ConfigType type;
  154. std::unique_ptr<QSettings> qt_config;
  155. std::string qt_config_loc;
  156. bool global;
  157. };
  158. // These metatype declarations cannot be in common/settings.h because core is devoid of QT
  159. Q_DECLARE_METATYPE(Settings::CPUAccuracy);
  160. Q_DECLARE_METATYPE(Settings::RendererBackend);
  161. Q_DECLARE_METATYPE(Settings::GPUAccuracy);