DolphinQt: Show raw memory card path and AGP cartridge path in config window.

This commit is contained in:
Admiral H. Curtiss 2022-01-19 01:32:32 +01:00
parent 43d4923e78
commit d11839fd64
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
2 changed files with 104 additions and 16 deletions

View File

@ -10,6 +10,7 @@
#include <QFormLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QInputDialog>
#include <QLabel>
#include <QLineEdit>
@ -100,6 +101,21 @@ void GameCubePane::CreateWidgets()
m_slot_buttons[slot]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
for (ExpansionInterface::Slot slot : ExpansionInterface::MEMCARD_SLOTS)
{
m_memcard_path_layouts[slot] = new QHBoxLayout();
m_memcard_path_labels[slot] = new QLabel(tr("Memory Card Path:"));
m_memcard_paths[slot] = new QLineEdit();
m_memcard_path_layouts[slot]->addWidget(m_memcard_path_labels[slot]);
m_memcard_path_layouts[slot]->addWidget(m_memcard_paths[slot]);
m_agp_path_layouts[slot] = new QHBoxLayout();
m_agp_path_labels[slot] = new QLabel(tr("GBA Cartridge Path:"));
m_agp_paths[slot] = new QLineEdit();
m_agp_path_layouts[slot]->addWidget(m_agp_path_labels[slot]);
m_agp_path_layouts[slot]->addWidget(m_agp_paths[slot]);
}
// Add slot devices
for (const auto device : {EXIDeviceType::None, EXIDeviceType::Dummy, EXIDeviceType::MemoryCard,
EXIDeviceType::MemoryCardFolder, EXIDeviceType::Gecko,
@ -127,15 +143,34 @@ void GameCubePane::CreateWidgets()
static_cast<int>(device));
}
device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::A], 0, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::A], 0, 2);
device_layout->addWidget(new QLabel(tr("Slot B:")), 1, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::B], 1, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::B], 1, 2);
device_layout->addWidget(new QLabel(tr("SP1:")), 2, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::SP1], 2, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::SP1], 2, 2);
{
int row = 0;
device_layout->addWidget(new QLabel(tr("Slot A:")), row, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::A], row, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::A], row, 2);
++row;
device_layout->addLayout(m_memcard_path_layouts[ExpansionInterface::Slot::A], row, 0, 1, 3);
++row;
device_layout->addLayout(m_agp_path_layouts[ExpansionInterface::Slot::A], row, 0, 1, 3);
++row;
device_layout->addWidget(new QLabel(tr("Slot B:")), row, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::B], row, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::B], row, 2);
++row;
device_layout->addLayout(m_memcard_path_layouts[ExpansionInterface::Slot::B], row, 0, 1, 3);
++row;
device_layout->addLayout(m_agp_path_layouts[ExpansionInterface::Slot::B], row, 0, 1, 3);
++row;
device_layout->addWidget(new QLabel(tr("SP1:")), row, 0);
device_layout->addWidget(m_slot_combos[ExpansionInterface::Slot::SP1], row, 1);
device_layout->addWidget(m_slot_buttons[ExpansionInterface::Slot::SP1], row, 2);
}
#ifdef HAS_LIBMGBA
// GBA Settings
@ -205,6 +240,17 @@ void GameCubePane::ConnectWidgets()
connect(m_slot_buttons[slot], &QPushButton::clicked, [this, slot] { OnConfigPressed(slot); });
}
for (ExpansionInterface::Slot slot : ExpansionInterface::MEMCARD_SLOTS)
{
connect(m_memcard_paths[slot], &QLineEdit::editingFinished, [this, slot] {
// revert path change on failure
if (!SetMemcard(slot, m_memcard_paths[slot]->text()))
LoadSettings();
});
connect(m_agp_paths[slot], &QLineEdit::editingFinished,
[this, slot] { SetAGPRom(slot, m_agp_paths[slot]->text()); });
}
#ifdef HAS_LIBMGBA
// GBA Settings
connect(m_gba_threads, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings);
@ -257,6 +303,10 @@ void GameCubePane::UpdateButton(ExpansionInterface::Slot slot)
has_config = (device == ExpansionInterface::EXIDeviceType::MemoryCard ||
device == ExpansionInterface::EXIDeviceType::AGP ||
device == ExpansionInterface::EXIDeviceType::Microphone);
m_memcard_path_labels[slot]->setHidden(device != ExpansionInterface::EXIDeviceType::MemoryCard);
m_memcard_paths[slot]->setHidden(device != ExpansionInterface::EXIDeviceType::MemoryCard);
m_agp_path_labels[slot]->setHidden(device != ExpansionInterface::EXIDeviceType::AGP);
m_agp_paths[slot]->setHidden(device != ExpansionInterface::EXIDeviceType::AGP);
break;
case ExpansionInterface::Slot::SP1:
has_config = (device == ExpansionInterface::EXIDeviceType::Ethernet ||
@ -315,8 +365,17 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
tr("GameCube Memory Cards (*.raw *.gcp)"), 0, QFileDialog::DontConfirmOverwrite);
if (!filename.isEmpty())
SetMemcard(slot, filename);
}
bool GameCubePane::SetMemcard(ExpansionInterface::Slot slot, const QString& filename)
{
if (filename.isEmpty())
return;
{
ModalMessageBox::critical(this, tr("Error"), tr("Cannot set memory card to an empty path."));
return false;
}
const std::string raw_path =
WithUnifiedPathSeparators(QFileInfo(filename).absoluteFilePath().toStdString());
@ -338,7 +397,7 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
.arg(QString::fromStdString(PathToFileName(us_path)))
.arg(QString::fromStdString(PathToFileName(eu_path)))
.arg(QString::fromStdString(PathToFileName(jp_path))));
return;
return false;
}
// Memcard validity checks
@ -355,7 +414,7 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
tr("The file\n%1\nis either corrupted or not a GameCube memory card file.\n%2")
.arg(QString::fromStdString(path))
.arg(GCMemcardManager::GetErrorMessagesForErrorCode(error_code)));
return;
return false;
}
}
}
@ -375,7 +434,7 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
this, tr("Error"),
tr("The same file can't be used in multiple slots; it is already used by %1.")
.arg(QString::fromStdString(fmt::to_string(other_slot))));
return;
return false;
}
}
@ -394,6 +453,9 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
ExpansionInterface::ChangeDevice(slot, ExpansionInterface::EXIDeviceType::MemoryCard);
}
}
LoadSettings();
return true;
}
void GameCubePane::BrowseAGPRom(ExpansionInterface::Slot slot)
@ -404,10 +466,13 @@ void GameCubePane::BrowseAGPRom(ExpansionInterface::Slot slot)
this, tr("Choose a file to open"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
tr("Game Boy Advance Carts (*.gba)"), 0, QFileDialog::DontConfirmOverwrite);
if (filename.isEmpty())
return;
if (!filename.isEmpty())
SetAGPRom(slot, filename);
}
QString path_abs = QFileInfo(filename).absoluteFilePath();
void GameCubePane::SetAGPRom(ExpansionInterface::Slot slot, const QString& filename)
{
QString path_abs = filename.isEmpty() ? QString() : QFileInfo(filename).absoluteFilePath();
QString path_old =
QFileInfo(QString::fromStdString(Config::Get(Config::GetInfoForAGPCartPath(slot))))
@ -423,6 +488,8 @@ void GameCubePane::BrowseAGPRom(ExpansionInterface::Slot slot)
// we might as well do it for the AGP too.
ExpansionInterface::ChangeDevice(slot, ExpansionInterface::EXIDeviceType::AGP);
}
LoadSettings();
}
void GameCubePane::BrowseGBABios()
@ -499,6 +566,14 @@ void GameCubePane::LoadSettings()
UpdateButton(slot);
}
for (ExpansionInterface::Slot slot : ExpansionInterface::MEMCARD_SLOTS)
{
SignalBlocking(m_memcard_paths[slot])
->setText(QString::fromStdString(Config::GetMemcardPath(slot, std::nullopt)));
SignalBlocking(m_agp_paths[slot])
->setText(QString::fromStdString(Config::Get(Config::GetInfoForAGPCartPath(slot))));
}
#ifdef HAS_LIBMGBA
// GBA Settings
SignalBlocking(m_gba_threads)->setChecked(Config::Get(Config::MAIN_GBA_THREADS));

