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