diff --git a/core/daemon.cpp b/core/daemon.cpp index ca01283a9..1f5d76c60 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -21,6 +21,7 @@ #include "daemon.h" #include +#include #include #include #include @@ -90,6 +91,7 @@ Daemon::Daemon(QObject* parent, bool testMode) } //Register on DBus + qDBusRegisterMetaType< QMap >(); QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect")); QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents); @@ -168,6 +170,17 @@ QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const return ret; } +QMap Daemon::deviceNames(bool onlyReachable, bool onlyTrusted) const +{ + QMap ret; + for (Device* device : qAsConst(d->m_devices)) { + if (onlyReachable && !device->isReachable()) continue; + if (onlyTrusted && !device->isTrusted()) continue; + ret[device->id()] = device->name(); + } + return ret; +} + void Daemon::onNewDeviceLink(const NetworkPacket& identityPacket, DeviceLink* dl) { const QString& id = identityPacket.get(QStringLiteral("deviceId")); diff --git a/core/daemon.h b/core/daemon.h index 0d3742c5e..aa147fadb 100644 --- a/core/daemon.h +++ b/core/daemon.h @@ -71,6 +71,8 @@ public Q_SLOTS: //Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyPaired = false) const; + Q_SCRIPTABLE QMap deviceNames(bool onlyReachable = false, bool onlyPaired = false) const; + Q_SCRIPTABLE QString deviceIdByName(const QString& name) const; Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) = 0;