all repos — mgba @ 99a063858bb432bccd02d8482ade56258b65bae7

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