From 70e175fb0deb01e4664213686491c49bff85faf6 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 8 Nov 2017 22:30:03 +0100 Subject: [PATCH] Give a warning before quitting if there are clients connected. --- httpd.h | 3 +++ mainwindow.cpp | 10 ++++++++++ mixer.h | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/httpd.h b/httpd.h index 6e37c52..630b0c3 100644 --- a/httpd.h +++ b/httpd.h @@ -28,6 +28,9 @@ public: void start(int port); void add_data(const char *buf, size_t size, bool keyframe); + int64_t get_num_connected_clients() const { + return metric_num_connected_clients.load(); + } private: static int answer_to_connection_thunk(void *cls, MHD_Connection *connection, diff --git a/mainwindow.cpp b/mainwindow.cpp index d46c87c..d3d2981 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1330,6 +1330,16 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) void MainWindow::closeEvent(QCloseEvent *event) { + if (global_mixer->get_num_connected_clients() > 0) { + QMessageBox::StandardButton reply = + QMessageBox::question(this, "Nageru", "There are clients connected. Do you really want to quit?", + QMessageBox::Yes | QMessageBox::No); + if (reply != QMessageBox::Yes) { + event->ignore(); + return; + } + } + analyzer->hide(); event->accept(); } diff --git a/mixer.h b/mixer.h index ff501b1..89676bd 100644 --- a/mixer.h +++ b/mixer.h @@ -399,6 +399,10 @@ public: display_timecode_on_stdout = enable; } + int64_t get_num_connected_clients() const { + return httpd.get_num_connected_clients(); + } + private: struct CaptureCard; -- 2.39.2