2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 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
|
2019-06-04 14:22:35 +02:00
|
|
|
|
|
|
|
|
#include "qdbmakedefaultappstep.h"
|
|
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
#include "qdbconstants.h"
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2019-06-13 18:25:17 +02:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2019-06-13 18:25:17 +02:00
|
|
|
|
2022-05-27 15:41:57 +02:00
|
|
|
#include <remotelinux/abstractremotelinuxdeployservice.h>
|
2020-02-20 13:51:49 +01:00
|
|
|
#include <remotelinux/abstractremotelinuxdeploystep.h>
|
|
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <utils/commandline.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
2019-06-13 18:25:17 +02:00
|
|
|
using namespace ProjectExplorer;
|
2020-09-18 12:11:40 +02:00
|
|
|
using namespace Utils;
|
2022-11-24 17:57:15 +01:00
|
|
|
using namespace Utils::Tasking;
|
2019-06-04 14:22:35 +02:00
|
|
|
|
|
|
|
|
namespace Qdb {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
// QdbMakeDefaultAppService
|
|
|
|
|
|
|
|
|
|
class QdbMakeDefaultAppService : public RemoteLinux::AbstractRemoteLinuxDeployService
|
2020-02-20 13:51:49 +01:00
|
|
|
{
|
2022-05-04 08:01:57 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbMakeDefaultAppService)
|
2020-02-20 13:51:49 +01:00
|
|
|
public:
|
2022-11-24 17:57:15 +01:00
|
|
|
void setMakeDefault(bool makeDefault) { m_makeDefault = makeDefault; }
|
2022-05-04 08:01:57 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool isDeploymentNecessary() const final { return true; }
|
|
|
|
|
|
2022-11-24 21:45:00 +01:00
|
|
|
Group deployRecipe() final
|
2022-05-04 08:01:57 +02:00
|
|
|
{
|
2022-11-24 17:57:15 +01:00
|
|
|
const auto setupHandler = [this](QtcProcess &process) {
|
|
|
|
|
QString remoteExe;
|
|
|
|
|
if (RunConfiguration *rc = target()->activeRunConfiguration()) {
|
|
|
|
|
if (auto exeAspect = rc->aspect<ExecutableAspect>())
|
2022-12-02 12:00:51 +01:00
|
|
|
remoteExe = exeAspect->executable().nativePath();
|
2022-11-24 17:57:15 +01:00
|
|
|
}
|
2022-12-12 11:26:08 +01:00
|
|
|
CommandLine cmd{deviceConfiguration()->filePath(Constants::AppcontrollerFilepath)};
|
|
|
|
|
if (m_makeDefault && !remoteExe.isEmpty())
|
|
|
|
|
cmd.addArgs({"--make-default", remoteExe});
|
|
|
|
|
else
|
|
|
|
|
cmd.addArg("--remove-default");
|
|
|
|
|
process.setCommand(cmd);
|
2022-11-24 17:57:15 +01:00
|
|
|
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()));
|
|
|
|
|
};
|
2022-11-24 21:45:00 +01:00
|
|
|
return Group { Process(setupHandler, doneHandler, errorHandler) };
|
2022-05-04 08:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool m_makeDefault = true;
|
2020-02-20 13:51:49 +01:00
|
|
|
};
|
|
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
// QdbMakeDefaultAppStep
|
|
|
|
|
|
|
|
|
|
class QdbMakeDefaultAppStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep
|
2019-06-04 14:22:35 +02:00
|
|
|
{
|
2022-05-04 08:01:57 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Qdb::Internal::QdbMakeDefaultAppStep)
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
public:
|
|
|
|
|
QdbMakeDefaultAppStep(BuildStepList *bsl, Id id)
|
|
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
|
|
|
|
{
|
2022-10-13 14:35:25 +02:00
|
|
|
auto service = new QdbMakeDefaultAppService;
|
|
|
|
|
setDeployService(service);
|
2022-05-04 08:01:57 +02:00
|
|
|
|
|
|
|
|
auto selection = addAspect<SelectionAspect>();
|
|
|
|
|
selection->setSettingsKey("QdbMakeDefaultDeployStep.MakeDefault");
|
|
|
|
|
selection->addOption(tr("Set this application to start by default"));
|
|
|
|
|
selection->addOption(tr("Reset default application"));
|
|
|
|
|
|
|
|
|
|
setInternalInitializer([service, selection] {
|
|
|
|
|
service->setMakeDefault(selection->value() == 0);
|
|
|
|
|
return service->isDeploymentPossible();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-06-13 18:25:17 +02:00
|
|
|
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
// QdbMakeDefaultAppStepFactory
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
QdbMakeDefaultAppStepFactory::QdbMakeDefaultAppStepFactory()
|
2019-06-04 14:22:35 +02:00
|
|
|
{
|
2020-02-20 13:51:49 +01:00
|
|
|
registerStep<QdbMakeDefaultAppStep>(Constants::QdbMakeDefaultAppStepId);
|
2020-09-24 17:29:46 +02:00
|
|
|
setDisplayName(QdbMakeDefaultAppStep::tr("Change default application"));
|
2020-02-20 13:51:49 +01:00
|
|
|
setSupportedDeviceType(Qdb::Constants::QdbLinuxOsType);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
2019-06-04 14:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qdb
|