forked from qt-creator/qt-creator
ProjectExplorer: Remove cloned DeviceManager
Change-Id: I2b8e3538c4ab0c34c88df5daac0c70a13f239e88 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -745,7 +745,7 @@ static void handleDevicesListChange(const QString &serialNumber)
|
||||
|
||||
qCDebug(androidDeviceLog, "Registering new Android device id \"%s\".",
|
||||
newDev->id().toString().toUtf8().data());
|
||||
devMgr->addDevice(IDevice::ConstPtr(newDev));
|
||||
devMgr->addDevice(IDevice::Ptr(newDev));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -819,7 +819,7 @@ static void handleAvdListChange(const AndroidDeviceInfoList &avdList)
|
||||
}
|
||||
}
|
||||
|
||||
AndroidDevice *newDev = new AndroidDevice;
|
||||
AndroidDevice::Ptr newDev = std::make_shared<AndroidDevice>();
|
||||
newDev->setupId(IDevice::AutoDetected, deviceId);
|
||||
newDev->setDisplayName(displayName);
|
||||
newDev->setMachineType(item.type);
|
||||
@@ -833,9 +833,8 @@ static void handleAvdListChange(const AndroidDeviceInfoList &avdList)
|
||||
|
||||
qCDebug(androidDeviceLog, "Registering new Android device id \"%s\".",
|
||||
newDev->id().toString().toUtf8().data());
|
||||
const IDevice::ConstPtr constNewDev = IDevice::ConstPtr(newDev);
|
||||
devMgr->addDevice(IDevice::ConstPtr(constNewDev));
|
||||
connectedDevs.append(constNewDev->id());
|
||||
devMgr->addDevice(newDev);
|
||||
connectedDevs.append(newDev->id());
|
||||
}
|
||||
|
||||
// Set devices no longer connected to disconnected state.
|
||||
|
@@ -18,6 +18,8 @@ namespace Android::Internal {
|
||||
class AndroidDevice final : public ProjectExplorer::IDevice
|
||||
{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<AndroidDevice>;
|
||||
|
||||
AndroidDevice();
|
||||
|
||||
static IDevice::Ptr create();
|
||||
|
@@ -381,9 +381,9 @@ void IosConfigurations::updateSimulators()
|
||||
// currently we have just one simulator
|
||||
DeviceManager *devManager = DeviceManager::instance();
|
||||
Id devId = Constants::IOS_SIMULATOR_DEVICE_ID;
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
IDevice::Ptr dev = devManager->find(devId);
|
||||
if (!dev) {
|
||||
dev = IDevice::ConstPtr(new IosSimulator(devId));
|
||||
dev = IDevice::Ptr(new IosSimulator(devId));
|
||||
devManager->addDevice(dev);
|
||||
}
|
||||
Utils::futureSynchronizer()->addFuture(SimulatorControl::updateAvailableSimulators(this));
|
||||
|
@@ -263,20 +263,21 @@ void IosDeviceManager::deviceConnected(const QString &uid, const QString &name)
|
||||
Utils::Id baseDevId(Constants::IOS_DEVICE_ID);
|
||||
Utils::Id devType(Constants::IOS_DEVICE_TYPE);
|
||||
Utils::Id devId = baseDevId.withSuffix(uid);
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
IDevice::Ptr dev = devManager->find(devId);
|
||||
if (!dev) {
|
||||
auto newDev = new IosDevice(uid);
|
||||
auto newDev = IosDevice::make(uid);
|
||||
if (!name.isNull())
|
||||
newDev->setDisplayName(name);
|
||||
qCDebug(detectLog) << "adding ios device " << uid;
|
||||
devManager->addDevice(IDevice::ConstPtr(newDev));
|
||||
devManager->addDevice(newDev);
|
||||
} else if (dev->deviceState() != IDevice::DeviceConnected &&
|
||||
dev->deviceState() != IDevice::DeviceReadyToUse) {
|
||||
qCDebug(detectLog) << "updating ios device " << uid;
|
||||
|
||||
if (dev->type() == devType) // FIXME: Should that be a QTC_ASSERT?
|
||||
devManager->addDevice(dev->clone());
|
||||
devManager->addDevice(dev);
|
||||
else
|
||||
devManager->addDevice(IDevice::ConstPtr(new IosDevice(uid)));
|
||||
devManager->addDevice(IosDevice::make(uid));
|
||||
}
|
||||
updateInfo(uid);
|
||||
}
|
||||
@@ -381,22 +382,22 @@ void IosDeviceManager::deviceInfo(const QString &uid,
|
||||
Utils::Id baseDevId(Constants::IOS_DEVICE_ID);
|
||||
Utils::Id devType(Constants::IOS_DEVICE_TYPE);
|
||||
Utils::Id devId = baseDevId.withSuffix(uid);
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
IDevice::Ptr dev = devManager->find(devId);
|
||||
bool skipUpdate = false;
|
||||
IosDevice *newDev = nullptr;
|
||||
IosDevice::Ptr newDev;
|
||||
if (dev && dev->type() == devType) {
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.get());
|
||||
IosDevice::Ptr iosDev = std::static_pointer_cast<IosDevice>(dev);
|
||||
if (iosDev->m_handler == handler && iosDev->m_extraInfo == info) {
|
||||
skipUpdate = true;
|
||||
newDev = const_cast<IosDevice *>(iosDev);
|
||||
newDev = iosDev;
|
||||
} else {
|
||||
Store store;
|
||||
iosDev->toMap(store);
|
||||
newDev = new IosDevice();
|
||||
newDev = IosDevice::make();
|
||||
newDev->fromMap(store);
|
||||
}
|
||||
} else {
|
||||
newDev = new IosDevice(uid);
|
||||
newDev = IosDevice::make(uid);
|
||||
}
|
||||
if (!skipUpdate) {
|
||||
if (info.contains(kDeviceName))
|
||||
@@ -404,7 +405,7 @@ void IosDeviceManager::deviceInfo(const QString &uid,
|
||||
newDev->m_extraInfo = info;
|
||||
newDev->m_handler = handler;
|
||||
qCDebug(detectLog) << "updated info of ios device " << uid;
|
||||
dev = IDevice::ConstPtr(newDev);
|
||||
dev = newDev;
|
||||
devManager->addDevice(dev);
|
||||
}
|
||||
QLatin1String devStatusKey = QLatin1String("developerStatus");
|
||||
|
@@ -45,6 +45,9 @@ public:
|
||||
|
||||
static QString name();
|
||||
|
||||
static IosDevice::Ptr make() { return IosDevice::Ptr(new IosDevice()); }
|
||||
static IosDevice::Ptr make(const QString &uid) { return IosDevice::Ptr(new IosDevice(uid)); }
|
||||
|
||||
private:
|
||||
void fromMap(const Utils::Store &map) final;
|
||||
void toMap(Utils::Store &map) const final;
|
||||
|
@@ -297,7 +297,6 @@ private:
|
||||
fix(k);
|
||||
|
||||
DeviceManager *dm = DeviceManager::instance();
|
||||
connect(dm, &DeviceManager::deviceListReplaced, this, &DeviceKitAspectFactory::devicesChanged);
|
||||
connect(dm, &DeviceManager::deviceAdded, this, &DeviceKitAspectFactory::devicesChanged);
|
||||
connect(dm, &DeviceManager::deviceRemoved, this, &DeviceKitAspectFactory::devicesChanged);
|
||||
connect(dm, &DeviceManager::deviceUpdated, this, &DeviceKitAspectFactory::deviceUpdated);
|
||||
|
@@ -56,14 +56,11 @@ public:
|
||||
return devices;
|
||||
}
|
||||
|
||||
static DeviceManager *clonedInstance;
|
||||
|
||||
mutable QMutex mutex;
|
||||
QList<IDevice::Ptr> devices;
|
||||
QHash<Id, Id> defaultDevices;
|
||||
PersistentSettingsWriter *writer = nullptr;
|
||||
};
|
||||
DeviceManager *DeviceManagerPrivate::clonedInstance = nullptr;
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -81,60 +78,8 @@ int DeviceManager::deviceCount() const
|
||||
return d->devices.count();
|
||||
}
|
||||
|
||||
void DeviceManager::replaceInstance()
|
||||
{
|
||||
const QList<Id> newIds =
|
||||
Utils::transform(DeviceManagerPrivate::clonedInstance->d->devices, &IDevice::id);
|
||||
|
||||
for (const IDevice::Ptr &dev : std::as_const(m_instance->d->devices)) {
|
||||
if (!newIds.contains(dev->id()))
|
||||
dev->aboutToBeRemoved();
|
||||
}
|
||||
|
||||
{
|
||||
QMutexLocker locker(&instance()->d->mutex);
|
||||
copy(DeviceManagerPrivate::clonedInstance, instance(), false);
|
||||
}
|
||||
|
||||
emit instance()->deviceListReplaced();
|
||||
emit instance()->updated();
|
||||
}
|
||||
|
||||
void DeviceManager::removeClonedInstance()
|
||||
{
|
||||
delete DeviceManagerPrivate::clonedInstance;
|
||||
DeviceManagerPrivate::clonedInstance = nullptr;
|
||||
}
|
||||
|
||||
DeviceManager *DeviceManager::cloneInstance()
|
||||
{
|
||||
QTC_ASSERT(!DeviceManagerPrivate::clonedInstance, return nullptr);
|
||||
|
||||
DeviceManagerPrivate::clonedInstance = new DeviceManager(false);
|
||||
copy(instance(), DeviceManagerPrivate::clonedInstance, true);
|
||||
return DeviceManagerPrivate::clonedInstance;
|
||||
}
|
||||
|
||||
DeviceManager *DeviceManager::clonedInstance()
|
||||
{
|
||||
return DeviceManagerPrivate::clonedInstance;
|
||||
}
|
||||
|
||||
void DeviceManager::copy(const DeviceManager *source, DeviceManager *target, bool deep)
|
||||
{
|
||||
if (deep) {
|
||||
for (const IDevice::Ptr &device : std::as_const(source->d->devices))
|
||||
target->d->devices << device->clone();
|
||||
} else {
|
||||
target->d->devices = source->d->devices;
|
||||
}
|
||||
target->d->defaultDevices = source->d->defaultDevices;
|
||||
}
|
||||
|
||||
void DeviceManager::save()
|
||||
{
|
||||
if (d->clonedInstance == this || !d->writer)
|
||||
return;
|
||||
Store data;
|
||||
data.insert(DeviceManagerKey, variantFromStore(toMap()));
|
||||
d->writer->save(data);
|
||||
@@ -169,7 +114,7 @@ void DeviceManager::load()
|
||||
userDevices = fromMap(storeFromVariant(reader.restoreValues().value(DeviceManagerKey)), &defaultDevices);
|
||||
// Insert devices into the model. Prefer the higher device version when there are multiple
|
||||
// devices with the same id.
|
||||
for (IDevice::ConstPtr device : std::as_const(userDevices)) {
|
||||
for (IDevice::Ptr device : std::as_const(userDevices)) {
|
||||
for (const IDevice::Ptr &sdkDevice : std::as_const(sdkDevices)) {
|
||||
if (device->id() == sdkDevice->id() || device->rootPath() == sdkDevice->rootPath()) {
|
||||
if (device->version() < sdkDevice->version())
|
||||
@@ -250,10 +195,8 @@ Store DeviceManager::toMap() const
|
||||
return map;
|
||||
}
|
||||
|
||||
void DeviceManager::addDevice(const IDevice::ConstPtr &_device)
|
||||
void DeviceManager::addDevice(const IDevice::Ptr &device)
|
||||
{
|
||||
const IDevice::Ptr device = _device->clone();
|
||||
|
||||
QStringList names;
|
||||
for (const IDevice::Ptr &tmp : std::as_const(d->devices)) {
|
||||
if (tmp->id() != device->id())
|
||||
@@ -267,8 +210,6 @@ void DeviceManager::addDevice(const IDevice::ConstPtr &_device)
|
||||
|
||||
if (!defaultDevice(device->type()))
|
||||
d->defaultDevices.insert(device->type(), device->id());
|
||||
if (this == DeviceManager::instance() && d->clonedInstance)
|
||||
d->clonedInstance->addDevice(device->clone());
|
||||
|
||||
if (pos >= 0) {
|
||||
{
|
||||
@@ -294,7 +235,6 @@ void DeviceManager::removeDevice(Id id)
|
||||
{
|
||||
const IDevice::Ptr device = mutableDevice(id);
|
||||
QTC_ASSERT(device, return);
|
||||
QTC_ASSERT(this != instance() || device->isAutoDetected(), return);
|
||||
|
||||
const bool wasDefault = d->defaultDevices.value(device->type()) == device->id();
|
||||
const Id deviceType = device->type();
|
||||
@@ -316,19 +256,12 @@ void DeviceManager::removeDevice(Id id)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this == instance() && d->clonedInstance)
|
||||
d->clonedInstance->removeDevice(id);
|
||||
|
||||
emit updated();
|
||||
}
|
||||
|
||||
void DeviceManager::setDeviceState(Id deviceId, IDevice::DeviceState deviceState)
|
||||
{
|
||||
// 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.
|
||||
if (this == instance() && d->clonedInstance)
|
||||
d->clonedInstance->setDeviceState(deviceId, deviceState);
|
||||
|
||||
const int pos = d->indexForId(deviceId);
|
||||
if (pos < 0)
|
||||
return;
|
||||
@@ -389,13 +322,9 @@ void DeviceManager::setDefaultDevice(Id id)
|
||||
emit updated();
|
||||
}
|
||||
|
||||
DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManagerPrivate>())
|
||||
DeviceManager::DeviceManager()
|
||||
: d(std::make_unique<DeviceManagerPrivate>())
|
||||
{
|
||||
QTC_ASSERT(isInstance == !m_instance, return);
|
||||
|
||||
if (!isInstance)
|
||||
return;
|
||||
|
||||
m_instance = this;
|
||||
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
|
||||
this, &DeviceManager::save);
|
||||
@@ -482,15 +411,13 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
|
||||
DeviceManager::~DeviceManager()
|
||||
{
|
||||
if (d->clonedInstance != this)
|
||||
delete d->writer;
|
||||
if (m_instance == this)
|
||||
m_instance = nullptr;
|
||||
delete d->writer;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
IDevice::ConstPtr DeviceManager::deviceAt(int idx) const
|
||||
IDevice::Ptr DeviceManager::deviceAt(int idx) const
|
||||
{
|
||||
QTC_ASSERT(idx >= 0 && idx < deviceCount(), return IDevice::ConstPtr());
|
||||
QTC_ASSERT(idx >= 0 && idx < deviceCount(), return IDevice::Ptr());
|
||||
return d->devices.at(idx);
|
||||
}
|
||||
|
||||
@@ -515,16 +442,16 @@ bool DeviceManager::hasDevice(const QString &name) const
|
||||
});
|
||||
}
|
||||
|
||||
IDevice::ConstPtr DeviceManager::find(Id id) const
|
||||
IDevice::Ptr DeviceManager::find(Id id) const
|
||||
{
|
||||
const int index = d->indexForId(id);
|
||||
return index == -1 ? IDevice::ConstPtr() : deviceAt(index);
|
||||
return index == -1 ? IDevice::Ptr() : deviceAt(index);
|
||||
}
|
||||
|
||||
IDevice::ConstPtr DeviceManager::defaultDevice(Id deviceType) const
|
||||
IDevice::Ptr DeviceManager::defaultDevice(Id deviceType) const
|
||||
{
|
||||
const Id id = d->defaultDevices.value(deviceType);
|
||||
return id.isValid() ? find(id) : IDevice::ConstPtr();
|
||||
return id.isValid() ? find(id) : IDevice::Ptr();
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
@@ -574,9 +501,6 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QCOMPARE(dev->deviceState(), IDevice::DeviceStateUnknown);
|
||||
QCOMPARE(dev->type(), TestDevice::testTypeId());
|
||||
|
||||
TestDevice::Ptr dev2 = dev->clone();
|
||||
QCOMPARE(dev->id(), dev2->id());
|
||||
|
||||
DeviceManager * const mgr = DeviceManager::instance();
|
||||
QVERIFY(!mgr->find(dev->id()));
|
||||
const int oldDeviceCount = mgr->deviceCount();
|
||||
@@ -584,7 +508,6 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QSignalSpy deviceAddedSpy(mgr, &DeviceManager::deviceAdded);
|
||||
QSignalSpy deviceRemovedSpy(mgr, &DeviceManager::deviceRemoved);
|
||||
QSignalSpy deviceUpdatedSpy(mgr, &DeviceManager::deviceUpdated);
|
||||
QSignalSpy deviceListReplacedSpy(mgr, &DeviceManager::deviceListReplaced);
|
||||
QSignalSpy updatedSpy(mgr, &DeviceManager::updated);
|
||||
|
||||
mgr->addDevice(dev);
|
||||
@@ -594,7 +517,6 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QCOMPARE(deviceAddedSpy.count(), 1);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 0);
|
||||
QCOMPARE(deviceUpdatedSpy.count(), 0);
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
QCOMPARE(updatedSpy.count(), 1);
|
||||
deviceAddedSpy.clear();
|
||||
updatedSpy.clear();
|
||||
@@ -603,7 +525,6 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QCOMPARE(deviceAddedSpy.count(), 0);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 0);
|
||||
QCOMPARE(deviceUpdatedSpy.count(), 0);
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
QCOMPARE(updatedSpy.count(), 0);
|
||||
|
||||
mgr->setDeviceState(dev->id(), IDevice::DeviceReadyToUse);
|
||||
@@ -611,18 +532,6 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QCOMPARE(deviceAddedSpy.count(), 0);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 0);
|
||||
QCOMPARE(deviceUpdatedSpy.count(), 1);
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
QCOMPARE(updatedSpy.count(), 1);
|
||||
deviceUpdatedSpy.clear();
|
||||
updatedSpy.clear();
|
||||
|
||||
mgr->addDevice(dev2);
|
||||
QCOMPARE(mgr->deviceCount(), oldDeviceCount + 1);
|
||||
QVERIFY(mgr->find(dev->id()));
|
||||
QCOMPARE(deviceAddedSpy.count(), 0);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 0);
|
||||
QCOMPARE(deviceUpdatedSpy.count(), 1);
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
QCOMPARE(updatedSpy.count(), 1);
|
||||
deviceUpdatedSpy.clear();
|
||||
updatedSpy.clear();
|
||||
@@ -632,12 +541,12 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
|
||||
dev3->setDisplayName(dev->displayName());
|
||||
mgr->addDevice(dev3);
|
||||
QCOMPARE(mgr->deviceAt(mgr->deviceCount() - 1)->displayName(),
|
||||
QString(dev3->displayName() + QLatin1Char('2')));
|
||||
QCOMPARE(
|
||||
mgr->deviceAt(mgr->deviceCount() - 1)->displayName(),
|
||||
QString(dev->displayName() + QLatin1Char('2')));
|
||||
QCOMPARE(deviceAddedSpy.count(), 1);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 0);
|
||||
QCOMPARE(deviceUpdatedSpy.count(), 0);
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
QCOMPARE(updatedSpy.count(), 1);
|
||||
deviceAddedSpy.clear();
|
||||
updatedSpy.clear();
|
||||
@@ -649,8 +558,7 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
QVERIFY(!mgr->find(dev3->id()));
|
||||
QCOMPARE(deviceAddedSpy.count(), 0);
|
||||
QCOMPARE(deviceRemovedSpy.count(), 2);
|
||||
// QCOMPARE(deviceUpdatedSpy.count(), 0); Uncomment once the "default" stuff is gone.
|
||||
QCOMPARE(deviceListReplacedSpy.count(), 0);
|
||||
// QCOMPARE(deviceUpdatedSpy.count(), 0); Uncomment once the "default" stuff is gone.
|
||||
QCOMPARE(updatedSpy.count(), 2);
|
||||
}
|
||||
|
||||
|
@@ -31,18 +31,17 @@ public:
|
||||
~DeviceManager() override;
|
||||
|
||||
static DeviceManager *instance();
|
||||
static DeviceManager *clonedInstance();
|
||||
|
||||
int deviceCount() const;
|
||||
IDevice::ConstPtr deviceAt(int index) const;
|
||||
IDevice::Ptr deviceAt(int index) const;
|
||||
|
||||
void forEachDevice(const std::function<void(const IDeviceConstPtr &)> &) const;
|
||||
|
||||
IDevice::ConstPtr find(Utils::Id id) const;
|
||||
IDevice::ConstPtr defaultDevice(Utils::Id deviceType) const;
|
||||
IDevice::Ptr find(Utils::Id id) const;
|
||||
IDevice::Ptr defaultDevice(Utils::Id deviceType) const;
|
||||
bool hasDevice(const QString &name) const;
|
||||
|
||||
void addDevice(const IDevice::ConstPtr &device);
|
||||
void addDevice(const IDevice::Ptr &device);
|
||||
void removeDevice(Utils::Id id);
|
||||
void setDeviceState(Utils::Id deviceId, IDevice::DeviceState deviceState);
|
||||
|
||||
@@ -55,7 +54,6 @@ signals:
|
||||
void deviceAdded(Utils::Id id);
|
||||
void deviceRemoved(Utils::Id id);
|
||||
void deviceUpdated(Utils::Id id);
|
||||
void deviceListReplaced(); // For bulk changes via the settings dialog.
|
||||
void updated(); // Emitted for all of the above.
|
||||
|
||||
void devicesLoaded(); // Emitted once load() is done
|
||||
@@ -63,7 +61,7 @@ signals:
|
||||
private:
|
||||
void save();
|
||||
|
||||
DeviceManager(bool isInstance = true);
|
||||
DeviceManager();
|
||||
|
||||
void load();
|
||||
QList<IDevice::Ptr> fromMap(const Utils::Store &map, QHash<Utils::Id, Utils::Id> *defaultDevices);
|
||||
@@ -72,11 +70,6 @@ private:
|
||||
// For SettingsWidget.
|
||||
IDevice::Ptr mutableDevice(Utils::Id id) const;
|
||||
void setDefaultDevice(Utils::Id id);
|
||||
static DeviceManager *cloneInstance();
|
||||
static void replaceInstance();
|
||||
static void removeClonedInstance();
|
||||
|
||||
static void copy(const DeviceManager *source, DeviceManager *target, bool deep);
|
||||
|
||||
const std::unique_ptr<Internal::DeviceManagerPrivate> d;
|
||||
|
||||
|
@@ -18,7 +18,7 @@ class DeviceManagerModelPrivate
|
||||
{
|
||||
public:
|
||||
const DeviceManager *deviceManager;
|
||||
QList<IDevice::ConstPtr> devices;
|
||||
QList<IDevice::Ptr> devices;
|
||||
QList<Id> filter;
|
||||
Id typeToKeep;
|
||||
};
|
||||
@@ -36,8 +36,6 @@ DeviceManagerModel::DeviceManagerModel(const DeviceManager *deviceManager, QObje
|
||||
this, &DeviceManagerModel::handleDeviceRemoved);
|
||||
connect(deviceManager, &DeviceManager::deviceUpdated,
|
||||
this, &DeviceManagerModel::handleDeviceUpdated);
|
||||
connect(deviceManager, &DeviceManager::deviceListReplaced,
|
||||
this, &DeviceManagerModel::handleDeviceListChanged);
|
||||
}
|
||||
|
||||
DeviceManagerModel::~DeviceManagerModel() = default;
|
||||
@@ -61,10 +59,10 @@ void DeviceManagerModel::updateDevice(Id id)
|
||||
handleDeviceUpdated(id);
|
||||
}
|
||||
|
||||
IDevice::ConstPtr DeviceManagerModel::device(int pos) const
|
||||
IDevice::Ptr DeviceManagerModel::device(int pos) const
|
||||
{
|
||||
if (pos < 0 || pos >= d->devices.count())
|
||||
return IDevice::ConstPtr();
|
||||
return nullptr;
|
||||
return d->devices.at(pos);
|
||||
}
|
||||
|
||||
@@ -90,7 +88,7 @@ void DeviceManagerModel::handleDeviceAdded(Id id)
|
||||
{
|
||||
if (d->filter.contains(id))
|
||||
return;
|
||||
IDevice::ConstPtr dev = d->deviceManager->find(id);
|
||||
IDevice::Ptr dev = d->deviceManager->find(id);
|
||||
if (!matchesTypeFilter(dev))
|
||||
return;
|
||||
|
||||
@@ -124,7 +122,7 @@ void DeviceManagerModel::handleDeviceListChanged()
|
||||
d->devices.clear();
|
||||
|
||||
for (int i = 0; i < d->deviceManager->deviceCount(); ++i) {
|
||||
IDevice::ConstPtr dev = d->deviceManager->deviceAt(i);
|
||||
IDevice::Ptr dev = d->deviceManager->deviceAt(i);
|
||||
if (d->filter.contains(dev->id()))
|
||||
continue;
|
||||
if (!matchesTypeFilter(dev))
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
void setFilter(const QList<Utils::Id> &filter);
|
||||
void setTypeFilter(Utils::Id type);
|
||||
|
||||
IDeviceConstPtr device(int pos) const;
|
||||
IDevicePtr device(int pos) const;
|
||||
Utils::Id deviceId(int pos) const;
|
||||
int indexOf(IDeviceConstPtr dev) const;
|
||||
int indexForId(Utils::Id id) const;
|
||||
|
@@ -45,14 +45,11 @@ class DeviceSettingsWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
DeviceSettingsWidget();
|
||||
~DeviceSettingsWidget() final
|
||||
{
|
||||
DeviceManager::removeClonedInstance();
|
||||
delete m_configWidget;
|
||||
}
|
||||
~DeviceSettingsWidget() final { delete m_configWidget; }
|
||||
|
||||
private:
|
||||
void apply() final { saveSettings(); }
|
||||
void cancel() final;
|
||||
|
||||
void saveSettings();
|
||||
|
||||
@@ -73,7 +70,6 @@ private:
|
||||
QString parseTestOutput();
|
||||
void updateDeviceFromUi();
|
||||
|
||||
DeviceManager * const m_deviceManager;
|
||||
DeviceManagerModel * const m_deviceManagerModel;
|
||||
QList<QPushButton *> m_additionalActionButtons;
|
||||
IDeviceWidget *m_configWidget = nullptr;
|
||||
@@ -93,9 +89,15 @@ private:
|
||||
QLayout *m_generalFormLayout;
|
||||
};
|
||||
|
||||
void DeviceSettingsWidget::cancel()
|
||||
{
|
||||
for (int i = 0; i < m_deviceManagerModel->rowCount(); i++)
|
||||
m_deviceManagerModel->device(i)->cancel();
|
||||
IOptionsPageWidget::cancel();
|
||||
}
|
||||
|
||||
DeviceSettingsWidget::DeviceSettingsWidget()
|
||||
: m_deviceManager(DeviceManager::cloneInstance())
|
||||
, m_deviceManagerModel(new DeviceManagerModel(m_deviceManager, this))
|
||||
: m_deviceManagerModel(new DeviceManagerModel(DeviceManager::instance(), this))
|
||||
{
|
||||
m_configurationLabel = new QLabel(Tr::tr("&Device:"));
|
||||
m_configurationComboBox = new QComboBox;
|
||||
@@ -132,7 +134,7 @@ DeviceSettingsWidget::DeviceSettingsWidget()
|
||||
connect(action, &QAction::triggered, this, [factory, this] {
|
||||
IDevice::Ptr device = factory->construct();
|
||||
QTC_ASSERT(device, return);
|
||||
m_deviceManager->addDevice(device);
|
||||
DeviceManager::instance()->addDevice(device);
|
||||
m_removeConfigButton->setEnabled(true);
|
||||
m_configurationComboBox->setCurrentIndex(m_deviceManagerModel->indexOf(device));
|
||||
saveSettings();
|
||||
@@ -206,7 +208,7 @@ DeviceSettingsWidget::DeviceSettingsWidget()
|
||||
this, &DeviceSettingsWidget::setDefaultDevice);
|
||||
connect(m_removeConfigButton, &QAbstractButton::clicked,
|
||||
this, &DeviceSettingsWidget::removeDevice);
|
||||
connect(m_deviceManager, &DeviceManager::deviceUpdated,
|
||||
connect(DeviceManager::instance(), &DeviceManager::deviceUpdated,
|
||||
this, &DeviceSettingsWidget::handleDeviceUpdated);
|
||||
}
|
||||
|
||||
@@ -228,7 +230,7 @@ void DeviceSettingsWidget::addDevice()
|
||||
|
||||
Utils::asyncRun([device] { device->checkOsType(); });
|
||||
|
||||
m_deviceManager->addDevice(device);
|
||||
DeviceManager::instance()->addDevice(device);
|
||||
m_removeConfigButton->setEnabled(true);
|
||||
m_configurationComboBox->setCurrentIndex(m_deviceManagerModel->indexOf(device));
|
||||
saveSettings();
|
||||
@@ -238,8 +240,8 @@ void DeviceSettingsWidget::addDevice()
|
||||
|
||||
void DeviceSettingsWidget::removeDevice()
|
||||
{
|
||||
m_deviceManager->removeDevice(currentDevice()->id());
|
||||
if (m_deviceManager->deviceCount() == 0)
|
||||
DeviceManager::instance()->removeDevice(currentDevice()->id());
|
||||
if (DeviceManager::instance()->deviceCount() == 0)
|
||||
currentDeviceChanged(-1);
|
||||
}
|
||||
|
||||
@@ -247,7 +249,7 @@ void DeviceSettingsWidget::displayCurrent()
|
||||
{
|
||||
const IDevice::ConstPtr ¤t = currentDevice();
|
||||
m_defaultDeviceButton->setEnabled(
|
||||
m_deviceManager->defaultDevice(current->type()) != current);
|
||||
DeviceManager::instance()->defaultDevice(current->type()) != current);
|
||||
m_osTypeValueLabel->setText(current->displayType());
|
||||
m_autoDetectionLabel->setText(current->isAutoDetected()
|
||||
? Tr::tr("Yes (id is \"%1\")").arg(current->id().toString()) : Tr::tr("No"));
|
||||
@@ -281,7 +283,6 @@ void DeviceSettingsWidget::saveSettings()
|
||||
{
|
||||
updateDeviceFromUi();
|
||||
ICore::settings()->setValueWithDefault(LastDeviceIndexKey, currentIndex(), 0);
|
||||
DeviceManager::replaceInstance();
|
||||
}
|
||||
|
||||
int DeviceSettingsWidget::currentIndex() const
|
||||
@@ -298,7 +299,7 @@ IDevice::ConstPtr DeviceSettingsWidget::currentDevice() const
|
||||
|
||||
void DeviceSettingsWidget::setDefaultDevice()
|
||||
{
|
||||
m_deviceManager->setDefaultDevice(currentDevice()->id());
|
||||
DeviceManager::instance()->setDefaultDevice(currentDevice()->id());
|
||||
m_defaultDeviceButton->setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@ void DeviceSettingsWidget::testDevice()
|
||||
{
|
||||
const IDevice::ConstPtr &device = currentDevice();
|
||||
QTC_ASSERT(device && device->hasDeviceTester(), return);
|
||||
auto dlg = new DeviceTestDialog(m_deviceManager->mutableDevice(device->id()), this);
|
||||
auto dlg = new DeviceTestDialog(DeviceManager::instance()->mutableDevice(device->id()), this);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->setModal(true);
|
||||
dlg->show();
|
||||
@@ -368,7 +369,7 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
|
||||
QPushButton * const button = new QPushButton(deviceAction.display);
|
||||
m_additionalActionButtons << button;
|
||||
connect(button, &QAbstractButton::clicked, this, [this, deviceAction] {
|
||||
const IDevice::Ptr device = m_deviceManager->mutableDevice(currentDevice()->id());
|
||||
const IDevice::Ptr device = DeviceManager::instance()->mutableDevice(currentDevice()->id());
|
||||
QTC_ASSERT(device, return);
|
||||
updateDeviceFromUi();
|
||||
deviceAction.execute(device);
|
||||
@@ -382,7 +383,7 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
|
||||
|
||||
if (!m_osSpecificGroupBox->layout())
|
||||
new QVBoxLayout(m_osSpecificGroupBox);
|
||||
m_configWidget = m_deviceManager->mutableDevice(device->id())->createWidget();
|
||||
m_configWidget = DeviceManager::instance()->mutableDevice(device->id())->createWidget();
|
||||
if (m_configWidget)
|
||||
m_osSpecificGroupBox->layout()->addWidget(m_configWidget);
|
||||
displayCurrent();
|
||||
|
@@ -224,7 +224,7 @@ IDevice::IDevice()
|
||||
if (newValue.trimmed().isEmpty())
|
||||
return ResultError(Tr::tr("The device name cannot be empty."));
|
||||
|
||||
if (DeviceManager::clonedInstance()->hasDevice(newValue))
|
||||
if (DeviceManager::instance()->hasDevice(newValue))
|
||||
return ResultError(Tr::tr("A device with this name already exists."));
|
||||
|
||||
return ResultOk;
|
||||
@@ -647,22 +647,6 @@ void IDevice::toMap(Store &map) const
|
||||
map.insert(HostKeyCheckingKey, ssh.hostKeyCheckingMode());
|
||||
}
|
||||
|
||||
IDevice::Ptr IDevice::clone() const
|
||||
{
|
||||
IDeviceFactory *factory = IDeviceFactory::find(d->type);
|
||||
QTC_ASSERT(factory, return {});
|
||||
Store store;
|
||||
toMap(store);
|
||||
IDevice::Ptr device = factory->construct();
|
||||
QTC_ASSERT(device, return {});
|
||||
device->d->deviceState = d->deviceState;
|
||||
device->d->deviceActions = d->deviceActions;
|
||||
device->d->deviceIcons = d->deviceIcons;
|
||||
device->d->osType = d->osType;
|
||||
device->fromMap(store);
|
||||
return device;
|
||||
}
|
||||
|
||||
QString IDevice::displayName() const
|
||||
{
|
||||
return d->displayName();
|
||||
|
@@ -91,8 +91,6 @@ public:
|
||||
|
||||
virtual ~IDevice();
|
||||
|
||||
virtual Ptr clone() const;
|
||||
|
||||
QString displayName() const;
|
||||
void setDisplayName(const QString &name);
|
||||
|
||||
|
@@ -618,7 +618,7 @@ public:
|
||||
#endif
|
||||
QThreadPool m_threadPool;
|
||||
|
||||
DeviceManager m_deviceManager{true};
|
||||
DeviceManager m_deviceManager;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
WinDebugInterface m_winDebugInterface;
|
||||
|
Reference in New Issue
Block a user