Commit 253f183d authored by Christian Kandeler's avatar Christian Kandeler

Maemo: Introduce abstract base class for deploy steps targeting devices.

This will make it possible for a MaemoRunConfiguration to work
with deploy steps that do not use Utils::SshConnection, but still
want to make use of our device configurations.
parent f0486a4b
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "abstractlinuxdevicedeploystep.h"
#include "maemoconstants.h"
#include "maemodeploystepwidget.h"
#include "maemopertargetdeviceconfigurationlistmodel.h"
#include "qt4maemodeployconfiguration.h"
using namespace ProjectExplorer;
namespace Qt4ProjectManager {
namespace Internal {
AbstractLinuxDeviceDeployStep::AbstractLinuxDeviceDeployStep(DeployConfiguration *dc)
: m_helper(qobject_cast<Qt4MaemoDeployConfiguration *>(dc))
{
}
bool AbstractLinuxDeviceDeployStep::isDeploymentPossible(QString &whyNot) const
{
if (!m_helper.deviceConfig()) {
whyNot = tr("No valid device set.");
return false;
}
return isDeploymentPossibleInternal(whyNot);
}
bool AbstractLinuxDeviceDeployStep::initialize(QString &errorMsg)
{
if (!isDeploymentPossible(errorMsg))
return false;
m_helper.prepareDeployment();
return true;
}
LinuxDeviceDeployStepHelper::LinuxDeviceDeployStepHelper(Qt4MaemoDeployConfiguration *dc)
: m_deployConfiguration(dc)
{
m_deviceConfig = dc->deviceConfigModel()->defaultDeviceConfig();
connect(dc->deviceConfigModel(), SIGNAL(updated()),
SLOT(handleDeviceConfigurationsUpdated()));
}
LinuxDeviceDeployStepHelper::~LinuxDeviceDeployStepHelper() {}
void LinuxDeviceDeployStepHelper::handleDeviceConfigurationsUpdated()
{
setDeviceConfig(MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
}
void LinuxDeviceDeployStepHelper::setDeviceConfig(MaemoDeviceConfig::Id internalId)
{
m_deviceConfig = deployConfiguration()->deviceConfigModel()->find(internalId);
emit deviceConfigChanged();
}
void LinuxDeviceDeployStepHelper::setDeviceConfig(int i)
{
m_deviceConfig = deployConfiguration()->deviceConfigModel()->deviceAt(i);
emit deviceConfigChanged();
}
QVariantMap LinuxDeviceDeployStepHelper::toMap() const
{
QVariantMap map;
map.insert(DeviceIdKey,
MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
return map;
}
bool LinuxDeviceDeployStepHelper::fromMap(const QVariantMap &map)
{
setDeviceConfig(map.value(DeviceIdKey, MaemoDeviceConfig::InvalidId).toULongLong());
return true;
}
} // namespace Internal
} // namespace Qt4ProjectManager
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef ABSTRACTLINUXDEVICEDEPLOYSTEP_H
#define ABSTRACTLINUXDEVICEDEPLOYSTEP_H
#include "maemodeviceconfigurations.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QSharedPointer>
#include <QtCore/QVariantMap>
namespace ProjectExplorer { class DeployConfiguration; }
namespace Qt4ProjectManager {
namespace Internal {
class Qt4MaemoDeployConfiguration;
class LinuxDeviceDeployStepHelper : public QObject
{
Q_OBJECT
public:
LinuxDeviceDeployStepHelper(Qt4MaemoDeployConfiguration *dc);
~LinuxDeviceDeployStepHelper();
QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
QSharedPointer<const MaemoDeviceConfig> cachedDeviceConfig() const { return m_cachedDeviceConfig; }
Qt4MaemoDeployConfiguration *deployConfiguration() const { return m_deployConfiguration; }
void setDeviceConfig(int i);
void prepareDeployment() { m_cachedDeviceConfig = m_deviceConfig; }
QVariantMap toMap() const;
bool fromMap(const QVariantMap &map);
signals:
void deviceConfigChanged();
private:
void setDeviceConfig(MaemoDeviceConfig::Id internalId);
Q_SLOT void handleDeviceConfigurationsUpdated();
QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
Qt4MaemoDeployConfiguration * const m_deployConfiguration;
};
class AbstractLinuxDeviceDeployStep
{
Q_DECLARE_TR_FUNCTIONS(AbstractLinuxDeviceDeployStep)
public:
virtual ~AbstractLinuxDeviceDeployStep() {}
Qt4MaemoDeployConfiguration *maemoDeployConfig() const { return m_helper.deployConfiguration(); }
bool isDeploymentPossible(QString &whyNot) const;
LinuxDeviceDeployStepHelper &helper() { return m_helper; }
const LinuxDeviceDeployStepHelper &helper() const { return m_helper; }
protected:
AbstractLinuxDeviceDeployStep(ProjectExplorer::DeployConfiguration *dc);
bool initialize(QString &errorMsg);
private:
virtual bool isDeploymentPossibleInternal(QString &whynot) const=0;
LinuxDeviceDeployStepHelper m_helper;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // ABSTRACTLINUXDEVICEDEPLOYSTEP_H
......@@ -87,14 +87,18 @@ private:
AbstractMaemoDeployStep::AbstractMaemoDeployStep(BuildStepList *parent,
const QString &id) : BuildStep(parent, id)
const QString &id)
: BuildStep(parent, id),
AbstractLinuxDeviceDeployStep(deployConfiguration())
{
baseCtor();
}
AbstractMaemoDeployStep::AbstractMaemoDeployStep(BuildStepList *parent,
AbstractMaemoDeployStep *other)
: BuildStep(parent, other), m_lastDeployed(other->m_lastDeployed)
AbstractMaemoDeployStep *other)
: BuildStep(parent, other),
AbstractLinuxDeviceDeployStep(deployConfiguration()),
m_lastDeployed(other->m_lastDeployed)
{
baseCtor();
}
......@@ -104,9 +108,16 @@ AbstractMaemoDeployStep::~AbstractMaemoDeployStep() { }
void AbstractMaemoDeployStep::baseCtor()
{
m_baseState = BaseInactive;
m_deviceConfig = maemoDeployConfig()->deviceConfigModel()->defaultDeviceConfig();
connect(maemoDeployConfig()->deviceConfigModel(), SIGNAL(updated()),
SLOT(handleDeviceConfigurationsUpdated()));
}
bool AbstractMaemoDeployStep::init()
{
QString errorMsg;
if (!initialize(errorMsg)) {
writeOutput(errorMsg, ErrorMessageOutput);
return false;
}
return true;
}
void AbstractMaemoDeployStep::run(QFutureInterface<bool> &fi)
......@@ -126,8 +137,7 @@ QVariantMap AbstractMaemoDeployStep::toMap() const
{
QVariantMap map(BuildStep::toMap());
addDeployTimesToMap(map);
map.insert(DeviceIdKey,
MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
map.unite(helper().toMap());
return map;
}
......@@ -154,8 +164,9 @@ bool AbstractMaemoDeployStep::fromMap(const QVariantMap &map)
{
if (!BuildStep::fromMap(map))
return false;
if (!helper().fromMap(map))
return false;
getDeployTimesFromMap(map);
setDeviceConfig(map.value(DeviceIdKey, MaemoDeviceConfig::InvalidId).toULongLong());
return true;
}
......@@ -228,32 +239,6 @@ void AbstractMaemoDeployStep::setDeployed(const QString &host,
QDateTime::currentDateTime());
}
void AbstractMaemoDeployStep::handleDeviceConfigurationsUpdated()
{
setDeviceConfig(MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
}
void AbstractMaemoDeployStep::setDeviceConfig(MaemoDeviceConfig::Id internalId)
{
m_deviceConfig = maemoDeployConfig()->deviceConfigModel()->find(internalId);
emit deviceConfigChanged();
}
void AbstractMaemoDeployStep::setDeviceConfig(int i)
{
m_deviceConfig = maemoDeployConfig()->deviceConfigModel()->deviceAt(i);
emit deviceConfigChanged();
}
bool AbstractMaemoDeployStep::isDeploymentPossible(QString &whyNot) const
{
if (!m_deviceConfig) {
whyNot = tr("No valid device set.");
return false;
}
return isDeploymentPossibleInternal(whyNot);
}
void AbstractMaemoDeployStep::start()
{
if (m_baseState != BaseInactive) {
......@@ -262,18 +247,9 @@ void AbstractMaemoDeployStep::start()
return;
}
m_cachedDeviceConfig = m_deviceConfig;
QString message;
if (!isDeploymentPossible(message)) {
raiseError(tr("Cannot deploy: %1").arg(message));
emit done();
return;
}
m_hasError = false;
if (isDeploymentNeeded(m_cachedDeviceConfig->sshParameters().host)) {
if (m_cachedDeviceConfig->type() == MaemoDeviceConfig::Emulator
if (isDeploymentNeeded(helper().cachedDeviceConfig()->sshParameters().host)) {
if (helper().cachedDeviceConfig()->type() == MaemoDeviceConfig::Emulator
&& !MaemoQemuManager::instance().qemuIsRunning()) {
MaemoQemuManager::instance().startRuntime();
raiseError(tr("Cannot deploy: Qemu was not running. "
......@@ -296,7 +272,7 @@ void AbstractMaemoDeployStep::handleConnectionFailure()
return;
const QString errorMsg = m_baseState == Connecting
? MaemoGlobal::failedToConnectToServerMessage(m_connection, m_cachedDeviceConfig)
? MaemoGlobal::failedToConnectToServerMessage(m_connection, helper().cachedDeviceConfig())
: tr("Connection error: %1").arg(m_connection->errorString());
raiseError(errorMsg);
setDeploymentFinished();
......@@ -307,7 +283,7 @@ void AbstractMaemoDeployStep::connectToDevice()
ASSERT_STATE(QList<BaseState>() << BaseInactive);
setBaseState(Connecting);
m_connection = SshConnectionManager::instance().acquireConnection(m_cachedDeviceConfig->sshParameters());
m_connection = SshConnectionManager::instance().acquireConnection(helper().cachedDeviceConfig()->sshParameters());
connect(m_connection.data(), SIGNAL(error(Utils::SshError)), this,
SLOT(handleConnectionFailure()));
if (m_connection->state() == SshConnection::Connected) {
......@@ -407,11 +383,6 @@ const Qt4BuildConfiguration *AbstractMaemoDeployStep::qt4BuildConfiguration() co
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}
Qt4MaemoDeployConfiguration *AbstractMaemoDeployStep::maemoDeployConfig() const
{
return qobject_cast<Qt4MaemoDeployConfiguration *>(deployConfiguration());
}
MaemoDeployEventHandler::MaemoDeployEventHandler(AbstractMaemoDeployStep *deployStep,
QFutureInterface<bool> &future)
: m_deployStep(deployStep), m_future(future), m_eventLoop(new QEventLoop),
......
......@@ -34,6 +34,7 @@
#ifndef ABSTRACTMAEMODEPLOYSTEP_H
#define ABSTRACTMAEMODEPLOYSTEP_H
#include "abstractlinuxdevicedeploystep.h"
#include "maemodeployable.h"
#include "maemodeployables.h"
#include "maemodeviceconfigurations.h"
......@@ -58,22 +59,18 @@ class AbstractMaemoPackageCreationStep;
class MaemoDeviceConfig;
class Qt4MaemoDeployConfiguration;
class AbstractMaemoDeployStep : public ProjectExplorer::BuildStep
class AbstractMaemoDeployStep
: public ProjectExplorer::BuildStep, public AbstractLinuxDeviceDeployStep
{
Q_OBJECT
public:
virtual ~AbstractMaemoDeployStep();
QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
void setDeviceConfig(int i);
Qt4MaemoDeployConfiguration *maemoDeployConfig() const;
bool isDeploymentPossible(QString &whyNot) const;
Q_INVOKABLE void stop();
signals:
void done();
void error();
void deviceConfigChanged();
protected:
AbstractMaemoDeployStep(ProjectExplorer::BuildStepList *bc,
......@@ -98,7 +95,6 @@ protected:
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
MaemoPortList freePorts(const QSharedPointer<const MaemoDeviceConfig> &devConfig) const;
QSharedPointer<Utils::SshConnection> connection() const { return m_connection; }
QSharedPointer<const MaemoDeviceConfig> cachedDeviceConfig() const { return m_cachedDeviceConfig; }
private slots:
void start();
......@@ -107,16 +103,14 @@ private slots:
void handleProgressReport(const QString &progressMsg);
void handleRemoteStdout(const QString &output);
void handleRemoteStderr(const QString &output);
void handleDeviceConfigurationsUpdated();
private:
virtual bool init() { return true; }
virtual bool init();
virtual void run(QFutureInterface<bool> &fi);
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual QVariantMap toMap() const;
virtual bool fromMap(const QVariantMap &map);
virtual bool isDeploymentPossibleInternal(QString &whynot) const=0;
virtual bool isDeploymentNeeded(const QString &hostName) const=0;
virtual void startInternal()=0;
virtual void stopInternal()=0;
......@@ -126,13 +120,10 @@ private:
void getDeployTimesFromMap(const QVariantMap &map);
void connectToDevice();
void setBaseState(BaseState newState);
void setDeviceConfig(MaemoDeviceConfig::Id internalId);
QSharedPointer<Utils::SshConnection> m_connection;
typedef QPair<MaemoDeployable, QString> DeployablePerHost;
QHash<DeployablePerHost, QDateTime> m_lastDeployed;
QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
BaseState m_baseState;
bool m_hasError;
};
......
......@@ -31,7 +31,6 @@
#include "maemodebugsupport.h"
#include "abstractmaemodeploystep.h"
#include "maemodeployables.h"
#include "maemoglobal.h"
#include "maemosshrunner.h"
......
......@@ -154,7 +154,7 @@ void AbstractMaemoDeployByMountStep::mount()
{
m_extendedState = Mounting;
m_mounter->setupMounts(connection(), mountSpecifications(),
freePorts(cachedDeviceConfig()), qt4BuildConfiguration());
freePorts(helper().cachedDeviceConfig()), qt4BuildConfiguration());
}
QString AbstractMaemoDeployByMountStep::deployMountPoint() const
......
......@@ -33,7 +33,7 @@
#include "maemodeploystepwidget.h"
#include "ui_maemodeploystepwidget.h"
#include "abstractmaemodeploystep.h"
#include "abstractlinuxdevicedeploystep.h"
#include "maemodeviceconfigurations.h"
#include "maemosettingspages.h"
#include "maemoglobal.h"
......@@ -51,14 +51,14 @@
namespace Qt4ProjectManager {
namespace Internal {
MaemoDeployStepWidget::MaemoDeployStepWidget(AbstractMaemoDeployStep *step) :
MaemoDeployStepWidget::MaemoDeployStepWidget(AbstractLinuxDeviceDeployStep *step) :
ProjectExplorer::BuildStepConfigWidget(),
ui(new Ui::MaemoDeployStepWidget),
m_step(step)
{
ui->setupUi(this);
ProjectExplorer::BuildStepList * const list
= qobject_cast<ProjectExplorer::BuildStepList *>(step->parent());
= step->maemoDeployConfig()->stepList();
connect(list, SIGNAL(stepInserted(int)), SIGNAL(updateSummary()));
connect(list, SIGNAL(stepMoved(int,int)), SIGNAL(updateSummary()));
connect(list, SIGNAL(stepRemoved(int)), SIGNAL(updateSummary()));
......@@ -74,7 +74,8 @@ MaemoDeployStepWidget::~MaemoDeployStepWidget()
void MaemoDeployStepWidget::init()
{
ui->deviceConfigComboBox->setModel(m_step->maemoDeployConfig()->deviceConfigModel());
connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
connect(&m_step->helper(), SIGNAL(deviceConfigChanged()),
SLOT(handleDeviceUpdate()));
handleDeviceUpdate();
connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
SLOT(setCurrentDeviceConfig(int)));
......@@ -84,7 +85,7 @@ void MaemoDeployStepWidget::init()
void MaemoDeployStepWidget::handleDeviceUpdate()
{
const MaemoDeviceConfig::ConstPtr &devConf = m_step->deviceConfig();
const MaemoDeviceConfig::ConstPtr &devConf = m_step->helper().deviceConfig();
const MaemoDeviceConfig::Id internalId
= MaemoDeviceConfigurations::instance()->internalId(devConf);
const int newIndex = m_step->maemoDeployConfig()->deviceConfigModel()
......@@ -96,8 +97,10 @@ void MaemoDeployStepWidget::handleDeviceUpdate()
void MaemoDeployStepWidget::handleStepToBeRemoved(int step)
{
ProjectExplorer::BuildStepList * const list
= qobject_cast<ProjectExplorer::BuildStepList *>(m_step->parent());
if (list->steps().at(step) == m_step)
= m_step->maemoDeployConfig()->stepList();
const AbstractLinuxDeviceDeployStep * const alds
= dynamic_cast<AbstractLinuxDeviceDeployStep *>(list->steps().at(step));
if (alds && alds == m_step)
disconnect(list, 0, this, 0);
}
......@@ -110,7 +113,7 @@ QString MaemoDeployStepWidget::summaryText() const
+ QLatin1String("</font>");
}
return tr("<b>Deploy to device</b>: %1")
.arg(MaemoGlobal::deviceConfigurationName(m_step->deviceConfig()));
.arg(MaemoGlobal::deviceConfigurationName(m_step->helper().deviceConfig()));
}
QString MaemoDeployStepWidget::displayName() const
......@@ -120,10 +123,11 @@ QString MaemoDeployStepWidget::displayName() const
void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
{
disconnect(m_step, SIGNAL(deviceConfigChanged()), this,
disconnect(&m_step->helper(), SIGNAL(deviceConfigChanged()), this,
SLOT(handleDeviceUpdate()));
m_step->helper().setDeviceConfig(index);
connect(&m_step->helper(), SIGNAL(deviceConfigChanged()),
SLOT(handleDeviceUpdate()));
m_step->setDeviceConfig(index);
connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
updateSummary();
}
......
......@@ -43,14 +43,14 @@ QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class AbstractMaemoDeployStep;
class AbstractLinuxDeviceDeployStep;
class MaemoDeployStepWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
MaemoDeployStepWidget(AbstractMaemoDeployStep *step);
MaemoDeployStepWidget(AbstractLinuxDeviceDeployStep *step);
~MaemoDeployStepWidget();
private:
......@@ -64,7 +64,7 @@ private:
virtual QString displayName() const;
Ui::MaemoDeployStepWidget *ui;
AbstractMaemoDeployStep * const m_step;
AbstractLinuxDeviceDeployStep *const m_step;
};
} // namespace Internal
......
......@@ -153,7 +153,7 @@ void MaemoDirectDeviceUploadStep::handleMkdirFinished(int exitStatus)
raiseError(tr("Failed to upload file '%1'.").arg(nativePath));
setFinished();
} else if (fi.isDir()) {
setDeployed(cachedDeviceConfig()->sshParameters().host, d);
setDeployed(helper().cachedDeviceConfig()->sshParameters().host, d);
m_filesToUpload.removeFirst();
uploadNextFile();
} else {
......
......@@ -130,7 +130,7 @@ public:
for (int i = 0; i < buildSteps.count(); ++i) {
if (buildSteps.at(i) == laterBuildStep)
return 0;
if (T * const step = qobject_cast<T *>(buildSteps.at(i)))
if (T * const step = dynamic_cast<T *>(buildSteps.at(i)))
return step;
}
return 0;
......
......@@ -32,7 +32,7 @@
#include "maemorunconfiguration.h"
#include "abstractmaemodeploystep.h"
#include "abstractlinuxdevicedeploystep.h"
#include "maemodeployables.h"
#include "maemoglobal.h"
#include "maemoqemumanager.h"
......@@ -213,8 +213,8 @@ QString MaemoRunConfiguration::defaultDisplayName()
MaemoDeviceConfig::ConstPtr MaemoRunConfiguration::deviceConfig() const
{
const AbstractMaemoDeployStep * const step = deployStep();
return step ? st