all repos — mgba @ 6e1ae2321eab2562bd7db11dd096a9bd1e7cd1a2

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	}
184
185#ifdef BUILD_QT_MULTIMEDIA
186	m_ui.cameraDriver->addItem(tr("Qt Multimedia"), static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA));
187	if (!cameraDriver.isNull() && cameraDriver.toInt() == static_cast<int>(InputController::CameraDriver::QT_MULTIMEDIA)) {
188		m_ui.cameraDriver->setCurrentIndex(m_ui.cameraDriver->count() - 1);
189	}
190#endif
191
192#ifdef M_CORE_GBA
193	connect(m_ui.gbaBiosBrowse, &QPushButton::clicked, [this]() {
194		selectBios(m_ui.gbaBios);
195	});
196#else
197	m_ui.gbaBiosBrowse->hide();
198#endif
199
200#ifdef M_CORE_GB
201	connect(m_ui.gbBiosBrowse, &QPushButton::clicked, [this]() {
202		selectBios(m_ui.gbBios);
203	});
204	connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() {
205		selectBios(m_ui.gbcBios);
206	});
207	connect(m_ui.sgbBiosBrowse, &QPushButton::clicked, [this]() {
208		selectBios(m_ui.sgbBios);
209	});
210
211	QList<QColor> defaultColors;
212	defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
213	defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
214	defaultColors.append(QColor(0x50, 0x50, 0x50));
215	defaultColors.append(QColor(0x00, 0x00, 0x00));
216	defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
217	defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
218	defaultColors.append(QColor(0x50, 0x50, 0x50));
219	defaultColors.append(QColor(0x00, 0x00, 0x00));
220	defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
221	defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
222	defaultColors.append(QColor(0x50, 0x50, 0x50));
223	defaultColors.append(QColor(0x00, 0x00, 0x00));
224	QList<QWidget*> colors{
225		m_ui.color0,
226		m_ui.color1,
227		m_ui.color2,
228		m_ui.color3,
229		m_ui.color4,
230		m_ui.color5,
231		m_ui.color6,
232		m_ui.color7,
233		m_ui.color8,
234		m_ui.color9,
235		m_ui.color10,
236		m_ui.color11
237	};
238	for (int colorId = 0; colorId < 12; ++colorId) {
239		bool ok;
240		uint color = m_controller->getOption(QString("gb.pal[%0]").arg(colorId)).toUInt(&ok);
241		if (ok) {
242			defaultColors[colorId] = QColor::fromRgb(color);
243			m_gbColors[colorId] = color | 0xFF000000;
244		} else {
245			m_gbColors[colorId] = defaultColors[colorId].rgb() & ~0xFF000000;
246		}
247		m_colorPickers[colorId] = ColorPicker(colors[colorId], defaultColors[colorId]);
248		connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
249			m_gbColors[colorId] = color.rgb();
250		});
251	}
252#else
253	m_ui.gbBiosBrowse->hide();
254	m_ui.gbcBiosBrowse->hide();
255	m_ui.sgbBiosBrowse->hide();
256	m_ui.gb->hide();
257#endif
258
259	GBAKeyEditor* editor = new GBAKeyEditor(inputController, InputController::KEYBOARD, QString(), this);
260	m_ui.stackedWidget->addWidget(editor);
261	m_ui.tabs->addItem(tr("Keyboard"));
262	connect(m_ui.buttonBox, &QDialogButtonBox::accepted, editor, &GBAKeyEditor::save);
263
264	GBAKeyEditor* buttonEditor = nullptr;
265#ifdef BUILD_SDL
266	inputController->recalibrateAxes();
267	const char* profile = inputController->profileForType(SDL_BINDING_BUTTON);
268	buttonEditor = new GBAKeyEditor(inputController, SDL_BINDING_BUTTON, profile);
269	m_ui.stackedWidget->addWidget(buttonEditor);
270	m_ui.tabs->addItem(tr("Controllers"));
271	connect(m_ui.buttonBox, &QDialogButtonBox::accepted, buttonEditor, &GBAKeyEditor::save);
272#endif
273
274	connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &SettingsView::updateConfig);
275	connect(m_ui.buttonBox, &QDialogButtonBox::clicked, [this, editor, buttonEditor](QAbstractButton* button) {
276		if (m_ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
277			updateConfig();
278			editor->save();
279			if (buttonEditor) {
280				buttonEditor->save();
281			}
282		}
283	});
284
285	m_ui.languages->setItemData(0, QLocale("en"));
286	QDir ts(":/translations/");
287	for (auto name : ts.entryList()) {
288		if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
289			continue;
290		}
291		QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
292		m_ui.languages->addItem(locale.nativeLanguageName(), locale);
293		if (locale.bcp47Name() == QLocale().bcp47Name()) {
294			m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
295		}
296	}
297
298	m_ui.loggingView->setModel(&m_logModel);
299	m_ui.loggingView->setHorizontalHeader(new RotatedHeaderView(Qt::Horizontal));
300	m_ui.loggingView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
301	m_ui.loggingView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
302
303	connect(m_ui.logFileBrowse, &QAbstractButton::pressed, [this] () {
304		QString path = GBAApp::app()->getSaveFileName(this, "Select log file");
305		if (!path.isNull()) {
306			m_ui.logFile->setText(path);
307		}
308	});
309
310	ShortcutView* shortcutView = new ShortcutView();
311	shortcutView->setController(shortcutController);
312	shortcutView->setInputController(inputController);
313	m_ui.stackedWidget->addWidget(shortcutView);
314	m_ui.tabs->addItem(tr("Shortcuts"));
315}
316
317SettingsView::~SettingsView() {
318#if defined(BUILD_GL) || defined(BUILD_GLES2)
319	setShaderSelector(nullptr);
320#endif
321}
322
323void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
324#if defined(BUILD_GL) || defined(BUILD_GLES2)
325	if (m_shader) {
326		auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString);
327		for (const auto& item : items) {
328			m_ui.tabs->removeItemWidget(item);
329		}
330		m_ui.stackedWidget->removeWidget(m_shader);
331		m_shader->setParent(nullptr);
332	}
333	m_shader = shaderSelector;
334	if (shaderSelector) {
335		m_ui.stackedWidget->addWidget(m_shader);
336		m_ui.tabs->addItem(tr("Shaders"));
337		connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved);
338	}
339#endif
340}
341
342void SettingsView::selectBios(QLineEdit* bios) {
343	QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
344	if (!filename.isEmpty()) {
345		bios->setText(filename);
346	}
347}
348
349void SettingsView::updateConfig() {
350	saveSetting("gba.bios", m_ui.gbaBios);
351	saveSetting("gb.bios", m_ui.gbBios);
352	saveSetting("gbc.bios", m_ui.gbcBios);
353	saveSetting("sgb.bios", m_ui.sgbBios);
354	saveSetting("sgb.borders", m_ui.sgbBorders);
355	saveSetting("useBios", m_ui.useBios);
356	saveSetting("skipBios", m_ui.skipBios);
357	saveSetting("audioBuffers", m_ui.audioBufferSize);
358	saveSetting("sampleRate", m_ui.sampleRate);
359	saveSetting("videoSync", m_ui.videoSync);
360	saveSetting("audioSync", m_ui.audioSync);
361	saveSetting("frameskip", m_ui.frameskip);
362	saveSetting("fpsTarget", m_ui.fpsTarget);
363	saveSetting("autofireThreshold", m_ui.autofireThreshold);
364	saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
365	saveSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
366	saveSetting("volume", m_ui.volume);
367	saveSetting("mute", m_ui.mute);
368	saveSetting("fastForwardVolume", m_ui.volumeFf);
369	saveSetting("fastForwardMute", m_ui.muteFf);
370	saveSetting("rewindEnable", m_ui.rewind);
371	saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
372	saveSetting("resampleVideo", m_ui.resampleVideo);
373	saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
374	saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
375	saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
376	saveSetting("savegamePath", m_ui.savegamePath);
377	saveSetting("savestatePath", m_ui.savestatePath);
378	saveSetting("screenshotPath", m_ui.screenshotPath);
379	saveSetting("patchPath", m_ui.patchPath);
380	saveSetting("cheatsPath", m_ui.cheatsPath);
381	saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
382	saveSetting("showLibrary", m_ui.showLibrary);
383	saveSetting("preload", m_ui.preload);
384	saveSetting("showFps", m_ui.showFps);
385	saveSetting("cheatAutoload", m_ui.cheatAutoload);
386	saveSetting("cheatAutosave", m_ui.cheatAutosave);
387	saveSetting("autoload", m_ui.autoload);
388	saveSetting("autosave", m_ui.autosave);
389	saveSetting("logToFile", m_ui.logToFile);
390	saveSetting("logToStdout", m_ui.logToStdout);
391	saveSetting("logFile", m_ui.logFile);
392
393	if (m_ui.fastForwardUnbounded->isChecked()) {
394		saveSetting("fastForwardRatio", "-1");
395	} else {
396		saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
397	}
398
399	switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
400	case IDLE_LOOP_IGNORE:
401		saveSetting("idleOptimization", "ignore");
402		break;
403	case IDLE_LOOP_REMOVE:
404		saveSetting("idleOptimization", "remove");
405		break;
406	case IDLE_LOOP_DETECT:
407		saveSetting("idleOptimization", "detect");
408		break;
409	}
410
411	int loadState = SAVESTATE_RTC;
412	loadState |= m_ui.loadStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
413	loadState |= m_ui.loadStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
414	loadState |= m_ui.loadStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
415	saveSetting("loadStateExtdata", loadState);
416
417	int saveState = SAVESTATE_RTC | SAVESTATE_METADATA;
418	saveState |= m_ui.saveStateScreenshot->isChecked() ? SAVESTATE_SCREENSHOT : 0;
419	saveState |= m_ui.saveStateSave->isChecked() ? SAVESTATE_SAVEDATA : 0;
420	saveState |= m_ui.saveStateCheats->isChecked() ? SAVESTATE_CHEATS : 0;
421	saveSetting("saveStateExtdata", saveState);
422
423	QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
424	if (audioDriver != m_controller->getQtOption("audioDriver")) {
425		m_controller->setQtOption("audioDriver", audioDriver);
426		AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
427		emit audioDriverChanged();
428	}
429
430	QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
431	if (displayDriver != m_controller->getQtOption("displayDriver")) {
432		m_controller->setQtOption("displayDriver", displayDriver);
433		Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
434		setShaderSelector(nullptr);
435		emit displayDriverChanged();
436	}
437
438	QVariant cameraDriver = m_ui.cameraDriver->itemData(m_ui.cameraDriver->currentIndex());
439	if (cameraDriver != m_controller->getQtOption("cameraDriver")) {
440		m_controller->setQtOption("cameraDriver", cameraDriver);
441		emit cameraDriverChanged();
442	}
443
444	QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
445	if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {
446		m_controller->setQtOption("language", language.bcp47Name());
447		emit languageChanged();
448	}
449
450	m_logModel.save(m_controller);
451	m_logModel.logger()->setLogFile(m_ui.logFile->text());
452	m_logModel.logger()->logToFile(m_ui.logToFile->isChecked());
453	m_logModel.logger()->logToStdout(m_ui.logToStdout->isChecked());
454
455#ifdef M_CORE_GB
456	GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
457	m_controller->setOption("gb.model", GBModelToName(modelGB));
458
459	GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
460	m_controller->setOption("sgb.model", GBModelToName(modelSGB));
461
462	GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
463	m_controller->setOption("cgb.model", GBModelToName(modelCGB));
464
465	for (int colorId = 0; colorId < 12; ++colorId) {
466		if (!(m_gbColors[colorId] & 0xFF000000)) {
467			continue;
468		}
469		QString color = QString("gb.pal[%0]").arg(colorId);
470		m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
471
472	}
473#endif
474
475	m_controller->write();
476
477	emit pathsChanged();
478	emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
479}
480
481void SettingsView::reloadConfig() {	
482	loadSetting("bios", m_ui.gbaBios);
483	loadSetting("gba.bios", m_ui.gbaBios);
484	loadSetting("gb.bios", m_ui.gbBios);
485	loadSetting("gbc.bios", m_ui.gbcBios);
486	loadSetting("sgb.bios", m_ui.sgbBios);
487	loadSetting("sgb.borders", m_ui.sgbBorders, true);
488	loadSetting("useBios", m_ui.useBios);
489	loadSetting("skipBios", m_ui.skipBios);
490	loadSetting("audioBuffers", m_ui.audioBufferSize);
491	loadSetting("sampleRate", m_ui.sampleRate);
492	loadSetting("videoSync", m_ui.videoSync);
493	loadSetting("audioSync", m_ui.audioSync);
494	loadSetting("frameskip", m_ui.frameskip);
495	loadSetting("fpsTarget", m_ui.fpsTarget);
496	loadSetting("autofireThreshold", m_ui.autofireThreshold);
497	loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
498	loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
499	loadSetting("volume", m_ui.volume, 0x100);
500	loadSetting("mute", m_ui.mute, false);
501	loadSetting("fastForwardVolume", m_ui.volumeFf, m_ui.volume->value());
502	loadSetting("fastForwardMute", m_ui.muteFf, m_ui.mute->isChecked());
503	loadSetting("rewindEnable", m_ui.rewind);
504	loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
505	loadSetting("resampleVideo", m_ui.resampleVideo);
506	loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
507	loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
508	loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
509	loadSetting("savegamePath", m_ui.savegamePath);
510	loadSetting("savestatePath", m_ui.savestatePath);
511	loadSetting("screenshotPath", m_ui.screenshotPath);
512	loadSetting("patchPath", m_ui.patchPath);
513	loadSetting("cheatsPath", m_ui.cheatsPath);
514	loadSetting("showLibrary", m_ui.showLibrary);
515	loadSetting("preload", m_ui.preload);
516	loadSetting("showFps", m_ui.showFps, true);
517	loadSetting("cheatAutoload", m_ui.cheatAutoload, true);
518	loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
519	loadSetting("autoload", m_ui.autoload, true);
520	loadSetting("autosave", m_ui.autosave, false);
521	loadSetting("logToFile", m_ui.logToFile);
522	loadSetting("logToStdout", m_ui.logToStdout);
523	loadSetting("logFile", m_ui.logFile);
524
525	m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
526
527	double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
528	if (fastForwardRatio <= 0) {
529		m_ui.fastForwardUnbounded->setChecked(true);
530		m_ui.fastForwardRatio->setEnabled(false);
531	} else {
532		m_ui.fastForwardUnbounded->setChecked(false);
533		m_ui.fastForwardRatio->setEnabled(true);
534		m_ui.fastForwardRatio->setValue(fastForwardRatio);
535	}
536
537	QString idleOptimization = loadSetting("idleOptimization");
538	if (idleOptimization == "ignore") {
539		m_ui.idleOptimization->setCurrentIndex(0);
540	} else if (idleOptimization == "remove") {
541		m_ui.idleOptimization->setCurrentIndex(1);
542	} else if (idleOptimization == "detect") {
543		m_ui.idleOptimization->setCurrentIndex(2);
544	}
545
546	bool ok;
547	int loadState = loadSetting("loadStateExtdata").toInt(&ok);
548	if (!ok) {
549		loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
550	}
551	m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
552	m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
553	m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
554
555	int saveState = loadSetting("saveStateExtdata").toInt(&ok);
556	if (!ok) {
557		saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
558	}
559	m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
560	m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
561	m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
562
563	m_logModel.reset();
564
565#ifdef M_CORE_GB
566	QString modelGB = m_controller->getOption("gb.model");
567	if (!modelGB.isNull()) {
568		GBModel model = GBNameToModel(modelGB.toUtf8().constData());
569		int index = s_gbModelList.indexOf(model);
570		m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
571	}
572
573	QString modelSGB = m_controller->getOption("sgb.model");
574	if (!modelSGB.isNull()) {
575		GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
576		int index = s_gbModelList.indexOf(model);
577		m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
578	}
579
580	QString modelCGB = m_controller->getOption("cgb.model");
581	if (!modelCGB.isNull()) {
582		GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
583		int index = s_gbModelList.indexOf(model);
584		m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
585	}
586#endif
587}
588
589void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
590	m_controller->setOption(key, field->isChecked());
591	m_controller->updateOption(key);
592}
593
594void SettingsView::saveSetting(const char* key, const QComboBox* field) {
595	saveSetting(key, field->lineEdit());
596}
597
598void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
599	saveSetting(key, field->value());
600}
601
602void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
603	saveSetting(key, field->text());
604}
605
606void SettingsView::saveSetting(const char* key, const QSlider* field) {
607	saveSetting(key, field->value());
608}
609
610void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
611	saveSetting(key, field->value());
612}
613
614void SettingsView::saveSetting(const char* key, const QVariant& field) {
615	m_controller->setOption(key, field);
616	m_controller->updateOption(key);
617}
618
619void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
620	QString option = loadSetting(key);
621	field->setChecked(option.isNull() ? defaultVal : option != "0");
622}
623
624void SettingsView::loadSetting(const char* key, QComboBox* field) {
625	loadSetting(key, field->lineEdit());
626}
627
628void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
629	QString option = loadSetting(key);
630	field->setValue(option.toDouble());
631}
632
633void SettingsView::loadSetting(const char* key, QLineEdit* field) {
634	QString option = loadSetting(key);
635	field->setText(option);
636}
637
638void SettingsView::loadSetting(const char* key, QSlider* field, int defaultVal) {
639	QString option = loadSetting(key);
640	field->setValue(option.isNull() ? defaultVal : option.toInt());
641}
642
643void SettingsView::loadSetting(const char* key, QSpinBox* field) {
644	QString option = loadSetting(key);
645	field->setValue(option.toInt());
646}
647
648QString SettingsView::loadSetting(const char* key) {
649	return m_controller->getOption(key);
650}