aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/remotelinux/linuxdevice.cpp
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2019-01-11 14:50:08 +0100
committerhjk <hjk@qt.io>2019-01-14 12:55:51 +0000
commita3c6d30b75d83973ec292dc8d909d62b141110bd (patch)
treedbc9a4fa364f07b25e59a4397d840907dc1059f8 /src/plugins/remotelinux/linuxdevice.cpp
parentcc5c899ce0953799a702bd0828e6c9260facf9e1 (diff)
ProjectExplorer: Simplify IDevice extra device action setup
Function objects are easy nowadays. Change-Id: Iec2b770b99d8f11b7a090fb3bd51af8aa60f6fe0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/remotelinux/linuxdevice.cpp')
-rw-r--r--src/plugins/remotelinux/linuxdevice.cpp91
1 files changed, 34 insertions, 57 deletions
diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp
index 83dd01c6d8..ef483521ed 100644
--- a/src/plugins/remotelinux/linuxdevice.cpp
+++ b/src/plugins/remotelinux/linuxdevice.cpp
@@ -52,9 +52,6 @@ namespace RemoteLinux {
const char Delimiter0[] = "x--";
const char Delimiter1[] = "---";
-
-static Core::Id openShellActionId() { return "RemoteLinux.OpenShellAction"; }
-
static QString visualizeNull(QString s)
{
return s.replace(QLatin1Char('\0'), QLatin1String("<null>"));
@@ -185,60 +182,6 @@ IDeviceWidget *LinuxDevice::createWidget()
return new GenericLinuxDeviceConfigurationWidget(sharedFromThis());
}
-QList<Core::Id> LinuxDevice::actionIds() const
-{
- QList<Core::Id> ids({Core::Id(Constants::GenericDeployKeyToDeviceActionId)});
- if (Utils::HostOsInfo::isAnyUnixHost())
- ids << openShellActionId();
- return ids;
-}
-
-QString LinuxDevice::displayNameForActionId(Core::Id actionId) const
-{
- QTC_ASSERT(actionIds().contains(actionId), return QString());
-
- if (actionId == Constants::GenericDeployKeyToDeviceActionId)
- return tr("Deploy Public Key...");
- if (actionId == openShellActionId())
- return tr("Open Remote Shell");
- return QString(); // Can't happen.
-}
-
-void LinuxDevice::executeAction(Core::Id actionId, QWidget *parent)
-{
- QTC_ASSERT(actionIds().contains(actionId), return);
-
- if (actionId == Constants::GenericDeployKeyToDeviceActionId) {
- const LinuxDevice::ConstPtr device = sharedFromThis().staticCast<const LinuxDevice>();
- QDialog * const d = PublicKeyDeploymentDialog::createDialog(device, parent);
- if (d)
- d->exec();
- delete d;
- return;
- }
- if (actionId == openShellActionId()) {
- DeviceProcess * const proc = createProcess(nullptr);
- QObject::connect(proc, &DeviceProcess::finished, [proc] {
- if (!proc->errorString().isEmpty()) {
- Core::MessageManager::write(tr("Error running remote shell: %1")
- .arg(proc->errorString()),
- Core::MessageManager::ModeSwitch);
- }
- proc->deleteLater();
- });
- QObject::connect(proc, &DeviceProcess::error, [proc] {
- Core::MessageManager::write(tr("Error starting remote shell."),
- Core::MessageManager::ModeSwitch);
- proc->deleteLater();
- });
- Runnable runnable;
- runnable.device = sharedFromThis().staticCast<const LinuxDevice>();
- proc->setRunInTerminal(true);
- proc->start(runnable);
- return;
- }
-}
-
Utils::OsType LinuxDevice::osType() const
{
return Utils::OsTypeLinux;
@@ -249,10 +192,44 @@ LinuxDevice::LinuxDevice(const QString &name, Core::Id type, MachineType machine
: IDevice(type, origin, machineType, id)
{
setDisplayName(name);
+ init();
}
LinuxDevice::LinuxDevice(const LinuxDevice &other) = default;
+void LinuxDevice::init()
+{
+ addDeviceAction({tr("Deploy Public Key..."), [](const IDevice::Ptr &device, QWidget *parent) {
+ if (auto d = PublicKeyDeploymentDialog::createDialog(device, parent)) {
+ d->exec();
+ delete d;
+ }
+ }});
+
+ if (Utils::HostOsInfo::isAnyUnixHost()) {
+ addDeviceAction({tr("Open Remote Shell"), [](const IDevice::Ptr &device, QWidget *) {
+ DeviceProcess * const proc = device->createProcess(nullptr);
+ QObject::connect(proc, &DeviceProcess::finished, [proc] {
+ if (!proc->errorString().isEmpty()) {
+ Core::MessageManager::write(tr("Error running remote shell: %1")
+ .arg(proc->errorString()),
+ Core::MessageManager::ModeSwitch);
+ }
+ proc->deleteLater();
+ });
+ QObject::connect(proc, &DeviceProcess::error, [proc] {
+ Core::MessageManager::write(tr("Error starting remote shell."),
+ Core::MessageManager::ModeSwitch);
+ proc->deleteLater();
+ });
+ Runnable runnable;
+ runnable.device = device;
+ proc->setRunInTerminal(true);
+ proc->start(runnable);
+ }});
+ }
+}
+
LinuxDevice::Ptr LinuxDevice::create()
{
return Ptr(new LinuxDevice);