From 5dae162780e2a1d9ae3d4ea7091caa0e9680c92f Mon Sep 17 00:00:00 2001 From: Maksim Derbasov Date: Sun, 13 Jun 2021 11:51:42 +0300 Subject: [PATCH] [triage tool] Keep UI alive while wget and tar execution (#3296) --- tools/triage/mainwindow.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index 17c78b730..9edfd2010 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -152,10 +153,29 @@ void MainWindow::filter(QString filter) bool MainWindow::runProcess(const QString &programName, const QStringList &arguments) { + QProgressDialog dialog("Running external process: " + programName, "Kill", 0 /*min*/, 1 /*max*/, this); + dialog.setWindowModality(Qt::WindowModal); + dialog.setMinimumDuration(0 /*msec*/); + dialog.setValue(0); + QProcess process; process.setWorkingDirectory(WORK_FOLDER); - process.start(programName, arguments); - bool success = process.waitForFinished(-1); + process.start(programName, arguments); // async action + + bool success = false; + bool state = (QProcess::Running == process.state() || QProcess::Starting == process.state()); + while (!success && state) { + success = process.waitForFinished(50 /*msec*/); + // Not the best way to keep UI unfreeze, keep work async in other thread much more a Qt style + QCoreApplication::processEvents(); + if (dialog.wasCanceled()) { + process.kill(); + success = false; + break; + } + state = (QProcess::Running == process.state() || QProcess::Starting == process.state()); + } + dialog.setValue(1); if (!success) { QString errorstr(programName); errorstr.append(": ");