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