QdbMakeDefaultAppService: Reuse TaskTree

Change-Id: I03ee1935e7b0b0cc82f139f7f435d3194ff29f01
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-11-24 17:57:15 +01:00
parent 9e810acfbe
commit c01ab460c8

View File

@@ -18,6 +18,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
using namespace Utils::Tasking;
namespace Qdb { namespace Qdb {
namespace Internal { namespace Internal {
@@ -27,61 +28,64 @@ namespace Internal {
class QdbMakeDefaultAppService : public RemoteLinux::AbstractRemoteLinuxDeployService class QdbMakeDefaultAppService : public RemoteLinux::AbstractRemoteLinuxDeployService
{ {
Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbMakeDefaultAppService) Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbMakeDefaultAppService)
public: public:
QdbMakeDefaultAppService() void setMakeDefault(bool makeDefault) { m_makeDefault = makeDefault; }
{
connect(&m_process, &QtcProcess::done, this, [this] {
if (m_process.error() != QProcess::UnknownError)
emit errorMessage(tr("Remote process failed: %1").arg(m_process.errorString()));
else if (m_makeDefault)
emit progressMessage(tr("Application set as the default one."));
else
emit progressMessage(tr("Reset the default application."));
stopDeployment();
});
connect(&m_process, &QtcProcess::readyReadStandardError, this, [this] {
emit stdErrData(QString::fromUtf8(m_process.readAllStandardError()));
});
}
void setMakeDefault(bool makeDefault)
{
m_makeDefault = makeDefault;
}
private: private:
bool isDeploymentNecessary() const final { return true; } bool isDeploymentNecessary() const final { return true; }
void doDeploy() final void doDeploy() final
{ {
QString remoteExe; QTC_ASSERT(!m_taskTree, return);
const auto setupHandler = [this](QtcProcess &process) {
QString remoteExe;
if (RunConfiguration *rc = target()->activeRunConfiguration()) { if (RunConfiguration *rc = target()->activeRunConfiguration()) {
if (auto exeAspect = rc->aspect<ExecutableAspect>()) if (auto exeAspect = rc->aspect<ExecutableAspect>())
remoteExe = exeAspect->executable().toString(); remoteExe = exeAspect->executable().toString();
} }
const QString args = m_makeDefault && !remoteExe.isEmpty() const QString args = m_makeDefault && !remoteExe.isEmpty()
? QStringLiteral("--make-default ") + remoteExe ? QStringLiteral("--make-default ") + remoteExe
: QStringLiteral("--remove-default"); : QStringLiteral("--remove-default");
m_process.setCommand( process.setCommand({deviceConfiguration()->filePath(Constants::AppcontrollerFilepath),
{deviceConfiguration()->filePath(Constants::AppcontrollerFilepath), {args}}); {args}});
m_process.start(); QtcProcess *proc = &process;
connect(proc, &QtcProcess::readyReadStandardError, this, [this, proc] {
emit stdErrData(QString::fromUtf8(proc->readAllStandardError()));
});
};
const auto doneHandler = [this](const QtcProcess &) {
if (m_makeDefault)
emit progressMessage(tr("Application set as the default one."));
else
emit progressMessage(tr("Reset the default application."));
};
const auto errorHandler = [this](const QtcProcess &process) {
emit errorMessage(tr("Remote process failed: %1").arg(process.errorString()));
};
const auto endHandler = [this] {
m_taskTree.release()->deleteLater();
stopDeployment();
};
const Group root {
Process(setupHandler, doneHandler, errorHandler),
OnGroupDone(endHandler),
OnGroupError(endHandler)
};
m_taskTree.reset(new TaskTree(root));
m_taskTree->start();
} }
void stopDeployment() final void stopDeployment() final
{ {
m_process.close(); m_taskTree.reset();
handleDeploymentDone(); handleDeploymentDone();
} }
bool m_makeDefault = true; bool m_makeDefault = true;
QtcProcess m_process; std::unique_ptr<TaskTree> m_taskTree;
}; };
// QdbMakeDefaultAppStep // QdbMakeDefaultAppStep
class QdbMakeDefaultAppStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep class QdbMakeDefaultAppStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep