@@ -696,47 +696,46 @@ void MainWindow::onStartFileActionTriggered()
696696 startFileOrChangeDisc (filename);
697697}
698698
699- std::string MainWindow::getDeviceDiscPath (const QString& title)
699+ void MainWindow::openSelectDiscDialog (const QString& title, std::function< void (std::string)> callback )
700700{
701- std::string ret;
702-
703- auto devices = CDImage::GetDeviceList ();
701+ std::vector<std::pair<std::string, std::string>> devices = CDImage::GetDeviceList ();
704702 if (devices.empty ())
705703 {
706- QtUtils::MessageBoxCritical (
707- this , title,
704+ QtUtils::AsyncMessageBox (
705+ this , QMessageBox::Critical, title,
708706 tr (" Could not find any CD-ROM devices. Please ensure you have a CD-ROM drive connected and "
709707 " sufficient permissions to access it." ));
710- return ret ;
708+ return ;
711709 }
712710
713711 // if there's only one, select it automatically
714712 if (devices.size () == 1 )
715713 {
716- ret = std::move (devices.front ().first );
717- return ret ;
714+ callback ( std::move (devices.front ().first ) );
715+ return ;
718716 }
719717
720718 QStringList input_options;
721719 for (const auto & [path, name] : devices)
722720 input_options.append (tr (" %1 (%2)" ).arg (QString::fromStdString (name)).arg (QString::fromStdString (path)));
723721
724- QInputDialog input_dialog (this );
725- input_dialog.setWindowTitle (title);
726- input_dialog.setLabelText (tr (" Select disc drive:" ));
727- input_dialog.setInputMode (QInputDialog::TextInput);
728- input_dialog.setOptions (QInputDialog::UseListViewForComboBoxItems);
729- input_dialog.setComboBoxEditable (false );
730- input_dialog.setComboBoxItems (std::move (input_options));
731- if (input_dialog.exec () == QDialog::Rejected)
732- return ret;
733-
734- const qsizetype selected_index = input_dialog.comboBoxItems ().indexOf (input_dialog.textValue ());
735- if (selected_index < 0 || static_cast <u32 >(selected_index) >= devices.size ())
736- return ret;
737-
738- ret = std::move (devices[selected_index].first );
739- return ret;
722+ QInputDialog* input_dialog = new QInputDialog (this );
723+ input_dialog->setWindowTitle (title);
724+ input_dialog->setLabelText (tr (" Select disc drive:" ));
725+ input_dialog->setInputMode (QInputDialog::TextInput);
726+ input_dialog->setOptions (QInputDialog::UseListViewForComboBoxItems);
727+ input_dialog->setComboBoxEditable (false );
728+ input_dialog->setComboBoxItems (std::move (input_options));
729+ input_dialog->connect (input_dialog, &QInputDialog::accepted, this ,
730+ [input_dialog, callback = std::move (callback), devices = std::move (devices)]() mutable {
731+ const qsizetype selected_index =
732+ input_dialog->comboBoxItems ().indexOf (input_dialog->textValue ());
733+ if (selected_index < 0 || static_cast <u32 >(selected_index) >= devices.size ())
734+ return ;
735+
736+ callback (std::move (devices[selected_index].first ));
737+ });
738+ input_dialog->open ();
740739}
741740
742741void MainWindow::quit ()
@@ -1261,11 +1260,9 @@ void MainWindow::promptForDiscChange(const QString& path)
12611260
12621261void MainWindow::onStartDiscActionTriggered ()
12631262{
1264- std::string path (getDeviceDiscPath (tr (" Start Disc" )));
1265- if (path.empty ())
1266- return ;
1267-
1268- g_emu_thread->bootSystem (getSystemBootParameters (std::move (path)));
1263+ openSelectDiscDialog (tr (" Start Disc" ), [](std::string path) mutable {
1264+ g_emu_thread->bootSystem (g_main_window->getSystemBootParameters (std::move (path)));
1265+ });
12691266}
12701267
12711268void MainWindow::onStartBIOSActionTriggered ()
@@ -1291,11 +1288,8 @@ void MainWindow::onChangeDiscFromGameListActionTriggered()
12911288
12921289void MainWindow::onChangeDiscFromDeviceActionTriggered ()
12931290{
1294- std::string path (getDeviceDiscPath (tr (" Change Disc" )));
1295- if (path.empty ())
1296- return ;
1297-
1298- g_emu_thread->changeDisc (QString::fromStdString (path), false , true );
1291+ openSelectDiscDialog (tr (" Change Disc" ),
1292+ [](std::string path) { g_emu_thread->changeDisc (QString::fromStdString (path), false , true ); });
12991293}
13001294
13011295void MainWindow::onChangeDiscMenuAboutToShow ()
0 commit comments