Basic support for fetching and modifying device environment.

This commit is contained in:
kh1
2010-07-28 14:27:08 +02:00
parent e03a6b6ea2
commit c3350a1675
7 changed files with 182 additions and 25 deletions

View File

@@ -65,11 +65,13 @@ static const QLatin1String LastDeployedHostsKey(PREFIX ".LastDeployedHosts");
static const QLatin1String LastDeployedFilesKey(PREFIX ".LastDeployedFiles"); static const QLatin1String LastDeployedFilesKey(PREFIX ".LastDeployedFiles");
static const QLatin1String LastDeployedRemotePathsKey(PREFIX ".LastDeployedRemotePaths"); static const QLatin1String LastDeployedRemotePathsKey(PREFIX ".LastDeployedRemotePaths");
static const QLatin1String LastDeployedTimesKey(PREFIX ".LastDeployedTimes"); static const QLatin1String LastDeployedTimesKey(PREFIX ".LastDeployedTimes");
static const QLatin1String ProFileKey(".ProFile"); static const QLatin1String ProFileKey(PREFIX ".ProFile");
static const QLatin1String ExportedLocalDirsKey(".ExportedLocalDirs"); static const QLatin1String ExportedLocalDirsKey(PREFIX ".ExportedLocalDirs");
static const QLatin1String RemoteMountPointsKey(".RemoteMountPoints"); static const QLatin1String RemoteMountPointsKey(PREFIX ".RemoteMountPoints");
static const QLatin1String MountPortsKey(".MountPorts"); static const QLatin1String MountPortsKey(PREFIX ".MountPorts");
static const QLatin1String HostAddressFromDeviceKey(".HostAddressFromDevice"); static const QLatin1String HostAddressFromDeviceKey(PREFIX ".HostAddressFromDevice");
static const QLatin1String BaseEnvironmentBaseKey(PREFIX ".BaseEnvironmentBase");
static const QLatin1String UserEnvironmentChangesKey(PREFIX ".UserEnvironmentChanges");
} // namespace Internal } // namespace Internal
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager

View File

