all repos — mgba @ 8450417086c5b70904f93f2db720456d54c9cfeb

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