Skip to content

Commit 5dae162

Browse files
authored
[triage tool] Keep UI alive while wget and tar execution (#3296)
1 parent 071309d commit 5dae162

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tools/triage/mainwindow.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QDirIterator>
99
#include <QFileInfo>
1010
#include <QFileDialog>
11+
#include <QProgressDialog>
1112
#include <QMimeDatabase>
1213
#include <ctime>
1314
#include <cstdlib>
@@ -152,10 +153,29 @@ void MainWindow::filter(QString filter)
152153

153154
bool MainWindow::runProcess(const QString &programName, const QStringList &arguments)
154155
{
156+
QProgressDialog dialog("Running external process: " + programName, "Kill", 0 /*min*/, 1 /*max*/, this);
157+
dialog.setWindowModality(Qt::WindowModal);
158+
dialog.setMinimumDuration(0 /*msec*/);
159+
dialog.setValue(0);
160+
155161
QProcess process;
156162
process.setWorkingDirectory(WORK_FOLDER);
157-
process.start(programName, arguments);
158-
bool success = process.waitForFinished(-1);
163+
process.start(programName, arguments); // async action
164+
165+
bool success = false;
166+
bool state = (QProcess::Running == process.state() || QProcess::Starting == process.state());
167+
while (!success && state) {
168+
success = process.waitForFinished(50 /*msec*/);
169+
// Not the best way to keep UI unfreeze, keep work async in other thread much more a Qt style
170+
QCoreApplication::processEvents();
171+
if (dialog.wasCanceled()) {
172+
process.kill();
173+
success = false;
174+
break;
175+
}
176+
state = (QProcess::Running == process.state() || QProcess::Starting == process.state());
177+
}
178+
dialog.setValue(1);
159179
if (!success) {
160180
QString errorstr(programName);
161181
errorstr.append(": ");

0 commit comments

Comments
 (0)