all repos — mgba @ cda0f95464f1e2a7c9f1202b87c476bfb07ed6e1

mGBA Game Boy Advance Emulator

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