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 "InputController.h"
13#include "RotatedHeaderView.h"
14#include "ShaderSelector.h"
15#include "ShortcutView.h"
16
17#include <mgba/core/serialize.h>
18#include <mgba/core/version.h>
19#include <mgba/internal/gba/gba.h>
20
21using namespace QGBA;
22
23#ifdef M_CORE_GB
24QList<enum GBModel> SettingsView::s_gbModelList;
25#endif
26
27SettingsView::SettingsView(ConfigController* controller, InputController* inputController, LogController* logController, QWidget* parent)
28 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
29 , m_controller(controller)
30 , m_input(inputController)
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#ifdef M_CORE_DS
260 connect(m_ui.dsBios7Browse, &QPushButton::clicked, [this]() {
261 selectBios(m_ui.dsBios7);
262 });
263 connect(m_ui.dsBios9Browse, &QPushButton::clicked, [this]() {
264 selectBios(m_ui.dsBios9);
265 });
266 connect(m_ui.dsFirmwareBrowse, &QPushButton::clicked, [this]() {
267 selectBios(m_ui.dsFirmware);
268 });
269#else
270 m_ui.dsBios7Browse->hide();
271 m_ui.dsBios9Browse->hide();
272 m_ui.dsFirmwareBrowse->hide();
273#endif
274
275 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &SettingsView::updateConfig);
276 connect(m_ui.buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button) {
277 if (m_ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
278 updateConfig();
279 }
280 });
281
282 m_ui.languages->setItemData(0, QLocale("en"));
283 QDir ts(":/translations/");
284 for (auto name : ts.entryList()) {
285 if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
286 continue;
287 }
288 QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));
289 m_ui.languages->addItem(locale.nativeLanguageName(), locale);
290 if (locale.bcp47Name() == QLocale().bcp47Name()) {
291 m_ui.languages->setCurrentIndex(m_ui.languages->count() - 1);
292 }
293 }
294
295 m_ui.loggingView->setModel(&m_logModel);
296 m_ui.loggingView->setHorizontalHeader(new RotatedHeaderView(Qt::Horizontal));
297 m_ui.loggingView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
298 m_ui.loggingView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
299
300 connect(m_ui.logFileBrowse, &QAbstractButton::pressed, [this] () {
301 QString path = GBAApp::app()->getSaveFileName(this, "Select log file");
302 if (!path.isNull()) {
303 m_ui.logFile->setText(path);
304 }
305 });
306
307 m_keyView = new ShortcutView();
308 m_keyView->setModel(inputController->keyIndex());
309 m_keyView->setInputController(inputController);
310 m_shortcutView = new ShortcutView();
311 m_shortcutView->setModel(inputController->inputIndex());
312 m_shortcutView->setInputController(inputController);
313 m_ui.stackedWidget->addWidget(m_keyView);
314 m_ui.tabs->addItem(tr("Controls"));
315 m_ui.stackedWidget->addWidget(m_shortcutView);
316 m_ui.tabs->addItem(tr("Shortcuts"));
317}
318
319SettingsView::~SettingsView() {
320#if defined(BUILD_GL) || defined(BUILD_GLES2)
321 setShaderSelector(nullptr);
322#endif
323}
324
325void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) {
326#if defined(BUILD_GL) || defined(BUILD_GLES2)
327 if (m_shader) {
328 auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString);
329 for (const auto& item : items) {
330 m_ui.tabs->removeItemWidget(item);
331 }
332 m_ui.stackedWidget->removeWidget(m_shader);
333 m_shader->setParent(nullptr);
334 }
335 m_shader = shaderSelector;
336 if (shaderSelector) {
337 m_ui.stackedWidget->addWidget(m_shader);
338 m_ui.tabs->addItem(tr("Shaders"));
339 connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved);
340 }
341#endif
342}
343
344void SettingsView::selectBios(QLineEdit* bios) {
345 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
346 if (!filename.isEmpty()) {
347 bios->setText(filename);
348 }
349}
350
351void SettingsView::updateConfig() {
352 saveSetting("gba.bios", m_ui.gbaBios);
353 saveSetting("gb.bios", m_ui.gbBios);
354 saveSetting("gbc.bios", m_ui.gbcBios);
355 saveSetting("sgb.bios", m_ui.sgbBios);
356 saveSetting("sgb.borders", m_ui.sgbBorders);
357 saveSetting("ds.bios7", m_ui.dsBios7);
358 saveSetting("ds.bios9", m_ui.dsBios9);
359 saveSetting("ds.firmware", m_ui.dsFirmware);
360 saveSetting("useCgbColors", m_ui.useCgbColors);
361 saveSetting("useBios", m_ui.useBios);
362 saveSetting("skipBios", m_ui.skipBios);
363 saveSetting("audioBuffers", m_ui.audioBufferSize);
364 saveSetting("sampleRate", m_ui.sampleRate);
365 saveSetting("videoSync", m_ui.videoSync);
366 saveSetting("audioSync", m_ui.audioSync);
367 saveSetting("frameskip", m_ui.frameskip);
368 saveSetting("fpsTarget", m_ui.fpsTarget);
369 saveSetting("autofireThreshold", m_ui.autofireThreshold);
370 saveSetting("lockAspectRatio", m_ui.lockAspectRatio);
371 saveSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
372 saveSetting("volume", m_ui.volume);
373 saveSetting("mute", m_ui.mute);
374 saveSetting("fastForwardVolume", m_ui.volumeFf);
375 saveSetting("fastForwardMute", m_ui.muteFf);
376 saveSetting("rewindEnable", m_ui.rewind);
377 saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
378 saveSetting("resampleVideo", m_ui.resampleVideo);
379 saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
380 saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
381 saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
382 saveSetting("savegamePath", m_ui.savegamePath);
383 saveSetting("savestatePath", m_ui.savestatePath);
384 saveSetting("screenshotPath", m_ui.screenshotPath);
385 saveSetting("patchPath", m_ui.patchPath);
386 saveSetting("cheatsPath", m_ui.cheatsPath);
387 saveSetting("libraryStyle", m_ui.libraryStyle->currentIndex());
388 saveSetting("showLibrary", m_ui.showLibrary);
389 saveSetting("preload", m_ui.preload);
390 saveSetting("showFps", m_ui.showFps);
391 saveSetting("cheatAutoload", m_ui.cheatAutoload);
392 saveSetting("cheatAutosave", m_ui.cheatAutosave);
393 saveSetting("autoload", m_ui.autoload);
394 saveSetting("autosave", m_ui.autosave);
395 saveSetting("logToFile", m_ui.logToFile);
396 saveSetting("logToStdout", m_ui.logToStdout);
397 saveSetting("logFile", m_ui.logFile);
398
399 if (m_ui.fastForwardUnbounded->isChecked()) {
400 saveSetting("fastForwardRatio", "-1");
401 } else {
402 saveSetting("fastForwardRatio", m_ui.fastForwardRatio);
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 m_input->rebuildIndex(m_shortcutView->root());
484 m_input->rebuildKeyIndex(m_keyView->root());
485 m_input->saveConfiguration();
486
487 emit pathsChanged();
488 emit biosLoaded(PLATFORM_GBA, m_ui.gbaBios->text());
489}
490
491void SettingsView::reloadConfig() {
492 loadSetting("bios", m_ui.gbaBios);
493 loadSetting("gba.bios", m_ui.gbaBios);
494 loadSetting("gb.bios", m_ui.gbBios);
495 loadSetting("gbc.bios", m_ui.gbcBios);
496 loadSetting("sgb.bios", m_ui.sgbBios);
497 loadSetting("sgb.borders", m_ui.sgbBorders, true);
498 loadSetting("ds.bios7", m_ui.dsBios7);
499 loadSetting("ds.bios9", m_ui.dsBios9);
500 loadSetting("ds.firmware", m_ui.dsFirmware);
501 loadSetting("useCgbColors", m_ui.useCgbColors, true);
502 loadSetting("useBios", m_ui.useBios);
503 loadSetting("skipBios", m_ui.skipBios);
504 loadSetting("audioBuffers", m_ui.audioBufferSize);
505 loadSetting("sampleRate", m_ui.sampleRate);
506 loadSetting("videoSync", m_ui.videoSync);
507 loadSetting("audioSync", m_ui.audioSync);
508 loadSetting("frameskip", m_ui.frameskip);
509 loadSetting("fpsTarget", m_ui.fpsTarget);
510 loadSetting("autofireThreshold", m_ui.autofireThreshold);
511 loadSetting("lockAspectRatio", m_ui.lockAspectRatio);
512 loadSetting("lockIntegerScaling", m_ui.lockIntegerScaling);
513 loadSetting("volume", m_ui.volume, 0x100);
514 loadSetting("mute", m_ui.mute, false);
515 loadSetting("fastForwardVolume", m_ui.volumeFf, m_ui.volume->value());
516 loadSetting("fastForwardMute", m_ui.muteFf, m_ui.mute->isChecked());
517 loadSetting("rewindEnable", m_ui.rewind);
518 loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
519 loadSetting("resampleVideo", m_ui.resampleVideo);
520 loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
521 loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
522 loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
523 loadSetting("savegamePath", m_ui.savegamePath);
524 loadSetting("savestatePath", m_ui.savestatePath);
525 loadSetting("screenshotPath", m_ui.screenshotPath);
526 loadSetting("patchPath", m_ui.patchPath);
527 loadSetting("cheatsPath", m_ui.cheatsPath);
528 loadSetting("showLibrary", m_ui.showLibrary);
529 loadSetting("preload", m_ui.preload);
530 loadSetting("showFps", m_ui.showFps, true);
531 loadSetting("cheatAutoload", m_ui.cheatAutoload, true);
532 loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
533 loadSetting("autoload", m_ui.autoload, true);
534 loadSetting("autosave", m_ui.autosave, false);
535 loadSetting("logToFile", m_ui.logToFile);
536 loadSetting("logToStdout", m_ui.logToStdout);
537 loadSetting("logFile", m_ui.logFile);
538
539 m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
540
541 double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
542 if (fastForwardRatio <= 0) {
543 m_ui.fastForwardUnbounded->setChecked(true);
544 m_ui.fastForwardRatio->setEnabled(false);
545 } else {
546 m_ui.fastForwardUnbounded->setChecked(false);
547 m_ui.fastForwardRatio->setEnabled(true);
548 m_ui.fastForwardRatio->setValue(fastForwardRatio);
549 }
550
551 QString idleOptimization = loadSetting("idleOptimization");
552 if (idleOptimization == "ignore") {
553 m_ui.idleOptimization->setCurrentIndex(0);
554 } else if (idleOptimization == "remove") {
555 m_ui.idleOptimization->setCurrentIndex(1);
556 } else if (idleOptimization == "detect") {
557 m_ui.idleOptimization->setCurrentIndex(2);
558 }
559
560 bool ok;
561 int loadState = loadSetting("loadStateExtdata").toInt(&ok);
562 if (!ok) {
563 loadState = SAVESTATE_SCREENSHOT | SAVESTATE_RTC;
564 }
565 m_ui.loadStateScreenshot->setChecked(loadState & SAVESTATE_SCREENSHOT);
566 m_ui.loadStateSave->setChecked(loadState & SAVESTATE_SAVEDATA);
567 m_ui.loadStateCheats->setChecked(loadState & SAVESTATE_CHEATS);
568
569 int saveState = loadSetting("saveStateExtdata").toInt(&ok);
570 if (!ok) {
571 saveState = SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC | SAVESTATE_METADATA;
572 }
573 m_ui.saveStateScreenshot->setChecked(saveState & SAVESTATE_SCREENSHOT);
574 m_ui.saveStateSave->setChecked(saveState & SAVESTATE_SAVEDATA);
575 m_ui.saveStateCheats->setChecked(saveState & SAVESTATE_CHEATS);
576
577 m_logModel.reset();
578
579#ifdef M_CORE_GB
580 QString modelGB = m_controller->getOption("gb.model");
581 if (!modelGB.isNull()) {
582 GBModel model = GBNameToModel(modelGB.toUtf8().constData());
583 int index = s_gbModelList.indexOf(model);
584 m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
585 }
586
587 QString modelSGB = m_controller->getOption("sgb.model");
588 if (!modelSGB.isNull()) {
589 GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
590 int index = s_gbModelList.indexOf(model);
591 m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
592 }
593
594 QString modelCGB = m_controller->getOption("cgb.model");
595 if (!modelCGB.isNull()) {
596 GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
597 int index = s_gbModelList.indexOf(model);
598 m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
599 }
600#endif
601}
602
603void SettingsView::saveSetting(const char* key, const QAbstractButton* field) {
604 m_controller->setOption(key, field->isChecked());
605 m_controller->updateOption(key);
606}
607
608void SettingsView::saveSetting(const char* key, const QComboBox* field) {
609 saveSetting(key, field->lineEdit());
610}
611
612void SettingsView::saveSetting(const char* key, const QDoubleSpinBox* field) {
613 saveSetting(key, field->value());
614}
615
616void SettingsView::saveSetting(const char* key, const QLineEdit* field) {
617 saveSetting(key, field->text());
618}
619
620void SettingsView::saveSetting(const char* key, const QSlider* field) {
621 saveSetting(key, field->value());
622}
623
624void SettingsView::saveSetting(const char* key, const QSpinBox* field) {
625 saveSetting(key, field->value());
626}
627
628void SettingsView::saveSetting(const char* key, const QVariant& field) {
629 m_controller->setOption(key, field);
630 m_controller->updateOption(key);
631}
632
633void SettingsView::loadSetting(const char* key, QAbstractButton* field, bool defaultVal) {
634 QString option = loadSetting(key);
635 field->setChecked(option.isNull() ? defaultVal : option != "0");
636}
637
638void SettingsView::loadSetting(const char* key, QComboBox* field) {
639 loadSetting(key, field->lineEdit());
640}
641
642void SettingsView::loadSetting(const char* key, QDoubleSpinBox* field) {
643 QString option = loadSetting(key);
644 field->setValue(option.toDouble());
645}
646
647void SettingsView::loadSetting(const char* key, QLineEdit* field) {
648 QString option = loadSetting(key);
649 field->setText(option);
650}
651
652void SettingsView::loadSetting(const char* key, QSlider* field, int defaultVal) {
653 QString option = loadSetting(key);
654 field->setValue(option.isNull() ? defaultVal : option.toInt());
655}
656
657void SettingsView::loadSetting(const char* key, QSpinBox* field) {
658 QString option = loadSetting(key);
659 field->setValue(option.toInt());
660}
661
662QString SettingsView::loadSetting(const char* key) {
663 return m_controller->getOption(key);
664}