diff --git a/src/qt/qt_vmmanager_main.cpp b/src/qt/qt_vmmanager_main.cpp index cbfdc3c0a..3973bebfd 100644 --- a/src/qt/qt_vmmanager_main.cpp +++ b/src/qt/qt_vmmanager_main.cpp @@ -459,6 +459,12 @@ VMManagerMain::onPreferencesUpdated() } } +int +VMManagerMain::getActiveMachineCount() +{ + return vm_model->getActiveMachineCount(); +} + #if EMU_BUILD_NUM != 0 void VMManagerMain::backgroundUpdateCheckStart() const diff --git a/src/qt/qt_vmmanager_main.hpp b/src/qt/qt_vmmanager_main.hpp index 075af76f1..d4591d418 100644 --- a/src/qt/qt_vmmanager_main.hpp +++ b/src/qt/qt_vmmanager_main.hpp @@ -77,6 +77,7 @@ public slots: #endif void modelDataChange(); void onPreferencesUpdated(); + int getActiveMachineCount(); private: Ui::VMManagerMain *ui; diff --git a/src/qt/qt_vmmanager_mainwindow.cpp b/src/qt/qt_vmmanager_mainwindow.cpp index 0ab4fcc2e..76b8ccb15 100644 --- a/src/qt/qt_vmmanager_mainwindow.cpp +++ b/src/qt/qt_vmmanager_mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include VMManagerMainWindow:: @@ -159,6 +160,15 @@ VMManagerMainWindow::saveSettings() const void VMManagerMainWindow::closeEvent(QCloseEvent *event) { + int running = vmm->getActiveMachineCount(); + if (running > 0) { + QMessageBox warningbox(QMessageBox::Icon::Warning, tr("%1 VM Manager").arg(EMU_NAME), tr("%1 machine(s) are currently active. Are you sure you want to exit the VM manager anyway?").arg(running), QMessageBox::Yes | QMessageBox::No, this); + warningbox.exec(); + if (warningbox.result() == QMessageBox::No) { + event->ignore(); + return; + } + } saveSettings(); QMainWindow::closeEvent(event); } diff --git a/src/qt/qt_vmmanager_model.cpp b/src/qt/qt_vmmanager_model.cpp index 848970f80..6c7cf09a0 100644 --- a/src/qt/qt_vmmanager_model.cpp +++ b/src/qt/qt_vmmanager_model.cpp @@ -160,4 +160,15 @@ VMManagerModel::getProcessStats() } } return stats; +} + +int +VMManagerModel::getActiveMachineCount() +{ + int running = 0; + for (const auto& system: machines) { + if (system->getProcessStatus() != VMManagerSystem::ProcessStatus::Stopped) + running++; + } + return running; } \ No newline at end of file diff --git a/src/qt/qt_vmmanager_model.hpp b/src/qt/qt_vmmanager_model.hpp index bc13cc16f..43757c78d 100644 --- a/src/qt/qt_vmmanager_model.hpp +++ b/src/qt/qt_vmmanager_model.hpp @@ -57,6 +57,7 @@ public: void reload(QWidget* parent = nullptr); void updateDisplayName(const QModelIndex &index, const QString &newDisplayName); QHash getProcessStats(); + int getActiveMachineCount(); signals: void systemDataChanged();