pcsx2/pcsx2-qt/Settings/BIOSSettingsWidget.cpp

172 lines
5.1 KiB
C++
Raw Normal View History

2021-12-13 12:12:54 +00:00
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2022 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include <QtGui/QIcon>
#include <QtWidgets/QFileDialog>
#include <algorithm>
#include "pcsx2/HostSettings.h"
2021-12-13 12:12:54 +00:00
#include "pcsx2/ps2/BiosTools.h"
#include "BIOSSettingsWidget.h"
2022-06-04 05:53:31 +00:00
#include "QtHost.h"
2021-12-13 12:12:54 +00:00
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"
2022-02-15 14:29:18 +00:00
BIOSSettingsWidget::BIOSSettingsWidget(SettingsDialog* dialog, QWidget* parent)
2021-12-13 12:12:54 +00:00
: QWidget(parent)
{
2022-02-15 14:29:18 +00:00
SettingsInterface* sif = dialog->getSettingsInterface();
2021-12-13 12:12:54 +00:00
m_ui.setupUi(this);
2022-02-15 14:29:18 +00:00
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "EmuCore", "EnableFastBoot", true);
2022-06-14 10:05:11 +00:00
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory, m_ui.openSearchDirectory,
m_ui.resetSearchDirectory, "Folders", "Bios", Path::Combine(EmuFolders::DataRoot, "bios"));
2021-12-13 12:12:54 +00:00
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Checked"),
2021-12-13 12:12:54 +00:00
tr("Patches the BIOS to skip the console's boot animation."));
refreshList();
2022-06-14 10:05:11 +00:00
connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
2021-12-13 12:12:54 +00:00
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
connect(m_ui.fileList, &QTreeWidget::currentItemChanged, this, &BIOSSettingsWidget::listItemChanged);
}
BIOSSettingsWidget::~BIOSSettingsWidget()
{
if (m_refresh_thread)
m_refresh_thread->wait();
}
void BIOSSettingsWidget::refreshList()
{
if (m_refresh_thread)
{
m_refresh_thread->wait();
delete m_refresh_thread;
}
QSignalBlocker blocker(m_ui.fileList);
m_ui.fileList->clear();
m_ui.fileList->setEnabled(false);
m_refresh_thread = new RefreshThread(this, m_ui.searchDirectory->text());
m_refresh_thread->start();
}
void BIOSSettingsWidget::listRefreshed(const QVector<BIOSInfo>& items)
{
const std::string selected_bios(Host::GetBaseStringSettingValue("Filenames", "BIOS"));
2022-06-04 05:53:31 +00:00
const QString res_path(QtHost::GetResourcesBasePath());
2021-12-13 12:12:54 +00:00
QSignalBlocker sb(m_ui.fileList);
for (const BIOSInfo& bi : items)
{
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0, QString::fromStdString(bi.filename));
item->setText(1, QString::fromStdString(bi.description));
switch (bi.region)
{
case 0: // Japan
2022-06-04 05:53:31 +00:00
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-J.png").arg(res_path)));
2021-12-13 12:12:54 +00:00
break;
case 1: // USA
2022-06-04 05:53:31 +00:00
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-U.png").arg(res_path)));
2021-12-13 12:12:54 +00:00
break;
case 2: // Europe
2022-06-04 05:53:31 +00:00
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-E.png").arg(res_path)));
2021-12-13 12:12:54 +00:00
break;
case 3: // Oceania
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-A.png").arg(res_path)));
2022-02-10 20:02:55 +00:00
break;
case 4: // Asia
2022-06-04 05:53:31 +00:00
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-HK.png").arg(res_path)));
2022-02-14 18:39:24 +00:00
break;
case 5: // Russia
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-R.png").arg(res_path)));
break;
case 6: // China
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-C.png").arg(res_path)));
break;
case 7: // Mexico, flag is missing
case 8: // T10K
case 9: // Test
case 10: // Free
2021-12-13 12:12:54 +00:00
default:
2022-06-04 05:53:31 +00:00
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-J.png").arg(res_path)));
2021-12-13 12:12:54 +00:00
break;
}
m_ui.fileList->addTopLevelItem(item);
if (bi.filename == selected_bios)
item->setSelected(true);
}
m_ui.fileList->setEnabled(true);
}
void BIOSSettingsWidget::listItemChanged(const QTreeWidgetItem* current, const QTreeWidgetItem* previous)
{
2022-09-07 07:44:10 +00:00
Host::SetBaseStringSettingValue("Filenames", "BIOS", current->text(0).toUtf8().constData());
Host::CommitBaseSettingChanges();
g_emu_thread->applySettings();
2021-12-13 12:12:54 +00:00
}
BIOSSettingsWidget::RefreshThread::RefreshThread(BIOSSettingsWidget* parent, const QString& directory)
: QThread(parent)
, m_parent(parent)
, m_directory(directory)
{
}
BIOSSettingsWidget::RefreshThread::~RefreshThread() = default;
void BIOSSettingsWidget::RefreshThread::run()
{
QVector<BIOSInfo> items;
QDir dir(m_directory);
if (dir.exists())
{
for (const QFileInfo& info : dir.entryInfoList(QDir::Files))
{
BIOSInfo bi;
QString full_path(info.absoluteFilePath());
if (!IsBIOS(full_path.toUtf8().constData(), bi.version, bi.description, bi.region, bi.zone))
continue;
bi.filename = info.fileName().toStdString();
items.push_back(std::move(bi));
}
}
QMetaObject::invokeMethod(m_parent, "listRefreshed", Qt::QueuedConnection, Q_ARG(const QVector<BIOSInfo>&, items));
}