all repos — mgba @ 7cad9ab33a3ac07060bc971c3a2f9e86d15424ff

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 "ConfigController.h"
  9
 10#include <QFileDialog>
 11
 12using namespace QGBA;
 13
 14SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
 15 	: QWidget(parent)
 16 	, m_controller(controller)
 17{
 18	m_ui.setupUi(this);
 19
 20	loadSetting("bios", m_ui.bios);
 21	loadSetting("skipBios", m_ui.skipBios);
 22	loadSetting("audioBuffers", m_ui.audioBufferSize);
 23	loadSetting("videoSync", m_ui.videoSync);
 24	loadSetting("audioSync", m_ui.audioSync);
 25	loadSetting("frameskip", m_ui.frameskip);
 26	loadSetting("fpsTarget", m_ui.fpsTarget);
 27	loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
 28	loadSetting("rewindEnable", m_ui.rewind);
 29	loadSetting("rewindBufferInterval", m_ui.rewindInterval);
 30	loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
 31	loadSetting("resampleVideo", m_ui.resampleVideo);
 32
 33	QString idleOptimization = loadSetting("idleOptimization");
 34	if (idleOptimization == "ignore") {
 35		m_ui.idleOptimization->setCurrentIndex(0);
 36	} else if (idleOptimization == "remove") {
 37		m_ui.idleOptimization->setCurrentIndex(1);
 38	} else if (idleOptimization == "detect") {
 39		m_ui.idleOptimization->setCurrentIndex(2);
 40	}
 41
 42	connect(m_ui.biosBrowse, SIGNAL(clicked()), this, SLOT(selectBios()));
 43	connect(m_ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateConfig()));
 44}
 45
 46void SettingsView::selectBios() {
 47	QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"));
 48	if (!filename.isEmpty()) {
 49		m_ui.bios->setText(filename);
 50	}
 51}
 52
 53void SettingsView::updateConfig() {
 54	saveSetting("bios", m_ui.bios);
 55	saveSetting("skipBios", m_ui.skipBios);
 56	saveSetting("audioBuffers", m_ui.audioBufferSize);
 57	saveSetting("videoSync", m_ui.videoSync);
 58	saveSetting("audioSync", m_ui.audioSync);
 59	saveSetting("frameskip", m_ui.frameskip);
 60	saveSetting("fpsTarget", m_ui.fpsTarget);
 61	saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
 62	saveSetting("rewindEnable", m_ui.rewind);
 63	saveSetting("rewindBufferInterval", m_ui.rewindInterval);
 64	saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
 65	saveSetting("resampleVideo", m_ui.resampleVideo);
 66
 67	switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
 68	case IDLE_LOOP_IGNORE:
 69		saveSetting("idleOptimization", "ignore");
 70		break;
 71	case IDLE_LOOP_REMOVE:
 72		saveSetting("idleOptimization", "remove");
 73		break;
 74	case IDLE_LOOP_DETECT:
 75		saveSetting("idleOptimization", "detect");
 76		break;
 77	}
 78
 79	m_controller->write();
 80
 81	emit biosLoaded(m_ui.bios->text());
 82}
 83
 84void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
 85	m_controller->setOption(key, field->isChecked());
 86	m_controller->updateOption(key);
 87}
 88
 89void SettingsView::saveSetting(const char* key, const QComboBox* field) {
 90	saveSetting(key, field->lineEdit());
 91}
 92
 93void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
 94	saveSetting(key, field->text());
 95}
 96
 97void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
 98	saveSetting(key, field->cleanText());
 99}
100
101void SettingsView::saveSetting(const char* key, const QString& field) {
102	m_controller->setOption(key, field);
103	m_controller->updateOption(key);
104}
105
106void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
107	QString option = loadSetting(key);
108	field->setChecked(option != "0");
109}
110
111void SettingsView::loadSetting(const char* key, QComboBox* field) {
112	loadSetting(key, field->lineEdit());
113}
114
115void SettingsView::loadSetting(const char* key, QLineEdit* field) {
116	QString option = loadSetting(key);
117	field->setText(option);
118}
119
120void SettingsView::loadSetting(const char* key, QSpinBox* field) {
121	QString option = loadSetting(key);
122	field->setValue(option.toInt());
123}
124
125QString SettingsView::loadSetting(const char* key) {
126	return m_controller->getOption(key);
127}