Merge pull request #9938 from Pokechu22/e-reader-context-menu-item
GBA: Add "Scan e-Reader Card(s)" context menu item
This commit is contained in:
commit
4f87821f21
|
@ -50,6 +50,16 @@ static void RestartCore(const std::weak_ptr<HW::GBA::Core>& core, std::string_vi
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void QueueEReaderCard(const std::weak_ptr<HW::GBA::Core>& 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<HW::GBA::Core> core, int device_number,
|
GBAWidget::GBAWidget(std::weak_ptr<HW::GBA::Core> core, int device_number,
|
||||||
std::string_view game_title, int width, int height, QWidget* parent,
|
std::string_view game_title, int width, int height, QWidget* parent,
|
||||||
Qt::WindowFlags flags)
|
Qt::WindowFlags flags)
|
||||||
|
@ -166,6 +176,16 @@ void GBAWidget::UnloadROM()
|
||||||
RestartCore(m_core);
|
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()
|
void GBAWidget::ResetCore()
|
||||||
{
|
{
|
||||||
if (!CanResetCore())
|
if (!CanResetCore())
|
||||||
|
@ -281,6 +301,10 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||||
unload_action->setEnabled(CanControlCore() && !m_game_title.empty());
|
unload_action->setEnabled(CanControlCore() && !m_game_title.empty());
|
||||||
connect(unload_action, &QAction::triggered, this, &GBAWidget::UnloadROM);
|
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);
|
auto* reset_action = new QAction(tr("&Reset"), menu);
|
||||||
reset_action->setEnabled(CanResetCore());
|
reset_action->setEnabled(CanResetCore());
|
||||||
connect(reset_action, &QAction::triggered, this, &GBAWidget::ResetCore);
|
connect(reset_action, &QAction::triggered, this, &GBAWidget::ResetCore);
|
||||||
|
@ -322,6 +346,7 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction(load_action);
|
menu->addAction(load_action);
|
||||||
menu->addAction(unload_action);
|
menu->addAction(unload_action);
|
||||||
|
menu->addAction(card_action);
|
||||||
menu->addAction(reset_action);
|
menu->addAction(reset_action);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addMenu(state_menu);
|
menu->addMenu(state_menu);
|
||||||
|
@ -395,18 +420,9 @@ void GBAWidget::dropEvent(QDropEvent* event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_info.suffix() == QStringLiteral("raw"))
|
if (file_info.suffix() == QStringLiteral("raw"))
|
||||||
{
|
QueueEReaderCard(m_core, path.toStdString());
|
||||||
Core::RunOnCPUThread(
|
|
||||||
[core = m_core, card_path = path.toStdString()] {
|
|
||||||
if (auto core_ptr = core.lock())
|
|
||||||
core_ptr->EReaderQueueCard(card_path);
|
|
||||||
},
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
RestartCore(m_core, path.toStdString());
|
RestartCore(m_core, path.toStdString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
void LoadROM();
|
void LoadROM();
|
||||||
void UnloadROM();
|
void UnloadROM();
|
||||||
|
void PromptForEReaderCards();
|
||||||
void ResetCore();
|
void ResetCore();
|
||||||
void DoState(bool export_state);
|
void DoState(bool export_state);
|
||||||
void Resize(int scale);
|
void Resize(int scale);
|
||||||
|
|
Loading…
Reference in New Issue