From 50109d70b60aa7edbd199644c4af2da835b10cdc Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 22 Jul 2021 00:15:49 -0700 Subject: [PATCH] GBA: Add "Scan e-Reader Card(s)" context menu item --- Source/Core/DolphinQt/GBAWidget.cpp | 36 +++++++++++++++++++++-------- Source/Core/DolphinQt/GBAWidget.h | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Source/Core/DolphinQt/GBAWidget.cpp b/Source/Core/DolphinQt/GBAWidget.cpp index 291720e99e..7d625c687d 100644 --- a/Source/Core/DolphinQt/GBAWidget.cpp +++ b/Source/Core/DolphinQt/GBAWidget.cpp @@ -50,6 +50,16 @@ static void RestartCore(const std::weak_ptr& core, std::string_vi false); } +static void QueueEReaderCard(const std::weak_ptr& core, std::string_view card_path) +{ + Core::RunOnCPUThread( + [core, card_path = std::string(card_path)] { + if (auto core_ptr = core.lock()) + core_ptr->EReaderQueueCard(card_path); + }, + false); +} + GBAWidget::GBAWidget(std::weak_ptr core, int device_number, std::string_view game_title, int width, int height, QWidget* parent, Qt::WindowFlags flags) @@ -166,6 +176,16 @@ void GBAWidget::UnloadROM() RestartCore(m_core); } +void GBAWidget::PromptForEReaderCards() +{ + const QStringList card_paths = QFileDialog::getOpenFileNames( + this, tr("Select e-Reader Cards"), QString(), tr("e-Reader Cards (*.raw);;All Files (*)"), + nullptr, QFileDialog::Options()); + + for (const QString& card_path : card_paths) + QueueEReaderCard(m_core, QDir::toNativeSeparators(card_path).toStdString()); +} + void GBAWidget::ResetCore() { if (!CanResetCore()) @@ -281,6 +301,10 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event) unload_action->setEnabled(CanControlCore() && !m_game_title.empty()); connect(unload_action, &QAction::triggered, this, &GBAWidget::UnloadROM); + auto* card_action = new QAction(tr("&Scan e-Reader Card(s)"), menu); + card_action->setEnabled(CanControlCore() && !m_game_title.empty()); + connect(card_action, &QAction::triggered, this, &GBAWidget::PromptForEReaderCards); + auto* reset_action = new QAction(tr("&Reset"), menu); reset_action->setEnabled(CanResetCore()); connect(reset_action, &QAction::triggered, this, &GBAWidget::ResetCore); @@ -322,6 +346,7 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event) menu->addSeparator(); menu->addAction(load_action); menu->addAction(unload_action); + menu->addAction(card_action); menu->addAction(reset_action); menu->addSeparator(); menu->addMenu(state_menu); @@ -395,18 +420,9 @@ void GBAWidget::dropEvent(QDropEvent* event) } if (file_info.suffix() == QStringLiteral("raw")) - { - Core::RunOnCPUThread( - [core = m_core, card_path = path.toStdString()] { - if (auto core_ptr = core.lock()) - core_ptr->EReaderQueueCard(card_path); - }, - false); - } + QueueEReaderCard(m_core, path.toStdString()); else - { RestartCore(m_core, path.toStdString()); - } } } diff --git a/Source/Core/DolphinQt/GBAWidget.h b/Source/Core/DolphinQt/GBAWidget.h index 24b2147cd1..1ca585f299 100644 --- a/Source/Core/DolphinQt/GBAWidget.h +++ b/Source/Core/DolphinQt/GBAWidget.h @@ -44,6 +44,7 @@ public: void LoadROM(); void UnloadROM(); + void PromptForEReaderCards(); void ResetCore(); void DoState(bool export_state); void Resize(int scale);