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