From 36e520aadb614a59890e2f3855bc213e9be70415 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 18 Mar 2021 14:47:47 +0200 Subject: [PATCH] kemu: ask if user really wants to quit if machines are running Signed-off-by: Ivailo Monev --- kemu/kemumainwindow.cpp | 16 ++++++++++++++++ kemu/kemumainwindow.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/kemu/kemumainwindow.cpp b/kemu/kemumainwindow.cpp index d1b312b1..1d3acd2b 100644 --- a/kemu/kemumainwindow.cpp +++ b/kemu/kemumainwindow.cpp @@ -198,6 +198,22 @@ void KEmuMainWindow::quit() qApp->quit(); } +void KEmuMainWindow::closeEvent(QCloseEvent *event) +{ + const int running = m_machines.size(); + if (running != 0) { + const QMessageBox::StandardButton answer = QMessageBox::question(this, + i18n("Stop machines and quit?"), + i18n("There are still %1 machines running, do you really want to quit?", running), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (answer != QMessageBox::Yes) { + event->ignore(); + return; + } + } + event->accept(); +} + void KEmuMainWindow::updateStatus() { if (m_machines.size() == 0) { diff --git a/kemu/kemumainwindow.h b/kemu/kemumainwindow.h index 8c060a16..d3153f8b 100644 --- a/kemu/kemumainwindow.h +++ b/kemu/kemumainwindow.h @@ -23,6 +23,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class Ui_KEmuWindow; @@ -39,6 +40,9 @@ public slots: void createHardDisk(); void quit(); +protected: + virtual void closeEvent(QCloseEvent *event); + private slots: void machineLoad(const QString machine); void machineSave(const QString ignored);