@@ -45,7 +45,6 @@ namespace Qt4ProjectManager {
MaemoDeviceEnvReader::MaemoDeviceEnvReader(QObject *parent, MaemoRunConfiguration *config) MaemoDeviceEnvReader::MaemoDeviceEnvReader(QObject *parent, MaemoRunConfiguration *config)
: QObject(parent) : QObject(parent)
, m_stop(false) , m_stop(false)
, m_runConfig(config)
, m_devConfig(config->deviceConfig()) , m_devConfig(config->deviceConfig())
{ {
} }
@@ -91,7 +90,7 @@ void MaemoDeviceEnvReader::stop()
void MaemoDeviceEnvReader::setEnvironment() void MaemoDeviceEnvReader::setEnvironment()
{ {
if (m_remoteOutput.isEmpty() && !m_runConfig.isNull()) if (m_remoteOutput.isEmpty())
return; return;
m_env = ProjectExplorer::Environment(m_remoteOutput.split(QLatin1Char('\n'), m_env = ProjectExplorer::Environment(m_remoteOutput.split(QLatin1Char('\n'),
QString::SkipEmptyParts)); QString::SkipEmptyParts));
@@ -102,7 +101,8 @@ void MaemoDeviceEnvReader::executeRemoteCall()
if (m_stop) if (m_stop)
return; return;
const QByteArray remoteCall("source ./.profile;source /etc/profile;env"); const QByteArray remoteCall("test -f /etc/profile && source /etc/profile; "
"test -f ~/.profile && source ~/.profile; env");
m_remoteProcess = m_connection->createRemoteProcess(remoteCall); m_remoteProcess = m_connection->createRemoteProcess(remoteCall);
connect(m_remoteProcess.data(), SIGNAL(closed(int)), this, connect(m_remoteProcess.data(), SIGNAL(closed(int)), this,

View File

@@ -40,7 +40,6 @@
#include <projectexplorer/environment.h> #include <projectexplorer/environment.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QPointer>
namespace Core { namespace Core {
class SshConnection; class SshConnection;
@@ -83,7 +82,6 @@ private:
bool m_stop; bool m_stop;
QString m_remoteOutput; QString m_remoteOutput;
ProjectExplorer::Environment m_env; ProjectExplorer::Environment m_env;
QPointer<MaemoRunConfiguration> m_runConfig;
MaemoDeviceConfig m_devConfig; MaemoDeviceConfig m_devConfig;
QSharedPointer<Core::SshConnection> m_connection; QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_remoteProcess; QSharedPointer<Core::SshRemoteProcess> m_remoteProcess;

View File

@@ -63,6 +63,7 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
const QString &proFilePath) const QString &proFilePath)
: RunConfiguration(parent, QLatin1String(MAEMO_RC_ID)) : RunConfiguration(parent, QLatin1String(MAEMO_RC_ID))
, m_proFilePath(proFilePath) , m_proFilePath(proFilePath)
, m_baseEnvironmentBase(SystemEnvironmentBase)
{ {
init(); init();
} }
@@ -73,6 +74,9 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
, m_proFilePath(source->m_proFilePath) , m_proFilePath(source->m_proFilePath)
, m_gdbPath(source->m_gdbPath) , m_gdbPath(source->m_gdbPath)
, m_arguments(source->m_arguments) , m_arguments(source->m_arguments)
, m_baseEnvironmentBase(source->m_baseEnvironmentBase)
, m_systemEnvironment(source->m_systemEnvironment)
, m_userEnvironmentChanges(source->m_userEnvironmentChanges)
{ {
init(); init();
} }
@@ -140,6 +144,9 @@ QVariantMap MaemoRunConfiguration::toMap() const
const QDir dir = QDir(target()->project()->projectDirectory()); const QDir dir = QDir(target()->project()->projectDirectory());
map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath)); map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
map.insert(HostAddressFromDeviceKey, m_hostAddressFromDevice); map.insert(HostAddressFromDeviceKey, m_hostAddressFromDevice);
map.insert(BaseEnvironmentBaseKey, m_baseEnvironmentBase);
map.insert(UserEnvironmentChangesKey,
ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
map.unite(m_devConfigModel->toMap()); map.unite(m_devConfigModel->toMap());
map.unite(m_remoteMounts->toMap()); map.unite(m_remoteMounts->toMap());
return map; return map;
@@ -155,6 +162,11 @@ bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
m_proFilePath = dir.filePath(map.value(ProFileKey).toString()); m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
m_hostAddressFromDevice = map.value(HostAddressFromDeviceKey, m_hostAddressFromDevice = map.value(HostAddressFromDeviceKey,
DefaultHostAddress).toString(); DefaultHostAddress).toString();
m_userEnvironmentChanges =
ProjectExplorer::EnvironmentItem::fromStringList(map.value(UserEnvironmentChangesKey)
.toStringList());
m_baseEnvironmentBase = static_cast<BaseEnvironmentBase> (map.value(BaseEnvironmentBaseKey,
SystemEnvironmentBase).toInt());
m_devConfigModel->fromMap(map); m_devConfigModel->fromMap(map);
m_remoteMounts->fromMap(map); m_remoteMounts->fromMap(map);
@@ -275,5 +287,67 @@ void MaemoRunConfiguration::updateDeviceConfigurations()
emit deviceConfigurationChanged(target()); emit deviceConfigurationChanged(target());
} }
QString MaemoRunConfiguration::baseEnvironmentText() const
{
if (m_baseEnvironmentBase == CleanEnvironmentBase)
return tr("Clean Environment");
else if (m_baseEnvironmentBase == SystemEnvironmentBase)
return tr("System Environment");
return QString();
}
MaemoRunConfiguration::BaseEnvironmentBase MaemoRunConfiguration::baseEnvironmentBase() const
{
return m_baseEnvironmentBase;
}
void MaemoRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
if (m_baseEnvironmentBase != env) {
m_baseEnvironmentBase = env;
emit baseEnvironmentChanged();
}
}
ProjectExplorer::Environment MaemoRunConfiguration::environment() const
{
ProjectExplorer::Environment env = baseEnvironment();
env.modify(userEnvironmentChanges());
return env;
}
ProjectExplorer::Environment MaemoRunConfiguration::baseEnvironment() const
{
return (m_baseEnvironmentBase == SystemEnvironmentBase ? systemEnvironment()
: ProjectExplorer::Environment());
}
QList<ProjectExplorer::EnvironmentItem> MaemoRunConfiguration::userEnvironmentChanges() const
{
return m_userEnvironmentChanges;
}
void MaemoRunConfiguration::setUserEnvironmentChanges(
const QList<ProjectExplorer::EnvironmentItem> &diff)
{
if (m_userEnvironmentChanges != diff) {
m_userEnvironmentChanges = diff;
emit userEnvironmentChangesChanged(diff);
}
}
ProjectExplorer::Environment MaemoRunConfiguration::systemEnvironment() const
{
return m_systemEnvironment;
}
void MaemoRunConfiguration::setSystemEnvironment(const ProjectExplorer::Environment &environment)
{
if (m_systemEnvironment.size() == 0 || m_systemEnvironment != environment) {
m_systemEnvironment = environment;
emit systemEnvironmentChanged();
}
}
} // namespace Internal } // namespace Internal
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager

View File

@@ -34,6 +34,7 @@
#include "maemodeviceconfigurations.h" #include "maemodeviceconfigurations.h"
#include "maemodeployable.h" #include "maemodeployable.h"
#include <projectexplorer/environment.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
@@ -65,6 +66,11 @@ class MaemoRunConfiguration : public ProjectExplorer::RunConfiguration
friend class MaemoRunConfigurationFactory; friend class MaemoRunConfigurationFactory;
public: public:
enum BaseEnvironmentBase {
CleanEnvironmentBase = 0,
SystemEnvironmentBase = 1
};
MaemoRunConfiguration(Qt4Target *parent, const QString &proFilePath); MaemoRunConfiguration(Qt4Target *parent, const QString &proFilePath);
virtual ~MaemoRunConfiguration(); virtual ~MaemoRunConfiguration();
@@ -96,10 +102,27 @@ public:
virtual QVariantMap toMap() const; virtual QVariantMap toMap() const;
QString baseEnvironmentText() const;
BaseEnvironmentBase baseEnvironmentBase() const;
void setBaseEnvironmentBase(BaseEnvironmentBase env);
ProjectExplorer::Environment environment() const;
ProjectExplorer::Environment baseEnvironment() const;
QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges() const;
void setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff);
ProjectExplorer::Environment systemEnvironment() const;
void setSystemEnvironment(const ProjectExplorer::Environment &environment);
signals: signals:
void deviceConfigurationChanged(ProjectExplorer::Target *target); void deviceConfigurationChanged(ProjectExplorer::Target *target);
void targetInformationChanged() const; void targetInformationChanged() const;
void baseEnvironmentChanged();
void systemEnvironmentChanged();
void userEnvironmentChangesChanged(const QList<ProjectExplorer::EnvironmentItem> &diff);
protected: protected:
MaemoRunConfiguration(Qt4Target *parent, MaemoRunConfiguration *source); MaemoRunConfiguration(Qt4Target *parent, MaemoRunConfiguration *source);
virtual bool fromMap(const QVariantMap &map); virtual bool fromMap(const QVariantMap &map);
@@ -111,12 +134,17 @@ private slots:
private: private:
void init(); void init();
private:
QString m_proFilePath; QString m_proFilePath;
mutable QString m_gdbPath; mutable QString m_gdbPath;
MaemoDeviceConfigListModel *m_devConfigModel; MaemoDeviceConfigListModel *m_devConfigModel;
MaemoRemoteMountsModel *m_remoteMounts; MaemoRemoteMountsModel *m_remoteMounts;
QStringList m_arguments; QStringList m_arguments;
QString m_hostAddressFromDevice; QString m_hostAddressFromDevice;
BaseEnvironmentBase m_baseEnvironmentBase;
ProjectExplorer::Environment m_systemEnvironment;
QList<ProjectExplorer::EnvironmentItem> m_userEnvironmentChanges;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -63,6 +63,7 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
MaemoRunConfiguration *runConfiguration, QWidget *parent) MaemoRunConfiguration *runConfiguration, QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_runConfiguration(runConfiguration), m_runConfiguration(runConfiguration),
m_ignoreChange(false),
m_deviceEnvReader(new MaemoDeviceEnvReader(this, runConfiguration)) m_deviceEnvReader(new MaemoDeviceEnvReader(this, runConfiguration))
{ {
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -141,25 +142,20 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
baseEnvironmentLayout->setMargin(0); baseEnvironmentLayout->setMargin(0);
QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this); QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
baseEnvironmentLayout->addWidget(label); baseEnvironmentLayout->addWidget(label);
QComboBox *m_baseEnvironmentComboBox = new QComboBox(this); m_baseEnvironmentComboBox = new QComboBox(this);
m_baseEnvironmentComboBox->addItems(QStringList() << tr("Clean Environment") m_baseEnvironmentComboBox->addItems(QStringList() << tr("Clean Environment")
<< tr("System Environment")); << tr("System Environment"));
m_baseEnvironmentComboBox->setEnabled(false); m_baseEnvironmentComboBox->setCurrentIndex(m_runConfiguration->baseEnvironmentBase());
m_baseEnvironmentComboBox->setCurrentIndex(1); // TODO: see next
//m_baseEnvironmentComboBox->setCurrentIndex(rc->baseEnvironmentBase());
//connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
// this, SLOT(baseEnvironmentSelected(int)));
baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox); baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
m_fetchEnv = new QPushButton(tr("Fetch Device Environment")); m_fetchEnv = new QPushButton(tr("Fetch Device Environment"));
connect(m_fetchEnv, SIGNAL(pressed()), this, SLOT(fetchEnvironment()));
baseEnvironmentLayout->addStretch(10);
baseEnvironmentLayout->addWidget(m_fetchEnv); baseEnvironmentLayout->addWidget(m_fetchEnv);
baseEnvironmentLayout->addStretch(10);
m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget); m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
m_environmentWidget->setBaseEnvironment(m_deviceEnvReader->deviceEnvironment()); m_environmentWidget->setBaseEnvironment(m_deviceEnvReader->deviceEnvironment());
m_environmentWidget->setBaseEnvironmentText(tr("System Environment")); // TODO: see next m_environmentWidget->setBaseEnvironmentText(m_runConfiguration->baseEnvironmentText());
//m_environmentWidget->setBaseEnvironmentText(rc->baseEnvironmentText()); m_environmentWidget->setUserChanges(m_runConfiguration->userEnvironmentChanges());
// m_environmentWidget->setUserChanges(rc->userEnvironmentChanges());
mainLayout->addWidget(m_environmentWidget); mainLayout->addWidget(m_environmentWidget);
handleCurrentDeviceConfigChanged(); handleCurrentDeviceConfigChanged();
@@ -186,8 +182,20 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
connect(m_mountView->selectionModel(), connect(m_mountView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton())); SLOT(enableOrDisableRemoveButton()));
connect(m_deviceEnvReader, SIGNAL(finished()), this,
SLOT(fetchEnvironmentFinished())); connect(m_environmentWidget, SIGNAL(userChangesChanged()), this,
SLOT(userChangesEdited()));
connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(baseEnvironmentSelected(int)));
connect(m_runConfiguration, SIGNAL(baseEnvironmentChanged()),
this, SLOT(baseEnvironmentChanged()));
connect(m_runConfiguration, SIGNAL(systemEnvironmentChanged()),
this, SLOT(systemEnvironmentChanged()));
connect(m_runConfiguration,
SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
this, SLOT(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)));
connect(m_fetchEnv, SIGNAL(pressed()), this, SLOT(fetchEnvironment()));
connect(m_deviceEnvReader, SIGNAL(finished()), this, SLOT(fetchEnvironmentFinished()));
} }
void MaemoRunConfigurationWidget::configNameEdited(const QString &text) void MaemoRunConfigurationWidget::configNameEdited(const QString &text)
@@ -285,7 +293,46 @@ void MaemoRunConfigurationWidget::fetchEnvironment()
void MaemoRunConfigurationWidget::fetchEnvironmentFinished() void MaemoRunConfigurationWidget::fetchEnvironmentFinished()
{ {
m_fetchEnv->setEnabled(true); m_fetchEnv->setEnabled(true);
m_environmentWidget->setBaseEnvironment(m_deviceEnvReader->deviceEnvironment()); m_runConfiguration->setSystemEnvironment(m_deviceEnvReader->deviceEnvironment());
}
void MaemoRunConfigurationWidget::userChangesEdited()
{
m_ignoreChange = true;
m_runConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
m_ignoreChange = false;
}
void MaemoRunConfigurationWidget::baseEnvironmentSelected(int index)
{
m_ignoreChange = true;
m_runConfiguration->setBaseEnvironmentBase(MaemoRunConfiguration::BaseEnvironmentBase(index));
m_environmentWidget->setBaseEnvironment(m_runConfiguration->baseEnvironment());
m_environmentWidget->setBaseEnvironmentText(m_runConfiguration->baseEnvironmentText());
m_ignoreChange = false;
}
void MaemoRunConfigurationWidget::baseEnvironmentChanged()
{
if (m_ignoreChange)
return;
m_baseEnvironmentComboBox->setCurrentIndex(m_runConfiguration->baseEnvironmentBase());
m_environmentWidget->setBaseEnvironment(m_runConfiguration->baseEnvironment());
m_environmentWidget->setBaseEnvironmentText(m_runConfiguration->baseEnvironmentText());
}
void MaemoRunConfigurationWidget::systemEnvironmentChanged()
{
m_environmentWidget->setBaseEnvironment(m_runConfiguration->systemEnvironment());
}
void MaemoRunConfigurationWidget::userEnvironmentChangesChanged(const QList<ProjectExplorer::EnvironmentItem> &userChanges)
{
if (m_ignoreChange)
return;
m_environmentWidget->setUserChanges(userChanges);
} }
} // namespace Internal } // namespace Internal