View File

@ -14,8 +14,11 @@
class QCheckBox;
class QComboBox;
class QHBoxLayout;
class QLabel;
class QLineEdit;
class QPushButton;
class QString;
class GameCubePane : public QWidget
{
@ -38,7 +41,9 @@ private:
void OnConfigPressed(ExpansionInterface::Slot slot);
void BrowseMemcard(ExpansionInterface::Slot slot);
bool SetMemcard(ExpansionInterface::Slot slot, const QString& filename);
void BrowseAGPRom(ExpansionInterface::Slot slot);
void SetAGPRom(ExpansionInterface::Slot slot, const QString& filename);
void BrowseGBABios();
void BrowseGBARom(size_t index);
void SaveRomPathChanged();
@ -50,6 +55,14 @@ private:
Common::EnumMap<QPushButton*, ExpansionInterface::MAX_SLOT> m_slot_buttons;
Common::EnumMap<QComboBox*, ExpansionInterface::MAX_SLOT> m_slot_combos;
Common::EnumMap<QHBoxLayout*, ExpansionInterface::MAX_MEMCARD_SLOT> m_memcard_path_layouts;
Common::EnumMap<QLabel*, ExpansionInterface::MAX_MEMCARD_SLOT> m_memcard_path_labels;
Common::EnumMap<QLineEdit*, ExpansionInterface::MAX_MEMCARD_SLOT> m_memcard_paths;
Common::EnumMap<QHBoxLayout*, ExpansionInterface::MAX_MEMCARD_SLOT> m_agp_path_layouts;
Common::EnumMap<QLabel*, ExpansionInterface::MAX_MEMCARD_SLOT> m_agp_path_labels;
Common::EnumMap<QLineEdit*, ExpansionInterface::MAX_MEMCARD_SLOT> m_agp_paths;
QCheckBox* m_gba_threads;
QCheckBox* m_gba_save_rom_path;
QPushButton* m_gba_browse_bios;