Commit 0d079a63 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

RemoteLinux: Use toMap() and fromMap() to serialize device info.



One more step towards extracting an abstract base device class.
Note that the device settings now go into a dedicated file, like
the Qt version and toolchain information, and no longer into the
QtCreator.ini file. Reading the "old style" settings is still
supported.

Change-Id: Ic4766420930c1ab650d72068d3f6d188aa9c203b
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 709f24b0
......@@ -94,6 +94,7 @@ LinuxDeviceConfiguration::~LinuxDeviceConfiguration()
delete d;
}
// TODO: For pre-2.6 versions. Remove in 2.8.
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QSettings &settings)
{
return Ptr(new LinuxDeviceConfiguration(settings));
......@@ -109,7 +110,12 @@ LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &na
const SshConnectionParameters &sshParams, const QVariantHash &attributes, Origin origin)
{
return Ptr(new LinuxDeviceConfiguration(name, osType, deviceType, freePorts, sshParams,
attributes, origin));
attributes, origin));
}
LinuxDeviceConfiguration::LinuxDeviceConfiguration()
: d(new LinuxDeviceConfigurationPrivate(SshConnectionParameters(SshConnectionParameters::NoProxy)))
{
}
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QString &osType,
......@@ -125,6 +131,7 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QS
d->attributes = attributes;
}
// TODO: For pre-2.6 versions. Remove in 2.8.
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QSettings &settings)
: d(new LinuxDeviceConfigurationPrivate(SshConnectionParameters::NoProxy))
{
......@@ -181,21 +188,56 @@ QString LinuxDeviceConfiguration::defaultPublicKeyFilePath()
return defaultPrivateKeyFilePath() + QLatin1String(".pub");
}
void LinuxDeviceConfiguration::save(QSettings &settings) const
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create()
{
return Ptr(new LinuxDeviceConfiguration);
}
void LinuxDeviceConfiguration::fromMap(const QVariantMap &map)
{
settings.setValue(NameKey, d->displayName);
settings.setValue(OsTypeKey, d->osType);
settings.setValue(TypeKey, d->deviceType);
settings.setValue(HostKey, d->sshParameters.host);
settings.setValue(SshPortKey, d->sshParameters.port);
settings.setValue(PortsSpecKey, d->freePorts.toString());
settings.setValue(UserNameKey, d->sshParameters.userName);
settings.setValue(AuthKey, d->sshParameters.authenticationType);
settings.setValue(PasswordKey, d->sshParameters.password);
settings.setValue(KeyFileKey, d->sshParameters.privateKeyFile);
settings.setValue(TimeoutKey, d->sshParameters.timeout);
settings.setValue(InternalIdKey, d->internalId);
settings.setValue(AttributesKey, d->attributes);
d->origin = ManuallyAdded;
d->displayName = map.value(NameKey).toString();
d->osType = map.value(OsTypeKey).toString();
d->deviceType = static_cast<DeviceType>(map.value(TypeKey, DefaultDeviceType).toInt());
d->internalId = map.value(InternalIdKey, InvalidId).toULongLong();
const QVariantMap attrMap = map.value(AttributesKey).toMap();
for (QVariantMap::ConstIterator it = attrMap.constBegin(); it != attrMap.constEnd(); ++it)
d->attributes.insert(it.key(), it.value());
d->freePorts = PortList::fromString(map.value(PortsSpecKey,
QLatin1String("10000-10100")).toString());
d->sshParameters.host = map.value(HostKey).toString();
d->sshParameters.port = map.value(SshPortKey, 22).toInt();
d->sshParameters.userName = map.value(UserNameKey).toString();
d->sshParameters.authenticationType
= static_cast<AuthType>(map.value(AuthKey, DefaultAuthType).toInt());
d->sshParameters.password = map.value(PasswordKey).toString();
d->sshParameters.privateKeyFile = map.value(KeyFileKey, defaultPrivateKeyFilePath()).toString();
d->sshParameters.timeout = map.value(TimeoutKey, DefaultTimeout).toInt();
}
QVariantMap LinuxDeviceConfiguration::toMap() const
{
QVariantMap map;
map.insert(NameKey, d->displayName);
map.insert(OsTypeKey, d->osType);
map.insert(TypeKey, d->deviceType);
map.insert(HostKey, d->sshParameters.host);
map.insert(SshPortKey, d->sshParameters.port);
map.insert(PortsSpecKey, d->freePorts.toString());
map.insert(UserNameKey, d->sshParameters.userName);
map.insert(AuthKey, d->sshParameters.authenticationType);
map.insert(PasswordKey, d->sshParameters.password);
map.insert(KeyFileKey, d->sshParameters.privateKeyFile);
map.insert(TimeoutKey, d->sshParameters.timeout);
map.insert(InternalIdKey, d->internalId);
QVariantMap attrMap;
for (QVariantHash::ConstIterator it = d->attributes.constBegin();
it != d->attributes.constEnd(); ++it) {
attrMap.insert(it.key(), it.value());
}
map.insert(AttributesKey, attrMap);
return map;
}
SshConnectionParameters LinuxDeviceConfiguration::sshParameters() const
......
......@@ -38,6 +38,7 @@
#include <QString>
#include <QStringList>
#include <QVariantHash>
#include <QVariantMap>
#include <QWizard>
QT_BEGIN_NAMESPACE
......@@ -90,10 +91,12 @@ public:
static const Id InvalidId;
static Ptr create();
static Ptr create(const QString &name, const QString &osType, DeviceType deviceType,
const Utils::PortList &freePorts, const Utils::SshConnectionParameters &sshParams,
const QVariantHash &attributes = QVariantHash(), Origin origin = ManuallyAdded);
private:
LinuxDeviceConfiguration();
LinuxDeviceConfiguration(const QString &name, const QString &osType, DeviceType deviceType,
const Utils::PortList &freePorts, const Utils::SshConnectionParameters &sshParams,
const QVariantHash &attributes, Origin origin);
......@@ -109,7 +112,9 @@ private:
void setDisplayName(const QString &name);
void setInternalId(Id id);
void setDefault(bool isDefault);
void save(QSettings &settings) const;
void fromMap(const QVariantMap &map);
QVariantMap toMap() const;
Internal::LinuxDeviceConfigurationPrivate *d;
};
......
......@@ -34,13 +34,18 @@
#include "remotelinuxutils.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <QHash>
#include <QList>
#include <QMainWindow>
#include <QSettings>
#include <QString>
#include <QVariantHash>
#include <QVariantList>
#include <algorithm>
#include <limits>
......@@ -48,11 +53,13 @@
namespace RemoteLinux {
namespace Internal {
const char FileFormatVersionKey[] = "DeviceManagerFileFormatVersion";
const char DeviceManagerKey[] = "DeviceManager";
const char DeviceListKey[] = "DeviceList";
const char DefaultKeyFilePathKey[] = "DefaultKeyFile";
const char DefaultDevicesKey[] = "DefaultDevices";
namespace {
const QLatin1String SettingsGroup("MaemoDeviceConfigs");
const QLatin1String ConfigListKey("ConfigList");
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
const char DefaultConfigsKey[] = "DefaultConfigs";
class DevConfNameMatcher
{
......@@ -141,31 +148,94 @@ void LinuxDeviceConfigurations::copy(const LinuxDeviceConfigurations *source,
}
void LinuxDeviceConfigurations::save()
{
Utils::PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(FileFormatVersionKey), 1);
writer.saveValue(QLatin1String(DeviceManagerKey), toMap());
writer.save(settingsFilePath(), QLatin1String("QtCreatorDevices"), Core::ICore::mainWindow());
}
void LinuxDeviceConfigurations::load()
{
Utils::PersistentSettingsReader reader;
if (reader.load(settingsFilePath())) {
const QVariantMap data = reader.restoreValues();
const int version = data.value(QLatin1String(FileFormatVersionKey), 0).toInt();
if (version < 1)
return;
fromMap(data.value(QLatin1String(DeviceManagerKey)).toMap());
} else {
loadPre2_6();
}
ensureOneDefaultConfigurationPerOsType();
}
void LinuxDeviceConfigurations::loadPre2_6()
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->setValue(DefaultKeyFilePathKey, d->defaultSshKeyFilePath);
QVariantHash defaultDevsHash;
for (QHash<QString, LinuxDeviceConfiguration::Id>::ConstIterator it = d->defaultConfigs.constBegin();
it != d->defaultConfigs.constEnd(); ++it) {
defaultDevsHash.insert(it.key(), it.value());
settings->beginGroup(QLatin1String("MaemoDeviceConfigs"));
d->defaultSshKeyFilePath = settings->value(QLatin1String(DefaultKeyFilePathKey),
LinuxDeviceConfiguration::defaultPrivateKeyFilePath()).toString();
const QVariantHash defaultDevsHash = settings->value(QLatin1String("DefaultConfigs")).toHash();
for (QVariantHash::ConstIterator it = defaultDevsHash.constBegin();
it != defaultDevsHash.constEnd(); ++it) {
d->defaultConfigs.insert(it.key(), it.value().toULongLong());
}
settings->setValue(QLatin1String(DefaultConfigsKey), defaultDevsHash);
settings->beginWriteArray(ConfigListKey);
int skippedCount = 0;
for (int i = 0; i < d->devConfigs.count(); ++i) {
const LinuxDeviceConfiguration::ConstPtr &devConf = d->devConfigs.at(i);
if (devConf->isAutoDetected()) {
++skippedCount;
} else {
settings->setArrayIndex(i-skippedCount);
devConf->save(*settings);
}
int count = settings->beginReadArray(QLatin1String("ConfigList"));
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
LinuxDeviceConfiguration::Ptr devConf = LinuxDeviceConfiguration::create(*settings);
if (devConf->internalId() == LinuxDeviceConfiguration::InvalidId)
devConf->setInternalId(unusedId());
d->devConfigs << devConf;
}
settings->endArray();
settings->endGroup();
}
void LinuxDeviceConfigurations::fromMap(const QVariantMap &map)
{
d->defaultSshKeyFilePath = map.value(QLatin1String(DefaultKeyFilePathKey),
LinuxDeviceConfiguration::defaultPrivateKeyFilePath()).toString();
const QVariantMap defaultDevsMap = map.value(QLatin1String(DefaultDevicesKey)).toMap();
for (QVariantMap::ConstIterator it = defaultDevsMap.constBegin();
it != defaultDevsMap.constEnd(); ++it) {
d->defaultConfigs.insert(it.key(), it.value().toULongLong());
}
const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList();
foreach (const QVariant &v, deviceList) {
LinuxDeviceConfiguration::Ptr device = LinuxDeviceConfiguration::create();
device->fromMap(v.toMap());
d->devConfigs << device;
}
}
QVariantMap LinuxDeviceConfigurations::toMap() const
{
QVariantMap map;
map.insert(QLatin1String(DefaultKeyFilePathKey), d->defaultSshKeyFilePath);
QVariantMap defaultDeviceMap;
typedef QHash<QString, LinuxDeviceConfiguration::Id> TypeIdHash;
for (TypeIdHash::ConstIterator it = d->defaultConfigs.constBegin();
it != d->defaultConfigs.constEnd(); ++it) {
defaultDeviceMap.insert(it.key(), it.value());
}
map.insert(QLatin1String(DefaultDevicesKey), defaultDeviceMap);
QVariantList deviceList;
foreach (const LinuxDeviceConfiguration::ConstPtr &device, d->devConfigs) {
if (!device->isAutoDetected())
deviceList << device->toMap();
}
map.insert(QLatin1String(DeviceListKey), deviceList);
return map;
}
QString LinuxDeviceConfigurations::settingsFilePath()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
return QFileInfo(pm->settings()->fileName()).absolutePath() + QLatin1String("/devices.xml");
}
void LinuxDeviceConfigurations::addConfiguration(const LinuxDeviceConfiguration::Ptr &devConfig)
{
QTC_ASSERT(this != LinuxDeviceConfigurationsPrivate::instance
......@@ -253,7 +323,7 @@ void LinuxDeviceConfigurations::setDefaultDevice(int idx)
const LinuxDeviceConfiguration::ConstPtr &devConf = d->devConfigs.at(idx);
const LinuxDeviceConfiguration::ConstPtr &oldDefaultDevConf
= defaultDeviceConfig(devConf->osType());
if (defaultDeviceConfig(devConf->osType()) == devConf)
if (devConf == oldDefaultDevConf)
return;
d->defaultConfigs.insert(devConf->osType(), devConf->internalId());
emit defaultStatusChanged(idx);
......@@ -283,30 +353,6 @@ LinuxDeviceConfigurations::~LinuxDeviceConfigurations()
delete d;
}
void LinuxDeviceConfigurations::load()
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
d->defaultSshKeyFilePath = settings->value(DefaultKeyFilePathKey,
LinuxDeviceConfiguration::defaultPrivateKeyFilePath()).toString();
const QVariantHash defaultDevsHash = settings->value(QLatin1String(DefaultConfigsKey)).toHash();
for (QVariantHash::ConstIterator it = defaultDevsHash.constBegin();
it != defaultDevsHash.constEnd(); ++it) {
d->defaultConfigs.insert(it.key(), it.value().toULongLong());
}
int count = settings->beginReadArray(ConfigListKey);
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
LinuxDeviceConfiguration::Ptr devConf = LinuxDeviceConfiguration::create(*settings);
if (devConf->internalId() == LinuxDeviceConfiguration::InvalidId)
devConf->setInternalId(unusedId());
d->devConfigs << devConf;
}
settings->endArray();
settings->endGroup();
ensureOneDefaultConfigurationPerOsType();
}
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::deviceAt(int idx) const
{
QTC_ASSERT(idx >= 0 && idx < deviceCount(), return LinuxDeviceConfiguration::ConstPtr());
......
......@@ -87,6 +87,11 @@ private:
void load();
void save();
void loadPre2_6();
void fromMap(const QVariantMap &map);
QVariantMap toMap() const;
static QString settingsFilePath();
static LinuxDeviceConfigurations *cloneInstance();
static void replaceInstance();
static void removeClonedInstance();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment