2020-05-20 13:26:24 +00:00
|
|
|
#include "memorycardsettingswidget.h"
|
2020-07-21 09:49:04 +00:00
|
|
|
#include "common/string_util.h"
|
2020-05-20 13:26:24 +00:00
|
|
|
#include "core/controller.h"
|
|
|
|
#include "core/settings.h"
|
|
|
|
#include "inputbindingwidgets.h"
|
|
|
|
#include "qthostinterface.h"
|
|
|
|
#include "qtutils.h"
|
2020-08-15 10:38:54 +00:00
|
|
|
#include "settingsdialog.h"
|
2020-05-20 13:26:24 +00:00
|
|
|
#include "settingwidgetbinder.h"
|
|
|
|
#include <QtCore/QUrl>
|
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
#include <QtWidgets/QLabel>
|
|
|
|
|
2020-08-23 12:47:49 +00:00
|
|
|
static constexpr char MEMORY_CARD_IMAGE_FILTER[] = QT_TRANSLATE_NOOP("MemoryCardSettingsWidget", "All Memory Card Types (*.mcd *.mcr *.mc)");
|
2020-05-20 13:26:24 +00:00
|
|
|
|
2020-08-15 10:38:54 +00:00
|
|
|
MemoryCardSettingsWidget::MemoryCardSettingsWidget(QtHostInterface* host_interface, QWidget* parent,
|
|
|
|
SettingsDialog* dialog)
|
2020-05-20 13:26:24 +00:00
|
|
|
: QWidget(parent), m_host_interface(host_interface)
|
|
|
|
{
|
2020-08-15 10:38:54 +00:00
|
|
|
createUi(dialog);
|
2020-05-20 13:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardSettingsWidget::~MemoryCardSettingsWidget() = default;
|
|
|
|
|
2020-08-15 10:38:54 +00:00
|
|
|
void MemoryCardSettingsWidget::createUi(SettingsDialog* dialog)
|
2020-05-20 13:26:24 +00:00
|
|
|
{
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++)
|
|
|
|
{
|
2020-08-15 10:38:54 +00:00
|
|
|
createPortSettingsUi(dialog, i, &m_port_ui[i]);
|
2020-05-20 13:26:24 +00:00
|
|
|
layout->addWidget(m_port_ui[i].container);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-08-15 10:38:54 +00:00
|
|
|
QGroupBox* box = new QGroupBox(tr("Shared Settings"), this);
|
|
|
|
QVBoxLayout* box_layout = new QVBoxLayout(box);
|
|
|
|
|
|
|
|
QCheckBox* playlist_title_as_game_title = new QCheckBox(tr("Use Single Card For Playlist"), box);
|
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, playlist_title_as_game_title, "MemoryCards",
|
|
|
|
"UsePlaylistTitle", true);
|
|
|
|
box_layout->addWidget(playlist_title_as_game_title);
|
|
|
|
dialog->registerWidgetHelp(
|
|
|
|
playlist_title_as_game_title, tr("Use Single Card For Playlist"), tr("Checked"),
|
|
|
|
tr("When using a playlist (m3u) and per-game (title) memory cards, a single memory card "
|
|
|
|
"will be used for all discs. If unchecked, a separate card will be used for each disc."));
|
|
|
|
|
|
|
|
QHBoxLayout* note_layout = new QHBoxLayout();
|
2020-05-20 13:26:24 +00:00
|
|
|
QLabel* note_label =
|
|
|
|
new QLabel(tr("If one of the \"separate card per game\" memory card modes is chosen, these memory "
|
|
|
|
"cards will be saved to the memcards directory."),
|
2020-08-15 10:38:54 +00:00
|
|
|
box);
|
2020-05-20 13:26:24 +00:00
|
|
|
note_label->setWordWrap(true);
|
|
|
|
note_layout->addWidget(note_label, 1);
|
|
|
|
|
2020-08-15 10:38:54 +00:00
|
|
|
QPushButton* open_memcards = new QPushButton(tr("Open..."), box);
|
2020-05-20 13:26:24 +00:00
|
|
|
connect(open_memcards, &QPushButton::clicked, this, &MemoryCardSettingsWidget::onOpenMemCardsDirectoryClicked);
|
|
|
|
note_layout->addWidget(open_memcards);
|
2020-08-15 10:38:54 +00:00
|
|
|
box_layout->addLayout(note_layout);
|
|
|
|
|
|
|
|
layout->addWidget(box);
|
2020-05-20 13:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layout->addStretch(1);
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2020-08-15 10:38:54 +00:00
|
|
|
void MemoryCardSettingsWidget::createPortSettingsUi(SettingsDialog* dialog, int index, PortSettingsUI* ui)
|
2020-05-20 13:26:24 +00:00
|
|
|
{
|
|
|
|
ui->container = new QGroupBox(tr("Memory Card %1").arg(index + 1), this);
|
|
|
|
ui->layout = new QVBoxLayout(ui->container);
|
|
|
|
|
|
|
|
ui->memory_card_type = new QComboBox(ui->container);
|
|
|
|
for (int i = 0; i < static_cast<int>(MemoryCardType::Count); i++)
|
|
|
|
{
|
|
|
|
ui->memory_card_type->addItem(
|
2020-08-22 03:01:52 +00:00
|
|
|
qApp->translate("MemoryCardType", Settings::GetMemoryCardTypeDisplayName(static_cast<MemoryCardType>(i))));
|
2020-05-20 13:26:24 +00:00
|
|
|
}
|
2020-06-30 14:33:53 +00:00
|
|
|
|
|
|
|
const MemoryCardType default_value = (index == 0) ? MemoryCardType::PerGameTitle : MemoryCardType::None;
|
|
|
|
SettingWidgetBinder::BindWidgetToEnumSetting(
|
2020-07-21 09:49:04 +00:00
|
|
|
m_host_interface, ui->memory_card_type, "MemoryCards", StringUtil::StdStringFromFormat("Card%dType", index + 1),
|
2020-06-30 14:33:53 +00:00
|
|
|
&Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName, default_value);
|
2020-05-20 13:26:24 +00:00
|
|
|
ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container));
|
|
|
|
ui->layout->addWidget(ui->memory_card_type);
|
|
|
|
|
|
|
|
QHBoxLayout* memory_card_layout = new QHBoxLayout();
|
|
|
|
ui->memory_card_path = new QLineEdit(ui->container);
|
2020-07-21 09:49:04 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, ui->memory_card_path, "MemoryCards",
|
|
|
|
StringUtil::StdStringFromFormat("Card%dPath", index + 1));
|
2020-05-20 13:26:24 +00:00
|
|
|
memory_card_layout->addWidget(ui->memory_card_path);
|
|
|
|
|
|
|
|
QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container);
|
|
|
|
connect(memory_card_path_browse, &QPushButton::clicked, [this, index]() { onBrowseMemoryCardPathClicked(index); });
|
|
|
|
memory_card_layout->addWidget(memory_card_path_browse);
|
|
|
|
|
|
|
|
ui->layout->addWidget(new QLabel(tr("Shared Memory Card Path:"), ui->container));
|
|
|
|
ui->layout->addLayout(memory_card_layout);
|
|
|
|
|
|
|
|
ui->layout->addStretch(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::onBrowseMemoryCardPathClicked(int index)
|
|
|
|
{
|
|
|
|
QString path =
|
|
|
|
QFileDialog::getOpenFileName(this, tr("Select path to memory card image"), QString(), tr(MEMORY_CARD_IMAGE_FILTER));
|
|
|
|
if (path.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_port_ui[index].memory_card_path->setText(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardSettingsWidget::onOpenMemCardsDirectoryClicked()
|
|
|
|
{
|
|
|
|
QtUtils::OpenURL(this,
|
|
|
|
QUrl::fromLocalFile(m_host_interface->getUserDirectoryRelativePath(QStringLiteral("memcards"))));
|
|
|
|
}
|