src/platform/qt/SettingsView.cpp (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "SettingsView.h"
7
8#include "AudioProcessor.h"
9#include "ConfigController.h"
10#include "Display.h"
11#include "GBAApp.h"
12#include "InputController.h"
13#include "RotatedHeaderView.h"
14#include "ShaderSelector.h"
15#include "ShortcutView.h"
16
17#include <mgba/core/serialize.h>
18#include <mgba/core/version.h>
19#include <mgba/internal/gba/gba.h>
20
21using namespace QGBA;
22
23#ifdef M_CORE_GB
24QList<enum GBModel> SettingsView::s_gbModelList;
25#endif
26
27SettingsView::SettingsView(ConfigController* controller, InputController* inputController, LogController* logController, QWidget* parent)
28 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
29 , m_controller(controller)
30 , m_input(inputController)
31 , m_logModel(logController)
32{
33 m_ui.setupUi(this);
34
35#ifdef M_CORE_GB
36 if (s_gbModelList.isEmpty()) {
37 // NB: Keep in sync with SettingsView.ui
38 s_gbModelList.append(GB_MODEL_AUTODETECT);
39 s_gbModelList.append(GB_MODEL_DMG);
40 s_gbModelList.append(GB_MODEL_SGB);
41 s_gbModelList.append(GB_MODEL_CGB);
42 s_gbModelList.append(GB_MODEL_AGB);
43 }
44#endif
45
46 reloadConfig();
47
48 connect(m_ui.volume, static_cast<void (QSlider::*)(int)>(&QSlider::valueChanged), [this](int v) {
49 if (v < m_ui.volumeFf->value()) {
50 m_ui.volumeFf->setValue(v);
51 }
52 });
53
54 connect(m_ui.mute, &QAbstractButton::toggled, [this](bool e) {
55 if (e) {
56 m_ui.muteFf->setChecked(e);
57 }
58 });
59
60 if (m_ui.savegamePath->text().isEmpty()) {
61 m_ui.savegameSameDir->setChecked(true);
62 }
63 connect(m_ui.savegameSameDir, &QAbstractButton::toggled, [this] (bool e) {
64 if (e) {
65 m_ui.savegamePath->clear();
66 }
67 });
68 connect(m_ui.savegameBrowse, &QAbstractButton::pressed, [this] () {
69 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
70 if (!path.isNull()) {
71 m_ui.savegameSameDir->setChecked(false);
72 m_ui.savegamePath->setText(path);
73 }
74 });
75
76 if (m_ui.savestatePath->text().isEmpty()) {
77 m_ui.savestateSameDir->setChecked(true);
78 }
79 connect(m_ui.savestateSameDir, &QAbstractButton::toggled, [this] (bool e) {
80 if (e) {
81 m_ui.savestatePath->clear();
82 }
83 });
84 connect(m_ui.savestateBrowse, &QAbstractButton::pressed, [this] () {
85 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
86 if (!path.isNull()) {
87 m_ui.savestateSameDir->setChecked(false);
88 m_ui.savestatePath->setText(path);
89 }
90 });
91
92 if (m_ui.screenshotPath->text().isEmpty()) {
93 m_ui.screenshotSameDir->setChecked(true);
94 }
95 connect(m_ui.screenshotSameDir, &QAbstractButton::toggled, [this] (bool e) {
96 if (e) {
97 m_ui.screenshotPath->clear();
98 }
99 });
100 connect(m_ui.screenshotBrowse, &QAbstractButton::pressed, [this] () {
101 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
102 if (!path.isNull()) {
103 m_ui.screenshotSameDir->setChecked(false);
104 m_ui.screenshotPath->setText(path);
105 }
106 });
107
108 if (m_ui.patchPath->text().isEmpty()) {
109 m_ui.patchSameDir->setChecked(true);
110 }
111 connect(m_ui.patchSameDir, &QAbstractButton::toggled, [this] (bool e) {
112 if (e) {
113 m_ui.patchPath->clear();
114 }
115 });
116 connect(m_ui.patchBrowse, &QAbstractButton::pressed, [this] () {
117 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
118 if (!path.isNull()) {
119 m_ui.patchSameDir->setChecked(false);
120 m_ui.patchPath->setText(path);
121 }
122 });
123
124 if (m_ui.cheatsPath->text().isEmpty()) {
125 m_ui.cheatsSameDir->setChecked(true);
126 }
127 connect(m_ui.cheatsSameDir, &QAbstractButton::toggled, [this] (bool e) {
128 if (e) {
129 m_ui.cheatsPath->clear();
130 }
131 });
132 connect(m_ui.cheatsBrowse, &QAbstractButton::pressed, [this] () {
133 QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
134 if (!path.isNull()) {
135 m_ui.cheatsSameDir->setChecked(false);
136 m_ui.cheatsPath->setText(path);
137 }
138 });
139 connect(m_ui.clearCache, &QAbstractButton::pressed, this, &SettingsView::libraryCleared);
140
141 // TODO: Move to reloadConfig()
142 QVariant audioDriver = m_controller->getQtOption("audioDriver");
143#ifdef BUILD_QT_MULTIMEDIA
144 m_ui.audioDriver->addItem(tr("Qt Multimedia"), static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA));
145 if (!audioDriver.isNull() && audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA)) {
146 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
147 }
148#endif
149
150#ifdef BUILD_SDL
151 m_ui.audioDriver->addItem(tr("SDL"), static_cast<int>(AudioProcessor::Driver::SDL));
152 if (audioDriver.isNull() || audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::SDL)) {
153 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
154 }
155#endif
156
157 // TODO: Move to reloadConfig()
158 QVariant displayDriver = m_controller->getQtOption("displayDriver");
159 m_ui.displayDriver->addItem(tr("Software (Qt)"), static_cast<int>(Display::Driver::QT));
160 if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::QT)) {
161 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
162 }
163
164#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
165 m_ui.displayDriver->addItem(tr("OpenGL"), static_cast<int>(Display::Driver::OPENGL));
166 if (displayDriver.isNull() || displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL)) {
167 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
168 }
169#endif
170
171#ifdef BUILD_GL
172 m_ui.displayDriver->addItem(tr("OpenGL (force version 1.x)"), static_cast<int>(Display::Driver::OPENGL1));
173 if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL1)) {
174 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
175 }
176#endif
177
178 // TODO: Move to reloadConfig()
179 QVariant cameraDriver = m_controller->getQtOption("cameraDriver");
180 m_ui.cameraDriver->addItem(tr("None (Still Image)"), static_cast<int>(InputController::CameraDriver::NONE));
181 if (cameraDriver.isNull() || cameraDriver.toInt() == static_cast<int>(InputController::CameraDriver::NONE)) {
182 m_ui.cameraDriver->setCurrentIndex(m_ui.cameraDriver->count() - 1);
183 m_ui.camera->setEnabled(false);
184 }
185
186#ifdef BUILD_QT_MULTIMEDIA
187 m_ui.cameraDriver->addItem(tr("Qt Multimedia"), static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA));
188 if (!cameraDriver.isNull() && cameraDriver.toInt() == static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA)) {
189 m_ui.cameraDriver->setCurrentIndex(m_ui.cameraDriver->count() - 1);
190 m_ui.camera->setEnabled(true);
191 }
192 QList<QPair<QByteArray, QString>> cameras = inputController->listCameras();
193 QByteArray currentCamera = m_controller->getQtOption("camera").toByteArray();
194 for (const auto& camera : cameras) {
195 m_ui.camera->addItem(camera.second, camera.first);
196 if (camera.first == currentCamera) {
197 m_ui.camera->setCurrentIndex(m_ui.camera->count() - 1);
198 }
199 }
200#endif
201
202#ifdef M_CORE_GBA
203 connect(m_ui.gbaBiosBrowse, &QPushButton::clicked, [this]() {
204 selectBios(m_ui.gbaBios);
205 });
206#else
207 m_ui.gbaBiosBrowse->hide();
208#endif
209
210#ifdef M_CORE_GB
211 connect(m_ui.gbBiosBrowse, &QPushButton::clicked, [this]() {
212 selectBios(m_ui.gbBios);
213 });
214 connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() {
215 selectBios(m_ui.gbcBios);
216 });
217 connect(m_ui.sgbBiosBrowse, &QPushButton::clicked, [this]() {
218 selectBios(m_ui.sgbBios);
219 });
220
221 QList<QColor> defaultColors;
222 defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
223 defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
224 defaultColors.append(QColor(0x50, 0x50, 0x50));
225 defaultColors.append(QColor(0x00, 0x00, 0x00));
226 defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
227 defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
228 defaultColors.append(QColor(0x50, 0x50, 0x50));
229 defaultColors.append(QColor(0x00, 0x00, 0x00));
230 defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
231 defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
232 defaultColors.append(QColor(0x50, 0x50, 0x50));
233 defaultColors.append(QColor(0x00, 0x00, 0x00));
234 QList<QWidget*> colors{
235 m_ui.color0,
236 m_ui.color1,
237 m_ui.color2,
238 m_ui.color3,
239 m_ui.color4,
240 m_ui.color5,
241 m_ui.color6,
242 m_ui.color7,
243 m_ui.color8,
244 m_ui.color9,
245 m_ui.color10,
246 m_ui.color11
247 };
248 for (int colorId = 0; colorId < 12; ++colorId) {
249 bool ok;
250 uint color = m_controller->getOption(QString("gb.pal[%0]").arg(colorId)).toUInt(&ok);
251 if (ok) {
252 defaultColors[colorId] = QColor::fromRgb(color);
253 m_gbColors[colorId] = color | 0xFF000000;
254 } else {
255 m_gbColors[colorId] = defaultColors[colorId].rgb() & ~0xFF000000;
256 }
257 m_colorPickers[colorId] = ColorPicker(colors[colorId], defaultColors[colorId]);
258 connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
259 m_gbColors[colorId] = color.rgb();
260 });
261 }
262#else
263 m_ui.gbBiosBrowse->hide();
264 m_ui.gbcBiosBrowse->hide();
265 m_ui.sgbBiosBrowse->hide();
266 m_ui.gb->hide();
267#endif
268
269#ifdef M_CORE_DS
270 connect(m_ui.dsBios7Browse, &QPushButton::clicked, [this]() {
271 selectBios(m_ui.dsBios7);
272 });
273 connect(m_ui.dsBios9Browse, &QPushButton::clicked, [this]() {
274 selectBios(m_ui.dsBios9);
275 });
276 connect(m_ui.dsFirmwareBrowse, &QPushButton::clicked, [this]() {
277 selectBios(m_ui.dsFirmware);
278 });
279#else
280 m_ui.dsBios7Browse->hide();
281 m_ui.dsBios9Browse->hide();
282 m_ui.dsFirmwareBrowse->hide();
283#endif
284
285 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &SettingsView::updateConfig);
286 connect(m_ui.buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button) {
287 if (m_ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
288 updateConfig();
289 }
290 });
291
292 m_ui.languages->setItemData(0, QLocale("en"));
293 QDir ts(":/translations/");
294 for (auto name : ts.entryList()) {
295 if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
296 continue;
297 }
298 QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
299 m_ui.languages->addItem(locale.nativeLanguageName(), locale);
300 if (locale.bcp47Name() == QLocale().bcp47Name()) {
301 m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
302 }
303 }
304
305 m_ui.loggingView->setModel(&m_logModel);
306 m_ui.loggingView->setHorizontalHeader(new RotatedHeaderView(Qt::Horizontal));
307 m_ui.loggingView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
308 m_ui.loggingView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
309
310 connect(m_ui.logFileBrowse, &QAbstractButton::pressed, [this] () {
311 QString path = GBAApp::app()->getSaveFileName(this, "Select log file");
312 if (!path.isNull()) {
313 m_ui.logFile->setText(path);
314 }
315 });
316
317 m_keyView = new ShortcutView();
318 m_keyView->setModel(inputController->keyIndex());
319 m_keyView->setInputController(inputController);
320 m_shortcutView = new ShortcutView();
321 m_shortcutView->setModel(inputController->inputIndex());
322 m_shortcutView->setInputController(inputController);
323 m_ui.stackedWidget->addWidget(m_keyView);
324 m_ui.tabs->addItem(tr("Controls"));
325 m_ui.stackedWidget->addWidget(m_shortcutView);
326 m_ui.tabs->addItem(tr("Shortcuts"));
327}
328
329SettingsView::~SettingsView() {
330#if defined(BUILD_GL) || defined(BUILD_GLES2)
331 setShaderSelector(nullptr);
332#endif
333}
334
335void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
336#if defined(BUILD_GL) || defined(BUILD_GLES2)
337 if (m_shader) {
338 auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString);
339 for (const auto& item : items) {
340 m_ui.tabs->removeItemWidget(item);
341 }
342 m_ui.stackedWidget->removeWidget(m_shader);
343 m_shader->setParent(nullptr);
344 }
345 m_shader = shaderSelector;
346 if (shaderSelector) {
347 m_ui.stackedWidget->addWidget(m_shader);
348 m_ui.tabs->addItem(tr("Shaders"));
349 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved);
350 }
351#endif
352}
353
354void SettingsView::selectBios(QLineEdit* bios) {
355 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
356 if (!filename.isEmpty()) {
357 bios->setText(filename);
358 }
359}
360
361void SettingsView::updateConfig() {
362 saveSetting("gba.bios", m_ui.gbaBios);
363 saveSetting("gb.bios", m_ui.gbBios);
364 saveSetting("gbc.bios", m_ui.gbcBios);
365 saveSetting("sgb.bios", m_ui.sgbBios);
366 saveSetting("sgb.borders", m_ui.sgbBorders);
367 saveSetting("ds.bios7", m_ui.dsBios7);
368 saveSetting("ds.bios9", m_ui.dsBios9);
369 saveSetting("ds.firmware", m_ui.dsFirmware);
370 saveSetting("useCgbColors", m_ui.useCgbColors);
371 saveSetting("useBios", m_ui.useBios);
372 saveSetting("skipBios", m_ui.skipBios);
373 saveSetting("audioBuffers", m_ui.audioBufferSize);
374 saveSetting("sampleRate", m_ui.sampleRate);
375 saveSetting("videoSync", m_ui.videoSync);
376 saveSetting("audioSync", m_ui.audioSync);
377 saveSetting("frameskip", m_ui.frameskip);
378 saveSetting("fpsTarget", m_ui.fpsTarget);
379 saveSetting("autofireThreshold", m_ui.autofireThreshold);
380 saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
381 saveSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
382 saveSetting("volume", m_ui.volume);
383 saveSetting("mute", m_ui.mute);
384 saveSetting("fastForwardVolume", m_ui.volumeFf);
385 saveSetting("fastForwardMute", m_ui.muteFf);
386 saveSetting("rewindEnable", m_ui.rewind);
387 saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
388 saveSetting("resampleVideo", m_ui.resampleVideo);
389 saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
390 saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
391 saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
392 saveSetting("savegamePath", m_ui.savegamePath);
393 saveSetting("savestatePath", m_ui.savestatePath);
394 saveSetting("screenshotPath", m_ui.screenshotPath);
395 saveSetting("patchPath", m_ui.patchPath);
396 saveSetting("cheatsPath", m_ui.cheatsPath);
397 saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
398 saveSetting("showLibrary", m_ui.showLibrary);
399 saveSetting("preload", m_ui.preload);
400 saveSetting("showFps", m_ui.showFps);
401 saveSetting("cheatAutoload", m_ui.cheatAutoload);
402 saveSetting("cheatAutosave", m_ui.cheatAutosave);
403 saveSetting("autoload", m_ui.autoload);
404 saveSetting("autosave", m_ui.autosave);
405 saveSetting("logToFile", m_ui.logToFile);
406 saveSetting("logToStdout", m_ui.logToStdout);
407 saveSetting("logFile", m_ui.logFile);
408 saveSetting("useDiscordPresence", m_ui.useDiscordPresence);
409
410 if (m_ui.fastForwardUnbounded->isChecked()) {
411 saveSetting("fastForwardRatio", "-1");
412 } else {
413 saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
414 }
415
416 switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
417 case IDLE_LOOP_IGNORE:
418 saveSetting("idleOptimization", "ignore");
419 break;
420 case IDLE_LOOP_REMOVE:
421 saveSetting("idleOptimization", "remove");
422 break;
423 case IDLE_LOOP_DETECT:
424 saveSetting("idleOptimization", "detect");
425 break;
426 }
427
428 int loadState = SAVESTATE_RTC;
429 loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
430 loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
431 loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
432 saveSetting("loadStateExtdata", loadState);
433
434 int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
435 saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
436 saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
437 saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
438 saveSetting("saveStateExtdata", saveState);
439
440 QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
441 if (audioDriver != m_controller->getQtOption("audioDriver")) {
442 m_controller->setQtOption("audioDriver", audioDriver);
443 AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
444 emit audioDriverChanged();
445 }
446
447 QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
448 if (displayDriver != m_controller->getQtOption("displayDriver")) {
449 m_controller->setQtOption("displayDriver", displayDriver);
450 Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
451 setShaderSelector(nullptr);
452 emit displayDriverChanged();
453 }
454
455 QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
456 if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
457 m_controller->setQtOption("cameraDriver", cameraDriver);
458 emit cameraDriverChanged();
459 }
460
461 QVariant camera = m_ui.camera->itemData(m_ui.camera->currentIndex());
462 if (camera != m_controller->getQtOption("camera")) {
463 m_controller->setQtOption("camera", camera);
464 emit cameraChanged(camera.toByteArray());
465 }
466
467 QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
468 if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
469 m_controller->setQtOption("language", language.bcp47Name());
470 emit languageChanged();
471 }
472
473 m_logModel.save(m_controller);
474 m_logModel.logger()->setLogFile(m_ui.logFile->text());
475 m_logModel.logger()->logToFile(m_ui.logToFile->isChecked());
476 m_logModel.logger()->logToStdout(m_ui.logToStdout->isChecked());
477
478#ifdef M_CORE_GB
479 GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
480 m_controller->setOption("gb.model", GBModelToName(modelGB));
481
482 GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
483 m_controller->setOption("sgb.model", GBModelToName(modelSGB));
484
485 GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
486 m_controller->setOption("cgb.model", GBModelToName(modelCGB));
487
488 for (int colorId = 0; colorId < 12; ++colorId) {
489 if (!(m_gbColors[colorId] & 0xFF000000)) {
490 continue;
491 }
492 QString color = QString("gb.pal[%0]").arg(colorId);
493 m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
494
495 }
496#endif
497
498 m_controller->write();
499
500 m_input->rebuildIndex(m_shortcutView->root());
501 m_input->rebuildKeyIndex(m_keyView->root());
502 m_input->saveConfiguration();
503
504 emit pathsChanged();
505 emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
506}
507
508void SettingsView::reloadConfig() {
509 loadSetting("bios", m_ui.gbaBios);
510 loadSetting("gba.bios", m_ui.gbaBios);
511 loadSetting("gb.bios", m_ui.gbBios);
512 loadSetting("gbc.bios", m_ui.gbcBios);
513 loadSetting("sgb.bios", m_ui.sgbBios);
514 loadSetting("sgb.borders", m_ui.sgbBorders, true);
515 loadSetting("ds.bios7", m_ui.dsBios7);
516 loadSetting("ds.bios9", m_ui.dsBios9);
517 loadSetting("ds.firmware", m_ui.dsFirmware);
518 loadSetting("useCgbColors", m_ui.useCgbColors, true);
519 loadSetting("useBios", m_ui.useBios);
520 loadSetting("skipBios", m_ui.skipBios);
521 loadSetting("audioBuffers", m_ui.audioBufferSize);
522 loadSetting("sampleRate", m_ui.sampleRate);
523 loadSetting("videoSync", m_ui.videoSync);
524 loadSetting("audioSync", m_ui.audioSync);
525 loadSetting("frameskip", m_ui.frameskip);
526 loadSetting("fpsTarget", m_ui.fpsTarget);
527 loadSetting("autofireThreshold", m_ui.autofireThreshold);
528 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
529 loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
530 loadSetting("volume", m_ui.volume, 0x100);
531 loadSetting("mute", m_ui.mute, false);
532 loadSetting("fastForwardVolume", m_ui.volumeFf, m_ui.volume->value());
533 loadSetting("fastForwardMute", m_ui.muteFf, m_ui.mute->isChecked());
534 loadSetting("rewindEnable", m_ui.rewind);
535 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
536 loadSetting("resampleVideo", m_ui.resampleVideo);
537 loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
538 loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
539 loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
540 loadSetting("savegamePath", m_ui.savegamePath);
541 loadSetting("savestatePath", m_ui.savestatePath);
542 loadSetting("screenshotPath", m_ui.screenshotPath);
543 loadSetting("patchPath", m_ui.patchPath);
544 loadSetting("cheatsPath", m_ui.cheatsPath);
545 loadSetting("showLibrary", m_ui.showLibrary);
546 loadSetting("preload", m_ui.preload);
547 loadSetting("showFps", m_ui.showFps, true);
548 loadSetting("cheatAutoload", m_ui.cheatAutoload, true);
549 loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
550 loadSetting("autoload", m_ui.autoload, true);
551 loadSetting("autosave", m_ui.autosave, false);
552 loadSetting("logToFile", m_ui.logToFile);
553 loadSetting("logToStdout", m_ui.logToStdout);
554 loadSetting("logFile", m_ui.logFile);
555 loadSetting("useDiscordPresence", m_ui.useDiscordPresence);
556
557 m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
558
559 double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
560 if (fastForwardRatio <= 0) {
561 m_ui.fastForwardUnbounded->setChecked(true);
562 m_ui.fastForwardRatio->setEnabled(false);
563 } else {
564 m_ui.fastForwardUnbounded->setChecked(false);
565 m_ui.fastForwardRatio->setEnabled(true);
566 m_ui.fastForwardRatio->setValue(fastForwardRatio);
567 }
568
569 QString idleOptimization = loadSetting("idleOptimization");
570 if (idleOptimization == "ignore") {
571 m_ui.idleOptimization->setCurrentIndex(0);
572 } else if (idleOptimization == "remove") {
573 m_ui.idleOptimization->setCurrentIndex(1);
574 } else if (idleOptimization == "detect") {
575 m_ui.idleOptimization->setCurrentIndex(2);
576 }
577
578 bool ok;
579 int loadState = loadSetting("loadStateExtdata").toInt(&ok);
580 if (!ok) {
581 loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
582 }
583 m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
584 m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
585 m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
586
587 int saveState = loadSetting("saveStateExtdata").toInt(&ok);
588 if (!ok) {
589 saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
590 }
591 m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
592 m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
593 m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
594
595 m_logModel.reset();
596
597#ifdef M_CORE_GB
598 QString modelGB = m_controller->getOption("gb.model");
599 if (!modelGB.isNull()) {
600 GBModel model = GBNameToModel(modelGB.toUtf8().constData());
601 int index = s_gbModelList.indexOf(model);
602 m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
603 }
604
605 QString modelSGB = m_controller->getOption("sgb.model");
606 if (!modelSGB.isNull()) {
607 GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
608 int index = s_gbModelList.indexOf(model);
609 m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
610 }
611
612 QString modelCGB = m_controller->getOption("cgb.model");
613 if (!modelCGB.isNull()) {
614 GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
615 int index = s_gbModelList.indexOf(model);
616 m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
617 }
618#endif
619}
620
621void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
622 m_controller->setOption(key, field->isChecked());
623 m_controller->updateOption(key);
624}
625
626void SettingsView::saveSetting(const char* key, const QComboBox* field) {
627 saveSetting(key, field->lineEdit());
628}
629
630void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
631 saveSetting(key, field->value());
632}
633
634void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
635 saveSetting(key, field->text());
636}
637
638void SettingsView::saveSetting(const char* key, const QSlider* field) {
639 saveSetting(key, field->value());
640}
641
642void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
643 saveSetting(key, field->value());
644}
645
646void SettingsView::saveSetting(const char* key, const QVariant& field) {
647 m_controller->setOption(key, field);
648 m_controller->updateOption(key);
649}
650
651void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
652 QString option = loadSetting(key);
653 field->setChecked(option.isNull() ? defaultVal : option != "0");
654}
655
656void SettingsView::loadSetting(const char* key, QComboBox* field) {
657 loadSetting(key, field->lineEdit());
658}
659
660void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
661 QString option = loadSetting(key);
662 field->setValue(option.toDouble());
663}
664
665void SettingsView::loadSetting(const char* key, QLineEdit* field) {
666 QString option = loadSetting(key);
667 field->setText(option);
668}
669
670void SettingsView::loadSetting(const char* key, QSlider* field, int defaultVal) {
671 QString option = loadSetting(key);
672 field->setValue(option.isNull() ? defaultVal : option.toInt());
673}
674
675void SettingsView::loadSetting(const char* key, QSpinBox* field) {
676 QString option = loadSetting(key);
677 field->setValue(option.toInt());
678}
679
680QString SettingsView::loadSetting(const char* key) {
681 return m_controller->getOption(key);
682}