Manager: Warn on close when machines are running

This commit is contained in:
Alexander Babikov
2025-07-29 05:39:43 +05:00
parent 1d421b4db0
commit 2657a5bade
5 changed files with 29 additions and 0 deletions

View File

@@ -459,6 +459,12 @@ VMManagerMain::onPreferencesUpdated()
} }
} }
int
VMManagerMain::getActiveMachineCount()
{
return vm_model->getActiveMachineCount();
}
#if EMU_BUILD_NUM != 0 #if EMU_BUILD_NUM != 0
void void
VMManagerMain::backgroundUpdateCheckStart() const VMManagerMain::backgroundUpdateCheckStart() const

View File

@@ -77,6 +77,7 @@ public slots:
#endif #endif
void modelDataChange(); void modelDataChange();
void onPreferencesUpdated(); void onPreferencesUpdated();
int getActiveMachineCount();
private: private:
Ui::VMManagerMain *ui; Ui::VMManagerMain *ui;

View File

@@ -27,6 +27,7 @@
#include <QLineEdit> #include <QLineEdit>
#include <QStringListModel> #include <QStringListModel>
#include <QCompleter> #include <QCompleter>
#include <QCloseEvent>
#include <QDesktopServices> #include <QDesktopServices>
VMManagerMainWindow:: VMManagerMainWindow::
@@ -159,6 +160,15 @@ VMManagerMainWindow::saveSettings() const
void void
VMManagerMainWindow::closeEvent(QCloseEvent *event) 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(); saveSettings();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }

View File

@@ -160,4 +160,15 @@ VMManagerModel::getProcessStats()
} }
} }
return stats; return stats;
}
int
VMManagerModel::getActiveMachineCount()
{
int running = 0;
for (const auto& system: machines) {
if (system->getProcessStatus() != VMManagerSystem::ProcessStatus::Stopped)
running++;
}
return running;
} }

View File

@@ -57,6 +57,7 @@ public:
void reload(QWidget* parent = nullptr); void reload(QWidget* parent = nullptr);
void updateDisplayName(const QModelIndex &index, const QString &newDisplayName); void updateDisplayName(const QModelIndex &index, const QString &newDisplayName);
QHash <QString, int> getProcessStats(); QHash <QString, int> getProcessStats();
int getActiveMachineCount();
signals: signals:
void systemDataChanged(); void systemDataChanged();