forked from qt-creator/qt-creator
Fix default device not being saved
Task-number: QTCREATORBUG-17396 Change-Id: Idcee60b1fa3043690cd77de899a0a40cb0e25947 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -148,13 +148,14 @@ void DeviceManager::load()
|
|||||||
|
|
||||||
Utils::PersistentSettingsReader reader;
|
Utils::PersistentSettingsReader reader;
|
||||||
// read devices file from global settings path
|
// read devices file from global settings path
|
||||||
|
QHash<Core::Id, Core::Id> defaultDevices;
|
||||||
QList<IDevice::Ptr> sdkDevices;
|
QList<IDevice::Ptr> sdkDevices;
|
||||||
if (reader.load(systemSettingsFilePath(QLatin1String("/qtcreator/devices.xml"))))
|
if (reader.load(systemSettingsFilePath(QLatin1String("/qtcreator/devices.xml"))))
|
||||||
sdkDevices = fromMap(reader.restoreValues().value(QLatin1String(DeviceManagerKey)).toMap());
|
sdkDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices);
|
||||||
// read devices file from user settings path
|
// read devices file from user settings path
|
||||||
QList<IDevice::Ptr> userDevices;
|
QList<IDevice::Ptr> userDevices;
|
||||||
if (reader.load(settingsFilePath(QLatin1String("/devices.xml"))))
|
if (reader.load(settingsFilePath(QLatin1String("/devices.xml"))))
|
||||||
userDevices = fromMap(reader.restoreValues().value(QLatin1String(DeviceManagerKey)).toMap());
|
userDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices);
|
||||||
// Insert devices into the model. Prefer the higher device version when there are multiple
|
// Insert devices into the model. Prefer the higher device version when there are multiple
|
||||||
// devices with the same id.
|
// devices with the same id.
|
||||||
foreach (IDevice::Ptr device, userDevices) {
|
foreach (IDevice::Ptr device, userDevices) {
|
||||||
@@ -172,18 +173,25 @@ void DeviceManager::load()
|
|||||||
foreach (const IDevice::Ptr &sdkDevice, sdkDevices)
|
foreach (const IDevice::Ptr &sdkDevice, sdkDevices)
|
||||||
addDevice(sdkDevice);
|
addDevice(sdkDevice);
|
||||||
|
|
||||||
ensureOneDefaultDevicePerType();
|
// Overwrite with the saved default devices.
|
||||||
|
for (auto itr = defaultDevices.constBegin(); itr != defaultDevices.constEnd(); ++itr) {
|
||||||
|
IDevice::ConstPtr device = find(itr.value());
|
||||||
|
if (device)
|
||||||
|
d->defaultDevices[device->type()] = device->id();
|
||||||
|
}
|
||||||
|
|
||||||
emit devicesLoaded();
|
emit devicesLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IDevice::Ptr> DeviceManager::fromMap(const QVariantMap &map)
|
QList<IDevice::Ptr> DeviceManager::fromMap(const QVariantMap &map,
|
||||||
|
QHash<Core::Id, Core::Id> *defaultDevices)
|
||||||
{
|
{
|
||||||
QList<IDevice::Ptr> devices;
|
QList<IDevice::Ptr> devices;
|
||||||
const QVariantMap defaultDevsMap = map.value(QLatin1String(DefaultDevicesKey)).toMap();
|
|
||||||
for (QVariantMap::ConstIterator it = defaultDevsMap.constBegin();
|
if (defaultDevices) {
|
||||||
it != defaultDevsMap.constEnd(); ++it) {
|
const QVariantMap defaultDevsMap = map.value(DefaultDevicesKey).toMap();
|
||||||
d->defaultDevices.insert(Core::Id::fromString(it.key()), Core::Id::fromSetting(it.value()));
|
for (auto it = defaultDevsMap.constBegin(); it != defaultDevsMap.constEnd(); ++it)
|
||||||
|
defaultDevices->insert(Core::Id::fromString(it.key()), Core::Id::fromSetting(it.value()));
|
||||||
}
|
}
|
||||||
const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList();
|
const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList();
|
||||||
foreach (const QVariant &v, deviceList) {
|
foreach (const QVariant &v, deviceList) {
|
||||||
@@ -398,14 +406,6 @@ IDevice::ConstPtr DeviceManager::defaultDevice(Core::Id deviceType) const
|
|||||||
return id.isValid() ? find(id) : IDevice::ConstPtr();
|
return id.isValid() ? find(id) : IDevice::ConstPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::ensureOneDefaultDevicePerType()
|
|
||||||
{
|
|
||||||
foreach (const IDevice::Ptr &device, d->devices) {
|
|
||||||
if (!defaultDevice(device->type()))
|
|
||||||
d->defaultDevices.insert(device->type(), device->id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceManager::hostKeysFilePath()
|
QString DeviceManager::hostKeysFilePath()
|
||||||
{
|
{
|
||||||
return settingsFilePath(QLatin1String("/ssh-hostkeys")).toString();
|
return settingsFilePath(QLatin1String("/ssh-hostkeys")).toString();
|
||||||
|
@@ -85,9 +85,8 @@ private:
|
|||||||
|
|
||||||
void load();
|
void load();
|
||||||
static const IDeviceFactory *restoreFactory(const QVariantMap &map);
|
static const IDeviceFactory *restoreFactory(const QVariantMap &map);
|
||||||
QList<IDevice::Ptr> fromMap(const QVariantMap &map);
|
QList<IDevice::Ptr> fromMap(const QVariantMap &map, QHash<Core::Id, Core::Id> *defaultDevices);
|
||||||
QVariantMap toMap() const;
|
QVariantMap toMap() const;
|
||||||
void ensureOneDefaultDevicePerType();
|
|
||||||
|
|
||||||
// For SettingsWidget.
|
// For SettingsWidget.
|
||||||
IDevice::Ptr mutableDevice(Core::Id id) const;
|
IDevice::Ptr mutableDevice(Core::Id id) const;
|
||||||
|
Reference in New Issue
Block a user