all repos — mgba @ 5e7333e20f63989b81ede8fd456eb522a1db90d6

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