From 4d382811f1a4119afabe5c539a5ea28f452965b2 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 6 Apr 2016 13:56:32 +0200 Subject: [PATCH] ProjectExplorer: Introduce a DeviceEnvironmentFetcher Also, provide implementations for desktop and remote linux. Change-Id: Ib02202bf1829367334035a361ac73317338cd7a6 Reviewed-by: Christian Kandeler --- .../devicesupport/desktopdevice.cpp | 18 +++++++++++++ .../devicesupport/desktopdevice.h | 1 + .../projectexplorer/devicesupport/idevice.cpp | 9 +++++++ .../projectexplorer/devicesupport/idevice.h | 22 +++++++++++++++- src/plugins/remotelinux/linuxdevice.cpp | 26 +++++++++++++++++++ src/plugins/remotelinux/linuxdevice.h | 1 + .../remotelinuxenvironmentaspectwidget.cpp | 21 ++++++++++++--- .../remotelinuxenvironmentreader.cpp | 18 ++++++------- .../remotelinuxenvironmentreader.h | 21 ++++++--------- 9 files changed, 109 insertions(+), 28 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp index 2a69b1563de..71ecf037d54 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp @@ -32,6 +32,8 @@ #include #include + +#include #include #include @@ -116,6 +118,22 @@ DeviceProcessSignalOperation::Ptr DesktopDevice::signalOperation() const return DeviceProcessSignalOperation::Ptr(new DesktopProcessSignalOperation()); } +class DesktopDeviceEnvironmentFetcher : public DeviceEnvironmentFetcher +{ +public: + DesktopDeviceEnvironmentFetcher() {} + + void start() override + { + emit finished(Utils::Environment::systemEnvironment(), true); + } +}; + +DeviceEnvironmentFetcher::Ptr DesktopDevice::environmentFetcher() const +{ + return DeviceEnvironmentFetcher::Ptr(new DesktopDeviceEnvironmentFetcher()); +} + QString DesktopDevice::qmlProfilerHost() const { return QLatin1String("localhost"); diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.h b/src/plugins/projectexplorer/devicesupport/desktopdevice.h index da6c1fada9e..b99d83457de 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.h +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.h @@ -51,6 +51,7 @@ public: bool canCreateProcess() const override { return true; } DeviceProcess *createProcess(QObject *parent) const override; DeviceProcessSignalOperation::Ptr signalOperation() const override; + DeviceEnvironmentFetcher::Ptr environmentFetcher() const override; QString qmlProfilerHost() const override; IDevice::Ptr clone() const override; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 2f7a19ec9bc..b48a6b51eca 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -277,6 +277,11 @@ DeviceProcess *IDevice::createProcess(QObject * /* parent */) const return 0; } +DeviceEnvironmentFetcher::Ptr IDevice::environmentFetcher() const +{ + return DeviceEnvironmentFetcher::Ptr(); +} + IDevice::DeviceState IDevice::deviceState() const { return d->deviceState; @@ -457,4 +462,8 @@ DeviceProcessSignalOperation::DeviceProcessSignalOperation() { } +DeviceEnvironmentFetcher::DeviceEnvironmentFetcher() +{ +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index d1484e25ff5..3ab1ff03cd6 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -40,7 +40,11 @@ class QWidget; QT_END_NAMESPACE namespace QSsh { class SshConnectionParameters; } -namespace Utils { class PortList; } + +namespace Utils { +class Environment; +class PortList; +} // Utils namespace ProjectExplorer { class DeviceProcess; @@ -77,6 +81,21 @@ protected: QString m_errorMessage; }; +class PROJECTEXPLORER_EXPORT DeviceEnvironmentFetcher : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + + virtual void start() = 0; + +signals: + void finished(const Utils::Environment &env, bool success); + +protected: + explicit DeviceEnvironmentFetcher(); +}; + class PROJECTEXPLORER_EXPORT PortsGatheringMethod { public: @@ -138,6 +157,7 @@ public: virtual bool canCreateProcess() const { return false; } virtual DeviceProcess *createProcess(QObject *parent) const; virtual DeviceProcessSignalOperation::Ptr signalOperation() const = 0; + virtual DeviceEnvironmentFetcher::Ptr environmentFetcher() const; enum DeviceState { DeviceReadyToUse, DeviceConnected, DeviceDisconnected, DeviceStateUnknown }; DeviceState deviceState() const; diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 40f5bb37a8e..6f960c07860 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -31,6 +31,7 @@ #include "publickeydeploymentdialog.h" #include "remotelinux_constants.h" #include "remotelinuxsignaloperation.h" +#include "remotelinuxenvironmentreader.h" #include #include @@ -254,4 +255,29 @@ DeviceProcessSignalOperation::Ptr LinuxDevice::signalOperation() const return DeviceProcessSignalOperation::Ptr(new RemoteLinuxSignalOperation(sshParameters())); } +class LinuxDeviceEnvironmentFetcher : public DeviceEnvironmentFetcher +{ +public: + LinuxDeviceEnvironmentFetcher(const IDevice::ConstPtr &device) + : m_reader(device) + { + connect(&m_reader, &Internal::RemoteLinuxEnvironmentReader::finished, + this, &LinuxDeviceEnvironmentFetcher::readerFinished); + connect(&m_reader, &Internal::RemoteLinuxEnvironmentReader::error, + this, &LinuxDeviceEnvironmentFetcher::readerError); + } + +private: + void start() override { m_reader.start(); } + void readerFinished() { emit finished(m_reader.remoteEnvironment(), true); } + void readerError() { emit finished(Utils::Environment(), false); } + + Internal::RemoteLinuxEnvironmentReader m_reader; +}; + +DeviceEnvironmentFetcher::Ptr LinuxDevice::environmentFetcher() const +{ + return DeviceEnvironmentFetcher::Ptr(new LinuxDeviceEnvironmentFetcher(sharedFromThis())); +} + } // namespace RemoteLinux diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h index 7a5f7520249..4f18a177048 100644 --- a/src/plugins/remotelinux/linuxdevice.h +++ b/src/plugins/remotelinux/linuxdevice.h @@ -66,6 +66,7 @@ public: bool hasDeviceTester() const { return true; } ProjectExplorer::DeviceTester *createDeviceTester() const; ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const; + ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const; protected: LinuxDevice() {} diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp index f3f68203118..dce7464e8e9 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp @@ -28,10 +28,16 @@ #include "remotelinuxrunconfiguration.h" #include "remotelinuxenvironmentreader.h" +#include +#include + #include #include #include +using namespace ProjectExplorer; +using namespace RemoteLinux::Internal; + namespace { const QString FetchEnvButtonText = QCoreApplication::translate("RemoteLinux::RemoteLinuxEnvironmentAspectWidget", @@ -41,15 +47,22 @@ const QString FetchEnvButtonText namespace RemoteLinux { RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget(RemoteLinuxEnvironmentAspect *aspect) : - ProjectExplorer::EnvironmentAspectWidget(aspect, new QPushButton), - deviceEnvReader(new Internal::RemoteLinuxEnvironmentReader(aspect->runConfiguration(), this)) + EnvironmentAspectWidget(aspect, new QPushButton) { + RunConfiguration *runConfiguration = aspect->runConfiguration(); + Target *target = runConfiguration->target(); + IDevice::ConstPtr device = DeviceKitInformation::device(target->kit()); + + deviceEnvReader = new RemoteLinuxEnvironmentReader(device, this); + connect(target, &ProjectExplorer::Target::kitChanged, + deviceEnvReader, &RemoteLinuxEnvironmentReader::handleCurrentDeviceConfigChanged); + QPushButton *button = fetchButton(); button->setText(FetchEnvButtonText); connect(button, &QPushButton::clicked, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment); - connect(deviceEnvReader, &Internal::RemoteLinuxEnvironmentReader::finished, + connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::finished, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished); - connect(deviceEnvReader, &Internal::RemoteLinuxEnvironmentReader::error, + connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::error, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError); } diff --git a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp index c0da4463aee..81bca05e974 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp @@ -27,9 +27,6 @@ #include #include -#include -#include -#include #include using namespace ProjectExplorer; @@ -37,24 +34,25 @@ using namespace ProjectExplorer; namespace RemoteLinux { namespace Internal { -RemoteLinuxEnvironmentReader::RemoteLinuxEnvironmentReader(RunConfiguration *config, QObject *parent) +RemoteLinuxEnvironmentReader::RemoteLinuxEnvironmentReader(const IDevice::ConstPtr &device, + QObject *parent) : QObject(parent) , m_stop(false) , m_env(Utils::OsTypeLinux) - , m_kit(config->target()->kit()) + , m_device(device) , m_deviceProcess(0) { - connect(config->target(), SIGNAL(kitChanged()), - this, SLOT(handleCurrentDeviceConfigChanged())); } void RemoteLinuxEnvironmentReader::start() { - IDevice::ConstPtr device = DeviceKitInformation::device(m_kit); - if (!device) + if (!m_device) { + emit error(tr("Error: No device")); + setFinished(); return; + } m_stop = false; - m_deviceProcess = device->createProcess(this); + m_deviceProcess = m_device->createProcess(this); connect(m_deviceProcess, &DeviceProcess::error, this, &RemoteLinuxEnvironmentReader::handleError); connect(m_deviceProcess, &DeviceProcess::finished, diff --git a/src/plugins/remotelinux/remotelinuxenvironmentreader.h b/src/plugins/remotelinux/remotelinuxenvironmentreader.h index d1fd34e4692..ab1e49b52fe 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentreader.h +++ b/src/plugins/remotelinux/remotelinuxenvironmentreader.h @@ -26,15 +26,12 @@ #ifndef REMOTELINUXENVIRONMENTREADER_H #define REMOTELINUXENVIRONMENTREADER_H +#include #include #include -namespace ProjectExplorer { -class DeviceProcess; -class Kit; -class RunConfiguration; -} +namespace ProjectExplorer { class DeviceProcess; } namespace RemoteLinux { namespace Internal { @@ -44,29 +41,27 @@ class RemoteLinuxEnvironmentReader : public QObject Q_OBJECT public: - RemoteLinuxEnvironmentReader(ProjectExplorer::RunConfiguration *config, QObject *parent = 0); - + RemoteLinuxEnvironmentReader(const ProjectExplorer::IDevice::ConstPtr &device, + QObject *parent = 0); void start(); void stop(); Utils::Environment remoteEnvironment() const { return m_env; } + void handleCurrentDeviceConfigChanged(); signals: void finished(); void error(const QString &error); -private slots: - void handleError(); - void handleCurrentDeviceConfigChanged(); - void remoteProcessFinished(); - private: + void handleError(); + void remoteProcessFinished(); void setFinished(); void destroyProcess(); bool m_stop; Utils::Environment m_env; - ProjectExplorer::Kit *m_kit; + ProjectExplorer::IDevice::ConstPtr m_device; ProjectExplorer::DeviceProcess *m_deviceProcess; };