diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index b528bbf0a..cb6d3cdeb 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -609,26 +610,7 @@ void MainWindow::onGameListEntrySelected(const GameListEntry* entry) void MainWindow::onGameListEntryDoubleClicked(const GameListEntry* entry) { - // if we're not running, boot the system, otherwise swap discs - QString path = QString::fromStdString(entry->path); - if (!m_emulation_running) - { - if (!entry->code.empty() && m_host_interface->GetBoolSettingValue("Main", "SaveStateOnExit", true) && - !m_host_interface->IsCheevosChallengeModeActive()) - { - m_host_interface->resumeSystemFromState(path, true); - } - else - { - m_host_interface->bootSystem(std::make_shared(path.toStdString())); - } - } - else - { - m_host_interface->changeDisc(path); - m_host_interface->pauseSystem(false); - switchToEmulationView(); - } + startGameOrChangeDiscs(entry->path); } void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameListEntry* entry) @@ -952,6 +934,34 @@ void MainWindow::switchToEmulationView() m_display_widget->setFocus(); } +void MainWindow::startGameOrChangeDiscs(const std::string& path) +{ + // if we're not running, boot the system, otherwise swap discs + if (!m_emulation_running) + { + if (m_host_interface->GetBoolSettingValue("Main", "SaveStateOnExit", true) && + !m_host_interface->IsCheevosChallengeModeActive()) + { + const GameListEntry* entry = m_host_interface->getGameList()->GetEntryForPath(path.c_str()); + if ((entry && !entry->code.empty()) || !System::GetGameCodeForPath(path.c_str(), true).empty()) + { + m_host_interface->resumeSystemFromState(QString::fromStdString(path), true); + return; + } + } + else + { + m_host_interface->bootSystem(std::make_shared(path)); + } + } + else + { + m_host_interface->changeDisc(QString::fromStdString(path)); + m_host_interface->pauseSystem(false); + switchToEmulationView(); + } +} + void MainWindow::connectSignals() { updateEmulationActions(false, false, m_host_interface->IsCheevosChallengeModeActive()); @@ -1418,6 +1428,39 @@ void MainWindow::changeEvent(QEvent* event) QMainWindow::changeEvent(event); } +static std::string getFilenameFromMimeData(const QMimeData* md) +{ + std::string filename; + if (md->hasUrls()) + { + // only one url accepted + const QList urls(md->urls()); + if (urls.size() == 1) + filename = urls.front().toLocalFile().toStdString(); + } + + return filename; +} + +void MainWindow::dragEnterEvent(QDragEnterEvent* event) +{ + const std::string filename(getFilenameFromMimeData(event->mimeData())); + if (!System::IsLoadableFilename(filename.c_str())) + return; + + event->acceptProposedAction(); +} + +void MainWindow::dropEvent(QDropEvent* event) +{ + const std::string filename(getFilenameFromMimeData(event->mimeData())); + if (!System::IsLoadableFilename(filename.c_str())) + return; + + event->acceptProposedAction(); + startGameOrChangeDiscs(filename); +} + void MainWindow::startupUpdateCheck() { if (!m_host_interface->GetBoolSettingValue("AutoUpdater", "CheckAtStartup", true)) diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index b13f00577..a802f7533 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -111,6 +111,8 @@ private Q_SLOTS: protected: void closeEvent(QCloseEvent* event) override; void changeEvent(QEvent* event) override; + void dragEnterEvent(QDragEnterEvent* event) override; + void dropEvent(QDropEvent* event) override; private: void setupAdditionalUi(); @@ -120,6 +122,7 @@ private: bool isShowingGameList() const; void switchToGameListView(); void switchToEmulationView(); + void startGameOrChangeDiscs(const std::string& path); void saveStateToConfig(); void restoreStateFromConfig(); void saveDisplayWindowGeometryToConfig(); diff --git a/src/duckstation-qt/mainwindow.ui b/src/duckstation-qt/mainwindow.ui index 58bb531bd..cbc2d7340 100644 --- a/src/duckstation-qt/mainwindow.ui +++ b/src/duckstation-qt/mainwindow.ui @@ -17,6 +17,9 @@ :/icons/duck.png:/icons/duck.png + + true + 0