Commit bafd3f0b authored by Tobias Hunger's avatar Tobias Hunger
Browse files

IDevice: Make id creation (a bit) less magic



Change-Id: Icf5743a5b5a6305d18860cf6f87d70079c3effbc
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 1eb1effb
......@@ -54,9 +54,9 @@ MaddeDevice::Ptr MaddeDevice::create()
}
MaddeDevice::Ptr MaddeDevice::create(const QString &name, const QString &type,
MachineType machineType, Origin origin, const QString &fingerprint)
MachineType machineType, Origin origin, const Core::Id &id)
{
return Ptr(new MaddeDevice(name, type, machineType, origin, fingerprint));
return Ptr(new MaddeDevice(name, type, machineType, origin, id));
}
MaddeDevice::MaddeDevice()
......@@ -64,8 +64,8 @@ MaddeDevice::MaddeDevice()
}
MaddeDevice::MaddeDevice(const QString &name, const QString &type, MachineType machineType,
Origin origin, const QString &fingerprint)
: LinuxDeviceConfiguration(name, type, machineType, origin, fingerprint)
Origin origin, const Core::Id &id)
: LinuxDeviceConfiguration(name, type, machineType, origin, id)
{
}
......
......@@ -48,7 +48,7 @@ public:
static Ptr create();
static Ptr create(const QString &name, const QString &type, MachineType machineType,
Origin origin = ManuallyAdded, const QString &fingerprint = QString());
Origin origin = ManuallyAdded, const Core::Id &id = Core::Id());
QString displayType() const;
QStringList actionIds() const;
......@@ -60,7 +60,7 @@ public:
private:
MaddeDevice();
MaddeDevice(const QString &name, const QString &type, MachineType machineType,
Origin origin, const QString &fingerprint);
Origin origin, const Core::Id &id);
MaddeDevice(const MaddeDevice &other);
};
......
......@@ -54,9 +54,8 @@ namespace ProjectExplorer {
namespace Internal {
static IDevice::Ptr findAutoDetectedDevice(const QList<IDevice::Ptr> &deviceList,
const QString &type, const QString &fingerprint)
const QString &type, const Core::Id id)
{
const Core::Id id(fingerprint);
foreach (const IDevice::Ptr &device, deviceList) {
if (device->isAutoDetected() && device->type() == type && device->id() == id)
return device;
......@@ -372,9 +371,9 @@ IDevice::ConstPtr DeviceManager::find(const Core::Id &id) const
}
IDevice::ConstPtr DeviceManager::findInactiveAutoDetectedDevice(const QString &type,
const QString &fingerprint)
const Core::Id id)
{
return findAutoDetectedDevice(d->inactiveAutoDetectedDevices, type, fingerprint);
return findAutoDetectedDevice(d->inactiveAutoDetectedDevices, type, id);
}
IDevice::ConstPtr DeviceManager::defaultDevice(const QString &deviceType) const
......
......@@ -61,8 +61,7 @@ public:
int deviceCount() const;
IDevice::ConstPtr deviceAt(int index) const;
IDevice::ConstPtr find(const Core::Id &id) const;
IDevice::ConstPtr findInactiveAutoDetectedDevice(const QString &type,
const QString &fingerprint);
IDevice::ConstPtr findInactiveAutoDetectedDevice(const QString &type, const Core::Id id);
IDevice::ConstPtr defaultDevice(const QString &deviceType) const;
bool hasDevice(const QString &name) const;
Core::Id deviceId(const IDevice::ConstPtr &device) const;
......
......@@ -78,10 +78,10 @@
*/
/*!
* \fn Core::Id ProjectExplorer::IDevice::internalId() const
* \brief Identify the device internally.
* If a fingerprint is given when constructing the device, the id will be derived from it, and
* the fingerprint can later be retrieved from the id.
* \fn Core::Id ProjectExplorer::IDevice::id() const
* \brief Identify the device.
* If an id is given when constructing a device then this id is used. Otherwise a UUID is
* generated and used to identity the device.
* \sa ProjectExplorer::DeviceManager::findInactiveAutoDetectedDevice()
*/
......@@ -148,7 +148,7 @@ namespace ProjectExplorer {
const char DisplayNameKey[] = "Name";
const char TypeKey[] = "OsType";
const char InternalIdKey[] = "InternalId";
const char IdKey[] = "InternalId";
const char OriginKey[] = "Origin";
namespace Internal {
......@@ -158,7 +158,7 @@ public:
QString displayName;
QString type;
IDevice::Origin origin;
Core::Id internalId;
Core::Id id;
IDevice::AvailabilityState availability;
};
} // namespace Internal
......@@ -167,13 +167,13 @@ IDevice::IDevice() : d(new Internal::IDevicePrivate)
{
}
IDevice::IDevice(const QString &type, Origin origin, const QString &fingerprint)
IDevice::IDevice(const QString &type, Origin origin, const Core::Id &id)
: d(new Internal::IDevicePrivate)
{
d->type = type;
d->origin = origin;
QTC_CHECK(origin == ManuallyAdded || !fingerprint.isEmpty());
d->internalId = fingerprint.isEmpty() ? newId() : Core::Id(fingerprint);
QTC_CHECK(origin == ManuallyAdded || id.isValid());
d->id = id.isValid() ? id : newId();
d->availability = DeviceAvailabilityUnknown;
}
......@@ -227,7 +227,7 @@ bool IDevice::isAutoDetected() const
Core::Id IDevice::id() const
{
return d->internalId;
return d->id;
}
IDevice::AvailabilityState IDevice::availability() const
......@@ -256,7 +256,7 @@ void IDevice::fromMap(const QVariantMap &map)
{
d->type = typeFromMap(map);
d->displayName = map.value(QLatin1String(DisplayNameKey)).toString();
d->internalId = Core::Id(map.value(QLatin1String(InternalIdKey), newId().toString()).toString());
d->id = Core::Id(map.value(QLatin1String(IdKey), newId().name()).toByteArray().constData());
d->origin = static_cast<Origin>(map.value(QLatin1String(OriginKey), ManuallyAdded).toInt());
}
......@@ -265,7 +265,7 @@ QVariantMap IDevice::toMap() const
QVariantMap map;
map.insert(QLatin1String(DisplayNameKey), d->displayName);
map.insert(QLatin1String(TypeKey), d->type);
map.insert(QLatin1String(InternalIdKey), d->internalId.toString());
map.insert(QLatin1String(IdKey), d->id.name());
map.insert(QLatin1String(OriginKey), d->origin);
return map;
}
......
......@@ -32,7 +32,9 @@
#ifndef IDEVICE_H
#define IDEVICE_H
#include <projectexplorer/projectexplorer_export.h>
#include "../projectexplorer_export.h"
#include <coreplugin/id.h>
#include <coreplugin/id.h>
......@@ -99,7 +101,7 @@ public:
protected:
IDevice();
IDevice(const QString &type, Origin origin, const QString &fingerprint = QString());
IDevice(const QString &type, Origin origin, const Core::Id &id = Core::Id());
IDevice(const IDevice &other);
Ptr sharedFromThis();
......
......@@ -53,7 +53,7 @@ namespace Qt4ProjectManager {
SymbianIDevice::SymbianIDevice() :
ProjectExplorer::IDevice(Internal::SymbianIDeviceFactory::deviceType(),
ProjectExplorer::IDevice::AutoDetected,
QLatin1String("Symbian Device")),
Core::Id("Symbian Device")),
m_port(QLatin1String(DEFAULT_CODA_TCP_PORT)),
m_communicationChannel(CommunicationCodaSerialConnection)
{
......
......@@ -84,9 +84,9 @@ LinuxDeviceConfiguration::~LinuxDeviceConfiguration()
}
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &name,
const QString &type, MachineType machineType, Origin origin, const QString &fingerprint)
const QString &type, MachineType machineType, Origin origin, const Core::Id &id)
{
return Ptr(new LinuxDeviceConfiguration(name, type, machineType, origin, fingerprint));
return Ptr(new LinuxDeviceConfiguration(name, type, machineType, origin, id));
}
QString LinuxDeviceConfiguration::displayType() const
......@@ -140,8 +140,8 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration() : d(new LinuxDeviceConfigur
}
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QString &type,
MachineType machineType, Origin origin, const QString &fingerprint)
: IDevice(type, origin, fingerprint), d(new LinuxDeviceConfigurationPrivate)
MachineType machineType, Origin origin, const Core::Id &id)
: IDevice(type, origin, id), d(new LinuxDeviceConfigurationPrivate)
{
setDisplayName(name);
d->machineType = machineType;
......
......@@ -71,7 +71,7 @@ public:
static Ptr create();
static Ptr create(const QString &name, const QString &type, MachineType machineType,
Origin origin = ManuallyAdded, const QString &fingerprint = QString());
Origin origin = ManuallyAdded, const Core::Id &id = Core::Id());
QString displayType() const;
ProjectExplorer::IDeviceWidget *createWidget();
......@@ -84,7 +84,7 @@ public:
protected:
LinuxDeviceConfiguration();
LinuxDeviceConfiguration(const QString &name, const QString &type, MachineType machineType,
Origin origin, const QString &fingerprint);
Origin origin, const Core::Id &id);
LinuxDeviceConfiguration(const LinuxDeviceConfiguration &other);
QVariantMap toMap() const;
......
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