all repos — mgba @ 3e91c50f2dbfc9875a60e8be427639d23fd0e369

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