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_GLES)
293 setShaderSelector(nullptr);
294#endif
295}
296
297void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
298#if defined(BUILD_GL) || defined(BUILD_GLES)
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("rewindSave", m_ui.rewindSave);
345 saveSetting("resampleVideo", m_ui.resampleVideo);
346 saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
347 saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
348 saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
349 saveSetting("savegamePath", m_ui.savegamePath);
350 saveSetting("savestatePath", m_ui.savestatePath);
351 saveSetting("screenshotPath", m_ui.screenshotPath);
352 saveSetting("patchPath", m_ui.patchPath);
353 saveSetting("cheatsPath", m_ui.cheatsPath);
354 saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
355 saveSetting("showLibrary", m_ui.showLibrary);
356 saveSetting("preload", m_ui.preload);
357 saveSetting("showFps", m_ui.showFps);
358 saveSetting("cheatAutoload", m_ui.cheatAutoload);
359 saveSetting("cheatAutosave", m_ui.cheatAutosave);
360
361 if (m_ui.fastForwardUnbounded->isChecked()) {
362 saveSetting("fastForwardRatio", "-1");
363 } else {
364 saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
365 }
366
367 switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
368 case IDLE_LOOP_IGNORE:
369 saveSetting("idleOptimization", "ignore");
370 break;
371 case IDLE_LOOP_REMOVE:
372 saveSetting("idleOptimization", "remove");
373 break;
374 case IDLE_LOOP_DETECT:
375 saveSetting("idleOptimization", "detect");
376 break;
377 }
378
379 int loadState = SAVESTATE_RTC;
380 loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
381 loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
382 loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
383 saveSetting("loadStateExtdata", loadState);
384
385 int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
386 saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
387 saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
388 saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
389 saveSetting("saveStateExtdata", saveState);
390
391 QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
392 if (audioDriver != m_controller->getQtOption("audioDriver")) {
393 m_controller->setQtOption("audioDriver", audioDriver);
394 AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
395 emit audioDriverChanged();
396 }
397
398 QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
399 if (displayDriver != m_controller->getQtOption("displayDriver")) {
400 m_controller->setQtOption("displayDriver", displayDriver);
401 Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
402 setShaderSelector(nullptr);
403 emit displayDriverChanged();
404 }
405
406 QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
407 if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
408 m_controller->setQtOption("cameraDriver", cameraDriver);
409 emit cameraDriverChanged();
410 }
411
412 QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
413 if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
414 m_controller->setQtOption("language", language.bcp47Name());
415 emit languageChanged();
416 }
417
418#ifdef M_CORE_GB
419 GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
420 m_controller->setOption("gb.model", GBModelToName(modelGB));
421
422 GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
423 m_controller->setOption("sgb.model", GBModelToName(modelSGB));
424
425 GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
426 m_controller->setOption("cgb.model", GBModelToName(modelCGB));
427
428 for (int colorId = 0; colorId < 12; ++colorId) {
429 if (!(m_gbColors[colorId] & 0xFF000000)) {
430 continue;
431 }
432 QString color = QString("gb.pal[%0]").arg(colorId);
433 m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
434
435 }
436#endif
437
438 m_controller->write();
439
440 emit pathsChanged();
441 emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
442}
443
444void SettingsView::reloadConfig() {
445 loadSetting("bios", m_ui.gbaBios);
446 loadSetting("gba.bios", m_ui.gbaBios);
447 loadSetting("gb.bios", m_ui.gbBios);
448 loadSetting("gbc.bios", m_ui.gbcBios);
449 loadSetting("sgb.bios", m_ui.sgbBios);
450 loadSetting("sgb.borders", m_ui.sgbBorders, true);
451 loadSetting("useBios", m_ui.useBios);
452 loadSetting("skipBios", m_ui.skipBios);
453 loadSetting("audioBuffers", m_ui.audioBufferSize);
454 loadSetting("sampleRate", m_ui.sampleRate);
455 loadSetting("videoSync", m_ui.videoSync);
456 loadSetting("audioSync", m_ui.audioSync);
457 loadSetting("frameskip", m_ui.frameskip);
458 loadSetting("fpsTarget", m_ui.fpsTarget);
459 loadSetting("autofireThreshold", m_ui.autofireThreshold);
460 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
461 loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
462 loadSetting("volume", m_ui.volume);
463 loadSetting("mute", m_ui.mute);
464 loadSetting("rewindEnable", m_ui.rewind);
465 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
466 loadSetting("rewindSave", m_ui.rewindSave);
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
482 m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
483
484 double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
485 if (fastForwardRatio <= 0) {
486 m_ui.fastForwardUnbounded->setChecked(true);
487 m_ui.fastForwardRatio->setEnabled(false);
488 } else {
489 m_ui.fastForwardUnbounded->setChecked(false);
490 m_ui.fastForwardRatio->setEnabled(true);
491 m_ui.fastForwardRatio->setValue(fastForwardRatio);
492 }
493
494 QString idleOptimization = loadSetting("idleOptimization");
495 if (idleOptimization == "ignore") {
496 m_ui.idleOptimization->setCurrentIndex(0);
497 } else if (idleOptimization == "remove") {
498 m_ui.idleOptimization->setCurrentIndex(1);
499 } else if (idleOptimization == "detect") {
500 m_ui.idleOptimization->setCurrentIndex(2);
501 }
502
503 bool ok;
504 int loadState = loadSetting("loadStateExtdata").toInt(&ok);
505 if (!ok) {
506 loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
507 }
508 m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
509 m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
510 m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
511
512 int saveState = loadSetting("saveStateExtdata").toInt(&ok);
513 if (!ok) {
514 saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
515 }
516 m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
517 m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
518 m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
519
520#ifdef M_CORE_GB
521 QString modelGB = m_controller->getOption("gb.model");
522 if (!modelGB.isNull()) {
523 GBModel model = GBNameToModel(modelGB.toUtf8().constData());
524 int index = s_gbModelList.indexOf(model);
525 m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
526 }
527
528 QString modelSGB = m_controller->getOption("sgb.model");
529 if (!modelSGB.isNull()) {
530 GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
531 int index = s_gbModelList.indexOf(model);
532 m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
533 }
534
535 QString modelCGB = m_controller->getOption("cgb.model");
536 if (!modelCGB.isNull()) {
537 GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
538 int index = s_gbModelList.indexOf(model);
539 m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
540 }
541#endif
542}
543
544void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
545 m_controller->setOption(key, field->isChecked());
546 m_controller->updateOption(key);
547}
548
549void SettingsView::saveSetting(const char* key, const QComboBox* field) {
550 saveSetting(key, field->lineEdit());
551}
552
553void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
554 saveSetting(key, field->value());
555}
556
557void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
558 saveSetting(key, field->text());
559}
560
561void SettingsView::saveSetting(const char* key, const QSlider* field) {
562 saveSetting(key, field->value());
563}
564
565void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
566 saveSetting(key, field->value());
567}
568
569void SettingsView::saveSetting(const char* key, const QVariant& field) {
570 m_controller->setOption(key, field);
571 m_controller->updateOption(key);
572}
573
574void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
575 QString option = loadSetting(key);
576 field->setChecked(option.isNull() ? defaultVal : option != "0");
577}
578
579void SettingsView::loadSetting(const char* key, QComboBox* field) {
580 loadSetting(key, field->lineEdit());
581}
582
583void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
584 QString option = loadSetting(key);
585 field->setValue(option.toDouble());
586}
587
588void SettingsView::loadSetting(const char* key, QLineEdit* field) {
589 QString option = loadSetting(key);
590 field->setText(option);
591}
592
593void SettingsView::loadSetting(const char* key, QSlider* field) {
594 QString option = loadSetting(key);
595 field->setValue(option.toInt());
596}
597
598void SettingsView::loadSetting(const char* key, QSpinBox* field) {
599 QString option = loadSetting(key);
600 field->setValue(option.toInt());
601}
602
603QString SettingsView::loadSetting(const char* key) {
604 return m_controller->getOption(key);
605}