2023-12-22 11:57:49 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0+
|
2022-02-15 14:59:15 +00:00
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
#include <QtGui/QDrag>
|
2022-06-18 09:59:42 +00:00
|
|
|
#include <QtWidgets/QFileDialog>
|
2022-03-25 09:24:41 +00:00
|
|
|
#include <QtWidgets/QInputDialog>
|
|
|
|
#include <QtWidgets/QMenu>
|
2022-02-15 14:59:15 +00:00
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
#include "common/StringUtil.h"
|
|
|
|
|
2022-08-28 21:31:19 +00:00
|
|
|
#include "MemoryCardConvertDialog.h"
|
2023-07-04 10:51:56 +00:00
|
|
|
#include "MemoryCardCreateDialog.h"
|
2023-05-29 10:42:46 +00:00
|
|
|
#include "MemoryCardSettingsWidget.h"
|
|
|
|
#include "QtHost.h"
|
2022-02-15 14:59:15 +00:00
|
|
|
#include "QtUtils.h"
|
|
|
|
#include "SettingWidgetBinder.h"
|
2023-10-14 08:45:09 +00:00
|
|
|
#include "SettingsWindow.h"
|
2022-02-15 14:59:15 +00:00
|
|
|
|
2023-06-11 06:06:40 +00:00
|
|
|
#include "pcsx2/SIO/Memcard/MemoryCardFile.h"
|
2022-03-25 09:24:41 +00:00
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
static constexpr const char* CONFIG_SECTION = "MemoryCards";
|
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
static std::string getSlotFilenameKey(u32 slot)
|
|
|
|
{
|
|
|
|
return StringUtil::StdStringFromFormat("Slot%u_Filename", slot + 1);
|
|
|
|
}
|
|
|
|
|
2023-10-14 08:45:09 +00:00
|
|
|
MemoryCardSettingsWidget::MemoryCardSettingsWidget(SettingsWindow* dialog, QWidget* parent)
|
2022-02-15 14:59:15 +00:00
|
|
|
: QWidget(parent)
|
2022-03-25 09:24:41 +00:00
|
|
|
, m_dialog(dialog)
|
2022-02-15 14:59:15 +00:00
|
|
|
{
|
2022-03-25 09:24:41 +00:00
|
|
|
SettingsInterface* sif = m_dialog->getSettingsInterface();
|
2022-02-15 14:59:15 +00:00
|
|
|
|
|
|
|
m_ui.setupUi(this);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
// this is a bit lame, but resizeEvent() isn't good enough to autosize our columns,
|
|
|
|
// since the group box hasn't been resized at that point.
|
|
|
|
m_ui.cardGroupBox->installEventFilter(this);
|
2023-05-29 10:42:46 +00:00
|
|
|
|
|
|
|
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.directory, m_ui.browse, m_ui.open, m_ui.reset, "Folders",
|
|
|
|
"MemoryCards", Path::Combine(EmuFolders::DataRoot, "memcards"));
|
2022-03-25 09:24:41 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.automaticManagement, "EmuCore", "McdFolderAutoManage", true);
|
|
|
|
|
2022-06-06 13:04:14 +00:00
|
|
|
setupAdditionalUi();
|
2022-03-25 09:24:41 +00:00
|
|
|
|
2022-06-18 09:59:42 +00:00
|
|
|
connect(m_ui.directory, &QLineEdit::textChanged, this, &MemoryCardSettingsWidget::refresh);
|
2022-03-25 09:24:41 +00:00
|
|
|
m_ui.cardList->setContextMenuPolicy(Qt::CustomContextMenu);
|
2023-05-29 10:42:46 +00:00
|
|
|
connect(
|
|
|
|
m_ui.cardList, &MemoryCardListWidget::itemSelectionChanged, this, &MemoryCardSettingsWidget::updateCardActions);
|
|
|
|
connect(m_ui.cardList, &MemoryCardListWidget::customContextMenuRequested, this,
|
|
|
|
&MemoryCardSettingsWidget::listContextMenuRequested);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
connect(m_ui.refreshCard, &QPushButton::clicked, this, &MemoryCardSettingsWidget::refresh);
|
|
|
|
connect(m_ui.createCard, &QPushButton::clicked, this, &MemoryCardSettingsWidget::createCard);
|
|
|
|
connect(m_ui.renameCard, &QPushButton::clicked, this, &MemoryCardSettingsWidget::renameCard);
|
|
|
|
connect(m_ui.convertCard, &QPushButton::clicked, this, &MemoryCardSettingsWidget::convertCard);
|
|
|
|
connect(m_ui.deleteCard, &QPushButton::clicked, this, &MemoryCardSettingsWidget::deleteCard);
|
|
|
|
|
|
|
|
refresh();
|
2022-12-05 04:35:58 +00:00
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.automaticManagement, tr("Automatically manage saves based on running game"),
|
|
|
|
tr("Checked"),
|
|
|
|
tr("(Folder type only / Card size: Auto) Loads only the relevant booted game saves, ignoring others. Avoids "
|
|
|
|
"running out of space for saves."));
|
2022-02-15 14:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardSettingsWidget::~MemoryCardSettingsWidget() = default;
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
autoSizeUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryCardSettingsWidget::eventFilter(QObject* watched, QEvent* event)
|
|
|
|
{
|
|
|
|
if (watched == m_ui.cardGroupBox && event->type() == QEvent::Resize)
|
|
|
|
autoSizeUI();
|
|
|
|
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
2022-06-06 13:04:14 +00:00
|
|
|
void MemoryCardSettingsWidget::setupAdditionalUi()
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < static_cast<u32>(m_slots.size()); i++)
|
|
|
|
createSlotWidgets(&m_slots[i], i);
|
|
|
|
|
2023-03-13 00:34:20 +00:00
|
|
|
// button to swap Memory Cards
|
2024-01-24 08:45:28 +00:00
|
|
|
QToolButton* swap_button = new QToolButton(m_ui.slotGroupBox);
|
2022-06-06 13:04:14 +00:00
|
|
|
swap_button->setIcon(QIcon::fromTheme("arrow-left-right-line"));
|
|
|
|
swap_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
swap_button->setToolTip(tr("Swap Memory Cards"));
|
|
|
|
connect(swap_button, &QToolButton::clicked, this, &MemoryCardSettingsWidget::swapCards);
|
2024-01-24 08:45:28 +00:00
|
|
|
static_cast<QGridLayout*>(m_ui.slotGroupBox->layout())->addWidget(swap_button, 0, 1);
|
2022-06-06 13:04:14 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
void MemoryCardSettingsWidget::createSlotWidgets(SlotGroup* port, u32 slot)
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
const bool perGame = m_dialog->isPerGameSettings();
|
|
|
|
|
2024-01-24 08:45:28 +00:00
|
|
|
port->root = new QWidget(m_ui.slotGroupBox);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
SettingsInterface* sif = m_dialog->getSettingsInterface();
|
2024-01-24 08:45:28 +00:00
|
|
|
port->enable = new QCheckBox(tr("Slot %1").arg(slot + 1), port->root);
|
2023-05-29 10:42:46 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(
|
|
|
|
sif, port->enable, CONFIG_SECTION, StringUtil::StdStringFromFormat("Slot%u_Enable", slot + 1), true);
|
2024-04-12 12:22:58 +00:00
|
|
|
connect(port->enable, &QCheckBox::checkStateChanged, this, &MemoryCardSettingsWidget::refresh);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
port->eject = new QToolButton(port->root);
|
2023-05-29 10:42:46 +00:00
|
|
|
port->eject->setIcon(QIcon::fromTheme(perGame ? QStringLiteral("delete-back-2-line") : QStringLiteral("eject-line")));
|
2022-03-25 09:24:41 +00:00
|
|
|
port->eject->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2023-05-29 10:42:46 +00:00
|
|
|
port->eject->setToolTip(perGame ? tr("Reset") : tr("Eject Memory Card"));
|
2022-03-25 09:24:41 +00:00
|
|
|
connect(port->eject, &QToolButton::clicked, this, [this, slot]() { ejectSlot(slot); });
|
|
|
|
|
|
|
|
port->slot = new MemoryCardSlotWidget(port->root);
|
2023-05-29 10:42:46 +00:00
|
|
|
connect(port->slot, &MemoryCardSlotWidget::cardDropped, this,
|
|
|
|
[this, slot](const QString& card) { tryInsertCard(slot, card); });
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
QHBoxLayout* bottom_layout = new QHBoxLayout();
|
|
|
|
bottom_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
bottom_layout->addWidget(port->slot, 1);
|
|
|
|
bottom_layout->addWidget(port->eject, 0);
|
|
|
|
|
|
|
|
QVBoxLayout* vert_layout = new QVBoxLayout(port->root);
|
|
|
|
vert_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
vert_layout->addWidget(port->enable, 0);
|
|
|
|
vert_layout->addLayout(bottom_layout, 1);
|
|
|
|
|
2024-01-24 08:45:28 +00:00
|
|
|
static_cast<QGridLayout*>(m_ui.slotGroupBox->layout())->addWidget(port->root, 0, (slot != 0) ? 2 : 0);
|
2022-03-25 09:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::autoSizeUI()
|
|
|
|
{
|
|
|
|
QtUtils::ResizeColumnsForTreeView(m_ui.cardList, {-1, 100, 80, 150});
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::tryInsertCard(u32 slot, const QString& newCard)
|
|
|
|
{
|
|
|
|
// handle where the card is dragged in from explorer or something
|
|
|
|
const int lastSlashPos = std::max(newCard.lastIndexOf('/'), newCard.lastIndexOf('\\'));
|
2023-05-29 10:42:46 +00:00
|
|
|
const std::string newCardStr(
|
|
|
|
(lastSlashPos >= 0) ? newCard.mid(0, lastSlashPos).toStdString() : newCard.toStdString());
|
2022-03-25 09:24:41 +00:00
|
|
|
if (newCardStr.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// make sure it's a card in the directory
|
|
|
|
const std::vector<AvailableMcdInfo> mcds(FileMcd_GetAvailableCards(true));
|
2023-05-29 10:42:46 +00:00
|
|
|
if (std::none_of(
|
|
|
|
mcds.begin(), mcds.end(), [&newCardStr](const AvailableMcdInfo& mcd) { return mcd.name == newCardStr; }))
|
2022-03-25 09:24:41 +00:00
|
|
|
{
|
2024-02-10 17:21:15 +00:00
|
|
|
QMessageBox::critical(this, tr("Error"), tr("This Memory Card cannot be recognized or is not a valid file type."));
|
2022-03-25 09:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
m_dialog->setStringSettingValue(CONFIG_SECTION, getSlotFilenameKey(slot).c_str(), newCardStr.c_str());
|
2022-03-25 09:24:41 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::ejectSlot(u32 slot)
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
m_dialog->setStringSettingValue(CONFIG_SECTION, getSlotFilenameKey(slot).c_str(),
|
|
|
|
m_dialog->isPerGameSettings() ? std::nullopt : std::optional<const char*>(""));
|
2022-03-25 09:24:41 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::createCard()
|
|
|
|
{
|
2023-07-04 10:51:56 +00:00
|
|
|
MemoryCardCreateDialog dialog(QtUtils::GetRootWidget(this));
|
2022-03-25 09:24:41 +00:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MemoryCardSettingsWidget::getSelectedCard() const
|
|
|
|
{
|
|
|
|
QString ret;
|
|
|
|
|
|
|
|
const QList<QTreeWidgetItem*> selection(m_ui.cardList->selectedItems());
|
|
|
|
if (!selection.empty())
|
|
|
|
ret = selection[0]->text(0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::updateCardActions()
|
|
|
|
{
|
2022-08-28 21:31:19 +00:00
|
|
|
QString selectedCard = getSelectedCard();
|
|
|
|
const bool hasSelection = !selectedCard.isEmpty();
|
2023-05-29 10:42:46 +00:00
|
|
|
|
2022-08-28 21:31:19 +00:00
|
|
|
std::optional<AvailableMcdInfo> cardInfo = FileMcd_GetCardInfo(selectedCard.toStdString());
|
|
|
|
bool isPS1 = (cardInfo.has_value() ? cardInfo.value().file_type == MemoryCardFileType::PS1 : false);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
2022-08-28 21:31:19 +00:00
|
|
|
m_ui.convertCard->setEnabled(hasSelection && !isPS1);
|
2022-03-25 09:24:41 +00:00
|
|
|
m_ui.renameCard->setEnabled(hasSelection);
|
|
|
|
m_ui.deleteCard->setEnabled(hasSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::deleteCard()
|
|
|
|
{
|
|
|
|
const QString selectedCard(getSelectedCard());
|
|
|
|
if (selectedCard.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (QMessageBox::question(QtUtils::GetRootWidget(this), tr("Delete Memory Card"),
|
2023-03-13 00:34:20 +00:00
|
|
|
tr("Are you sure you wish to delete the Memory Card '%1'?\n\n"
|
2022-03-25 09:24:41 +00:00
|
|
|
"This action cannot be reversed, and you will lose any saves on the card.")
|
|
|
|
.arg(selectedCard)) != QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FileMcd_DeleteCard(selectedCard.toStdString()))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(QtUtils::GetRootWidget(this), tr("Delete Memory Card"),
|
2023-03-13 00:34:20 +00:00
|
|
|
tr("Failed to delete the Memory Card. The log may have more information."));
|
2022-03-25 09:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::renameCard()
|
|
|
|
{
|
|
|
|
const QString selectedCard(getSelectedCard());
|
|
|
|
if (selectedCard.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
const QString newName(QInputDialog::getText(
|
|
|
|
QtUtils::GetRootWidget(this), tr("Rename Memory Card"), tr("New Card Name"), QLineEdit::Normal, selectedCard));
|
2022-03-25 09:24:41 +00:00
|
|
|
if (newName.isEmpty() || newName == selectedCard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!newName.endsWith(QStringLiteral(".ps2")) || newName.length() <= 4)
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
QMessageBox::critical(
|
|
|
|
QtUtils::GetRootWidget(this), tr("Rename Memory Card"), tr("New name is invalid, it must end with .ps2"));
|
2022-03-25 09:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string newNameStr(newName.toStdString());
|
|
|
|
if (FileMcd_GetCardInfo(newNameStr).has_value())
|
|
|
|
{
|
|
|
|
QMessageBox::critical(QtUtils::GetRootWidget(this), tr("Rename Memory Card"),
|
|
|
|
tr("New name is invalid, a card with this name already exists."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FileMcd_RenameCard(selectedCard.toStdString(), newNameStr))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(QtUtils::GetRootWidget(this), tr("Rename Memory Card"),
|
2023-03-13 00:34:20 +00:00
|
|
|
tr("Failed to rename Memory Card. The log may contain more information."));
|
2022-03-25 09:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::convertCard()
|
|
|
|
{
|
|
|
|
const QString selectedCard(getSelectedCard());
|
2023-05-29 10:42:46 +00:00
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
if (selectedCard.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2022-08-28 21:31:19 +00:00
|
|
|
MemoryCardConvertDialog dialog(QtUtils::GetRootWidget(this), selectedCard);
|
2023-05-29 10:42:46 +00:00
|
|
|
|
2022-08-28 21:31:19 +00:00
|
|
|
if (dialog.IsSetup() && dialog.exec() == QDialog::Accepted)
|
|
|
|
refresh();
|
2022-03-25 09:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::listContextMenuRequested(const QPoint& pos)
|
|
|
|
{
|
|
|
|
QMenu menu(this);
|
|
|
|
|
|
|
|
const QString selectedCard(getSelectedCard());
|
|
|
|
if (!selectedCard.isEmpty())
|
|
|
|
{
|
|
|
|
for (u32 slot = 0; slot < MAX_SLOTS; slot++)
|
|
|
|
{
|
2024-01-24 08:45:28 +00:00
|
|
|
connect(menu.addAction(tr("Use for Slot %1").arg(slot + 1)), &QAction::triggered, this,
|
2023-05-29 10:42:46 +00:00
|
|
|
[this, &selectedCard, slot]() { tryInsertCard(slot, selectedCard); });
|
2022-03-25 09:24:41 +00:00
|
|
|
}
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
|
|
connect(menu.addAction(tr("Rename")), &QAction::triggered, this, &MemoryCardSettingsWidget::renameCard);
|
|
|
|
connect(menu.addAction(tr("Convert")), &QAction::triggered, this, &MemoryCardSettingsWidget::convertCard);
|
|
|
|
connect(menu.addAction(tr("Delete")), &QAction::triggered, this, &MemoryCardSettingsWidget::deleteCard);
|
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
2023-09-30 10:58:25 +00:00
|
|
|
connect(menu.addAction(tr("Create")), &QAction::triggered, this, &MemoryCardSettingsWidget::createCard);
|
2022-03-25 09:24:41 +00:00
|
|
|
|
|
|
|
menu.exec(m_ui.cardList->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::refresh()
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
const bool perGame = m_dialog->isPerGameSettings();
|
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
for (u32 slot = 0; slot < static_cast<u32>(m_slots.size()); slot++)
|
|
|
|
{
|
|
|
|
const bool enabled = m_slots[slot].enable->isChecked();
|
2023-05-29 10:42:46 +00:00
|
|
|
const std::string slotKey = getSlotFilenameKey(slot);
|
2022-03-25 09:24:41 +00:00
|
|
|
const std::optional<std::string> name(
|
2023-05-29 10:42:46 +00:00
|
|
|
m_dialog->getEffectiveStringValue(CONFIG_SECTION, slotKey.c_str(), FileMcd_GetDefaultName(slot).c_str()));
|
|
|
|
const bool inherited = perGame ? !m_dialog->containsSettingValue(CONFIG_SECTION, slotKey.c_str()) : false;
|
2022-03-25 09:24:41 +00:00
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
m_slots[slot].slot->setCard(name, inherited);
|
2022-03-25 09:24:41 +00:00
|
|
|
m_slots[slot].slot->setEnabled(enabled);
|
|
|
|
m_slots[slot].eject->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ui.cardList->refresh(m_dialog);
|
|
|
|
updateCardActions();
|
|
|
|
}
|
|
|
|
|
2022-06-06 13:04:14 +00:00
|
|
|
void MemoryCardSettingsWidget::swapCards()
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
const std::string card1Key = getSlotFilenameKey(0);
|
|
|
|
const std::string card2Key = getSlotFilenameKey(1);
|
|
|
|
std::optional<std::string> card1Name = m_dialog->getStringValue(CONFIG_SECTION, card1Key.c_str(), std::nullopt);
|
|
|
|
std::optional<std::string> card2Name = m_dialog->getStringValue(CONFIG_SECTION, card2Key.c_str(), std::nullopt);
|
|
|
|
if (!card1Name.has_value() || card1Name->empty() || !card2Name.has_value() || card2Name->empty())
|
2022-06-06 13:04:14 +00:00
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
QMessageBox::critical(
|
2024-01-24 08:45:28 +00:00
|
|
|
QtUtils::GetRootWidget(this), tr("Error"), tr("Both slots must have a card selected to swap."));
|
2022-06-06 13:04:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
m_dialog->setStringSettingValue(CONFIG_SECTION, card1Key.c_str(), card2Name->c_str());
|
|
|
|
m_dialog->setStringSettingValue(CONFIG_SECTION, card2Key.c_str(), card1Name->c_str());
|
2022-06-06 13:04:14 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:24:41 +00:00
|
|
|
static QString getSizeSummary(const AvailableMcdInfo& mcd)
|
|
|
|
{
|
|
|
|
if (mcd.type == MemoryCardType::File)
|
|
|
|
{
|
|
|
|
switch (mcd.file_type)
|
|
|
|
{
|
|
|
|
case MemoryCardFileType::PS2_8MB:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS2 (8MB)");
|
|
|
|
|
|
|
|
case MemoryCardFileType::PS2_16MB:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS2 (16MB)");
|
|
|
|
|
|
|
|
case MemoryCardFileType::PS2_32MB:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS2 (32MB)");
|
|
|
|
|
|
|
|
case MemoryCardFileType::PS2_64MB:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS2 (64MB)");
|
|
|
|
|
|
|
|
case MemoryCardFileType::PS1:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS1 (128KB)");
|
|
|
|
|
|
|
|
case MemoryCardFileType::Unknown:
|
|
|
|
default:
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "Unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mcd.type == MemoryCardType::Folder)
|
|
|
|
{
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "PS2 (Folder)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return qApp->translate("MemoryCardSettingsWidget", "Unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QIcon getCardIcon(const AvailableMcdInfo& mcd)
|
|
|
|
{
|
|
|
|
if (mcd.type == MemoryCardType::File)
|
2023-06-03 08:16:36 +00:00
|
|
|
return QIcon::fromTheme(QStringLiteral("memcard-line"));
|
2022-03-25 09:24:41 +00:00
|
|
|
else
|
|
|
|
return QIcon::fromTheme(QStringLiteral("folder-open-line"));
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardListWidget::MemoryCardListWidget(QWidget* parent)
|
|
|
|
: QTreeWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardListWidget::~MemoryCardListWidget() = default;
|
|
|
|
|
|
|
|
void MemoryCardListWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
m_dragStartPos = event->pos();
|
|
|
|
|
|
|
|
QTreeWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardListWidget::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (!(event->buttons() & Qt::LeftButton) ||
|
|
|
|
(event->pos() - m_dragStartPos).manhattanLength() < QApplication::startDragDistance())
|
|
|
|
{
|
|
|
|
QTreeWidget::mouseMoveEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QTreeWidgetItem*> selection(selectedItems());
|
|
|
|
if (selection.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QDrag* drag = new QDrag(this);
|
|
|
|
QMimeData* mimeData = new QMimeData();
|
|
|
|
mimeData->setText(selection[0]->text(0));
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
drag->exec(Qt::CopyAction);
|
|
|
|
}
|
|
|
|
|
2023-10-14 08:45:09 +00:00
|
|
|
void MemoryCardListWidget::refresh(SettingsWindow* dialog)
|
2022-03-25 09:24:41 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// we can't use the in use flag here anyway, because the config may not be in line with per game settings.
|
|
|
|
const std::vector<AvailableMcdInfo> mcds(FileMcd_GetAvailableCards(true));
|
|
|
|
if (mcds.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::array<std::string, MemoryCardSettingsWidget::MAX_SLOTS> currentCards;
|
|
|
|
for (u32 i = 0; i < static_cast<u32>(currentCards.size()); i++)
|
|
|
|
{
|
2023-05-29 10:42:46 +00:00
|
|
|
const std::optional<std::string> filename = dialog->getEffectiveStringValue(
|
|
|
|
CONFIG_SECTION, getSlotFilenameKey(i).c_str(), FileMcd_GetDefaultName(i).c_str());
|
2022-03-25 09:24:41 +00:00
|
|
|
if (filename.has_value())
|
|
|
|
currentCards[i] = std::move(filename.value());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const AvailableMcdInfo& mcd : mcds)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
const QDateTime mtime(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(mcd.modified_time)));
|
|
|
|
const bool inUse = (std::find(currentCards.begin(), currentCards.end(), mcd.name) != currentCards.end());
|
|
|
|
|
|
|
|
item->setDisabled(inUse);
|
|
|
|
item->setIcon(0, getCardIcon(mcd));
|
|
|
|
item->setText(0, QString::fromStdString(mcd.name));
|
|
|
|
item->setText(1, getSizeSummary(mcd));
|
|
|
|
item->setText(2, mcd.formatted ? tr("Yes") : tr("No"));
|
|
|
|
item->setText(3, mtime.toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat)));
|
|
|
|
addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardSlotWidget::MemoryCardSlotWidget(QWidget* parent)
|
|
|
|
: QListWidget(parent)
|
|
|
|
{
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setSelectionMode(NoSelection);
|
2023-09-09 05:08:13 +00:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2022-03-25 09:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardSlotWidget::~MemoryCardSlotWidget() = default;
|
|
|
|
|
|
|
|
void MemoryCardSlotWidget::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("text/plain"))
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSlotWidget::dragMoveEvent(QDragMoveEvent* event)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSlotWidget::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
const QMimeData* data = event->mimeData();
|
|
|
|
const QString text(data ? data->text() : QString());
|
|
|
|
if (text.isEmpty())
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
emit cardDropped(text);
|
|
|
|
}
|
|
|
|
|
2023-05-29 10:42:46 +00:00
|
|
|
void MemoryCardSlotWidget::setCard(const std::optional<std::string>& name, bool inherited)
|
2022-03-25 09:24:41 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
if (!name.has_value() || name->empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const std::optional<AvailableMcdInfo> mcd(FileMcd_GetCardInfo(name.value()));
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(this);
|
|
|
|
|
|
|
|
if (mcd.has_value())
|
|
|
|
{
|
|
|
|
item->setIcon(getCardIcon(mcd.value()));
|
|
|
|
item->setText(tr("%1 [%2]").arg(QString::fromStdString(mcd->name)).arg(getSizeSummary(mcd.value())));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->setIcon(QIcon::fromTheme("close-line"));
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Ignore Crowdin's warning for [Missing], the text should be translated.
|
2022-03-25 09:24:41 +00:00
|
|
|
item->setText(tr("%1 [Missing]").arg(QString::fromStdString(name.value())));
|
|
|
|
}
|
2023-05-29 10:42:46 +00:00
|
|
|
|
|
|
|
if (inherited)
|
|
|
|
{
|
|
|
|
QFont font = item->font();
|
|
|
|
font.setItalic(true);
|
|
|
|
item->setFont(font);
|
|
|
|
item->setForeground(palette().brush(QPalette::Disabled, QPalette::Text));
|
|
|
|
}
|
2023-09-09 05:08:13 +00:00
|
|
|
|
|
|
|
item->setToolTip(item->text());
|
2022-03-25 09:24:41 +00:00
|
|
|
}
|