2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2015-09-17 15:24:32 +02:00
|
|
|
|
|
|
|
|
#include "waitforstopdialog.h"
|
|
|
|
|
|
2022-10-24 23:44:24 +02:00
|
|
|
#include "runcontrol.h"
|
|
|
|
|
|
2015-09-17 15:24:32 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
2022-05-04 11:50:41 +02:00
|
|
|
WaitForStopDialog::WaitForStopDialog(const QList<ProjectExplorer::RunControl *> &runControls)
|
|
|
|
|
: m_runControls(runControls)
|
2015-09-17 15:24:32 +02:00
|
|
|
{
|
|
|
|
|
setWindowTitle(tr("Waiting for Applications to Stop"));
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto layout = new QVBoxLayout();
|
2015-09-17 15:24:32 +02:00
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
|
|
m_progressLabel = new QLabel;
|
|
|
|
|
layout->addWidget(m_progressLabel);
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto cancelButton = new QPushButton(tr("Cancel"));
|
2015-09-17 15:24:32 +02:00
|
|
|
connect(cancelButton, &QPushButton::clicked,
|
|
|
|
|
this, &QDialog::close);
|
|
|
|
|
layout->addWidget(cancelButton);
|
|
|
|
|
|
|
|
|
|
updateProgressText();
|
|
|
|
|
|
2022-05-04 11:50:41 +02:00
|
|
|
for (const RunControl *rc : runControls)
|
2022-07-20 17:47:10 +02:00
|
|
|
connect(rc, &RunControl::stopped, this, [this, rc] { runControlFinished(rc); });
|
2015-09-17 15:24:32 +02:00
|
|
|
|
|
|
|
|
m_timer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WaitForStopDialog::canceled()
|
|
|
|
|
{
|
|
|
|
|
return !m_runControls.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WaitForStopDialog::updateProgressText()
|
|
|
|
|
{
|
|
|
|
|
QString text = tr("Waiting for applications to stop.") + QLatin1String("\n\n");
|
|
|
|
|
QStringList names = Utils::transform(m_runControls, &RunControl::displayName);
|
|
|
|
|
text += names.join(QLatin1Char('\n'));
|
|
|
|
|
m_progressLabel->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-20 17:47:10 +02:00
|
|
|
void WaitForStopDialog::runControlFinished(const RunControl *runControl)
|
2015-09-17 15:24:32 +02:00
|
|
|
{
|
2022-07-20 17:47:10 +02:00
|
|
|
m_runControls.removeOne(runControl);
|
2015-09-17 15:24:32 +02:00
|
|
|
if (m_runControls.isEmpty()) {
|
|
|
|
|
if (m_timer.elapsed() < 1000)
|
|
|
|
|
QTimer::singleShot(1000 - m_timer.elapsed(), this, &QDialog::close);
|
|
|
|
|
else
|
|
|
|
|
QDialog::close();
|
|
|
|
|
} else {
|
|
|
|
|
updateProgressText();
|
|
|
|
|
}
|
|
|
|
|
}
|