Commit eb1336da authored by Christian Kandeler's avatar Christian Kandeler

RemoteLinux: Expose some currently internal classes.

This is needed in the short term to reverse the direction of
the dependency between this plugin and the analyzer.
It is expected that there'll be more users in the future.

Change-Id: I9603e8dfa70e442394ba5e8671c6353b65c46374
Reviewed-on: http://codereview.qt.nokia.com/266Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent e08b797e
......@@ -31,6 +31,7 @@
**************************************************************************/
#include "abstractlinuxdevicedeploystep.h"
#include "linuxdeviceconfigurations.h"
#include "maemoconstants.h"
#include "maemodeploystepwidget.h"
#include "maemopertargetdeviceconfigurationlistmodel.h"
......@@ -77,10 +78,10 @@ LinuxDeviceDeployStepHelper::~LinuxDeviceDeployStepHelper() {}
void LinuxDeviceDeployStepHelper::handleDeviceConfigurationsUpdated()
{
setDeviceConfig(MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
setDeviceConfig(LinuxDeviceConfigurations::instance()->internalId(m_deviceConfig));
}
void LinuxDeviceDeployStepHelper::setDeviceConfig(MaemoDeviceConfig::Id internalId)
void LinuxDeviceDeployStepHelper::setDeviceConfig(LinuxDeviceConfiguration::Id internalId)
{
m_deviceConfig = deployConfiguration()->deviceConfigModel()->find(internalId);
emit deviceConfigChanged();
......@@ -96,13 +97,13 @@ QVariantMap LinuxDeviceDeployStepHelper::toMap() const
{
QVariantMap map;
map.insert(DeviceIdKey,
MaemoDeviceConfigurations::instance()->internalId(m_deviceConfig));
LinuxDeviceConfigurations::instance()->internalId(m_deviceConfig));
return map;
}
bool LinuxDeviceDeployStepHelper::fromMap(const QVariantMap &map)
{
setDeviceConfig(map.value(DeviceIdKey, MaemoDeviceConfig::InvalidId).toULongLong());
setDeviceConfig(map.value(DeviceIdKey, LinuxDeviceConfiguration::InvalidId).toULongLong());
return true;
}
......
......@@ -32,7 +32,7 @@
#ifndef ABSTRACTLINUXDEVICEDEPLOYSTEP_H
#define ABSTRACTLINUXDEVICEDEPLOYSTEP_H
#include "maemodeviceconfigurations.h"
#include "linuxdeviceconfiguration.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QSharedPointer>
......@@ -52,8 +52,8 @@ public:
LinuxDeviceDeployStepHelper(Qt4MaemoDeployConfiguration *dc);
~LinuxDeviceDeployStepHelper();
QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
QSharedPointer<const MaemoDeviceConfig> cachedDeviceConfig() const { return m_cachedDeviceConfig; }
QSharedPointer<const LinuxDeviceConfiguration> deviceConfig() const { return m_deviceConfig; }
QSharedPointer<const LinuxDeviceConfiguration> cachedDeviceConfig() const { return m_cachedDeviceConfig; }
Qt4MaemoDeployConfiguration *deployConfiguration() const { return m_deployConfiguration; }
void setDeviceConfig(int i);
......@@ -66,11 +66,11 @@ signals:
void deviceConfigChanged();
private:
void setDeviceConfig(MaemoDeviceConfig::Id internalId);
void setDeviceConfig(LinuxDeviceConfiguration::Id internalId);
Q_SLOT void handleDeviceConfigurationsUpdated();
QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
QSharedPointer<const LinuxDeviceConfiguration> m_deviceConfig;
QSharedPointer<const LinuxDeviceConfiguration> m_cachedDeviceConfig;
Qt4MaemoDeployConfiguration * const m_deployConfiguration;
};
......
......@@ -248,7 +248,7 @@ void AbstractMaemoDeployStep::start()
m_hasError = false;
if (isDeploymentNeeded(helper().cachedDeviceConfig()->sshParameters().host)) {
if (helper().cachedDeviceConfig()->type() == MaemoDeviceConfig::Emulator
if (helper().cachedDeviceConfig()->type() == LinuxDeviceConfiguration::Emulator
&& !MaemoQemuManager::instance().qemuIsRunning()) {
MaemoQemuManager::instance().startRuntime();
raiseError(tr("Cannot deploy: Qemu was not running. "
......
......@@ -34,9 +34,9 @@
#define ABSTRACTMAEMODEPLOYSTEP_H
#include "abstractlinuxdevicedeploystep.h"
#include "linuxdeviceconfiguration.h"
#include "maemodeployable.h"
#include "maemodeployables.h"
#include "maemodeviceconfigurations.h"
#include <projectexplorer/buildstep.h>
......@@ -53,9 +53,10 @@ namespace Qt4ProjectManager { class Qt4BuildConfiguration; }
namespace Utils { class SshConnection; }
namespace RemoteLinux {
class LinuxDeviceConfiguration;
namespace Internal {
class AbstractMaemoPackageCreationStep;
class MaemoDeviceConfig;
class Qt4MaemoDeployConfiguration;
class AbstractMaemoDeployStep
......
......@@ -29,14 +29,13 @@
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef LINUXDEVICECONFIGURATION_H
#define LINUXDEVICECONFIGURATION_H
#ifndef MAEMODEVICECONFIGURATIONS_H
#define MAEMODEVICECONFIGURATIONS_H
#include "remotelinux_export.h"
#include <utils/ssh/sshconnection.h>
#include <QtCore/QAbstractListModel>
#include <QtCore/QList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
......@@ -45,10 +44,13 @@ QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace RemoteLinux {
namespace Internal {
class LinuxDeviceConfigurations;
}
class MaemoPortList
class REMOTELINUX_EXPORT PortList
{
public:
void addPort(int port);
......@@ -64,16 +66,16 @@ private:
};
class MaemoDeviceConfig
class REMOTELINUX_EXPORT LinuxDeviceConfiguration
{
friend class MaemoDeviceConfigurations;
friend class Internal::LinuxDeviceConfigurations;
public:
typedef QSharedPointer<const MaemoDeviceConfig> ConstPtr;
typedef QSharedPointer<const LinuxDeviceConfiguration> ConstPtr;
typedef quint64 Id;
enum OsVersion { Maemo5, Maemo6, Meego, GenericLinux };
enum DeviceType { Physical, Emulator };
MaemoPortList freePorts() const;
PortList freePorts() const;
Utils::SshConnectionParameters sshParameters() const { return m_sshParameters; }
QString name() const { return m_name; }
OsVersion osVersion() const { return m_osVersion; }
......@@ -92,16 +94,16 @@ public:
static const Id InvalidId;
private:
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
typedef QSharedPointer<LinuxDeviceConfiguration> Ptr;
MaemoDeviceConfig(const QString &name, OsVersion osVersion,
LinuxDeviceConfiguration(const QString &name, OsVersion osVersion,
DeviceType type, const Utils::SshConnectionParameters &sshParams,
Id &nextId);
MaemoDeviceConfig(const QSettings &settings, Id &nextId);
MaemoDeviceConfig(const ConstPtr &other);
LinuxDeviceConfiguration(const QSettings &settings, Id &nextId);
LinuxDeviceConfiguration(const ConstPtr &other);
MaemoDeviceConfig(const MaemoDeviceConfig &);
MaemoDeviceConfig &operator=(const MaemoDeviceConfig &);
LinuxDeviceConfiguration(const LinuxDeviceConfiguration &);
LinuxDeviceConfiguration &operator=(const LinuxDeviceConfiguration &);
static Ptr createHardwareConfig(const QString &name, OsVersion osVersion,
const QString &hostName, const QString &privateKeyFilePath, Id &nextId);
......@@ -129,66 +131,6 @@ private:
};
class MaemoDeviceConfigurations : public QAbstractListModel
{
Q_OBJECT
Q_DISABLE_COPY(MaemoDeviceConfigurations)
public:
static MaemoDeviceConfigurations *instance(QObject *parent = 0);
static void replaceInstance(const MaemoDeviceConfigurations *other);
static MaemoDeviceConfigurations *cloneInstance();
MaemoDeviceConfig::ConstPtr deviceAt(int index) const;
MaemoDeviceConfig::ConstPtr find(MaemoDeviceConfig::Id id) const;
MaemoDeviceConfig::ConstPtr defaultDeviceConfig(const MaemoDeviceConfig::OsVersion osVersion) const;
bool hasConfig(const QString &name) const;
int indexForInternalId(MaemoDeviceConfig::Id internalId) const;
MaemoDeviceConfig::Id internalId(MaemoDeviceConfig::ConstPtr devConf) const;
void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
void addHardwareDeviceConfiguration(const QString &name,
MaemoDeviceConfig::OsVersion osVersion, const QString &hostName,
const QString &privateKeyFilePath);
void addGenericLinuxConfigurationUsingPassword(const QString &name,
const QString &hostName, const QString &userName,
const QString &password);
void addGenericLinuxConfigurationUsingKey(const QString &name,
const QString &hostName, const QString &userName,
const QString &privateKeyFilePath);
void addEmulatorDeviceConfiguration(const QString &name,
MaemoDeviceConfig::OsVersion osVersion);
void removeConfiguration(int index);
void setConfigurationName(int i, const QString &name);
void setSshParameters(int i, const Utils::SshConnectionParameters &params);
void setPortsSpec(int i, const QString &portsSpec);
void setDefaultDevice(int index);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const;
signals:
void updated();
private:
MaemoDeviceConfigurations(QObject *parent);
void load();
void save();
static void copy(const MaemoDeviceConfigurations *source,
MaemoDeviceConfigurations *target, bool deep);
void addConfiguration(const MaemoDeviceConfig::Ptr &devConfig);
void ensureDefaultExists(MaemoDeviceConfig::OsVersion osVersion);
static MaemoDeviceConfigurations *m_instance;
MaemoDeviceConfig::Id m_nextId;
QList<MaemoDeviceConfig::Ptr> m_devConfigs;
QString m_defaultSshKeyFilePath;
};
} // namespace Internal
} // namespace RemoteLinux
#endif // MAEMODEVICECONFIGURATIONS_H
#endif // LINUXDEVICECONFIGURATION_H
/**************************************************************************
**
** 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 info@qt.nokia.com.
**
**************************************************************************/
#include "linuxdeviceconfigurations.h"
#include "maemoglobal.h"
#include <coreplugin/icore.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QSettings>
#include <QtCore/QStringBuilder>
#include <algorithm>
#include <cctype>
namespace RemoteLinux {
namespace Internal {
namespace {
const QLatin1String SettingsGroup("MaemoDeviceConfigs");
const QLatin1String IdCounterKey("IdCounter");
const QLatin1String ConfigListKey("ConfigList");
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
}
class DevConfNameMatcher
{
public:
DevConfNameMatcher(const QString &name) : m_name(name) {}
bool operator()(const LinuxDeviceConfiguration::ConstPtr &devConfig)
{
return devConfig->name() == m_name;
}
private:
const QString m_name;
};
LinuxDeviceConfigurations *LinuxDeviceConfigurations::instance(QObject *parent)
{
if (m_instance == 0) {
m_instance = new LinuxDeviceConfigurations(parent);
m_instance->load();
}
return m_instance;
}
void LinuxDeviceConfigurations::replaceInstance(const LinuxDeviceConfigurations *other)
{
Q_ASSERT(m_instance);
m_instance->beginResetModel();
copy(other, m_instance, false);
m_instance->save();
m_instance->endResetModel();
emit m_instance->updated();
}
LinuxDeviceConfigurations *LinuxDeviceConfigurations::cloneInstance()
{
LinuxDeviceConfigurations * const other = new LinuxDeviceConfigurations(0);
copy(m_instance, other, true);
return other;
}
void LinuxDeviceConfigurations::copy(const LinuxDeviceConfigurations *source,
LinuxDeviceConfigurations *target, bool deep)
{
if (deep) {
foreach (const LinuxDeviceConfiguration::ConstPtr &devConf, source->m_devConfigs)
target->m_devConfigs << LinuxDeviceConfiguration::create(devConf);
} else {
target->m_devConfigs = source->m_devConfigs;
}
target->m_defaultSshKeyFilePath = source->m_defaultSshKeyFilePath;
target->m_nextId = source->m_nextId;
}
void LinuxDeviceConfigurations::save()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(SettingsGroup);
settings->setValue(IdCounterKey, m_nextId);
settings->setValue(DefaultKeyFilePathKey, m_defaultSshKeyFilePath);
settings->beginWriteArray(ConfigListKey, m_devConfigs.count());
for (int i = 0; i < m_devConfigs.count(); ++i) {
settings->setArrayIndex(i);
m_devConfigs.at(i)->save(*settings);
}
settings->endArray();
settings->endGroup();
}
void LinuxDeviceConfigurations::addHardwareDeviceConfiguration(const QString &name,
LinuxDeviceConfiguration::OsVersion osVersion, const QString &hostName,
const QString &privateKeyFilePath)
{
const LinuxDeviceConfiguration::Ptr &devConf = LinuxDeviceConfiguration::createHardwareConfig(name,
osVersion, hostName, privateKeyFilePath, m_nextId);
addConfiguration(devConf);
}
void LinuxDeviceConfigurations::addGenericLinuxConfigurationUsingPassword(const QString &name,
const QString &hostName, const QString &userName, const QString &password)
{
const LinuxDeviceConfiguration::Ptr &devConf
= LinuxDeviceConfiguration::createGenericLinuxConfigUsingPassword(name,
hostName, userName, password, m_nextId);
addConfiguration(devConf);
}
void LinuxDeviceConfigurations::addGenericLinuxConfigurationUsingKey(const QString &name,
const QString &hostName, const QString &userName, const QString &privateKeyFilePath)
{
const LinuxDeviceConfiguration::Ptr &devConf = LinuxDeviceConfiguration::createGenericLinuxConfigUsingKey(name,
hostName, userName, privateKeyFilePath, m_nextId);
addConfiguration(devConf);
}
void LinuxDeviceConfigurations::addEmulatorDeviceConfiguration(const QString &name,
LinuxDeviceConfiguration::OsVersion osVersion)
{
const LinuxDeviceConfiguration::Ptr &devConf
= LinuxDeviceConfiguration::createEmulatorConfig(name, osVersion, m_nextId);
addConfiguration(devConf);
}
void LinuxDeviceConfigurations::addConfiguration(const LinuxDeviceConfiguration::Ptr &devConfig)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
if (!defaultDeviceConfig(devConfig->osVersion()))
devConfig->m_isDefault = true;
m_devConfigs << devConfig;
endInsertRows();
}
void LinuxDeviceConfigurations::removeConfiguration(int idx)
{
Q_ASSERT(idx >= 0 && idx < rowCount());
beginRemoveRows(QModelIndex(), idx, idx);
const bool wasDefault = deviceAt(idx)->m_isDefault;
const LinuxDeviceConfiguration::OsVersion osVersion = deviceAt(idx)->osVersion();
m_devConfigs.removeAt(idx);
endRemoveRows();
if (wasDefault) {
for (int i = 0; i < m_devConfigs.count(); ++i) {
if (deviceAt(i)->osVersion() == osVersion) {
m_devConfigs.at(i)->m_isDefault = true;
const QModelIndex changedIndex = index(i, 0);
emit dataChanged(changedIndex, changedIndex);
break;
}
}
}
}
void LinuxDeviceConfigurations::setConfigurationName(int i, const QString &name)
{
Q_ASSERT(i >= 0 && i < rowCount());
m_devConfigs.at(i)->m_name = name;
const QModelIndex changedIndex = index(i, 0);
emit dataChanged(changedIndex, changedIndex);
}
void LinuxDeviceConfigurations::setSshParameters(int i,
const Utils::SshConnectionParameters &params)
{
Q_ASSERT(i >= 0 && i < rowCount());
m_devConfigs.at(i)->m_sshParameters = params;
}
void LinuxDeviceConfigurations::setPortsSpec(int i, const QString &portsSpec)
{
Q_ASSERT(i >= 0 && i < rowCount());
m_devConfigs.at(i)->m_portsSpec = portsSpec;
}
void LinuxDeviceConfigurations::setDefaultDevice(int idx)
{
Q_ASSERT(idx >= 0 && idx < rowCount());
const LinuxDeviceConfiguration::Ptr &devConf = m_devConfigs.at(idx);
if (devConf->m_isDefault)
return;
QModelIndex oldDefaultIndex;
for (int i = 0; i < m_devConfigs.count(); ++i) {
const LinuxDeviceConfiguration::Ptr &oldDefaultDev = m_devConfigs.at(i);
if (oldDefaultDev->m_isDefault
&& oldDefaultDev->osVersion() == devConf->osVersion()) {
oldDefaultDev->m_isDefault = false;
oldDefaultIndex = index(i, 0);
break;
}
}
Q_ASSERT(oldDefaultIndex.isValid());
emit dataChanged(oldDefaultIndex, oldDefaultIndex);
devConf->m_isDefault = true;
const QModelIndex newDefaultIndex = index(idx, 0);
emit dataChanged(newDefaultIndex, newDefaultIndex);
}
LinuxDeviceConfigurations::LinuxDeviceConfigurations(QObject *parent)
: QAbstractListModel(parent)
{
}
void LinuxDeviceConfigurations::load()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(SettingsGroup);
m_nextId = settings->value(IdCounterKey, 1).toULongLong();
m_defaultSshKeyFilePath = settings->value(DefaultKeyFilePathKey,
LinuxDeviceConfiguration::defaultPrivateKeyFilePath()).toString();
int count = settings->beginReadArray(ConfigListKey);
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
LinuxDeviceConfiguration::Ptr devConf
= LinuxDeviceConfiguration::create(*settings, m_nextId);
m_devConfigs << devConf;
}
settings->endArray();
settings->endGroup();
ensureDefaultExists(LinuxDeviceConfiguration::Maemo5);
ensureDefaultExists(LinuxDeviceConfiguration::Maemo6);
ensureDefaultExists(LinuxDeviceConfiguration::Meego);
ensureDefaultExists(LinuxDeviceConfiguration::GenericLinux);
}
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::deviceAt(int idx) const
{
Q_ASSERT(idx >= 0 && idx < rowCount());
return m_devConfigs.at(idx);
}
bool LinuxDeviceConfigurations::hasConfig(const QString &name) const
{
QList<LinuxDeviceConfiguration::Ptr>::ConstIterator resultIt =
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
DevConfNameMatcher(name));
return resultIt != m_devConfigs.constEnd();
}
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::find(LinuxDeviceConfiguration::Id id) const
{
const int index = indexForInternalId(id);
return index == -1 ? LinuxDeviceConfiguration::ConstPtr() : deviceAt(index);
}
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::defaultDeviceConfig(const LinuxDeviceConfiguration::OsVersion osVersion) const
{
foreach (const LinuxDeviceConfiguration::ConstPtr &devConf, m_devConfigs) {
if (devConf->m_isDefault && devConf->osVersion() == osVersion)
return devConf;
}
return LinuxDeviceConfiguration::ConstPtr();
}
int LinuxDeviceConfigurations::indexForInternalId(LinuxDeviceConfiguration::Id internalId) const
{
for (int i = 0; i < m_devConfigs.count(); ++i) {
if (deviceAt(i)->m_internalId == internalId)
return i;
}
return -1;
}
LinuxDeviceConfiguration::Id LinuxDeviceConfigurations::internalId(LinuxDeviceConfiguration::ConstPtr devConf) const
{
return devConf ? devConf->m_internalId : LinuxDeviceConfiguration::InvalidId;
}
void LinuxDeviceConfigurations::ensureDefaultExists(LinuxDeviceConfiguration::OsVersion osVersion)
{
if (!defaultDeviceConfig(osVersion)) {
foreach (const LinuxDeviceConfiguration::Ptr &devConf, m_devConfigs) {
if (devConf->osVersion() == osVersion) {
devConf->m_isDefault = true;
break;
}
}
}
}
int LinuxDeviceConfigurations::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_devConfigs.count();
}