2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-09-22 13:08:07 +00:00
|
|
|
#include "biossettingswidget.h"
|
|
|
|
#include "core/bios.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "qthost.h"
|
2020-09-23 12:53:51 +00:00
|
|
|
#include "qtutils.h"
|
2020-09-22 13:08:07 +00:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "settingwidgetbinder.h"
|
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
BIOSSettingsWidget::BIOSSettingsWidget(SettingsDialog* dialog, QWidget* parent) : QWidget(parent), m_dialog(dialog)
|
|
|
|
{
|
|
|
|
SettingsInterface* sif = dialog->getSettingsInterface();
|
|
|
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
2023-08-29 11:18:04 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableTTYLogging, "BIOS", "TTYLogging", false);
|
2022-07-11 13:03:29 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "BIOS", "PatchFastBoot", false);
|
|
|
|
|
|
|
|
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Unchecked"),
|
|
|
|
tr("Patches the BIOS to skip the console's boot animation. Does not work with all games, "
|
|
|
|
"but usually safe to enable."));
|
|
|
|
dialog->registerWidgetHelp(
|
2023-08-29 11:18:04 +00:00
|
|
|
m_ui.enableTTYLogging, tr("Enable TTY Logging"), tr("Unchecked"),
|
|
|
|
tr("Logs BIOS calls to printf(). Not all games contain debugging messages."));
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
connect(m_ui.imageNTSCJ, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathNTSCJ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathNTSCJ",
|
|
|
|
m_ui.imageNTSCJ->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(m_ui.imageNTSCU, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathNTSCU");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathNTSCU",
|
|
|
|
m_ui.imageNTSCU->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(m_ui.imagePAL, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathPAL");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathPAL",
|
|
|
|
m_ui.imagePAL->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
|
|
|
|
|
|
|
|
m_ui.searchDirectory->setText(QString::fromStdString(EmuFolders::Bios));
|
|
|
|
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory,
|
|
|
|
m_ui.openSearchDirectory, nullptr, "BIOS", "SearchDirectory",
|
|
|
|
Path::Combine(EmuFolders::DataRoot, "bios"));
|
|
|
|
connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
|
|
|
BIOSSettingsWidget::~BIOSSettingsWidget() = default;
|
|
|
|
|
|
|
|
void BIOSSettingsWidget::refreshList()
|
|
|
|
{
|
|
|
|
auto images = BIOS::FindBIOSImagesInDirectory(m_ui.searchDirectory->text().toUtf8().constData());
|
|
|
|
populateDropDownForRegion(ConsoleRegion::NTSC_J, m_ui.imageNTSCJ, images);
|
|
|
|
populateDropDownForRegion(ConsoleRegion::NTSC_U, m_ui.imageNTSCU, images);
|
|
|
|
populateDropDownForRegion(ConsoleRegion::PAL, m_ui.imagePAL, images);
|
|
|
|
|
|
|
|
setDropDownValue(m_ui.imageNTSCJ, m_dialog->getStringValue("BIOS", "PathNTSCJ", std::nullopt));
|
|
|
|
setDropDownValue(m_ui.imageNTSCU, m_dialog->getStringValue("BIOS", "PathNTSCU", std::nullopt));
|
|
|
|
setDropDownValue(m_ui.imagePAL, m_dialog->getStringValue("BIOS", "PathPAL", std::nullopt));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BIOSSettingsWidget::populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
|
|
|
std::vector<std::pair<std::string, const BIOS::ImageInfo*>>& images)
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
2020-09-23 12:53:51 +00:00
|
|
|
QSignalBlocker sb(cb);
|
|
|
|
cb->clear();
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
if (m_dialog->isPerGameSettings())
|
|
|
|
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Use Global Setting"));
|
|
|
|
|
|
|
|
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Auto-Detect"));
|
2020-09-22 13:08:07 +00:00
|
|
|
|
|
|
|
std::sort(images.begin(), images.end(), [region](const auto& left, const auto& right) {
|
|
|
|
const bool left_region_match = (left.second && left.second->region == region);
|
|
|
|
const bool right_region_match = (right.second && right.second->region == region);
|
|
|
|
if (left_region_match && !right_region_match)
|
|
|
|
return true;
|
2020-11-01 12:12:04 +00:00
|
|
|
else if (right_region_match && !left_region_match)
|
2020-09-22 13:08:07 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return left.first < right.first;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto& [name, info] : images)
|
|
|
|
{
|
|
|
|
QString name_str(QString::fromStdString(name));
|
2022-07-11 13:03:29 +00:00
|
|
|
cb->addItem(QtUtils::GetIconForRegion(info ? info->region : ConsoleRegion::Count),
|
2020-09-22 13:08:07 +00:00
|
|
|
QStringLiteral("%1 (%2)")
|
|
|
|
.arg(info ? QString(info->description) : qApp->translate("BIOSSettingsWidget", "Unknown"))
|
|
|
|
.arg(name_str),
|
|
|
|
QVariant(name_str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
void BIOSSettingsWidget::setDropDownValue(QComboBox* cb, const std::optional<std::string>& name)
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
|
|
|
QSignalBlocker sb(cb);
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
if (!name.has_value() || name->empty())
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
2022-07-11 13:03:29 +00:00
|
|
|
cb->setCurrentIndex((m_dialog->isPerGameSettings() && name.has_value()) ? 1 : 0);
|
2020-09-22 13:08:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
QString qname(QString::fromStdString(name.value()));
|
2020-09-22 13:08:07 +00:00
|
|
|
for (int i = 1; i < cb->count(); i++)
|
|
|
|
{
|
|
|
|
if (cb->itemData(i) == qname)
|
|
|
|
{
|
|
|
|
cb->setCurrentIndex(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->addItem(qname, QVariant(qname));
|
|
|
|
cb->setCurrentIndex(cb->count() - 1);
|
|
|
|
}
|