AndroidDeployQtStep: Make it cancelable

And use QFutureInterface for it.

Change-Id: I1145b70b119d92af7316977c813f4f29b1f20b74
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-09 16:05:25 +01:00
parent 038771051d
commit 1e632d0c25
5 changed files with 34 additions and 23 deletions

View File

@@ -3,16 +3,14 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "androidavdmanager.h"
#include "androidbuildapkstep.h"
#include "androidconstants.h"
#include "androiddeployqtstep.h"
#include "androiddevice.h"
#include "androidglobal.h"
#include "androidmanager.h"
#include "androidqtversion.h"
#include "androidtr.h"
#include "androidtr.h"
#include "certificatesmodel.h"
#include "javaparser.h"
#include <coreplugin/fileutils.h>
#include <coreplugin/icore.h>
@@ -35,6 +33,7 @@
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <QCheckBox>
#include <QFileDialog>
@@ -402,15 +401,16 @@ void AndroidDeployQtStep::slotAskForUninstall(DeployErrorCode errorCode)
m_askForUninstall = button == QMessageBox::Yes;
}
bool AndroidDeployQtStep::runImpl()
void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
{
if (!m_avdName.isEmpty()) {
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, cancelChecker());
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, fi);
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
if (serialNumber.isEmpty()) {
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
.arg(m_avdName), Task::Error);
return false;
fi.reportResult(false);
return;
}
m_serialNumber = serialNumber;
qCDebug(deployStepLog) << "Deployment device serial number changed:" << serialNumber;
@@ -445,8 +445,7 @@ bool AndroidDeployQtStep::runImpl()
reportWarningOrError(error, Task::Error);
}
}
return returnValue == NoError;
fi.reportResult(returnValue == NoError);
}
void AndroidDeployQtStep::gatherFilesToPull()
@@ -480,7 +479,20 @@ void AndroidDeployQtStep::gatherFilesToPull()
void AndroidDeployQtStep::doRun()
{
m_synchronizer.addFuture(runInThread([this] { return runImpl(); }));
auto * const watcher = new QFutureWatcher<bool>(this);
connect(watcher, &QFutureWatcher<bool>::finished, this, [this, watcher] {
const bool success = !watcher->isCanceled() && watcher->result();
emit finished(success);
watcher->deleteLater();
});
auto future = Utils::runAsync(&AndroidDeployQtStep::runImpl, this);
watcher->setFuture(future);
m_synchronizer.addFuture(future);
}
void AndroidDeployQtStep::doCancel()
{
m_synchronizer.cancelAllFutures();
}
void AndroidDeployQtStep::runCommand(const CommandLine &command)