2013-06-06 04:57:06 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2013-06-06 04:57:06 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2013-06-06 04:57:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DEVICE_H
|
|
|
|
#define DEVICE_H
|
|
|
|
|
2013-06-25 17:08:34 +01:00
|
|
|
#include <QObject>
|
2013-06-06 04:57:06 +01:00
|
|
|
#include <QString>
|
2017-07-22 10:13:21 +01:00
|
|
|
#include <QHostAddress>
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
#include "networkpacket.h"
|
2015-09-12 19:53:05 +01:00
|
|
|
#include "backends/devicelink.h"
|
2013-08-13 04:15:57 +01:00
|
|
|
|
2013-07-03 02:52:44 +01:00
|
|
|
class DeviceLink;
|
2013-08-13 04:14:46 +01:00
|
|
|
class KdeConnectPlugin;
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2014-06-14 13:31:31 +01:00
|
|
|
class KDECONNECTCORE_EXPORT Device
|
2013-07-28 21:00:45 +01:00
|
|
|
: public QObject
|
2013-06-06 04:57:06 +01:00
|
|
|
{
|
2013-06-25 17:08:34 +01:00
|
|
|
Q_OBJECT
|
2013-07-26 15:21:19 +01:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device")
|
2020-08-02 12:57:58 +01:00
|
|
|
Q_PROPERTY(QString type READ type NOTIFY typeChanged)
|
2015-03-14 03:28:54 +00:00
|
|
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
2015-05-18 07:28:58 +01:00
|
|
|
Q_PROPERTY(QString iconName READ iconName CONSTANT)
|
2019-07-21 16:53:06 +01:00
|
|
|
Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged)
|
2016-11-23 16:24:03 +00:00
|
|
|
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChanged)
|
2015-12-01 18:45:14 +00:00
|
|
|
Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChanged)
|
2016-07-06 16:37:22 +01:00
|
|
|
Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged)
|
2017-01-25 00:18:14 +00:00
|
|
|
Q_PROPERTY(bool hasPairingRequests READ hasPairingRequests NOTIFY hasPairingRequestsChanged)
|
2013-06-25 17:08:34 +01:00
|
|
|
|
2015-09-12 21:03:39 +01:00
|
|
|
public:
|
2013-08-31 12:04:00 +01:00
|
|
|
|
2013-11-06 20:31:37 +00:00
|
|
|
enum DeviceType {
|
|
|
|
Unknown,
|
|
|
|
Desktop,
|
|
|
|
Laptop,
|
|
|
|
Phone,
|
|
|
|
Tablet,
|
2018-05-10 12:12:42 +01:00
|
|
|
Tv,
|
2013-11-06 20:31:37 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 14:19:23 +01:00
|
|
|
/**
|
2015-03-02 04:16:07 +00:00
|
|
|
* Restores the @p device from the saved configuration
|
2013-10-11 14:19:23 +01:00
|
|
|
*
|
|
|
|
* We already know it but we need to wait for an incoming DeviceLink to communicate
|
|
|
|
*/
|
2014-01-22 22:31:27 +00:00
|
|
|
Device(QObject* parent, const QString& id);
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-10-11 14:19:23 +01:00
|
|
|
/**
|
|
|
|
* Device known via an incoming connection sent to us via a devicelink.
|
|
|
|
*
|
|
|
|
* We know everything but we don't trust it yet
|
|
|
|
*/
|
2018-03-04 19:48:51 +00:00
|
|
|
Device(QObject* parent, const NetworkPacket& np, DeviceLink* dl);
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2016-06-20 08:05:02 +01:00
|
|
|
~Device() override;
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2018-05-15 23:15:05 +01:00
|
|
|
QString id() const;
|
|
|
|
QString name() const;
|
2019-06-10 15:40:28 +01:00
|
|
|
QString dbusPath() const { return QStringLiteral("/modules/kdeconnect/devices/") + id(); }
|
2018-05-15 23:15:05 +01:00
|
|
|
QString type() const;
|
2014-06-14 18:09:31 +01:00
|
|
|
QString iconName() const;
|
2015-05-18 07:28:58 +01:00
|
|
|
QString statusIconName() const;
|
2020-11-26 10:28:32 +00:00
|
|
|
Q_SCRIPTABLE QByteArray verificationKey() const;
|
2015-12-01 15:25:34 +00:00
|
|
|
Q_SCRIPTABLE QString encryptionInfo() const;
|
2013-07-26 15:21:19 +01:00
|
|
|
|
2013-07-04 18:17:22 +01:00
|
|
|
//Add and remove links
|
2018-03-04 19:48:51 +00:00
|
|
|
void addLink(const NetworkPacket& identityPacket, DeviceLink*);
|
2013-07-03 02:52:44 +01:00
|
|
|
void removeLink(DeviceLink*);
|
2015-05-18 07:28:58 +01:00
|
|
|
|
2015-12-01 18:45:14 +00:00
|
|
|
Q_SCRIPTABLE bool isTrusted() const;
|
2013-08-31 12:04:00 +01:00
|
|
|
|
2013-08-13 04:07:32 +01:00
|
|
|
Q_SCRIPTABLE QStringList availableLinks() const;
|
2019-06-05 03:42:06 +01:00
|
|
|
virtual bool isReachable() const;
|
2013-08-31 12:04:00 +01:00
|
|
|
|
2013-09-01 21:13:03 +01:00
|
|
|
Q_SCRIPTABLE QStringList loadedPlugins() const;
|
|
|
|
Q_SCRIPTABLE bool hasPlugin(const QString& name) const;
|
2013-07-28 21:00:45 +01:00
|
|
|
|
2015-03-02 04:16:07 +00:00
|
|
|
Q_SCRIPTABLE QString pluginsConfigFile() const;
|
|
|
|
|
2015-09-08 16:28:47 +01:00
|
|
|
KdeConnectPlugin* plugin(const QString& pluginName) const;
|
2017-08-22 14:33:33 +01:00
|
|
|
Q_SCRIPTABLE void setPluginEnabled(const QString& pluginName, bool enabled);
|
|
|
|
Q_SCRIPTABLE bool isPluginEnabled(const QString& pluginName) const;
|
2015-09-07 13:54:33 +01:00
|
|
|
|
2016-01-10 15:12:13 +00:00
|
|
|
void cleanUnneededLinks();
|
2015-09-12 19:53:05 +01:00
|
|
|
|
2018-05-15 23:15:05 +01:00
|
|
|
int protocolVersion();
|
|
|
|
QStringList supportedPlugins() const;
|
2016-04-15 02:52:31 +01:00
|
|
|
|
2017-07-22 10:13:21 +01:00
|
|
|
QHostAddress getLocalIpAddress() const;
|
|
|
|
|
2013-07-03 02:52:44 +01:00
|
|
|
public Q_SLOTS:
|
2018-03-04 19:48:51 +00:00
|
|
|
///sends a @p np packet to the device
|
2016-06-20 08:05:02 +01:00
|
|
|
///virtual for testing purposes.
|
2018-03-04 19:48:51 +00:00
|
|
|
virtual bool sendPacket(NetworkPacket& np);
|
2013-07-23 16:50:09 +01:00
|
|
|
|
2013-08-30 18:10:43 +01:00
|
|
|
//Dbus operations
|
2013-07-23 16:50:09 +01:00
|
|
|
public Q_SLOTS:
|
2015-12-01 18:45:14 +00:00
|
|
|
Q_SCRIPTABLE void requestPair(); //to all links
|
|
|
|
Q_SCRIPTABLE void unpair(); //from all links
|
|
|
|
Q_SCRIPTABLE void reloadPlugins(); //from kconf
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2017-01-24 23:22:22 +00:00
|
|
|
Q_SCRIPTABLE void acceptPairing();
|
|
|
|
Q_SCRIPTABLE void rejectPairing();
|
2017-02-20 20:00:26 +00:00
|
|
|
Q_SCRIPTABLE bool hasPairingRequests() const;
|
2017-01-24 23:22:22 +00:00
|
|
|
|
2018-08-03 00:53:21 +01:00
|
|
|
Q_SCRIPTABLE QString pluginIconName(const QString& pluginName);
|
2013-07-03 02:52:44 +01:00
|
|
|
private Q_SLOTS:
|
2018-03-04 19:48:51 +00:00
|
|
|
void privateReceivedPacket(const NetworkPacket& np);
|
2013-09-03 21:11:13 +01:00
|
|
|
void linkDestroyed(QObject* o);
|
2015-12-01 18:45:14 +00:00
|
|
|
void pairStatusChanged(DeviceLink::PairStatus current);
|
2017-01-24 23:22:22 +00:00
|
|
|
void addPairingRequest(PairingHandler* handler);
|
|
|
|
void removePairingRequest(PairingHandler* handler);
|
2015-07-27 16:28:58 +01:00
|
|
|
|
2013-08-13 22:23:32 +01:00
|
|
|
Q_SIGNALS:
|
2013-08-16 05:26:40 +01:00
|
|
|
Q_SCRIPTABLE void pluginsChanged();
|
2016-11-23 16:24:03 +00:00
|
|
|
Q_SCRIPTABLE void reachableChanged(bool reachable);
|
2015-12-01 18:45:14 +00:00
|
|
|
Q_SCRIPTABLE void trustedChanged(bool trusted);
|
|
|
|
Q_SCRIPTABLE void pairingError(const QString& error);
|
2015-03-14 03:28:54 +00:00
|
|
|
Q_SCRIPTABLE void nameChanged(const QString& name);
|
2020-08-02 12:57:58 +01:00
|
|
|
Q_SCRIPTABLE void typeChanged(const QString& type);
|
2019-07-21 16:53:06 +01:00
|
|
|
Q_SCRIPTABLE void statusIconNameChanged();
|
2013-08-13 22:23:32 +01:00
|
|
|
|
2017-01-25 00:18:14 +00:00
|
|
|
Q_SCRIPTABLE void hasPairingRequestsChanged(bool hasPairingRequests);
|
2017-01-24 23:22:22 +00:00
|
|
|
|
2015-05-18 07:28:58 +01:00
|
|
|
private: //Methods
|
2017-09-03 20:39:44 +01:00
|
|
|
static DeviceType str2type(const QString& deviceType);
|
2015-09-12 21:03:39 +01:00
|
|
|
static QString type2str(DeviceType deviceType);
|
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
void setName(const QString& name);
|
2020-08-02 12:57:58 +01:00
|
|
|
void setType(const QString& strtype);
|
2015-05-18 07:28:58 +01:00
|
|
|
QString iconForStatus(bool reachable, bool paired) const;
|
2020-11-26 10:28:32 +00:00
|
|
|
QSslCertificate certificate() const;
|
2015-03-14 03:28:54 +00:00
|
|
|
|
2018-05-15 23:15:05 +01:00
|
|
|
private:
|
|
|
|
class DevicePrivate;
|
|
|
|
DevicePrivate *d;
|
2013-06-06 04:57:06 +01:00
|
|
|
};
|
|
|
|
|
2013-08-13 04:07:32 +01:00
|
|
|
Q_DECLARE_METATYPE(Device*)
|
|
|
|
|
2013-06-06 04:57:06 +01:00
|
|
|
#endif // DEVICE_H
|