all repos — mgba @ 1a0e44c014ad34bea30d237d27015d82d02cda4b

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 "InputController.h"
 13#include "ShaderSelector.h"
 14#include "ShortcutView.h"
 15
 16#include <mgba/core/serialize.h>
 17#include <mgba/core/version.h>
 18#include <mgba/internal/gba/gba.h>
 19
 20using namespace QGBA;
 21
 22#ifdef M_CORE_GB
 23QList<enum GBModel> SettingsView::s_gbModelList;
 24#endif
 25
 26SettingsView::SettingsView(ConfigController* controller, InputController* inputController, QWidget* parent)
 27	: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
 28	, m_controller(controller)
 29	, m_input(inputController)
 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#ifdef M_CORE_DS
246	connect(m_ui.dsBios7Browse, &QPushButton::clicked, [this]() {
247		selectBios(m_ui.dsBios7);
248	});
249	connect(m_ui.dsBios9Browse, &QPushButton::clicked, [this]() {
250		selectBios(m_ui.dsBios9);
251	});
252	connect(m_ui.dsFirmwareBrowse, &QPushButton::clicked, [this]() {
253		selectBios(m_ui.dsFirmware);
254	});
255#else
256	m_ui.dsBios7Browse->hide();
257	m_ui.dsBios9Browse->hide();
258	m_ui.dsFirmwareBrowse->hide();
259#endif
260
261	connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &SettingsView::updateConfig);
262	connect(m_ui.buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button) {
263		if (m_ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
264			updateConfig();
265		}
266	});
267
268	m_ui.languages->setItemData(0, QLocale("en"));
269	QDir ts(":/translations/");
270	for (auto name : ts.entryList()) {
271		if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
272			continue;
273		}
274		QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
275		m_ui.languages->addItem(locale.nativeLanguageName(), locale);
276		if (locale.bcp47Name() == QLocale().bcp47Name()) {
277			m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
278		}
279	}
280
281	m_keyView = new ShortcutView();
282	m_keyView->setModel(inputController->keyIndex());
283	m_keyView->setInputController(inputController);
284	m_shortcutView = new ShortcutView();
285	m_shortcutView->setModel(inputController->inputIndex());
286	m_shortcutView->setInputController(inputController);
287	m_ui.stackedWidget->addWidget(m_keyView);
288	m_ui.tabs->addItem(tr("Controls"));
289	m_ui.stackedWidget->addWidget(m_shortcutView);
290	m_ui.tabs->addItem(tr("Shortcuts"));
291}
292
293SettingsView::~SettingsView() {
294#if defined(BUILD_GL) || defined(BUILD_GLES2)
295	setShaderSelector(nullptr);
296#endif
297}
298
299void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
300#if defined(BUILD_GL) || defined(BUILD_GLES2)
301	if (m_shader) {
302		auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString);
303		for (const auto& item : items) {
304			m_ui.tabs->removeItemWidget(item);
305		}
306		m_ui.stackedWidget->removeWidget(m_shader);
307		m_shader->setParent(nullptr);
308	}
309	m_shader = shaderSelector;
310	if (shaderSelector) {
311		m_ui.stackedWidget->addWidget(m_shader);
312		m_ui.tabs->addItem(tr("Shaders"));
313		connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved);
314	}
315#endif
316}
317
318void SettingsView::selectBios(QLineEdit* bios) {
319	QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
320	if (!filename.isEmpty()) {
321		bios->setText(filename);
322	}
323}
324
325void SettingsView::updateConfig() {
326	saveSetting("gba.bios", m_ui.gbaBios);
327	saveSetting("gb.bios", m_ui.gbBios);
328	saveSetting("gbc.bios", m_ui.gbcBios);
329	saveSetting("sgb.bios", m_ui.sgbBios);
330	saveSetting("sgb.borders", m_ui.sgbBorders);
331	saveSetting("ds.bios7", m_ui.dsBios7);
332	saveSetting("ds.bios9", m_ui.dsBios9);
333	saveSetting("ds.firmware", m_ui.dsFirmware);
334	saveSetting("useBios", m_ui.useBios);
335	saveSetting("skipBios", m_ui.skipBios);
336	saveSetting("audioBuffers", m_ui.audioBufferSize);
337	saveSetting("sampleRate", m_ui.sampleRate);
338	saveSetting("videoSync", m_ui.videoSync);
339	saveSetting("audioSync", m_ui.audioSync);
340	saveSetting("frameskip", m_ui.frameskip);
341	saveSetting("fpsTarget", m_ui.fpsTarget);
342	saveSetting("autofireThreshold", m_ui.autofireThreshold);
343	saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
344	saveSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
345	saveSetting("volume", m_ui.volume);
346	saveSetting("mute", m_ui.mute);
347	saveSetting("rewindEnable", m_ui.rewind);
348	saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
349	saveSetting("rewindSave", m_ui.rewindSave);
350	saveSetting("resampleVideo", m_ui.resampleVideo);
351	saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
352	saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
353	saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
354	saveSetting("savegamePath", m_ui.savegamePath);
355	saveSetting("savestatePath", m_ui.savestatePath);
356	saveSetting("screenshotPath", m_ui.screenshotPath);
357	saveSetting("patchPath", m_ui.patchPath);
358	saveSetting("cheatsPath", m_ui.cheatsPath);
359	saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
360	saveSetting("showLibrary", m_ui.showLibrary);
361	saveSetting("preload", m_ui.preload);
362	saveSetting("showFps", m_ui.showFps);
363	saveSetting("cheatAutoload", m_ui.cheatAutoload);
364	saveSetting("cheatAutosave", m_ui.cheatAutosave);
365	saveSetting("autoload", m_ui.autoload);
366	saveSetting("autosave", m_ui.autosave);
367
368	if (m_ui.fastForwardUnbounded->isChecked()) {
369		saveSetting("fastForwardRatio", "-1");
370	} else {
371		saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
372	}
373
374	switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
375	case IDLE_LOOP_IGNORE:
376		saveSetting("idleOptimization", "ignore");
377		break;
378	case IDLE_LOOP_REMOVE:
379		saveSetting("idleOptimization", "remove");
380		break;
381	case IDLE_LOOP_DETECT:
382		saveSetting("idleOptimization", "detect");
383		break;
384	}
385
386	int loadState = SAVESTATE_RTC;
387	loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
388	loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
389	loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
390	saveSetting("loadStateExtdata", loadState);
391
392	int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
393	saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
394	saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
395	saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
396	saveSetting("saveStateExtdata", saveState);
397
398	QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
399	if (audioDriver != m_controller->getQtOption("audioDriver")) {
400		m_controller->setQtOption("audioDriver", audioDriver);
401		AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
402		emit audioDriverChanged();
403	}
404
405	QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
406	if (displayDriver != m_controller->getQtOption("displayDriver")) {
407		m_controller->setQtOption("displayDriver", displayDriver);
408		Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
409		setShaderSelector(nullptr);
410		emit displayDriverChanged();
411	}
412
413	QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
414	if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
415		m_controller->setQtOption("cameraDriver", cameraDriver);
416		emit cameraDriverChanged();
417	}
418
419	QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
420	if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
421		m_controller->setQtOption("language", language.bcp47Name());
422		emit languageChanged();
423	}
424
425#ifdef M_CORE_GB
426	GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
427	m_controller->setOption("gb.model", GBModelToName(modelGB));
428
429	GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
430	m_controller->setOption("sgb.model", GBModelToName(modelSGB));
431
432	GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
433	m_controller->setOption("cgb.model", GBModelToName(modelCGB));
434
435	for (int colorId = 0; colorId < 12; ++colorId) {
436		if (!(m_gbColors[colorId] & 0xFF000000)) {
437			continue;
438		}
439		QString color = QString("gb.pal[%0]").arg(colorId);
440		m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
441
442	}
443#endif
444
445	m_controller->write();
446
447	m_input->rebuildIndex(m_shortcutView->root());
448	m_input->rebuildKeyIndex(m_keyView->root());
449	m_input->saveConfiguration();
450
451	emit pathsChanged();
452	emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
453}
454
455void SettingsView::reloadConfig() {	
456	loadSetting("bios", m_ui.gbaBios);
457	loadSetting("gba.bios", m_ui.gbaBios);
458	loadSetting("gb.bios", m_ui.gbBios);
459	loadSetting("gbc.bios", m_ui.gbcBios);
460	loadSetting("sgb.bios", m_ui.sgbBios);
461	loadSetting("sgb.borders", m_ui.sgbBorders, true);
462	loadSetting("ds.bios7", m_ui.dsBios7);
463	loadSetting("ds.bios9", m_ui.dsBios9);
464	loadSetting("ds.firmware", m_ui.dsFirmware);
465	loadSetting("useBios", m_ui.useBios);
466	loadSetting("skipBios", m_ui.skipBios);
467	loadSetting("audioBuffers", m_ui.audioBufferSize);
468	loadSetting("sampleRate", m_ui.sampleRate);
469	loadSetting("videoSync", m_ui.videoSync);
470	loadSetting("audioSync", m_ui.audioSync);
471	loadSetting("frameskip", m_ui.frameskip);
472	loadSetting("fpsTarget", m_ui.fpsTarget);
473	loadSetting("autofireThreshold", m_ui.autofireThreshold);
474	loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
475	loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
476	loadSetting("volume", m_ui.volume);
477	loadSetting("mute", m_ui.mute);
478	loadSetting("rewindEnable", m_ui.rewind);
479	loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
480	loadSetting("rewindSave", m_ui.rewindSave);
481	loadSetting("resampleVideo", m_ui.resampleVideo);
482	loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
483	loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
484	loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
485	loadSetting("savegamePath", m_ui.savegamePath);
486	loadSetting("savestatePath", m_ui.savestatePath);
487	loadSetting("screenshotPath", m_ui.screenshotPath);
488	loadSetting("patchPath", m_ui.patchPath);
489	loadSetting("cheatsPath", m_ui.cheatsPath);
490	loadSetting("showLibrary", m_ui.showLibrary);
491	loadSetting("preload", m_ui.preload);
492	loadSetting("showFps", m_ui.showFps, true);
493	loadSetting("cheatAutoload", m_ui.cheatAutoload, true);
494	loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
495	loadSetting("autoload", m_ui.autoload, true);
496	loadSetting("autosave", m_ui.autosave, false);
497
498	m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
499
500	double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
501	if (fastForwardRatio <= 0) {
502		m_ui.fastForwardUnbounded->setChecked(true);
503		m_ui.fastForwardRatio->setEnabled(false);
504	} else {
505		m_ui.fastForwardUnbounded->setChecked(false);
506		m_ui.fastForwardRatio->setEnabled(true);
507		m_ui.fastForwardRatio->setValue(fastForwardRatio);
508	}
509
510	QString idleOptimization = loadSetting("idleOptimization");
511	if (idleOptimization == "ignore") {
512		m_ui.idleOptimization->setCurrentIndex(0);
513	} else if (idleOptimization == "remove") {
514		m_ui.idleOptimization->setCurrentIndex(1);
515	} else if (idleOptimization == "detect") {
516		m_ui.idleOptimization->setCurrentIndex(2);
517	}
518
519	bool ok;
520	int loadState = loadSetting("loadStateExtdata").toInt(&ok);
521	if (!ok) {
522		loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
523	}
524	m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
525	m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
526	m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
527
528	int saveState = loadSetting("saveStateExtdata").toInt(&ok);
529	if (!ok) {
530		saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
531	}
532	m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
533	m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
534	m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
535
536#ifdef M_CORE_GB
537	QString modelGB = m_controller->getOption("gb.model");
538	if (!modelGB.isNull()) {
539		GBModel model = GBNameToModel(modelGB.toUtf8().constData());
540		int index = s_gbModelList.indexOf(model);
541		m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
542	}
543
544	QString modelSGB = m_controller->getOption("sgb.model");
545	if (!modelSGB.isNull()) {
546		GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
547		int index = s_gbModelList.indexOf(model);
548		m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
549	}
550
551	QString modelCGB = m_controller->getOption("cgb.model");
552	if (!modelCGB.isNull()) {
553		GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
554		int index = s_gbModelList.indexOf(model);
555		m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
556	}
557#endif
558}
559
560void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
561	m_controller->setOption(key, field->isChecked());
562	m_controller->updateOption(key);
563}
564
565void SettingsView::saveSetting(const char* key, const QComboBox* field) {
566	saveSetting(key, field->lineEdit());
567}
568
569void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
570	saveSetting(key, field->value());
571}
572
573void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
574	saveSetting(key, field->text());
575}
576
577void SettingsView::saveSetting(const char* key, const QSlider* field) {
578	saveSetting(key, field->value());
579}
580
581void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
582	saveSetting(key, field->value());
583}
584
585void SettingsView::saveSetting(const char* key, const QVariant& field) {
586	m_controller->setOption(key, field);
587	m_controller->updateOption(key);
588}
589
590void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
591	QString option = loadSetting(key);
592	field->setChecked(option.isNull() ? defaultVal : option != "0");
593}
594
595void SettingsView::loadSetting(const char* key, QComboBox* field) {
596	loadSetting(key, field->lineEdit());
597}
598
599void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
600	QString option = loadSetting(key);
601	field->setValue(option.toDouble());
602}
603
604void SettingsView::loadSetting(const char* key, QLineEdit* field) {
605	QString option = loadSetting(key);
606	field->setText(option);
607}
608
609void SettingsView::loadSetting(const char* key, QSlider* field) {
610	QString option = loadSetting(key);
611	field->setValue(option.toInt());
612}
613
614void SettingsView::loadSetting(const char* key, QSpinBox* field) {
615	QString option = loadSetting(key);
616	field->setValue(option.toInt());
617}
618
619QString SettingsView::loadSetting(const char* key) {
620	return m_controller->getOption(key);
621}