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