all repos — mgba @ 076ec733fd4f8f220027bcea001f8d6367915a4a

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