View File

@@ -48,6 +48,7 @@ class QToolButton;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace ProjectExplorer { namespace ProjectExplorer {
struct EnvironmentItem;
class EnvironmentWidget; class EnvironmentWidget;
} }
@@ -78,6 +79,11 @@ private slots:
void handleHostAddressChanged(); void handleHostAddressChanged();
void fetchEnvironment(); void fetchEnvironment();
void fetchEnvironmentFinished(); void fetchEnvironmentFinished();
void userChangesEdited();
void baseEnvironmentSelected(int index);
void baseEnvironmentChanged();
void systemEnvironmentChanged();
void userEnvironmentChangesChanged(const QList<ProjectExplorer::EnvironmentItem> &userChanges);
private: private:
QLineEdit *m_configNameLineEdit; QLineEdit *m_configNameLineEdit;
@@ -89,7 +95,9 @@ private:
QToolButton *m_removeMountButton; QToolButton *m_removeMountButton;
MaemoRunConfiguration *m_runConfiguration; MaemoRunConfiguration *m_runConfiguration;
bool m_ignoreChange;
QPushButton *m_fetchEnv; QPushButton *m_fetchEnv;
QComboBox *m_baseEnvironmentComboBox;
MaemoDeviceEnvReader *m_deviceEnvReader; MaemoDeviceEnvReader *m_deviceEnvReader;
ProjectExplorer::EnvironmentWidget *m_environmentWidget; ProjectExplorer::EnvironmentWidget *m_environmentWidget;
}; };