Qt: Add option to switch/change discs from physical device

This commit is contained in:
Connor McLaughlin 2021-07-27 18:23:11 +10:00
parent 0af334bba5
commit 96fb81733d
3 changed files with 39 additions and 7 deletions

View File

@ -504,22 +504,24 @@ void MainWindow::onStartFileActionTriggered()
m_host_interface->bootSystem(std::make_shared<SystemBootParameters>(filename.toStdString())); m_host_interface->bootSystem(std::make_shared<SystemBootParameters>(filename.toStdString()));
} }
void MainWindow::onStartDiscActionTriggered() std::string MainWindow::getDeviceDiscPath(const QString& title)
{ {
std::string ret;
const auto devices = CDImage::GetDeviceList(); const auto devices = CDImage::GetDeviceList();
if (devices.empty()) 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 " tr("Could not find any CD-ROM devices. Please ensure you have a CD-ROM drive connected and "
"sufficient permissions to access it.")); "sufficient permissions to access it."));
return; return ret;
} }
// if there's only one, select it automatically // if there's only one, select it automatically
if (devices.size() == 1) if (devices.size() == 1)
{ {
m_host_interface->bootSystem(std::make_shared<SystemBootParameters>(std::move(devices.front().first))); ret = std::move(devices.front().first);
return; return ret;
} }
QStringList input_options; QStringList input_options;
@ -527,19 +529,30 @@ void MainWindow::onStartDiscActionTriggered()
input_options.append(tr("%1 (%2)").arg(QString::fromStdString(name)).arg(QString::fromStdString(path))); input_options.append(tr("%1 (%2)").arg(QString::fromStdString(name)).arg(QString::fromStdString(path)));
QInputDialog input_dialog(this); QInputDialog input_dialog(this);
input_dialog.setWindowTitle(title);
input_dialog.setLabelText(tr("Select disc drive:")); input_dialog.setLabelText(tr("Select disc drive:"));
input_dialog.setInputMode(QInputDialog::TextInput); input_dialog.setInputMode(QInputDialog::TextInput);
input_dialog.setOptions(QInputDialog::UseListViewForComboBoxItems); input_dialog.setOptions(QInputDialog::UseListViewForComboBoxItems);
input_dialog.setComboBoxEditable(false); input_dialog.setComboBoxEditable(false);
input_dialog.setComboBoxItems(std::move(input_options)); input_dialog.setComboBoxItems(std::move(input_options));
if (input_dialog.exec() == 0) if (input_dialog.exec() == 0)
return; return ret;
const int selected_index = input_dialog.comboBoxItems().indexOf(input_dialog.textValue()); const int selected_index = input_dialog.comboBoxItems().indexOf(input_dialog.textValue());
if (selected_index < 0 || static_cast<u32>(selected_index) >= devices.size()) if (selected_index < 0 || static_cast<u32>(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; return;
m_host_interface->bootSystem(std::make_shared<SystemBootParameters>(std::move(devices[selected_index].first))); m_host_interface->bootSystem(std::make_shared<SystemBootParameters>(std::move(path)));
} }
void MainWindow::onStartBIOSActionTriggered() void MainWindow::onStartBIOSActionTriggered()
@ -563,6 +576,15 @@ void MainWindow::onChangeDiscFromGameListActionTriggered()
switchToGameListView(); 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() void MainWindow::onChangeDiscMenuAboutToShow()
{ {
m_host_interface->populateChangeDiscSubImageMenu(m_ui.menuChangeDisc, m_ui.actionGroupChangeDiscSubImages); m_host_interface->populateChangeDiscSubImageMenu(m_ui.menuChangeDisc, m_ui.actionGroupChangeDiscSubImages);
@ -1080,6 +1102,8 @@ void MainWindow::connectSignals()
&QtHostInterface::resumeSystemFromMostRecentState); &QtHostInterface::resumeSystemFromMostRecentState);
connect(m_ui.actionChangeDisc, &QAction::triggered, [this] { m_ui.menuChangeDisc->exec(QCursor::pos()); }); 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.actionChangeDiscFromFile, &QAction::triggered, this, &MainWindow::onChangeDiscFromFileActionTriggered);
connect(m_ui.actionChangeDiscFromDevice, &QAction::triggered, this,
&MainWindow::onChangeDiscFromDeviceActionTriggered);
connect(m_ui.actionChangeDiscFromGameList, &QAction::triggered, this, connect(m_ui.actionChangeDiscFromGameList, &QAction::triggered, this,
&MainWindow::onChangeDiscFromGameListActionTriggered); &MainWindow::onChangeDiscFromGameListActionTriggered);
connect(m_ui.menuChangeDisc, &QMenu::aboutToShow, this, &MainWindow::onChangeDiscMenuAboutToShow); connect(m_ui.menuChangeDisc, &QMenu::aboutToShow, this, &MainWindow::onChangeDiscMenuAboutToShow);

View File

@ -82,6 +82,7 @@ private Q_SLOTS:
void onStartBIOSActionTriggered(); void onStartBIOSActionTriggered();
void onChangeDiscFromFileActionTriggered(); void onChangeDiscFromFileActionTriggered();
void onChangeDiscFromGameListActionTriggered(); void onChangeDiscFromGameListActionTriggered();
void onChangeDiscFromDeviceActionTriggered();
void onChangeDiscMenuAboutToShow(); void onChangeDiscMenuAboutToShow();
void onChangeDiscMenuAboutToHide(); void onChangeDiscMenuAboutToHide();
void onLoadStateMenuAboutToShow(); void onLoadStateMenuAboutToShow();
@ -147,6 +148,7 @@ private:
void updateDebugMenuGPURenderer(); void updateDebugMenuGPURenderer();
void updateDebugMenuCropMode(); void updateDebugMenuCropMode();
void ensureGameListLoaded(); void ensureGameListLoaded();
std::string getDeviceDiscPath(const QString& title);
Ui::MainWindow m_ui; Ui::MainWindow m_ui;

View File

@ -49,6 +49,7 @@
<normaloff>:/icons/media-optical.png</normaloff>:/icons/media-optical.png</iconset> <normaloff>:/icons/media-optical.png</normaloff>:/icons/media-optical.png</iconset>
</property> </property>
<addaction name="actionChangeDiscFromFile"/> <addaction name="actionChangeDiscFromFile"/>
<addaction name="actionChangeDiscFromDevice"/>
<addaction name="actionChangeDiscFromGameList"/> <addaction name="actionChangeDiscFromGameList"/>
<addaction name="actionRemoveDisc"/> <addaction name="actionRemoveDisc"/>
<actiongroup name="actionGroupChangeDiscSubImages" /> <actiongroup name="actionGroupChangeDiscSubImages" />
@ -602,6 +603,11 @@
<string>From File...</string> <string>From File...</string>
</property> </property>
</action> </action>
<action name="actionChangeDiscFromDevice">
<property name="text">
<string>From Device...</string>
</property>
</action>
<action name="actionChangeDiscFromGameList"> <action name="actionChangeDiscFromGameList">
<property name="text"> <property name="text">
<string>From Game List...</string> <string>From Game List...</string>