summaryrefslogtreecommitdiff
path: root/src/plugins/remotelinux
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
parentcc5c899ce0953799a702bd0828e6c9260facf9e1 (diff)
downloadqt-creator-a3c6d30b75d83973ec292dc8d909d62b141110bd.tar.gz
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')
-rw-r--r--src/plugins/remotelinux/linuxdevice.cpp91
-rw-r--r--src/plugins/remotelinux/linuxdevice.h6
-rw-r--r--src/plugins/remotelinux/remotelinux_constants.h2
3 files changed, 36 insertions, 63 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);
diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h
index 919ccb092e..3ddf8294a8 100644
--- a/src/plugins/remotelinux/linuxdevice.h
+++ b/src/plugins/remotelinux/linuxdevice.h
@@ -48,9 +48,6 @@ public:
QString displayType() const override;
ProjectExplorer::IDeviceWidget *createWidget() override;
- QList<Core::Id> actionIds() const override;
- QString displayNameForActionId(Core::Id actionId) const override;
- void executeAction(Core::Id actionId, QWidget *parent) override;
Utils::OsType osType() const override;
ProjectExplorer::IDevice::Ptr clone() const override;
@@ -69,13 +66,14 @@ public:
bool supportsRSync() const;
protected:
- LinuxDevice() = default;
+ LinuxDevice() { init(); }
LinuxDevice(const QString &name, Core::Id type,
MachineType machineType, Origin origin, Core::Id id);
LinuxDevice(const LinuxDevice &other);
private:
LinuxDevice &operator=(const LinuxDevice &);
+ void init();
};
} // namespace RemoteLinux
diff --git a/src/plugins/remotelinux/remotelinux_constants.h b/src/plugins/remotelinux/remotelinux_constants.h
index 43bd85fe87..1b34d1d4d7 100644
--- a/src/plugins/remotelinux/remotelinux_constants.h
+++ b/src/plugins/remotelinux/remotelinux_constants.h
@@ -30,8 +30,6 @@ namespace Constants {
const char GenericLinuxOsType[] = "GenericLinuxOsType";
-const char GenericDeployKeyToDeviceActionId[] = "RemoteLinux.GenericDeployKeyToDeviceAction";
-
const char EMBEDDED_LINUX_QT[] = "RemoteLinux.EmbeddedLinuxQt";
} // Constants