all repos — mgba @ 6d93a3d12bf6a93960c6932f7eca0ad44b9b1bde

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