From e837b4846518e659a7ff0145c28a1c7174ae32d5 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 29 Jan 2013 17:54:26 +0100 Subject: [PATCH] Specialize environmentaspect for remote linux ... and attach it to remote linux runconfigurations Change-Id: I5596b7a237ac6ef4a834324f95f462adbe28e722 Reviewed-by: Tobias Hunger --- src/plugins/remotelinux/remotelinux.pro | 4 + src/plugins/remotelinux/remotelinux.qbs | 4 + .../remotelinuxenvironmentaspect.cpp | 113 ++++++++++++++++++ .../remotelinuxenvironmentaspect.h | 79 ++++++++++++ .../remotelinuxenvironmentaspectwidget.cpp | 101 ++++++++++++++++ .../remotelinuxenvironmentaspectwidget.h | 65 ++++++++++ .../remotelinuxrunconfiguration.cpp | 3 + 7 files changed, 369 insertions(+) create mode 100644 src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp create mode 100644 src/plugins/remotelinux/remotelinuxenvironmentaspect.h create mode 100644 src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp create mode 100644 src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h diff --git a/src/plugins/remotelinux/remotelinux.pro b/src/plugins/remotelinux/remotelinux.pro index 6fba2022f14..0c25de13787 100644 --- a/src/plugins/remotelinux/remotelinux.pro +++ b/src/plugins/remotelinux/remotelinux.pro @@ -5,6 +5,8 @@ include(../../qtcreatorplugin.pri) HEADERS += \ embeddedlinuxqtversion.h \ embeddedlinuxqtversionfactory.h \ + remotelinuxenvironmentaspect.h \ + remotelinuxenvironmentaspectwidget.h \ remotelinuxplugin.h \ remotelinux_export.h \ linuxdevice.h \ @@ -49,6 +51,8 @@ HEADERS += \ SOURCES += \ embeddedlinuxqtversion.cpp \ embeddedlinuxqtversionfactory.cpp \ + remotelinuxenvironmentaspect.cpp \ + remotelinuxenvironmentaspectwidget.cpp \ remotelinuxplugin.cpp \ linuxdevice.cpp \ remotelinuxrunconfiguration.cpp \ diff --git a/src/plugins/remotelinux/remotelinux.qbs b/src/plugins/remotelinux/remotelinux.qbs index 79beba45593..0be4b5907cb 100644 --- a/src/plugins/remotelinux/remotelinux.qbs +++ b/src/plugins/remotelinux/remotelinux.qbs @@ -77,6 +77,10 @@ QtcPlugin { "remotelinuxdeployconfigurationwidget.ui", "remotelinuxdeploymentdatamodel.cpp", "remotelinuxdeploymentdatamodel.h", + "remotelinuxenvironmentaspect.cpp", + "remotelinuxenvironmentaspect.h", + "remotelinuxenvironmentaspectwidget.cpp", + "remotelinuxenvironmentaspectwidget.h", "remotelinuxenvironmentreader.cpp", "remotelinuxenvironmentreader.h", "remotelinuxpackageinstaller.cpp", diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp b/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp new file mode 100644 index 00000000000..22b9ca97910 --- /dev/null +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "remotelinuxenvironmentaspect.h" + +#include "remotelinuxenvironmentaspectwidget.h" + +namespace RemoteLinux { + +// -------------------------------------------------------------------- +// RemoteLinuxEnvironmentAspect: +// -------------------------------------------------------------------- + +RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::RunConfiguration *rc) : + ProjectExplorer::EnvironmentAspect(rc) +{ } + +RemoteLinuxEnvironmentAspect *RemoteLinuxEnvironmentAspect::clone(ProjectExplorer::RunConfiguration *parent) const +{ + return new RemoteLinuxEnvironmentAspect(this, parent); +} + +ProjectExplorer::RunConfigWidget *RemoteLinuxEnvironmentAspect::createConfigurationWidget() +{ + return new RemoteLinuxEnvironmentAspectWidget(this); +} + +QList RemoteLinuxEnvironmentAspect::possibleBaseEnvironments() const +{ + return QList() << static_cast(RemoteBaseEnvironment) + << static_cast(CleanBaseEnvironment); +} + +QString RemoteLinuxEnvironmentAspect::baseEnvironmentDisplayName(int base) const +{ + if (base == static_cast(CleanBaseEnvironment)) + return tr("Clean Environment"); + else if (base == static_cast(RemoteBaseEnvironment)) + return tr("System Environment"); + return QString(); +} + +Utils::Environment RemoteLinuxEnvironmentAspect::baseEnvironment() const +{ + if (baseEnvironmentBase() == static_cast(RemoteBaseEnvironment)) + return m_remoteEnvironment; + return Utils::Environment(); +} + +RemoteLinuxRunConfiguration *RemoteLinuxEnvironmentAspect::runConfiguration() const +{ + return qobject_cast(EnvironmentAspect::runConfiguration()); +} + +Utils::Environment RemoteLinuxEnvironmentAspect::remoteEnvironment() const +{ + return m_remoteEnvironment; +} + +void RemoteLinuxEnvironmentAspect::setRemoteEnvironment(const Utils::Environment &env) +{ + if (env != m_remoteEnvironment) { + m_remoteEnvironment = env; + emit remoteEnvironmentChanged(); + if (baseEnvironmentBase() == static_cast(RemoteBaseEnvironment)) { + emit baseEnvironmentChanged(); + emit environmentChanged(); + } + } +} + +QString RemoteLinuxEnvironmentAspect::userEnvironmentChangesAsString() const +{ + QString env; + QString placeHolder = QLatin1String("%1=%2 "); + foreach (const Utils::EnvironmentItem &item, userEnvironmentChanges()) + env.append(placeHolder.arg(item.name, item.value)); + return env.mid(0, env.size() - 1); +} + +RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(const RemoteLinuxEnvironmentAspect *other, + ProjectExplorer::RunConfiguration *parent) : + ProjectExplorer::EnvironmentAspect(other, parent) +{ } + +} // namespace RemoteLinux + diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspect.h b/src/plugins/remotelinux/remotelinuxenvironmentaspect.h new file mode 100644 index 00000000000..44313727314 --- /dev/null +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspect.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef REMOTELINUXENVIRONMENTASPECT_H +#define REMOTELINUXENVIRONMENTASPECT_H + +#include "remotelinuxrunconfiguration.h" + +#include "remotelinux_export.h" + +#include + +namespace RemoteLinux { +class RemoteLinuxEnvironmentAspectWidget; +class RemoteLinuxRunConfiguration; + +class REMOTELINUX_EXPORT RemoteLinuxEnvironmentAspect : public ProjectExplorer::EnvironmentAspect +{ + Q_OBJECT + +public: + RemoteLinuxEnvironmentAspect(ProjectExplorer::RunConfiguration *rc); + RemoteLinuxEnvironmentAspect *clone(ProjectExplorer::RunConfiguration *parent) const; + ProjectExplorer::RunConfigWidget *createConfigurationWidget(); + + QList possibleBaseEnvironments() const; + QString baseEnvironmentDisplayName(int base) const; + Utils::Environment baseEnvironment() const; + + RemoteLinuxRunConfiguration *runConfiguration() const; + + Utils::Environment remoteEnvironment() const; + void setRemoteEnvironment(const Utils::Environment &env); + + QString userEnvironmentChangesAsString() const; + +signals: + void remoteEnvironmentChanged(); + +private: + enum BaseEnvironmentBase { + CleanBaseEnvironment = 0, + RemoteBaseEnvironment = 1 + }; + + RemoteLinuxEnvironmentAspect(const RemoteLinuxEnvironmentAspect *other, ProjectExplorer::RunConfiguration *parent); + + Utils::Environment m_remoteEnvironment; +}; + +} // namespace RemoteLinux + +#endif // REMOTELINUXENVIRONMENTASPECT_H diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp new file mode 100644 index 00000000000..69c0b57cc9f --- /dev/null +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "remotelinuxenvironmentaspectwidget.h" + +#include "remotelinuxenvironmentreader.h" + +#include +#include +#include + +namespace { +const QString FetchEnvButtonText + = QCoreApplication::translate("RemoteLinux::RemoteLinuxEnvironmentAspectWidget", + "Fetch Device Environment"); +} // anonymous namespace + +namespace RemoteLinux { + +RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget(RemoteLinuxEnvironmentAspect *aspect) : + ProjectExplorer::EnvironmentAspectWidget(aspect, new QPushButton), + deviceEnvReader(new Internal::RemoteLinuxEnvironmentReader(aspect->runConfiguration(), this)) +{ + QPushButton *button = fetchButton(); + button->setText(FetchEnvButtonText); + connect(button, SIGNAL(clicked()), this, SLOT(fetchEnvironment())); + connect(deviceEnvReader, SIGNAL(finished()), this, SLOT(fetchEnvironmentFinished())); + connect(deviceEnvReader, SIGNAL(error(QString)), this, SLOT(fetchEnvironmentError(QString))); +} + +RemoteLinuxEnvironmentAspect *RemoteLinuxEnvironmentAspectWidget::aspect() const +{ + return dynamic_cast(EnvironmentAspectWidget::aspect()); +} + +QPushButton *RemoteLinuxEnvironmentAspectWidget::fetchButton() const +{ + return qobject_cast(additionalWidget()); +} + +void RemoteLinuxEnvironmentAspectWidget::fetchEnvironment() +{ + QPushButton *button = fetchButton(); + disconnect(button, SIGNAL(clicked()), this, SLOT(fetchEnvironment())); + connect(button, SIGNAL(clicked()), this, SLOT(stopFetchEnvironment())); + button->setText(tr("Cancel Fetch Operation")); + deviceEnvReader->start(aspect()->runConfiguration()->environmentPreparationCommand()); +} + +void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished() +{ + QPushButton *button = fetchButton(); + disconnect(button, SIGNAL(clicked()), this, SLOT(stopFetchEnvironment())); + connect(button, SIGNAL(clicked()), this, SLOT(fetchEnvironment())); + button->setText(FetchEnvButtonText); + aspect()->setRemoteEnvironment(deviceEnvReader->remoteEnvironment()); +} + +void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError(const QString &error) +{ + QMessageBox::warning(this, tr("Device Error"), + tr("Fetching environment failed: %1").arg(error)); +} + +void RemoteLinuxEnvironmentAspectWidget::stopFetchEnvironment() +{ + deviceEnvReader->stop(); + fetchEnvironmentFinished(); +} + +// -------------------------------------------------------------------- +// RemoteLinuxEnvironmentAspectWidget: +// -------------------------------------------------------------------- + +} // namespace RemoteLinux diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h new file mode 100644 index 00000000000..4a1f9c6640e --- /dev/null +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef REMOTELINUXENVIRONMENTASPECTWIDGET_H +#define REMOTELINUXENVIRONMENTASPECTWIDGET_H + +#include "remotelinuxenvironmentaspect.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QPushButton) + +namespace RemoteLinux { + +namespace Internal { class RemoteLinuxEnvironmentReader; } + +class RemoteLinuxEnvironmentAspectWidget : public ProjectExplorer::EnvironmentAspectWidget +{ + Q_OBJECT + +public: + RemoteLinuxEnvironmentAspectWidget(RemoteLinuxEnvironmentAspect *aspect); + + RemoteLinuxEnvironmentAspect *aspect() const; + QPushButton *fetchButton() const; + +private slots: + void fetchEnvironment(); + void fetchEnvironmentFinished(); + void fetchEnvironmentError(const QString &error); + void stopFetchEnvironment(); + +private: + Internal::RemoteLinuxEnvironmentReader *deviceEnvReader; +}; + +} // namespace RemoteLinux + +#endif // REMOTELINUXENVIRONMENTASPECTWIDGET_H diff --git a/src/plugins/remotelinux/remotelinuxrunconfiguration.cpp b/src/plugins/remotelinux/remotelinuxrunconfiguration.cpp index e7a2e337336..3904d3121b5 100644 --- a/src/plugins/remotelinux/remotelinuxrunconfiguration.cpp +++ b/src/plugins/remotelinux/remotelinuxrunconfiguration.cpp @@ -29,6 +29,7 @@ #include "remotelinuxrunconfiguration.h" +#include "remotelinuxenvironmentaspect.h" #include "remotelinuxrunconfigurationwidget.h" #include @@ -119,6 +120,8 @@ void RemoteLinuxRunConfiguration::init() { setDefaultDisplayName(defaultDisplayName()); + addExtraAspect(new RemoteLinuxEnvironmentAspect(this)); + connect(target(), SIGNAL(deploymentDataChanged()), SLOT(handleBuildSystemDataUpdated())); connect(target(), SIGNAL(applicationTargetsChanged()), SLOT(handleBuildSystemDataUpdated())); connect(target(), SIGNAL(kitChanged()),