configure_general.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-FileCopyrightText: 2016 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <functional>
  4. #include <utility>
  5. #include <vector>
  6. #include <QMessageBox>
  7. #include "common/settings.h"
  8. #include "core/core.h"
  9. #include "ui_configure_general.h"
  10. #include "yuzu/configuration/configuration_shared.h"
  11. #include "yuzu/configuration/configure_general.h"
  12. #include "yuzu/configuration/shared_widget.h"
  13. #include "yuzu/uisettings.h"
  14. ConfigureGeneral::ConfigureGeneral(const Core::System& system_,
  15. std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
  16. const ConfigurationShared::Builder& builder, QWidget* parent)
  17. : Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGeneral>()}, system{system_} {
  18. ui->setupUi(this);
  19. Setup(builder);
  20. SetConfiguration();
  21. connect(ui->button_reset_defaults, &QPushButton::clicked, this,
  22. &ConfigureGeneral::ResetDefaults);
  23. if (!Settings::IsConfiguringGlobal()) {
  24. ui->button_reset_defaults->setVisible(false);
  25. }
  26. }
  27. ConfigureGeneral::~ConfigureGeneral() = default;
  28. void ConfigureGeneral::SetConfiguration() {}
  29. void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
  30. QLayout& general_layout = *ui->general_widget->layout();
  31. QLayout& linux_layout = *ui->linux_widget->layout();
  32. std::map<u32, QWidget*> general_hold{};
  33. std::map<u32, QWidget*> linux_hold{};
  34. std::vector<Settings::BasicSetting*> settings;
  35. auto push = [&settings](auto& list) {
  36. for (auto setting : list) {
  37. settings.push_back(setting);
  38. }
  39. };
  40. push(UISettings::values.linkage.by_category[Settings::Category::UiGeneral]);
  41. push(Settings::values.linkage.by_category[Settings::Category::Linux]);
  42. // Only show Linux group on Unix
  43. #ifndef __unix__
  44. ui->LinuxGroupBox->setVisible(false);
  45. #endif
  46. for (const auto setting : settings) {
  47. auto* widget = builder.BuildWidget(setting, apply_funcs);
  48. if (widget == nullptr) {
  49. continue;
  50. }
  51. if (!widget->Valid()) {
  52. widget->deleteLater();
  53. continue;
  54. }
  55. switch (setting->GetCategory()) {
  56. case Settings::Category::UiGeneral:
  57. general_hold.emplace(setting->Id(), widget);
  58. break;
  59. case Settings::Category::Linux:
  60. linux_hold.emplace(setting->Id(), widget);
  61. break;
  62. default:
  63. widget->deleteLater();
  64. }
  65. }
  66. for (const auto& [id, widget] : general_hold) {
  67. general_layout.addWidget(widget);
  68. }
  69. for (const auto& [id, widget] : linux_hold) {
  70. linux_layout.addWidget(widget);
  71. }
  72. }
  73. // Called to set the callback when resetting settings to defaults
  74. void ConfigureGeneral::SetResetCallback(std::function<void()> callback) {
  75. reset_callback = std::move(callback);
  76. }
  77. void ConfigureGeneral::ResetDefaults() {
  78. QMessageBox::StandardButton answer = QMessageBox::question(
  79. this, tr("yuzu"),
  80. tr("This reset all settings and remove all per-game configurations. This will not delete "
  81. "game directories, profiles, or input profiles. Proceed?"),
  82. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  83. if (answer == QMessageBox::No) {
  84. return;
  85. }
  86. UISettings::values.reset_to_defaults = true;
  87. UISettings::values.is_game_list_reload_pending.exchange(true);
  88. reset_callback();
  89. }
  90. void ConfigureGeneral::ApplyConfiguration() {
  91. bool powered_on = system.IsPoweredOn();
  92. for (const auto& func : apply_funcs) {
  93. func(powered_on);
  94. }
  95. }
  96. void ConfigureGeneral::changeEvent(QEvent* event) {
  97. if (event->type() == QEvent::LanguageChange) {
  98. RetranslateUI();
  99. }
  100. QWidget::changeEvent(event);
  101. }
  102. void ConfigureGeneral::RetranslateUI() {
  103. ui->retranslateUi(this);
  104. }