From b7420146eb3522b6b204a140e2ecc3ef575c64ad Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sat, 14 Jun 2014 19:09:31 +0200 Subject: [PATCH] Expose the icon name from the device instance --- core/device.cpp | 17 +++++++++++++++++ core/device.h | 4 +++- interfaces/devicesmodel.cpp | 5 ++++- interfaces/devicesmodel.h | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index 3f50ac0c1..65c5809ed 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -484,3 +484,20 @@ QString Device::type2str(Device::DeviceType deviceType) { if (deviceType == Tablet) return "tablet"; return "unknown"; } + +QString Device::iconName() const +{ + switch(m_deviceType) { + case Device::Desktop: + return "computer"; + case Device::Laptop: + return "computer-laptop"; + case Device::Phone: + return "smartphone"; + case Device::Tablet: + return "tablet"; + case Device::Unknown: + return "unknown"; + } + return QString(); +} diff --git a/core/device.h b/core/device.h index 7ebb5afbb..5ed10489d 100644 --- a/core/device.h +++ b/core/device.h @@ -38,7 +38,8 @@ class KDECONNECTCORE_EXPORT Device { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device") - Q_PROPERTY(QString id READ id) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString iconName READ iconName CONSTANT) Q_PROPERTY(QString name READ name) enum PairStatus { @@ -78,6 +79,7 @@ public: QString id() const { return m_deviceId; } QString name() const { return m_deviceName; } QString dbusPath() const { return "/modules/kdeconnect/devices/"+id(); } + QString iconName() const; //Add and remove links void addLink(const NetworkPackage& identityPackage, DeviceLink*); diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 8f2495f62..8242107cb 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -55,6 +55,7 @@ DevicesModel::DevicesModel(QObject *parent) //Role names for QML QHash names = roleNames(); names.insert(IdModelRole, "deviceId"); + names.insert(IconNameRole, "iconName"); setRoleNames(names); } @@ -167,8 +168,10 @@ QVariant DevicesModel::data(const QModelIndex& index, int role) const } return status; } + case IconNameRole: + return device->iconName(); default: - return QVariant(); + return QVariant(); } } diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index 33340f58d..15bcb6734 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -44,6 +44,7 @@ public: IconModelRole = Qt::DecorationRole, StatusModelRole = Qt::InitialSortOrderRole, IdModelRole = Qt::UserRole, + IconNameRole }; enum StatusFlags { StatusUnknown = 0x00,