From 96fb81733d4c2a9b66f2e3065bf59227781eb3f2 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 27 Jul 2021 18:23:11 +1000 Subject: [PATCH] Qt: Add option to switch/change discs from physical device --- src/duckstation-qt/mainwindow.cpp | 38 +++++++++++++++++++++++++------ src/duckstation-qt/mainwindow.h | 2 ++ src/duckstation-qt/mainwindow.ui | 6 +++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 409ae4350..28002da93 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -504,22 +504,24 @@ void MainWindow::onStartFileActionTriggered() m_host_interface->bootSystem(std::make_shared(filename.toStdString())); } -void MainWindow::onStartDiscActionTriggered() +std::string MainWindow::getDeviceDiscPath(const QString& title) { + std::string ret; + const auto devices = CDImage::GetDeviceList(); if (devices.empty()) { - QMessageBox::critical(this, tr("Start Disc"), + QMessageBox::critical(this, title, tr("Could not find any CD-ROM devices. Please ensure you have a CD-ROM drive connected and " "sufficient permissions to access it.")); - return; + return ret; } // if there's only one, select it automatically if (devices.size() == 1) { - m_host_interface->bootSystem(std::make_shared(std::move(devices.front().first))); - return; + ret = std::move(devices.front().first); + return ret; } QStringList input_options; @@ -527,19 +529,30 @@ void MainWindow::onStartDiscActionTriggered() input_options.append(tr("%1 (%2)").arg(QString::fromStdString(name)).arg(QString::fromStdString(path))); QInputDialog input_dialog(this); + input_dialog.setWindowTitle(title); input_dialog.setLabelText(tr("Select disc drive:")); input_dialog.setInputMode(QInputDialog::TextInput); input_dialog.setOptions(QInputDialog::UseListViewForComboBoxItems); input_dialog.setComboBoxEditable(false); input_dialog.setComboBoxItems(std::move(input_options)); if (input_dialog.exec() == 0) - return; + return ret; const int selected_index = input_dialog.comboBoxItems().indexOf(input_dialog.textValue()); if (selected_index < 0 || static_cast(selected_index) >= devices.size()) + return ret; + + ret = std::move(devices[selected_index].first); + return ret; +} + +void MainWindow::onStartDiscActionTriggered() +{ + std::string path(getDeviceDiscPath(tr("Start Disc"))); + if (path.empty()) return; - m_host_interface->bootSystem(std::make_shared(std::move(devices[selected_index].first))); + m_host_interface->bootSystem(std::make_shared(std::move(path))); } void MainWindow::onStartBIOSActionTriggered() @@ -563,6 +576,15 @@ void MainWindow::onChangeDiscFromGameListActionTriggered() switchToGameListView(); } +void MainWindow::onChangeDiscFromDeviceActionTriggered() +{ + std::string path(getDeviceDiscPath(tr("Change Disc"))); + if (path.empty()) + return; + + m_host_interface->changeDisc(QString::fromStdString(path)); +} + void MainWindow::onChangeDiscMenuAboutToShow() { m_host_interface->populateChangeDiscSubImageMenu(m_ui.menuChangeDisc, m_ui.actionGroupChangeDiscSubImages); @@ -1080,6 +1102,8 @@ void MainWindow::connectSignals() &QtHostInterface::resumeSystemFromMostRecentState); connect(m_ui.actionChangeDisc, &QAction::triggered, [this] { m_ui.menuChangeDisc->exec(QCursor::pos()); }); connect(m_ui.actionChangeDiscFromFile, &QAction::triggered, this, &MainWindow::onChangeDiscFromFileActionTriggered); + connect(m_ui.actionChangeDiscFromDevice, &QAction::triggered, this, + &MainWindow::onChangeDiscFromDeviceActionTriggered); connect(m_ui.actionChangeDiscFromGameList, &QAction::triggered, this, &MainWindow::onChangeDiscFromGameListActionTriggered); connect(m_ui.menuChangeDisc, &QMenu::aboutToShow, this, &MainWindow::onChangeDiscMenuAboutToShow); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 79d507e8a..0ffcdfe20 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -82,6 +82,7 @@ private Q_SLOTS: void onStartBIOSActionTriggered(); void onChangeDiscFromFileActionTriggered(); void onChangeDiscFromGameListActionTriggered(); + void onChangeDiscFromDeviceActionTriggered(); void onChangeDiscMenuAboutToShow(); void onChangeDiscMenuAboutToHide(); void onLoadStateMenuAboutToShow(); @@ -147,6 +148,7 @@ private: void updateDebugMenuGPURenderer(); void updateDebugMenuCropMode(); void ensureGameListLoaded(); + std::string getDeviceDiscPath(const QString& title); Ui::MainWindow m_ui; diff --git a/src/duckstation-qt/mainwindow.ui b/src/duckstation-qt/mainwindow.ui index e1cc0db1e..c63e7fd31 100644 --- a/src/duckstation-qt/mainwindow.ui +++ b/src/duckstation-qt/mainwindow.ui @@ -49,6 +49,7 @@ :/icons/media-optical.png:/icons/media-optical.png + @@ -602,6 +603,11 @@ From File... + + + From Device... + + From Game List...