all repos — mgba @ bdc4e2837d7f82189e2342851ef3c67340df0741

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	saveSetting("audioHle", m_ui.audioHle);
405
406	if (m_ui.fastForwardUnbounded->isChecked()) {
407		saveSetting("fastForwardRatio", "-1");
408	} else {
409		saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
410	}
411
412	switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
413	case IDLE_LOOP_IGNORE:
414		saveSetting("idleOptimization", "ignore");
415		break;
416	case IDLE_LOOP_REMOVE:
417		saveSetting("idleOptimization", "remove");
418		break;
419	case IDLE_LOOP_DETECT:
420		saveSetting("idleOptimization", "detect");
421		break;
422	}
423
424	int loadState = SAVESTATE_RTC;
425	loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
426	loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
427	loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
428	saveSetting("loadStateExtdata", loadState);
429
430	int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
431	saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
432	saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
433	saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
434	saveSetting("saveStateExtdata", saveState);
435
436	QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
437	if (audioDriver != m_controller->getQtOption("audioDriver")) {
438		m_controller->setQtOption("audioDriver", audioDriver);
439		AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
440		emit audioDriverChanged();
441	}
442
443	QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
444	if (displayDriver != m_controller->getQtOption("displayDriver")) {
445		m_controller->setQtOption("displayDriver", displayDriver);
446		Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
447		setShaderSelector(nullptr);
448		emit displayDriverChanged();
449	}
450
451	QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
452	if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
453		m_controller->setQtOption("cameraDriver", cameraDriver);
454		emit cameraDriverChanged();
455	}
456
457	QVariant camera = m_ui.camera->itemData(m_ui.camera->currentIndex());
458	if (camera != m_controller->getQtOption("camera")) {
459		m_controller->setQtOption("camera", camera);
460		emit cameraChanged(camera.toByteArray());
461	}
462
463	QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
464	if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
465		m_controller->setQtOption("language", language.bcp47Name());
466		emit languageChanged();
467	}
468
469	int videoScale = m_controller->getOption("videoScale").toInt();
470	int hwaccelVideo = m_controller->getOption("hwaccelVideo").toInt();
471	if (videoScale != m_ui.videoScale->value() || hwaccelVideo != m_ui.hwaccelVideo->currentIndex()) {
472		emit videoRendererChanged();
473	}
474	saveSetting("videoScale", m_ui.videoScale);
475	saveSetting("hwaccelVideo", m_ui.hwaccelVideo->currentIndex());
476
477	m_logModel.save(m_controller);
478	m_logModel.logger()->setLogFile(m_ui.logFile->text());
479	m_logModel.logger()->logToFile(m_ui.logToFile->isChecked());
480	m_logModel.logger()->logToStdout(m_ui.logToStdout->isChecked());
481
482#ifdef M_CORE_GB
483	GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
484	m_controller->setOption("gb.model", GBModelToName(modelGB));
485
486	GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
487	m_controller->setOption("sgb.model", GBModelToName(modelSGB));
488
489	GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
490	m_controller->setOption("cgb.model", GBModelToName(modelCGB));
491
492	for (int colorId = 0; colorId < 12; ++colorId) {
493		if (!(m_gbColors[colorId] & 0xFF000000)) {
494			continue;
495		}
496		QString color = QString("gb.pal[%0]").arg(colorId);
497		m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
498
499	}
500#endif
501
502	m_controller->write();
503
504	emit pathsChanged();
505	emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
506}
507
508void SettingsView::reloadConfig() {	
509	loadSetting("bios", m_ui.gbaBios);
510	loadSetting("gba.bios", m_ui.gbaBios);
511	loadSetting("gb.bios", m_ui.gbBios);
512	loadSetting("gbc.bios", m_ui.gbcBios);
513	loadSetting("sgb.bios", m_ui.sgbBios);
514	loadSetting("sgb.borders", m_ui.sgbBorders, true);
515	loadSetting("useCgbColors", m_ui.useCgbColors, true);
516	loadSetting("useBios", m_ui.useBios);
517	loadSetting("skipBios", m_ui.skipBios);
518	loadSetting("audioBuffers", m_ui.audioBufferSize);
519	loadSetting("sampleRate", m_ui.sampleRate);
520	loadSetting("videoSync", m_ui.videoSync);
521	loadSetting("audioSync", m_ui.audioSync);
522	loadSetting("frameskip", m_ui.frameskip);
523	loadSetting("fpsTarget", m_ui.fpsTarget);
524	loadSetting("autofireThreshold", m_ui.autofireThreshold);
525	loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
526	loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
527	loadSetting("volume", m_ui.volume, 0x100);
528	loadSetting("mute", m_ui.mute, false);
529	loadSetting("fastForwardVolume", m_ui.volumeFf, m_ui.volume->value());
530	loadSetting("fastForwardMute", m_ui.muteFf, m_ui.mute->isChecked());
531	loadSetting("rewindEnable", m_ui.rewind);
532	loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
533	loadSetting("resampleVideo", m_ui.resampleVideo);
534	loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
535	loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
536	loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
537	loadSetting("savegamePath", m_ui.savegamePath);
538	loadSetting("savestatePath", m_ui.savestatePath);
539	loadSetting("screenshotPath", m_ui.screenshotPath);
540	loadSetting("patchPath", m_ui.patchPath);
541	loadSetting("cheatsPath", m_ui.cheatsPath);
542	loadSetting("showLibrary", m_ui.showLibrary);
543	loadSetting("preload", m_ui.preload);
544	loadSetting("showFps", m_ui.showFps, true);
545	loadSetting("cheatAutoload", m_ui.cheatAutoload, true);
546	loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
547	loadSetting("autoload", m_ui.autoload, true);
548	loadSetting("autosave", m_ui.autosave, false);
549	loadSetting("logToFile", m_ui.logToFile);
550	loadSetting("logToStdout", m_ui.logToStdout);
551	loadSetting("logFile", m_ui.logFile);
552	loadSetting("useDiscordPresence", m_ui.useDiscordPresence);
553	loadSetting("audioHle", m_ui.audioHle);
554	loadSetting("videoScale", m_ui.videoScale);
555
556	m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
557
558	double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
559	if (fastForwardRatio <= 0) {
560		m_ui.fastForwardUnbounded->setChecked(true);
561		m_ui.fastForwardRatio->setEnabled(false);
562	} else {
563		m_ui.fastForwardUnbounded->setChecked(false);
564		m_ui.fastForwardRatio->setEnabled(true);
565		m_ui.fastForwardRatio->setValue(fastForwardRatio);
566	}
567
568	QString idleOptimization = loadSetting("idleOptimization");
569	if (idleOptimization == "ignore") {
570		m_ui.idleOptimization->setCurrentIndex(0);
571	} else if (idleOptimization == "remove") {
572		m_ui.idleOptimization->setCurrentIndex(1);
573	} else if (idleOptimization == "detect") {
574		m_ui.idleOptimization->setCurrentIndex(2);
575	}
576
577	bool ok;
578	int loadState = loadSetting("loadStateExtdata").toInt(&ok);
579	if (!ok) {
580		loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
581	}
582	m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
583	m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
584	m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
585
586	int saveState = loadSetting("saveStateExtdata").toInt(&ok);
587	if (!ok) {
588		saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
589	}
590	m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
591	m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
592	m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
593
594	m_logModel.reset();
595
596#ifdef M_CORE_GB
597	QString modelGB = m_controller->getOption("gb.model");
598	if (!modelGB.isNull()) {
599		GBModel model = GBNameToModel(modelGB.toUtf8().constData());
600		int index = s_gbModelList.indexOf(model);
601		m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
602	}
603
604	QString modelSGB = m_controller->getOption("sgb.model");
605	if (!modelSGB.isNull()) {
606		GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
607		int index = s_gbModelList.indexOf(model);
608		m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
609	}
610
611	QString modelCGB = m_controller->getOption("cgb.model");
612	if (!modelCGB.isNull()) {
613		GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
614		int index = s_gbModelList.indexOf(model);
615		m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
616	}
617#endif
618
619	int hwaccelVideo = m_controller->getOption("hwaccelVideo", 1).toInt();
620	if (hwaccelVideo < 1) {
621		hwaccelVideo = 1;
622	}
623	m_ui.hwaccelVideo->setCurrentIndex(hwaccelVideo);
624}
625
626void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
627	m_controller->setOption(key, field->isChecked());
628	m_controller->updateOption(key);
629}
630
631void SettingsView::saveSetting(const char* key, const QComboBox* field) {
632	saveSetting(key, field->lineEdit());
633}
634
635void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
636	saveSetting(key, field->value());
637}
638
639void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
640	saveSetting(key, field->text());
641}
642
643void SettingsView::saveSetting(const char* key, const QSlider* field) {
644	saveSetting(key, field->value());
645}
646
647void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
648	saveSetting(key, field->value());
649}
650
651void SettingsView::saveSetting(const char* key, const QVariant& field) {
652	m_controller->setOption(key, field);
653	m_controller->updateOption(key);
654}
655
656void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
657	QString option = loadSetting(key);
658	field->setChecked(option.isNull() ? defaultVal : option != "0");
659}
660
661void SettingsView::loadSetting(const char* key, QComboBox* field) {
662	loadSetting(key, field->lineEdit());
663}
664
665void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
666	QString option = loadSetting(key);
667	field->setValue(option.toDouble());
668}
669
670void SettingsView::loadSetting(const char* key, QLineEdit* field) {
671	QString option = loadSetting(key);
672	field->setText(option);
673}
674
675void SettingsView::loadSetting(const char* key, QSlider* field, int defaultVal) {
676	QString option = loadSetting(key);
677	field->setValue(option.isNull() ? defaultVal : option.toInt());
678}
679
680void SettingsView::loadSetting(const char* key, QSpinBox* field) {
681	QString option = loadSetting(key);
682	field->setValue(option.toInt());
683}
684
685QString SettingsView::loadSetting(const char* key) {
686	return m_controller->getOption(key);
687}