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