forked from qt-creator/qt-creator
ProjectExplorer: devicemanager.cpp code cosmetics
Unused code, namespaces. Change-Id: I6efcf3dc9b6aa9a030b92b7a116b1fcaf7b0823d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -5,30 +5,22 @@
|
|||||||
|
|
||||||
#include "idevicefactory.h"
|
#include "idevicefactory.h"
|
||||||
#include "../projectexplorertr.h"
|
#include "../projectexplorertr.h"
|
||||||
|
#include "../projectexplorerconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/devicefileaccess.h>
|
#include <utils/devicefileaccess.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/fsengine/fsengine.h>
|
#include <utils/fsengine/fsengine.h>
|
||||||
#include <utils/persistentsettings.h>
|
#include <utils/persistentsettings.h>
|
||||||
#include <utils/portlist.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QList>
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QString>
|
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -43,14 +35,12 @@ const char DeviceManagerKey[] = "DeviceManager";
|
|||||||
const char DeviceListKey[] = "DeviceList";
|
const char DeviceListKey[] = "DeviceList";
|
||||||
const char DefaultDevicesKey[] = "DefaultDevices";
|
const char DefaultDevicesKey[] = "DefaultDevices";
|
||||||
|
|
||||||
template <class ...Args> using Continuation = std::function<void(Args...)>;
|
|
||||||
|
|
||||||
class DeviceManagerPrivate
|
class DeviceManagerPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceManagerPrivate() = default;
|
DeviceManagerPrivate() = default;
|
||||||
|
|
||||||
int indexForId(Utils::Id id) const
|
int indexForId(Id id) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < devices.count(); ++i) {
|
for (int i = 0; i < devices.count(); ++i) {
|
||||||
if (devices.at(i)->id() == id)
|
if (devices.at(i)->id() == id)
|
||||||
@@ -69,8 +59,8 @@ public:
|
|||||||
|
|
||||||
mutable QMutex mutex;
|
mutable QMutex mutex;
|
||||||
QList<IDevice::Ptr> devices;
|
QList<IDevice::Ptr> devices;
|
||||||
QHash<Utils::Id, Utils::Id> defaultDevices;
|
QHash<Id, Id> defaultDevices;
|
||||||
Utils::PersistentSettingsWriter *writer = nullptr;
|
PersistentSettingsWriter *writer = nullptr;
|
||||||
};
|
};
|
||||||
DeviceManager *DeviceManagerPrivate::clonedInstance = nullptr;
|
DeviceManager *DeviceManagerPrivate::clonedInstance = nullptr;
|
||||||
|
|
||||||
@@ -161,9 +151,9 @@ void DeviceManager::load()
|
|||||||
// Only create writer now: We do not want to save before the settings were read!
|
// Only create writer now: We do not want to save before the settings were read!
|
||||||
d->writer = new PersistentSettingsWriter(settingsFilePath("devices.xml"), "QtCreatorDevices");
|
d->writer = new PersistentSettingsWriter(settingsFilePath("devices.xml"), "QtCreatorDevices");
|
||||||
|
|
||||||
Utils::PersistentSettingsReader reader;
|
PersistentSettingsReader reader;
|
||||||
// read devices file from global settings path
|
// read devices file from global settings path
|
||||||
QHash<Utils::Id, Utils::Id> defaultDevices;
|
QHash<Id, Id> defaultDevices;
|
||||||
QList<IDevice::Ptr> sdkDevices;
|
QList<IDevice::Ptr> sdkDevices;
|
||||||
if (reader.load(systemSettingsFilePath("devices.xml")))
|
if (reader.load(systemSettingsFilePath("devices.xml")))
|
||||||
sdkDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices);
|
sdkDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices);
|
||||||
@@ -200,7 +190,7 @@ void DeviceManager::load()
|
|||||||
|
|
||||||
static const IDeviceFactory *restoreFactory(const QVariantMap &map)
|
static const IDeviceFactory *restoreFactory(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
const Utils::Id deviceType = IDevice::typeFromMap(map);
|
const Id deviceType = IDevice::typeFromMap(map);
|
||||||
IDeviceFactory *factory = Utils::findOrDefault(IDeviceFactory::allDeviceFactories(),
|
IDeviceFactory *factory = Utils::findOrDefault(IDeviceFactory::allDeviceFactories(),
|
||||||
[&map, deviceType](IDeviceFactory *factory) {
|
[&map, deviceType](IDeviceFactory *factory) {
|
||||||
return factory->canRestore(map) && factory->deviceType() == deviceType;
|
return factory->canRestore(map) && factory->deviceType() == deviceType;
|
||||||
@@ -213,15 +203,14 @@ static const IDeviceFactory *restoreFactory(const QVariantMap &map)
|
|||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IDevice::Ptr> DeviceManager::fromMap(const QVariantMap &map,
|
QList<IDevice::Ptr> DeviceManager::fromMap(const QVariantMap &map, QHash<Id, Id> *defaultDevices)
|
||||||
QHash<Utils::Id, Utils::Id> *defaultDevices)
|
|
||||||
{
|
{
|
||||||
QList<IDevice::Ptr> devices;
|
QList<IDevice::Ptr> devices;
|
||||||
|
|
||||||
if (defaultDevices) {
|
if (defaultDevices) {
|
||||||
const QVariantMap defaultDevsMap = map.value(DefaultDevicesKey).toMap();
|
const QVariantMap defaultDevsMap = map.value(DefaultDevicesKey).toMap();
|
||||||
for (auto it = defaultDevsMap.constBegin(); it != defaultDevsMap.constEnd(); ++it)
|
for (auto it = defaultDevsMap.constBegin(); it != defaultDevsMap.constEnd(); ++it)
|
||||||
defaultDevices->insert(Utils::Id::fromString(it.key()), Utils::Id::fromSetting(it.value()));
|
defaultDevices->insert(Id::fromString(it.key()), Id::fromSetting(it.value()));
|
||||||
}
|
}
|
||||||
const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList();
|
const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList();
|
||||||
for (const QVariant &v : deviceList) {
|
for (const QVariant &v : deviceList) {
|
||||||
@@ -241,11 +230,9 @@ QVariantMap DeviceManager::toMap() const
|
|||||||
{
|
{
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
QVariantMap defaultDeviceMap;
|
QVariantMap defaultDeviceMap;
|
||||||
using TypeIdHash = QHash<Utils::Id, Utils::Id>;
|
for (auto it = d->defaultDevices.constBegin(); it != d->defaultDevices.constEnd(); ++it)
|
||||||
for (TypeIdHash::ConstIterator it = d->defaultDevices.constBegin();
|
|
||||||
it != d->defaultDevices.constEnd(); ++it) {
|
|
||||||
defaultDeviceMap.insert(it.key().toString(), it.value().toSetting());
|
defaultDeviceMap.insert(it.key().toString(), it.value().toSetting());
|
||||||
}
|
|
||||||
map.insert(QLatin1String(DefaultDevicesKey), defaultDeviceMap);
|
map.insert(QLatin1String(DefaultDevicesKey), defaultDeviceMap);
|
||||||
QVariantList deviceList;
|
QVariantList deviceList;
|
||||||
for (const IDevice::Ptr &device : std::as_const(d->devices))
|
for (const IDevice::Ptr &device : std::as_const(d->devices))
|
||||||
@@ -287,31 +274,29 @@ void DeviceManager::addDevice(const IDevice::ConstPtr &_device)
|
|||||||
}
|
}
|
||||||
emit deviceAdded(device->id());
|
emit deviceAdded(device->id());
|
||||||
|
|
||||||
if (FSEngine::isAvailable()) {
|
if (FSEngine::isAvailable())
|
||||||
Utils::FSEngine::addDevice(device->rootPath());
|
FSEngine::addDevice(device->rootPath());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::removeDevice(Utils::Id id)
|
void DeviceManager::removeDevice(Id id)
|
||||||
{
|
{
|
||||||
const IDevice::Ptr device = mutableDevice(id);
|
const IDevice::Ptr device = mutableDevice(id);
|
||||||
QTC_ASSERT(device, return);
|
QTC_ASSERT(device, return);
|
||||||
QTC_ASSERT(this != instance() || device->isAutoDetected(), return);
|
QTC_ASSERT(this != instance() || device->isAutoDetected(), return);
|
||||||
|
|
||||||
const bool wasDefault = d->defaultDevices.value(device->type()) == device->id();
|
const bool wasDefault = d->defaultDevices.value(device->type()) == device->id();
|
||||||
const Utils::Id deviceType = device->type();
|
const Id deviceType = device->type();
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&d->mutex);
|
QMutexLocker locker(&d->mutex);
|
||||||
d->devices.removeAt(d->indexForId(id));
|
d->devices.removeAt(d->indexForId(id));
|
||||||
}
|
}
|
||||||
emit deviceRemoved(device->id());
|
emit deviceRemoved(device->id());
|
||||||
|
|
||||||
if (FSEngine::isAvailable()) {
|
if (FSEngine::isAvailable())
|
||||||
Utils::FSEngine::removeDevice(device->rootPath());
|
FSEngine::removeDevice(device->rootPath());
|
||||||
}
|
|
||||||
|
|
||||||
if (wasDefault) {
|
if (wasDefault) {
|
||||||
for (int i = 0; i < d->devices.count(); ++i) {
|
for (int i = 0; i < d->devices.count(); ++i) {
|
||||||
@@ -328,7 +313,7 @@ void DeviceManager::removeDevice(Utils::Id id)
|
|||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::setDeviceState(Utils::Id deviceId, IDevice::DeviceState deviceState)
|
void DeviceManager::setDeviceState(Id deviceId, IDevice::DeviceState deviceState)
|
||||||
{
|
{
|
||||||
// To see the state change in the DeviceSettingsWidget. This has to happen before
|
// To see the state change in the DeviceSettingsWidget. This has to happen before
|
||||||
// the pos check below, in case the device is only present in the cloned instance.
|
// the pos check below, in case the device is only present in the cloned instance.
|
||||||
@@ -379,7 +364,7 @@ IDevice::ConstPtr DeviceManager::defaultDesktopDevice()
|
|||||||
return m_instance->defaultDevice(Constants::DESKTOP_DEVICE_TYPE);
|
return m_instance->defaultDevice(Constants::DESKTOP_DEVICE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::setDefaultDevice(Utils::Id id)
|
void DeviceManager::setDefaultDevice(Id id)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(this != instance(), return);
|
QTC_ASSERT(this != instance(), return);
|
||||||
|
|
||||||
@@ -482,7 +467,7 @@ IDevice::ConstPtr DeviceManager::deviceAt(int idx) const
|
|||||||
return d->devices.at(idx);
|
return d->devices.at(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr DeviceManager::mutableDevice(Utils::Id id) const
|
IDevice::Ptr DeviceManager::mutableDevice(Id id) const
|
||||||
{
|
{
|
||||||
const int index = d->indexForId(id);
|
const int index = d->indexForId(id);
|
||||||
return index == -1 ? IDevice::Ptr() : d->devices.at(index);
|
return index == -1 ? IDevice::Ptr() : d->devices.at(index);
|
||||||
@@ -495,15 +480,15 @@ bool DeviceManager::hasDevice(const QString &name) const
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::ConstPtr DeviceManager::find(Utils::Id id) const
|
IDevice::ConstPtr DeviceManager::find(Id id) const
|
||||||
{
|
{
|
||||||
const int index = d->indexForId(id);
|
const int index = d->indexForId(id);
|
||||||
return index == -1 ? IDevice::ConstPtr() : deviceAt(index);
|
return index == -1 ? IDevice::ConstPtr() : deviceAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::ConstPtr DeviceManager::defaultDevice(Utils::Id deviceType) const
|
IDevice::ConstPtr DeviceManager::defaultDevice(Id deviceType) const
|
||||||
{
|
{
|
||||||
const Utils::Id id = d->defaultDevices.value(deviceType);
|
const Id id = d->defaultDevices.value(deviceType);
|
||||||
return id.isValid() ? find(id) : IDevice::ConstPtr();
|
return id.isValid() ? find(id) : IDevice::ConstPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,14 +508,15 @@ class TestDevice : public IDevice
|
|||||||
public:
|
public:
|
||||||
TestDevice()
|
TestDevice()
|
||||||
{
|
{
|
||||||
setupId(AutoDetected, Utils::Id::fromString(QUuid::createUuid().toString()));
|
setupId(AutoDetected, Id::fromString(QUuid::createUuid().toString()));
|
||||||
setType(testTypeId());
|
setType(testTypeId());
|
||||||
setMachineType(Hardware);
|
setMachineType(Hardware);
|
||||||
setOsType(HostOsInfo::hostOs());
|
setOsType(HostOsInfo::hostOs());
|
||||||
setDisplayType("blubb");
|
setDisplayType("blubb");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::Id testTypeId() { return "TestType"; }
|
static Id testTypeId() { return "TestType"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IDeviceWidget *createWidget() override { return nullptr; }
|
IDeviceWidget *createWidget() override { return nullptr; }
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user