all repos — mgba @ f039234055a00181becf186ebceee71bfbbdc597

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