configure_system.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-FileCopyrightText: 2016 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <chrono>
  4. #include <optional>
  5. #include <vector>
  6. #include <QCheckBox>
  7. #include <QComboBox>
  8. #include <QDateTimeEdit>
  9. #include <QFileDialog>
  10. #include <QGraphicsItem>
  11. #include <QLineEdit>
  12. #include <QMessageBox>
  13. #include "common/settings.h"
  14. #include "core/core.h"
  15. #include "core/hle/service/time/time_manager.h"
  16. #include "ui_configure_system.h"
  17. #include "yuzu/configuration/config.h"
  18. #include "yuzu/configuration/configuration_shared.h"
  19. #include "yuzu/configuration/configure_system.h"
  20. #include "yuzu/configuration/shared_widget.h"
  21. constexpr std::array<u32, 7> LOCALE_BLOCKLIST{
  22. // pzzefezrpnkzeidfej
  23. // thhsrnhutlohsternp
  24. // BHH4CG U
  25. // Raa1AB S
  26. // nn9
  27. // ts
  28. 0b0100011100001100000, // Japan
  29. 0b0000001101001100100, // Americas
  30. 0b0100110100001000010, // Europe
  31. 0b0100110100001000010, // Australia
  32. 0b0000000000000000000, // China
  33. 0b0100111100001000000, // Korea
  34. 0b0100111100001000000, // Taiwan
  35. };
  36. static bool IsValidLocale(u32 region_index, u32 language_index) {
  37. if (region_index >= LOCALE_BLOCKLIST.size()) {
  38. return false;
  39. }
  40. return ((LOCALE_BLOCKLIST.at(region_index) >> language_index) & 1) == 0;
  41. }
  42. ConfigureSystem::ConfigureSystem(Core::System& system_,
  43. std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
  44. const ConfigurationShared::Builder& builder, QWidget* parent)
  45. : Tab(group_, parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_} {
  46. ui->setupUi(this);
  47. Setup(builder);
  48. const auto locale_check = [this]() {
  49. const auto region_index = combo_region->currentIndex();
  50. const auto language_index = combo_language->currentIndex();
  51. const bool valid_locale = IsValidLocale(region_index, language_index);
  52. ui->label_warn_invalid_locale->setVisible(!valid_locale);
  53. if (!valid_locale) {
  54. ui->label_warn_invalid_locale->setText(
  55. tr("Warning: \"%1\" is not a valid language for region \"%2\"")
  56. .arg(combo_language->currentText())
  57. .arg(combo_region->currentText()));
  58. }
  59. };
  60. connect(combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
  61. connect(combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
  62. ui->label_warn_invalid_locale->setVisible(false);
  63. locale_check();
  64. SetConfiguration();
  65. }
  66. ConfigureSystem::~ConfigureSystem() = default;
  67. void ConfigureSystem::changeEvent(QEvent* event) {
  68. if (event->type() == QEvent::LanguageChange) {
  69. RetranslateUI();
  70. }
  71. QWidget::changeEvent(event);
  72. }
  73. void ConfigureSystem::RetranslateUI() {
  74. ui->retranslateUi(this);
  75. }
  76. void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) {
  77. auto& core_layout = *ui->core_widget->layout();
  78. auto& system_layout = *ui->system_widget->layout();
  79. std::map<u32, QWidget*> core_hold{};
  80. std::map<u32, QWidget*> system_hold{};
  81. std::vector<Settings::BasicSetting*> settings;
  82. auto push = [&settings](auto& list) {
  83. for (auto setting : list) {
  84. settings.push_back(setting);
  85. }
  86. };
  87. push(Settings::values.linkage.by_category[Settings::Category::Core]);
  88. push(Settings::values.linkage.by_category[Settings::Category::System]);
  89. for (auto setting : settings) {
  90. if (setting->Id() == Settings::values.use_docked_mode.Id() &&
  91. Settings::IsConfiguringGlobal()) {
  92. continue;
  93. }
  94. ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs);
  95. if (widget == nullptr) {
  96. continue;
  97. }
  98. if (!widget->Valid()) {
  99. widget->deleteLater();
  100. continue;
  101. }
  102. if (setting->Id() == Settings::values.region_index.Id()) {
  103. // Keep track of the region_index (and langauge_index) combobox to validate the selected
  104. // settings
  105. combo_region = widget->combobox;
  106. } else if (setting->Id() == Settings::values.language_index.Id()) {
  107. combo_language = widget->combobox;
  108. }
  109. switch (setting->GetCategory()) {
  110. case Settings::Category::Core:
  111. core_hold.emplace(setting->Id(), widget);
  112. break;
  113. case Settings::Category::System:
  114. system_hold.emplace(setting->Id(), widget);
  115. break;
  116. default:
  117. widget->deleteLater();
  118. }
  119. }
  120. for (const auto& [label, widget] : core_hold) {
  121. core_layout.addWidget(widget);
  122. }
  123. for (const auto& [id, widget] : system_hold) {
  124. system_layout.addWidget(widget);
  125. }
  126. }
  127. void ConfigureSystem::SetConfiguration() {}
  128. void ConfigureSystem::ApplyConfiguration() {
  129. const bool powered_on = system.IsPoweredOn();
  130. for (const auto& func : apply_funcs) {
  131. func(powered_on);
  132. }
  133. }