all repos — mgba @ 99a6db6738c82d1cb286c29a9b431a41cd5ea8ba

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