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
13using namespace QGBA;
14
15SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
16 : QWidget(parent)
17 , m_controller(controller)
18{
19 m_ui.setupUi(this);
20
21 loadSetting("bios", m_ui.bios);
22 loadSetting("useBios", m_ui.useBios);
23 loadSetting("skipBios", m_ui.skipBios);
24 loadSetting("audioBuffers", m_ui.audioBufferSize);
25 loadSetting("videoSync", m_ui.videoSync);
26 loadSetting("audioSync", m_ui.audioSync);
27 loadSetting("frameskip", m_ui.frameskip);
28 loadSetting("fpsTarget", m_ui.fpsTarget);
29 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
30 loadSetting("volume", m_ui.volume);
31 loadSetting("mute", m_ui.mute);
32 loadSetting("rewindEnable", m_ui.rewind);
33 loadSetting("rewindBufferInterval", m_ui.rewindInterval);
34 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
35 loadSetting("resampleVideo", m_ui.resampleVideo);
36 loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
37 loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
38
39 QString idleOptimization = loadSetting("idleOptimization");
40 if (idleOptimization == "ignore") {
41 m_ui.idleOptimization->setCurrentIndex(0);
42 } else if (idleOptimization == "remove") {
43 m_ui.idleOptimization->setCurrentIndex(1);
44 } else if (idleOptimization == "detect") {
45 m_ui.idleOptimization->setCurrentIndex(2);
46 }
47
48 QVariant audioDriver = m_controller->getQtOption("audioDriver");
49#ifdef BUILD_QT_MULTIMEDIA
50 m_ui.audioDriver->addItem(tr("Qt Multimedia"), static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA));
51 if (!audioDriver.isNull() && audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::QT_MULTIMEDIA)) {
52 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
53 }
54#endif
55
56#ifdef BUILD_SDL
57 m_ui.audioDriver->addItem(tr("SDL"), static_cast<int>(AudioProcessor::Driver::SDL));
58 if (audioDriver.isNull() || audioDriver.toInt() == static_cast<int>(AudioProcessor::Driver::SDL)) {
59 m_ui.audioDriver->setCurrentIndex(m_ui.audioDriver->count() - 1);
60 }
61#endif
62
63 QVariant displayDriver = m_controller->getQtOption("displayDriver");
64 m_ui.displayDriver->addItem(tr("Software (Qt)"), static_cast<int>(Display::Driver::QT));
65 if (!displayDriver.isNull() && displayDriver.toInt() == static_cast<int>(Display::Driver::QT)) {
66 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
67 }
68
69#ifdef BUILD_GL
70 m_ui.displayDriver->addItem(tr("OpenGL"), static_cast<int>(Display::Driver::OPENGL));
71 if (displayDriver.isNull() || displayDriver.toInt() == static_cast<int>(Display::Driver::OPENGL)) {
72 m_ui.displayDriver->setCurrentIndex(m_ui.displayDriver->count() - 1);
73 }
74#endif
75
76 connect(m_ui.biosBrowse, SIGNAL(clicked()), this, SLOT(selectBios()));
77 connect(m_ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateConfig()));
78}
79
80void SettingsView::selectBios() {
81 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
82 if (!filename.isEmpty()) {
83 m_ui.bios->setText(filename);
84 }
85}
86
87void SettingsView::updateConfig() {
88 saveSetting("bios", m_ui.bios);
89 saveSetting("useBios", m_ui.useBios);
90 saveSetting("skipBios", m_ui.skipBios);
91 saveSetting("audioBuffers", m_ui.audioBufferSize);
92 saveSetting("videoSync", m_ui.videoSync);
93 saveSetting("audioSync", m_ui.audioSync);
94 saveSetting("frameskip", m_ui.frameskip);
95 saveSetting("fpsTarget", m_ui.fpsTarget);
96 saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
97 saveSetting("volume", m_ui.volume);
98 saveSetting("mute", m_ui.mute);
99 saveSetting("rewindEnable", m_ui.rewind);
100 saveSetting("rewindBufferInterval", m_ui.rewindInterval);
101 saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
102 saveSetting("resampleVideo", m_ui.resampleVideo);
103 saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
104 saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
105
106 switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
107 case IDLE_LOOP_IGNORE:
108 saveSetting("idleOptimization", "ignore");
109 break;
110 case IDLE_LOOP_REMOVE:
111 saveSetting("idleOptimization", "remove");
112 break;
113 case IDLE_LOOP_DETECT:
114 saveSetting("idleOptimization", "detect");
115 break;
116 }
117
118 QVariant audioDriver = m_ui.audioDriver->itemData(m_ui.audioDriver->currentIndex());
119 if (audioDriver != m_controller->getQtOption("audioDriver")) {
120 m_controller->setQtOption("audioDriver", audioDriver);
121 AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(audioDriver.toInt()));
122 emit audioDriverChanged();
123 }
124
125 QVariant displayDriver = m_ui.displayDriver->itemData(m_ui.displayDriver->currentIndex());
126 if (displayDriver != m_controller->getQtOption("displayDriver")) {
127 m_controller->setQtOption("displayDriver", displayDriver);
128 Display::setDriver(static_cast<Display::Driver>(displayDriver.toInt()));
129 emit displayDriverChanged();
130 }
131
132 m_controller->write();
133
134 emit biosLoaded(m_ui.bios->text());
135}
136
137void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
138 m_controller->setOption(key, field->isChecked());
139 m_controller->updateOption(key);
140}
141
142void SettingsView::saveSetting(const char* key, const QComboBox* field) {
143 saveSetting(key, field->lineEdit());
144}
145
146void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
147 saveSetting(key, field->cleanText());
148}
149
150void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
151 saveSetting(key, field->text());
152}
153
154void SettingsView::saveSetting(const char* key, const QSlider* field) {
155 saveSetting(key, QString::number(field->value()));
156}
157
158void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
159 saveSetting(key, field->cleanText());
160}
161
162void SettingsView::saveSetting(const char* key, const QString& field) {
163 m_controller->setOption(key, field);
164 m_controller->updateOption(key);
165}
166
167void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
168 QString option = loadSetting(key);
169 field->setChecked(!option.isNull() && option != "0");
170}
171
172void SettingsView::loadSetting(const char* key, QComboBox* field) {
173 loadSetting(key, field->lineEdit());
174}
175
176void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
177 QString option = loadSetting(key);
178 field->setValue(option.toDouble());
179}
180
181void SettingsView::loadSetting(const char* key, QLineEdit* field) {
182 QString option = loadSetting(key);
183 field->setText(option);
184}
185
186void SettingsView::loadSetting(const char* key, QSlider* field) {
187 QString option = loadSetting(key);
188 field->setValue(option.toInt());
189}
190
191void SettingsView::loadSetting(const char* key, QSpinBox* field) {
192 QString option = loadSetting(key);
193 field->setValue(option.toInt());
194}
195
196QString SettingsView::loadSetting(const char* key) {
197 return m_controller->getOption(key);
198}