forked from qt-creator/qt-creator
RemoteLinux: Move "is default" status out of the device configuration.
The information about which device is the default one is by definition "global" and therefore does not belong into the device configurations themselves. Change-Id: Ib7349aac4663a674fac5bf35c4d128aeb53fbec2 Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
@@ -59,7 +59,6 @@ const QLatin1String AuthKey("Authentication");
|
|||||||
const QLatin1String KeyFileKey("KeyFile");
|
const QLatin1String KeyFileKey("KeyFile");
|
||||||
const QLatin1String PasswordKey("Password");
|
const QLatin1String PasswordKey("Password");
|
||||||
const QLatin1String TimeoutKey("Timeout");
|
const QLatin1String TimeoutKey("Timeout");
|
||||||
const QLatin1String IsDefaultKey("IsDefault");
|
|
||||||
const QLatin1String InternalIdKey("InternalId");
|
const QLatin1String InternalIdKey("InternalId");
|
||||||
const QLatin1String AttributesKey("Attributes");
|
const QLatin1String AttributesKey("Attributes");
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ public:
|
|||||||
QString osType;
|
QString osType;
|
||||||
LinuxDeviceConfiguration::DeviceType deviceType;
|
LinuxDeviceConfiguration::DeviceType deviceType;
|
||||||
PortList freePorts;
|
PortList freePorts;
|
||||||
bool isDefault;
|
|
||||||
LinuxDeviceConfiguration::Origin origin;
|
LinuxDeviceConfiguration::Origin origin;
|
||||||
LinuxDeviceConfiguration::Id internalId;
|
LinuxDeviceConfiguration::Id internalId;
|
||||||
QVariantHash attributes;
|
QVariantHash attributes;
|
||||||
@@ -124,7 +122,6 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QS
|
|||||||
d->osType = osType;
|
d->osType = osType;
|
||||||
d->deviceType = deviceType;
|
d->deviceType = deviceType;
|
||||||
d->freePorts = freePorts;
|
d->freePorts = freePorts;
|
||||||
d->isDefault = false;
|
|
||||||
d->origin = origin;
|
d->origin = origin;
|
||||||
d->attributes = attributes;
|
d->attributes = attributes;
|
||||||
}
|
}
|
||||||
@@ -136,7 +133,6 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QSettings &settings, Id
|
|||||||
d->displayName = settings.value(NameKey).toString();
|
d->displayName = settings.value(NameKey).toString();
|
||||||
d->osType = settings.value(OsTypeKey).toString();
|
d->osType = settings.value(OsTypeKey).toString();
|
||||||
d->deviceType = static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt());
|
d->deviceType = static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt());
|
||||||
d->isDefault = settings.value(IsDefaultKey, false).toBool();
|
|
||||||
d->internalId = settings.value(InternalIdKey, nextId).toULongLong();
|
d->internalId = settings.value(InternalIdKey, nextId).toULongLong();
|
||||||
|
|
||||||
if (d->internalId == nextId)
|
if (d->internalId == nextId)
|
||||||
@@ -174,7 +170,6 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const LinuxDeviceConfiguratio
|
|||||||
d->osType = other->d->osType;
|
d->osType = other->d->osType;
|
||||||
d->deviceType = other->deviceType();
|
d->deviceType = other->deviceType();
|
||||||
d->freePorts = other->freePorts();
|
d->freePorts = other->freePorts();
|
||||||
d->isDefault = other->d->isDefault;
|
|
||||||
d->origin = other->d->origin;
|
d->origin = other->d->origin;
|
||||||
d->internalId = other->d->internalId;
|
d->internalId = other->d->internalId;
|
||||||
d->attributes = other->d->attributes;
|
d->attributes = other->d->attributes;
|
||||||
@@ -204,7 +199,6 @@ void LinuxDeviceConfiguration::save(QSettings &settings) const
|
|||||||
settings.setValue(PasswordKey, d->sshParameters.password);
|
settings.setValue(PasswordKey, d->sshParameters.password);
|
||||||
settings.setValue(KeyFileKey, d->sshParameters.privateKeyFile);
|
settings.setValue(KeyFileKey, d->sshParameters.privateKeyFile);
|
||||||
settings.setValue(TimeoutKey, d->sshParameters.timeout);
|
settings.setValue(TimeoutKey, d->sshParameters.timeout);
|
||||||
settings.setValue(IsDefaultKey, d->isDefault);
|
|
||||||
settings.setValue(InternalIdKey, d->internalId);
|
settings.setValue(InternalIdKey, d->internalId);
|
||||||
settings.setValue(AttributesKey, d->attributes);
|
settings.setValue(AttributesKey, d->attributes);
|
||||||
}
|
}
|
||||||
@@ -258,11 +252,9 @@ QVariant LinuxDeviceConfiguration::attribute(const QString &name) const
|
|||||||
PortList LinuxDeviceConfiguration::freePorts() const { return d->freePorts; }
|
PortList LinuxDeviceConfiguration::freePorts() const { return d->freePorts; }
|
||||||
QString LinuxDeviceConfiguration::displayName() const { return d->displayName; }
|
QString LinuxDeviceConfiguration::displayName() const { return d->displayName; }
|
||||||
QString LinuxDeviceConfiguration::osType() const { return d->osType; }
|
QString LinuxDeviceConfiguration::osType() const { return d->osType; }
|
||||||
bool LinuxDeviceConfiguration::isDefault() const { return d->isDefault; }
|
|
||||||
|
|
||||||
void LinuxDeviceConfiguration::setDisplayName(const QString &name) { d->displayName = name; }
|
void LinuxDeviceConfiguration::setDisplayName(const QString &name) { d->displayName = name; }
|
||||||
void LinuxDeviceConfiguration::setInternalId(Id id) { d->internalId = id; }
|
void LinuxDeviceConfiguration::setInternalId(Id id) { d->internalId = id; }
|
||||||
void LinuxDeviceConfiguration::setDefault(bool isDefault) { d->isDefault = isDefault; }
|
|
||||||
|
|
||||||
const LinuxDeviceConfiguration::Id LinuxDeviceConfiguration::InvalidId = 0;
|
const LinuxDeviceConfiguration::Id LinuxDeviceConfiguration::InvalidId = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ public:
|
|||||||
QString osType() const;
|
QString osType() const;
|
||||||
DeviceType deviceType() const;
|
DeviceType deviceType() const;
|
||||||
Id internalId() const;
|
Id internalId() const;
|
||||||
bool isDefault() const;
|
|
||||||
bool isAutoDetected() const;
|
bool isAutoDetected() const;
|
||||||
QVariantHash attributes() const;
|
QVariantHash attributes() const;
|
||||||
QVariant attribute(const QString &name) const;
|
QVariant attribute(const QString &name) const;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVariantHash>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ const QLatin1String SettingsGroup("MaemoDeviceConfigs");
|
|||||||
const QLatin1String IdCounterKey("IdCounter");
|
const QLatin1String IdCounterKey("IdCounter");
|
||||||
const QLatin1String ConfigListKey("ConfigList");
|
const QLatin1String ConfigListKey("ConfigList");
|
||||||
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
|
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
|
||||||
|
const char DefaultConfigsKey[] = "DefaultConfigs";
|
||||||
|
|
||||||
class DevConfNameMatcher
|
class DevConfNameMatcher
|
||||||
{
|
{
|
||||||
@@ -73,6 +75,7 @@ public:
|
|||||||
static LinuxDeviceConfigurations *clonedInstance;
|
static LinuxDeviceConfigurations *clonedInstance;
|
||||||
LinuxDeviceConfiguration::Id nextId;
|
LinuxDeviceConfiguration::Id nextId;
|
||||||
QList<LinuxDeviceConfiguration::Ptr> devConfigs;
|
QList<LinuxDeviceConfiguration::Ptr> devConfigs;
|
||||||
|
QHash<QString, LinuxDeviceConfiguration::Id> defaultConfigs;
|
||||||
QString defaultSshKeyFilePath;
|
QString defaultSshKeyFilePath;
|
||||||
};
|
};
|
||||||
LinuxDeviceConfigurations *LinuxDeviceConfigurationsPrivate::instance = 0;
|
LinuxDeviceConfigurations *LinuxDeviceConfigurationsPrivate::instance = 0;
|
||||||
@@ -132,6 +135,7 @@ void LinuxDeviceConfigurations::copy(const LinuxDeviceConfigurations *source,
|
|||||||
}
|
}
|
||||||
target->d->defaultSshKeyFilePath = source->d->defaultSshKeyFilePath;
|
target->d->defaultSshKeyFilePath = source->d->defaultSshKeyFilePath;
|
||||||
target->d->nextId = source->d->nextId;
|
target->d->nextId = source->d->nextId;
|
||||||
|
target->d->defaultConfigs = source->d->defaultConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxDeviceConfigurations::save()
|
void LinuxDeviceConfigurations::save()
|
||||||
@@ -140,6 +144,12 @@ void LinuxDeviceConfigurations::save()
|
|||||||
settings->beginGroup(SettingsGroup);
|
settings->beginGroup(SettingsGroup);
|
||||||
settings->setValue(IdCounterKey, d->nextId);
|
settings->setValue(IdCounterKey, d->nextId);
|
||||||
settings->setValue(DefaultKeyFilePathKey, d->defaultSshKeyFilePath);
|
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->setValue(QLatin1String(DefaultConfigsKey), defaultDevsHash);
|
||||||
settings->beginWriteArray(ConfigListKey);
|
settings->beginWriteArray(ConfigListKey);
|
||||||
int skippedCount = 0;
|
int skippedCount = 0;
|
||||||
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
||||||
@@ -176,7 +186,7 @@ void LinuxDeviceConfigurations::addConfiguration(const LinuxDeviceConfiguration:
|
|||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
if (!defaultDeviceConfig(devConfig->osType()))
|
if (!defaultDeviceConfig(devConfig->osType()))
|
||||||
devConfig->setDefault(true);
|
d->defaultConfigs.insert(devConfig->osType(), devConfig->internalId());
|
||||||
d->devConfigs << devConfig;
|
d->devConfigs << devConfig;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
if (this == d->instance && d->clonedInstance) {
|
if (this == d->instance && d->clonedInstance) {
|
||||||
@@ -194,14 +204,15 @@ void LinuxDeviceConfigurations::removeConfiguration(int idx)
|
|||||||
|| deviceConfig->isAutoDetected(), return);
|
|| deviceConfig->isAutoDetected(), return);
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
beginRemoveRows(QModelIndex(), idx, idx);
|
||||||
const bool wasDefault = deviceConfig->isDefault();
|
const bool wasDefault
|
||||||
|
= d->defaultConfigs.value(deviceConfig->osType()) == deviceConfig->internalId();
|
||||||
const QString osType = deviceConfig->osType();
|
const QString osType = deviceConfig->osType();
|
||||||
d->devConfigs.removeAt(idx);
|
d->devConfigs.removeAt(idx);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
if (wasDefault) {
|
if (wasDefault) {
|
||||||
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
||||||
if (deviceAt(i)->osType() == osType) {
|
if (deviceAt(i)->osType() == osType) {
|
||||||
d->devConfigs.at(i)->setDefault(true);
|
d->defaultConfigs.insert(deviceAt(i)->osType(), deviceAt(i)->internalId());
|
||||||
const QModelIndex changedIndex = index(i, 0);
|
const QModelIndex changedIndex = index(i, 0);
|
||||||
emit dataChanged(changedIndex, changedIndex);
|
emit dataChanged(changedIndex, changedIndex);
|
||||||
break;
|
break;
|
||||||
@@ -242,22 +253,22 @@ void LinuxDeviceConfigurations::setDefaultDevice(int idx)
|
|||||||
QTC_ASSERT(this != LinuxDeviceConfigurationsPrivate::instance, return);
|
QTC_ASSERT(this != LinuxDeviceConfigurationsPrivate::instance, return);
|
||||||
Q_ASSERT(idx >= 0 && idx < rowCount());
|
Q_ASSERT(idx >= 0 && idx < rowCount());
|
||||||
|
|
||||||
const LinuxDeviceConfiguration::Ptr &devConf = d->devConfigs.at(idx);
|
const LinuxDeviceConfiguration::ConstPtr &devConf = d->devConfigs.at(idx);
|
||||||
if (devConf->isDefault())
|
const LinuxDeviceConfiguration::ConstPtr &oldDefaultDevConf
|
||||||
|
= defaultDeviceConfig(devConf->osType());
|
||||||
|
if (defaultDeviceConfig(devConf->osType()) == devConf)
|
||||||
return;
|
return;
|
||||||
QModelIndex oldDefaultIndex;
|
QModelIndex oldDefaultIndex;
|
||||||
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
for (int i = 0; i < d->devConfigs.count(); ++i) {
|
||||||
const LinuxDeviceConfiguration::Ptr &oldDefaultDev = d->devConfigs.at(i);
|
if (d->devConfigs.at(i) == oldDefaultDevConf) {
|
||||||
if (oldDefaultDev->isDefault() && oldDefaultDev->osType() == devConf->osType()) {
|
|
||||||
oldDefaultDev->setDefault(false);
|
|
||||||
oldDefaultIndex = index(i, 0);
|
oldDefaultIndex = index(i, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTC_CHECK(oldDefaultIndex.isValid());
|
QTC_CHECK(oldDefaultIndex.isValid());
|
||||||
|
d->defaultConfigs.insert(devConf->osType(), devConf->internalId());
|
||||||
emit dataChanged(oldDefaultIndex, oldDefaultIndex);
|
emit dataChanged(oldDefaultIndex, oldDefaultIndex);
|
||||||
devConf->setDefault(true);
|
|
||||||
const QModelIndex newDefaultIndex = index(idx, 0);
|
const QModelIndex newDefaultIndex = index(idx, 0);
|
||||||
emit dataChanged(newDefaultIndex, newDefaultIndex);
|
emit dataChanged(newDefaultIndex, newDefaultIndex);
|
||||||
}
|
}
|
||||||
@@ -285,6 +296,11 @@ void LinuxDeviceConfigurations::load()
|
|||||||
d->nextId = settings->value(IdCounterKey, 1).toULongLong();
|
d->nextId = settings->value(IdCounterKey, 1).toULongLong();
|
||||||
d->defaultSshKeyFilePath = settings->value(DefaultKeyFilePathKey,
|
d->defaultSshKeyFilePath = settings->value(DefaultKeyFilePathKey,
|
||||||
LinuxDeviceConfiguration::defaultPrivateKeyFilePath()).toString();
|
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);
|
int count = settings->beginReadArray(ConfigListKey);
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
settings->setArrayIndex(i);
|
settings->setArrayIndex(i);
|
||||||
@@ -319,11 +335,11 @@ LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::find(LinuxDeviceCo
|
|||||||
|
|
||||||
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::defaultDeviceConfig(const QString &osType) const
|
LinuxDeviceConfiguration::ConstPtr LinuxDeviceConfigurations::defaultDeviceConfig(const QString &osType) const
|
||||||
{
|
{
|
||||||
foreach (const LinuxDeviceConfiguration::ConstPtr &devConf, d->devConfigs) {
|
const LinuxDeviceConfiguration::Id id = d->defaultConfigs.value(osType,
|
||||||
if (devConf->isDefault() && devConf->osType() == osType)
|
LinuxDeviceConfiguration::InvalidId);
|
||||||
return devConf;
|
if (id == LinuxDeviceConfiguration::InvalidId)
|
||||||
}
|
return LinuxDeviceConfiguration::ConstPtr();
|
||||||
return LinuxDeviceConfiguration::ConstPtr();
|
return find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LinuxDeviceConfigurations::indexForInternalId(LinuxDeviceConfiguration::Id internalId) const
|
int LinuxDeviceConfigurations::indexForInternalId(LinuxDeviceConfiguration::Id internalId) const
|
||||||
@@ -342,24 +358,9 @@ LinuxDeviceConfiguration::Id LinuxDeviceConfigurations::internalId(LinuxDeviceCo
|
|||||||
|
|
||||||
void LinuxDeviceConfigurations::ensureOneDefaultConfigurationPerOsType()
|
void LinuxDeviceConfigurations::ensureOneDefaultConfigurationPerOsType()
|
||||||
{
|
{
|
||||||
QHash<QString, bool> osTypeHasDefault;
|
|
||||||
|
|
||||||
// Step 1: Ensure there's at most one default configuration per device type.
|
|
||||||
foreach (const LinuxDeviceConfiguration::Ptr &devConf, d->devConfigs) {
|
foreach (const LinuxDeviceConfiguration::Ptr &devConf, d->devConfigs) {
|
||||||
if (devConf->isDefault()) {
|
if (!defaultDeviceConfig(devConf->osType()))
|
||||||
if (osTypeHasDefault.value(devConf->osType()))
|
d->defaultConfigs.insert(devConf->osType(), devConf->internalId());
|
||||||
devConf->setDefault(false);
|
|
||||||
else
|
|
||||||
osTypeHasDefault.insert(devConf->osType(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: Ensure there's at least one default configuration per device type.
|
|
||||||
foreach (const LinuxDeviceConfiguration::Ptr &devConf, d->devConfigs) {
|
|
||||||
if (!osTypeHasDefault.value(devConf->osType())) {
|
|
||||||
devConf->setDefault(true);
|
|
||||||
osTypeHasDefault.insert(devConf->osType(), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +376,7 @@ QVariant LinuxDeviceConfigurations::data(const QModelIndex &index, int role) con
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
const LinuxDeviceConfiguration::ConstPtr devConf = deviceAt(index.row());
|
const LinuxDeviceConfiguration::ConstPtr devConf = deviceAt(index.row());
|
||||||
QString name = devConf->displayName();
|
QString name = devConf->displayName();
|
||||||
if (devConf->isDefault()) {
|
if (defaultDeviceConfig(devConf->osType()) == devConf) {
|
||||||
name += QLatin1Char(' ') + tr("(default for %1)")
|
name += QLatin1Char(' ') + tr("(default for %1)")
|
||||||
.arg(RemoteLinuxUtils::osTypeToString(devConf->osType()));
|
.arg(RemoteLinuxUtils::osTypeToString(devConf->osType()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,8 @@ void LinuxDeviceConfigurationsSettingsWidget::deleteConfig()
|
|||||||
void LinuxDeviceConfigurationsSettingsWidget::displayCurrent()
|
void LinuxDeviceConfigurationsSettingsWidget::displayCurrent()
|
||||||
{
|
{
|
||||||
const LinuxDeviceConfiguration::ConstPtr ¤t = currentConfig();
|
const LinuxDeviceConfiguration::ConstPtr ¤t = currentConfig();
|
||||||
m_ui->defaultDeviceButton->setEnabled(!current->isDefault());
|
m_ui->defaultDeviceButton->setEnabled(
|
||||||
|
m_devConfigs->defaultDeviceConfig(current->osType()) != current);
|
||||||
m_ui->osTypeValueLabel->setText(RemoteLinuxUtils::osTypeToString(current->osType()));
|
m_ui->osTypeValueLabel->setText(RemoteLinuxUtils::osTypeToString(current->osType()));
|
||||||
|
|
||||||
if (current->deviceType() == LinuxDeviceConfiguration::Hardware)
|
if (current->deviceType() == LinuxDeviceConfiguration::Hardware)
|
||||||
|
|||||||
@@ -75,8 +75,10 @@ QVariant TypeSpecificDeviceConfigurationListModel::data(const QModelIndex &index
|
|||||||
const LinuxDeviceConfiguration::ConstPtr &devConf = deviceAt(index.row());
|
const LinuxDeviceConfiguration::ConstPtr &devConf = deviceAt(index.row());
|
||||||
Q_ASSERT(devConf);
|
Q_ASSERT(devConf);
|
||||||
QString displayedName = devConf->displayName();
|
QString displayedName = devConf->displayName();
|
||||||
if (devConf->isDefault() && devConf->osType() == m_targetOsType)
|
if (devConf->osType() == m_targetOsType && LinuxDeviceConfigurations::instance()
|
||||||
displayedName += QLatin1Char(' ') + tr("(default)");
|
->defaultDeviceConfig(devConf->osType()) == devConf) {
|
||||||
|
displayedName = tr("%1 (default)").arg(displayedName);
|
||||||
|
}
|
||||||
return displayedName;
|
return displayedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user