WiiPane.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DolphinQt/Settings/WiiPane.h"
  4. #include <array>
  5. #include <future>
  6. #include <utility>
  7. #include <QCheckBox>
  8. #include <QComboBox>
  9. #include <QDir>
  10. #include <QGridLayout>
  11. #include <QGroupBox>
  12. #include <QHBoxLayout>
  13. #include <QLabel>
  14. #include <QLineEdit>
  15. #include <QListWidget>
  16. #include <QPushButton>
  17. #include <QSlider>
  18. #include <QSpacerItem>
  19. #include <QStringList>
  20. #include "Common/Config/Config.h"
  21. #include "Common/FatFsUtil.h"
  22. #include "Common/FileUtil.h"
  23. #include "Core/Config/MainSettings.h"
  24. #include "Core/Config/SYSCONFSettings.h"
  25. #include "Core/ConfigManager.h"
  26. #include "Core/Core.h"
  27. #include "Core/System.h"
  28. #include "DolphinQt/QtUtils/DolphinFileDialog.h"
  29. #include "DolphinQt/QtUtils/ModalMessageBox.h"
  30. #include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
  31. #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
  32. #include "DolphinQt/QtUtils/QtUtils.h"
  33. #include "DolphinQt/QtUtils/SignalBlocking.h"
  34. #include "DolphinQt/Settings.h"
  35. #include "DolphinQt/Settings/USBDeviceAddToWhitelistDialog.h"
  36. #include "UICommon/USBUtils.h"
  37. // SYSCONF uses 0 for bottom and 1 for top, but we place them in
  38. // the other order in the GUI so that Top will be above Bottom,
  39. // matching the respective physical placements of the sensor bar.
  40. // This also matches the layout of the settings in the Wii Menu.
  41. static int TranslateSensorBarPosition(int position)
  42. {
  43. if (position == 0)
  44. return 1;
  45. if (position == 1)
  46. return 0;
  47. return position;
  48. }
  49. namespace
  50. {
  51. struct SDSizeComboEntry
  52. {
  53. u64 size;
  54. const char* name;
  55. };
  56. static constexpr u64 MebibytesToBytes(u64 mebibytes)
  57. {
  58. return mebibytes * 1024u * 1024u;
  59. }
  60. static constexpr u64 GibibytesToBytes(u64 gibibytes)
  61. {
  62. return MebibytesToBytes(gibibytes * 1024u);
  63. }
  64. constexpr std::array sd_size_combo_entries{
  65. SDSizeComboEntry{0, _trans("Auto")},
  66. SDSizeComboEntry{MebibytesToBytes(64), _trans("64 MiB")},
  67. SDSizeComboEntry{MebibytesToBytes(128), _trans("128 MiB")},
  68. SDSizeComboEntry{MebibytesToBytes(256), _trans("256 MiB")},
  69. SDSizeComboEntry{MebibytesToBytes(512), _trans("512 MiB")},
  70. SDSizeComboEntry{GibibytesToBytes(1), _trans("1 GiB")},
  71. SDSizeComboEntry{GibibytesToBytes(2), _trans("2 GiB")},
  72. SDSizeComboEntry{GibibytesToBytes(4), _trans("4 GiB (SDHC)")},
  73. SDSizeComboEntry{GibibytesToBytes(8), _trans("8 GiB (SDHC)")},
  74. SDSizeComboEntry{GibibytesToBytes(16), _trans("16 GiB (SDHC)")},
  75. SDSizeComboEntry{GibibytesToBytes(32), _trans("32 GiB (SDHC)")},
  76. };
  77. } // namespace
  78. WiiPane::WiiPane(QWidget* parent) : QWidget(parent)
  79. {
  80. CreateLayout();
  81. LoadConfig();
  82. ConnectLayout();
  83. ValidateSelectionState();
  84. OnEmulationStateChanged(!Core::IsUninitialized(Core::System::GetInstance()));
  85. }
  86. void WiiPane::CreateLayout()
  87. {
  88. m_main_layout = new QVBoxLayout{this};
  89. CreateMisc();
  90. CreateSDCard();
  91. CreateWhitelistedUSBPassthroughDevices();
  92. CreateWiiRemoteSettings();
  93. }
  94. void WiiPane::ConnectLayout()
  95. {
  96. // Misc Settings
  97. connect(m_aspect_ratio_choice, &QComboBox::currentIndexChanged, this, &WiiPane::OnSaveConfig);
  98. connect(m_system_language_choice, &QComboBox::currentIndexChanged, this, &WiiPane::OnSaveConfig);
  99. connect(m_sound_mode_choice, &QComboBox::currentIndexChanged, this, &WiiPane::OnSaveConfig);
  100. connect(m_screensaver_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  101. connect(m_pal60_mode_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  102. connect(m_connect_keyboard_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  103. connect(&Settings::Instance(), &Settings::SDCardInsertionChanged, m_sd_card_checkbox,
  104. &QCheckBox::setChecked);
  105. connect(&Settings::Instance(), &Settings::USBKeyboardConnectionChanged,
  106. m_connect_keyboard_checkbox, &QCheckBox::setChecked);
  107. connect(m_wiilink_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  108. // SD Card Settings
  109. connect(m_sd_card_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  110. connect(m_allow_sd_writes_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  111. connect(m_sync_sd_folder_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  112. connect(m_sd_card_size_combo, &QComboBox::currentIndexChanged, this, &WiiPane::OnSaveConfig);
  113. // Whitelisted USB Passthrough Devices
  114. connect(m_whitelist_usb_list, &QListWidget::itemClicked, this, &WiiPane::ValidateSelectionState);
  115. connect(m_whitelist_usb_add_button, &QPushButton::clicked, this,
  116. &WiiPane::OnUSBWhitelistAddButton);
  117. connect(m_whitelist_usb_remove_button, &QPushButton::clicked, this,
  118. &WiiPane::OnUSBWhitelistRemoveButton);
  119. // Wii Remote Settings
  120. connect(m_wiimote_ir_sensor_position, &QComboBox::currentIndexChanged, this,
  121. &WiiPane::OnSaveConfig);
  122. connect(m_wiimote_ir_sensitivity, &QSlider::valueChanged, this, &WiiPane::OnSaveConfig);
  123. connect(m_wiimote_speaker_volume, &QSlider::valueChanged, this, &WiiPane::OnSaveConfig);
  124. connect(m_wiimote_motor, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig);
  125. // Emulation State
  126. connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
  127. OnEmulationStateChanged(state != Core::State::Uninitialized);
  128. });
  129. }
  130. void WiiPane::CreateMisc()
  131. {
  132. auto* misc_settings_group = new QGroupBox(tr("Misc Settings"));
  133. auto* misc_settings_group_layout = new QGridLayout();
  134. misc_settings_group->setLayout(misc_settings_group_layout);
  135. m_main_layout->addWidget(misc_settings_group);
  136. m_pal60_mode_checkbox = new QCheckBox(tr("Use PAL60 Mode (EuRGB60)"));
  137. m_screensaver_checkbox = new QCheckBox(tr("Enable Screen Saver"));
  138. m_wiilink_checkbox = new QCheckBox(tr("Enable WiiConnect24 via WiiLink"));
  139. m_connect_keyboard_checkbox = new QCheckBox(tr("Connect USB Keyboard"));
  140. m_aspect_ratio_choice_label = new QLabel(tr("Aspect Ratio:"));
  141. m_aspect_ratio_choice = new QComboBox();
  142. m_aspect_ratio_choice->addItem(tr("4:3"));
  143. m_aspect_ratio_choice->addItem(tr("16:9"));
  144. m_system_language_choice_label = new QLabel(tr("System Language:"));
  145. m_system_language_choice = new QComboBox();
  146. m_system_language_choice->addItem(tr("Japanese"));
  147. m_system_language_choice->addItem(tr("English"));
  148. m_system_language_choice->addItem(tr("German"));
  149. m_system_language_choice->addItem(tr("French"));
  150. m_system_language_choice->addItem(tr("Spanish"));
  151. m_system_language_choice->addItem(tr("Italian"));
  152. m_system_language_choice->addItem(tr("Dutch"));
  153. m_system_language_choice->addItem(tr("Simplified Chinese"));
  154. m_system_language_choice->addItem(tr("Traditional Chinese"));
  155. m_system_language_choice->addItem(tr("Korean"));
  156. m_sound_mode_choice_label = new QLabel(tr("Sound:"));
  157. m_sound_mode_choice = new QComboBox();
  158. m_sound_mode_choice->addItem(tr("Mono"));
  159. m_sound_mode_choice->addItem(tr("Stereo"));
  160. // i18n: Surround audio (Dolby Pro Logic II)
  161. m_sound_mode_choice->addItem(tr("Surround"));
  162. m_pal60_mode_checkbox->setToolTip(tr("Sets the Wii display mode to 60Hz (480i) instead of 50Hz "
  163. "(576i) for PAL games.\nMay not work for all games."));
  164. m_screensaver_checkbox->setToolTip(tr("Dims the screen after five minutes of inactivity."));
  165. m_wiilink_checkbox->setToolTip(tr(
  166. "Enables the WiiLink service for WiiConnect24 channels.\nWiiLink is an alternate provider "
  167. "for the discontinued WiiConnect24 Channels such as the Forecast and Nintendo Channels\nRead "
  168. "the Terms of Service at: https://www.wiilink24.com/tos"));
  169. m_system_language_choice->setToolTip(tr("Sets the Wii system language."));
  170. m_connect_keyboard_checkbox->setToolTip(tr("May cause slow down in Wii Menu and some games."));
  171. misc_settings_group_layout->addWidget(m_pal60_mode_checkbox, 0, 0, 1, 1);
  172. misc_settings_group_layout->addWidget(m_connect_keyboard_checkbox, 0, 1, 1, 1);
  173. misc_settings_group_layout->addWidget(m_screensaver_checkbox, 1, 0, 1, 1);
  174. misc_settings_group_layout->addWidget(m_wiilink_checkbox, 1, 1, 1, 1);
  175. misc_settings_group_layout->addWidget(m_aspect_ratio_choice_label, 2, 0, 1, 1);
  176. misc_settings_group_layout->addWidget(m_aspect_ratio_choice, 2, 1, 1, 1);
  177. misc_settings_group_layout->addWidget(m_system_language_choice_label, 3, 0, 1, 1);
  178. misc_settings_group_layout->addWidget(m_system_language_choice, 3, 1, 1, 1);
  179. misc_settings_group_layout->addWidget(m_sound_mode_choice_label, 4, 0, 1, 1);
  180. misc_settings_group_layout->addWidget(m_sound_mode_choice, 4, 1, 1, 1);
  181. }
  182. void WiiPane::CreateSDCard()
  183. {
  184. auto* sd_settings_group = new QGroupBox(tr("SD Card Settings"));
  185. auto* sd_settings_group_layout = new QGridLayout();
  186. sd_settings_group->setLayout(sd_settings_group_layout);
  187. m_main_layout->addWidget(sd_settings_group);
  188. int row = 0;
  189. m_sd_card_checkbox = new QCheckBox(tr("Insert SD Card"));
  190. m_sd_card_checkbox->setToolTip(tr("Supports SD and SDHC. Default size is 128 MB."));
  191. m_allow_sd_writes_checkbox = new QCheckBox(tr("Allow Writes to SD Card"));
  192. sd_settings_group_layout->addWidget(m_sd_card_checkbox, row, 0, 1, 1);
  193. sd_settings_group_layout->addWidget(m_allow_sd_writes_checkbox, row, 1, 1, 1);
  194. ++row;
  195. {
  196. QHBoxLayout* hlayout = new QHBoxLayout;
  197. m_sd_raw_edit = new QLineEdit(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX)));
  198. connect(m_sd_raw_edit, &QLineEdit::editingFinished,
  199. [this] { SetSDRaw(m_sd_raw_edit->text()); });
  200. QPushButton* sdcard_open = new NonDefaultQPushButton(QStringLiteral("..."));
  201. connect(sdcard_open, &QPushButton::clicked, this, &WiiPane::BrowseSDRaw);
  202. hlayout->addWidget(new QLabel(tr("SD Card Path:")));
  203. hlayout->addWidget(m_sd_raw_edit);
  204. hlayout->addWidget(sdcard_open);
  205. sd_settings_group_layout->addLayout(hlayout, row, 0, 1, 2);
  206. ++row;
  207. }
  208. m_sync_sd_folder_checkbox = new QCheckBox(tr("Automatically Sync with Folder"));
  209. m_sync_sd_folder_checkbox->setToolTip(
  210. tr("Synchronizes the SD Card with the SD Sync Folder when starting and ending emulation."));
  211. sd_settings_group_layout->addWidget(m_sync_sd_folder_checkbox, row, 0, 1, 2);
  212. ++row;
  213. {
  214. QHBoxLayout* hlayout = new QHBoxLayout;
  215. m_sd_sync_folder_edit =
  216. new QLineEdit(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)));
  217. connect(m_sd_sync_folder_edit, &QLineEdit::editingFinished,
  218. [this] { SetSDSyncFolder(m_sd_sync_folder_edit->text()); });
  219. QPushButton* sdcard_open = new NonDefaultQPushButton(QStringLiteral("..."));
  220. connect(sdcard_open, &QPushButton::clicked, this, &WiiPane::BrowseSDSyncFolder);
  221. hlayout->addWidget(new QLabel(tr("SD Sync Folder:")));
  222. hlayout->addWidget(m_sd_sync_folder_edit);
  223. hlayout->addWidget(sdcard_open);
  224. sd_settings_group_layout->addLayout(hlayout, row, 0, 1, 2);
  225. ++row;
  226. }
  227. m_sd_card_size_combo = new QComboBox();
  228. for (size_t i = 0; i < sd_size_combo_entries.size(); ++i)
  229. m_sd_card_size_combo->addItem(tr(sd_size_combo_entries[i].name));
  230. sd_settings_group_layout->addWidget(new QLabel(tr("SD Card File Size:")), row, 0);
  231. sd_settings_group_layout->addWidget(m_sd_card_size_combo, row, 1);
  232. ++row;
  233. m_sd_pack_button = new NonDefaultQPushButton(tr(Common::SD_PACK_TEXT));
  234. m_sd_unpack_button = new NonDefaultQPushButton(tr(Common::SD_UNPACK_TEXT));
  235. connect(m_sd_pack_button, &QPushButton::clicked, [this] {
  236. auto result = ModalMessageBox::warning(
  237. this, tr(Common::SD_PACK_TEXT),
  238. tr("You are about to pack the content of the folder at %1 into the file at %2. All "
  239. "current content of the file will be deleted. Are you sure you want to continue?")
  240. .arg(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)))
  241. .arg(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX))),
  242. QMessageBox::Yes | QMessageBox::No);
  243. if (result == QMessageBox::Yes)
  244. {
  245. ParallelProgressDialog progress_dialog(tr("Converting..."), tr("Cancel"), 0, 0, this);
  246. progress_dialog.GetRaw()->setWindowModality(Qt::WindowModal);
  247. progress_dialog.GetRaw()->setWindowTitle(tr("Progress"));
  248. auto success = std::async(std::launch::async, [&] {
  249. const bool good = Common::SyncSDFolderToSDImage(
  250. [&progress_dialog] { return progress_dialog.WasCanceled(); }, false);
  251. progress_dialog.Reset();
  252. return good;
  253. });
  254. progress_dialog.GetRaw()->exec();
  255. if (!success.get())
  256. ModalMessageBox::warning(this, tr(Common::SD_PACK_TEXT), tr("Conversion failed."));
  257. }
  258. });
  259. connect(m_sd_unpack_button, &QPushButton::clicked, [this] {
  260. auto result = ModalMessageBox::warning(
  261. this, tr(Common::SD_UNPACK_TEXT),
  262. tr("You are about to unpack the content of the file at %2 into the folder at %1. All "
  263. "current content of the folder will be deleted. Are you sure you want to continue?")
  264. .arg(QString::fromStdString(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX)))
  265. .arg(QString::fromStdString(File::GetUserPath(F_WIISDCARDIMAGE_IDX))),
  266. QMessageBox::Yes | QMessageBox::No);
  267. if (result == QMessageBox::Yes)
  268. {
  269. ParallelProgressDialog progress_dialog(tr("Converting..."), tr("Cancel"), 0, 0, this);
  270. progress_dialog.GetRaw()->setWindowModality(Qt::WindowModal);
  271. progress_dialog.GetRaw()->setWindowTitle(tr("Progress"));
  272. auto success = std::async(std::launch::async, [&] {
  273. const bool good = Common::SyncSDImageToSDFolder(
  274. [&progress_dialog] { return progress_dialog.WasCanceled(); });
  275. progress_dialog.Reset();
  276. return good;
  277. });
  278. progress_dialog.GetRaw()->exec();
  279. if (!success.get())
  280. ModalMessageBox::warning(this, tr(Common::SD_UNPACK_TEXT), tr("Conversion failed."));
  281. }
  282. });
  283. sd_settings_group_layout->addWidget(m_sd_pack_button, row, 0, 1, 1);
  284. sd_settings_group_layout->addWidget(m_sd_unpack_button, row, 1, 1, 1);
  285. ++row;
  286. }
  287. void WiiPane::CreateWhitelistedUSBPassthroughDevices()
  288. {
  289. m_whitelist_usb_list = new QtUtils::MinimumSizeHintWidget<QListWidget>;
  290. m_whitelist_usb_add_button = new NonDefaultQPushButton(tr("Add..."));
  291. m_whitelist_usb_remove_button = new NonDefaultQPushButton(tr("Remove"));
  292. QHBoxLayout* hlayout = new QHBoxLayout;
  293. hlayout->addStretch();
  294. hlayout->addWidget(m_whitelist_usb_add_button);
  295. hlayout->addWidget(m_whitelist_usb_remove_button);
  296. QVBoxLayout* vlayout = new QVBoxLayout;
  297. vlayout->addWidget(m_whitelist_usb_list);
  298. vlayout->addLayout(hlayout);
  299. auto* whitelisted_usb_passthrough_devices_group =
  300. new QGroupBox(tr("Whitelisted USB Passthrough Devices"));
  301. whitelisted_usb_passthrough_devices_group->setLayout(vlayout);
  302. m_main_layout->addWidget(whitelisted_usb_passthrough_devices_group);
  303. }
  304. void WiiPane::CreateWiiRemoteSettings()
  305. {
  306. auto* wii_remote_settings_group = new QGroupBox(tr("Wii Remote Settings"));
  307. auto* wii_remote_settings_group_layout = new QGridLayout();
  308. wii_remote_settings_group->setLayout(wii_remote_settings_group_layout);
  309. m_main_layout->addWidget(wii_remote_settings_group);
  310. m_wiimote_motor = new QCheckBox(tr("Enable Rumble"));
  311. m_wiimote_sensor_position_label = new QLabel(tr("Sensor Bar Position:"));
  312. m_wiimote_ir_sensor_position = new QComboBox();
  313. m_wiimote_ir_sensor_position->addItem(tr("Top"));
  314. m_wiimote_ir_sensor_position->addItem(tr("Bottom"));
  315. // IR Sensitivity Slider
  316. // i18n: IR stands for infrared and refers to the pointer functionality of Wii Remotes
  317. m_wiimote_ir_sensitivity_label = new QLabel(tr("IR Sensitivity:"));
  318. m_wiimote_ir_sensitivity = new QSlider(Qt::Horizontal);
  319. // Wii menu saves values from 1 to 5.
  320. m_wiimote_ir_sensitivity->setMinimum(1);
  321. m_wiimote_ir_sensitivity->setMaximum(5);
  322. // Speaker Volume Slider
  323. m_wiimote_speaker_volume_label = new QLabel(tr("Speaker Volume:"));
  324. m_wiimote_speaker_volume = new QSlider(Qt::Horizontal);
  325. m_wiimote_speaker_volume->setMinimum(0);
  326. m_wiimote_speaker_volume->setMaximum(127);
  327. wii_remote_settings_group_layout->addWidget(m_wiimote_sensor_position_label, 0, 0);
  328. wii_remote_settings_group_layout->addWidget(m_wiimote_ir_sensor_position, 0, 1);
  329. wii_remote_settings_group_layout->addWidget(m_wiimote_ir_sensitivity_label, 1, 0);
  330. wii_remote_settings_group_layout->addWidget(m_wiimote_ir_sensitivity, 1, 1);
  331. wii_remote_settings_group_layout->addWidget(m_wiimote_speaker_volume_label, 2, 0);
  332. wii_remote_settings_group_layout->addWidget(m_wiimote_speaker_volume, 2, 1);
  333. wii_remote_settings_group_layout->addWidget(m_wiimote_motor, 3, 0, 1, -1);
  334. }
  335. void WiiPane::OnEmulationStateChanged(bool running)
  336. {
  337. m_screensaver_checkbox->setEnabled(!running);
  338. m_pal60_mode_checkbox->setEnabled(!running);
  339. m_system_language_choice->setEnabled(!running);
  340. m_aspect_ratio_choice->setEnabled(!running);
  341. m_sound_mode_choice->setEnabled(!running);
  342. m_sd_pack_button->setEnabled(!running);
  343. m_sd_unpack_button->setEnabled(!running);
  344. m_wiimote_motor->setEnabled(!running);
  345. m_wiimote_speaker_volume->setEnabled(!running);
  346. m_wiimote_ir_sensitivity->setEnabled(!running);
  347. m_wiimote_ir_sensor_position->setEnabled(!running);
  348. m_wiilink_checkbox->setEnabled(!running);
  349. }
  350. void WiiPane::LoadConfig()
  351. {
  352. m_screensaver_checkbox->setChecked(Config::Get(Config::SYSCONF_SCREENSAVER));
  353. m_pal60_mode_checkbox->setChecked(Config::Get(Config::SYSCONF_PAL60));
  354. m_connect_keyboard_checkbox->setChecked(Settings::Instance().IsUSBKeyboardConnected());
  355. m_aspect_ratio_choice->setCurrentIndex(Config::Get(Config::SYSCONF_WIDESCREEN));
  356. m_system_language_choice->setCurrentIndex(Config::Get(Config::SYSCONF_LANGUAGE));
  357. m_sound_mode_choice->setCurrentIndex(Config::Get(Config::SYSCONF_SOUND_MODE));
  358. m_wiilink_checkbox->setChecked(Config::Get(Config::MAIN_WII_WIILINK_ENABLE));
  359. m_sd_card_checkbox->setChecked(Settings::Instance().IsSDCardInserted());
  360. m_allow_sd_writes_checkbox->setChecked(Config::Get(Config::MAIN_ALLOW_SD_WRITES));
  361. m_sync_sd_folder_checkbox->setChecked(Config::Get(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC));
  362. const u64 sd_card_size = Config::Get(Config::MAIN_WII_SD_CARD_FILESIZE);
  363. for (size_t i = 0; i < sd_size_combo_entries.size(); ++i)
  364. {
  365. if (sd_size_combo_entries[i].size == sd_card_size)
  366. m_sd_card_size_combo->setCurrentIndex(static_cast<int>(i));
  367. }
  368. PopulateUSBPassthroughListWidget();
  369. m_wiimote_ir_sensor_position->setCurrentIndex(
  370. TranslateSensorBarPosition(Config::Get(Config::SYSCONF_SENSOR_BAR_POSITION)));
  371. m_wiimote_ir_sensitivity->setValue(Config::Get(Config::SYSCONF_SENSOR_BAR_SENSITIVITY));
  372. m_wiimote_speaker_volume->setValue(Config::Get(Config::SYSCONF_SPEAKER_VOLUME));
  373. m_wiimote_motor->setChecked(Config::Get(Config::SYSCONF_WIIMOTE_MOTOR));
  374. }
  375. void WiiPane::OnSaveConfig()
  376. {
  377. Config::ConfigChangeCallbackGuard config_guard;
  378. Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked());
  379. Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked());
  380. Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked());
  381. Config::SetBase<u32>(Config::SYSCONF_SENSOR_BAR_POSITION,
  382. TranslateSensorBarPosition(m_wiimote_ir_sensor_position->currentIndex()));
  383. Config::SetBase<u32>(Config::SYSCONF_SENSOR_BAR_SENSITIVITY, m_wiimote_ir_sensitivity->value());
  384. Config::SetBase<u32>(Config::SYSCONF_SPEAKER_VOLUME, m_wiimote_speaker_volume->value());
  385. Config::SetBase<u32>(Config::SYSCONF_LANGUAGE, m_system_language_choice->currentIndex());
  386. Config::SetBase<bool>(Config::SYSCONF_WIDESCREEN, m_aspect_ratio_choice->currentIndex());
  387. Config::SetBase<u32>(Config::SYSCONF_SOUND_MODE, m_sound_mode_choice->currentIndex());
  388. Config::SetBase(Config::SYSCONF_WIIMOTE_MOTOR, m_wiimote_motor->isChecked());
  389. Config::SetBase(Config::MAIN_WII_WIILINK_ENABLE, m_wiilink_checkbox->isChecked());
  390. Settings::Instance().SetSDCardInserted(m_sd_card_checkbox->isChecked());
  391. Config::SetBase(Config::MAIN_ALLOW_SD_WRITES, m_allow_sd_writes_checkbox->isChecked());
  392. Config::SetBase(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC,
  393. m_sync_sd_folder_checkbox->isChecked());
  394. const int sd_card_size_index = m_sd_card_size_combo->currentIndex();
  395. if (sd_card_size_index >= 0 &&
  396. static_cast<size_t>(sd_card_size_index) < sd_size_combo_entries.size())
  397. {
  398. Config::SetBase(Config::MAIN_WII_SD_CARD_FILESIZE,
  399. sd_size_combo_entries[sd_card_size_index].size);
  400. }
  401. }
  402. void WiiPane::ValidateSelectionState()
  403. {
  404. m_whitelist_usb_remove_button->setEnabled(m_whitelist_usb_list->currentIndex().isValid());
  405. }
  406. void WiiPane::OnUSBWhitelistAddButton()
  407. {
  408. USBDeviceAddToWhitelistDialog usb_whitelist_dialog(this);
  409. connect(&usb_whitelist_dialog, &USBDeviceAddToWhitelistDialog::accepted, this,
  410. &WiiPane::PopulateUSBPassthroughListWidget);
  411. usb_whitelist_dialog.exec();
  412. }
  413. void WiiPane::OnUSBWhitelistRemoveButton()
  414. {
  415. QString device = m_whitelist_usb_list->currentItem()->text().left(9);
  416. QStringList split = device.split(QString::fromStdString(":"));
  417. QString vid = QString(split[0]);
  418. QString pid = QString(split[1]);
  419. const u16 vid_u16 = static_cast<u16>(std::stoul(vid.toStdString(), nullptr, 16));
  420. const u16 pid_u16 = static_cast<u16>(std::stoul(pid.toStdString(), nullptr, 16));
  421. auto whitelist = Config::GetUSBDeviceWhitelist();
  422. whitelist.erase({vid_u16, pid_u16});
  423. Config::SetUSBDeviceWhitelist(whitelist);
  424. PopulateUSBPassthroughListWidget();
  425. }
  426. void WiiPane::PopulateUSBPassthroughListWidget()
  427. {
  428. m_whitelist_usb_list->clear();
  429. auto whitelist = Config::GetUSBDeviceWhitelist();
  430. for (const auto& device : whitelist)
  431. {
  432. QListWidgetItem* usb_lwi =
  433. new QListWidgetItem(QString::fromStdString(USBUtils::GetDeviceName(device)));
  434. m_whitelist_usb_list->addItem(usb_lwi);
  435. }
  436. ValidateSelectionState();
  437. }
  438. void WiiPane::BrowseSDRaw()
  439. {
  440. QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
  441. this, tr("Select SD Card Image"),
  442. QString::fromStdString(Config::Get(Config::MAIN_WII_SD_CARD_IMAGE_PATH)),
  443. tr("SD Card Image (*.raw);;"
  444. "All Files (*)")));
  445. if (!file.isEmpty())
  446. SetSDRaw(file);
  447. }
  448. void WiiPane::SetSDRaw(const QString& path)
  449. {
  450. Config::SetBase(Config::MAIN_WII_SD_CARD_IMAGE_PATH, path.toStdString());
  451. SignalBlocking(m_sd_raw_edit)->setText(path);
  452. }
  453. void WiiPane::BrowseSDSyncFolder()
  454. {
  455. QString file = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
  456. this, tr("Select a Folder to Sync with the SD Card Image"),
  457. QString::fromStdString(Config::Get(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH))));
  458. if (!file.isEmpty())
  459. SetSDSyncFolder(file);
  460. }
  461. void WiiPane::SetSDSyncFolder(const QString& path)
  462. {
  463. Config::SetBase(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH, path.toStdString());
  464. SignalBlocking(m_sd_sync_folder_edit)->setText(path);
  465. }