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