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
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QHostAddress>
|
2013-06-25 17:08:34 +01:00
|
|
|
#include <QObject>
|
2013-06-06 04:57:06 +01:00
|
|
|
#include <QString>
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2015-09-12 19:53:05 +01:00
|
|
|
#include "backends/devicelink.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include "networkpacket.h"
|
2023-06-01 01:25:37 +01:00
|
|
|
#include "pairstate.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
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class KDECONNECTCORE_EXPORT Device : 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)
|
2023-06-01 01:25:37 +01:00
|
|
|
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairStateChanged)
|
|
|
|
Q_PROPERTY(bool isPairRequested READ isPairRequested NOTIFY pairStateChanged)
|
|
|
|
Q_PROPERTY(bool isPairRequestedByPeer READ isPairRequestedByPeer NOTIFY pairStateChanged)
|
|
|
|
Q_PROPERTY(int pairState READ pairStateAsInt NOTIFY pairStateChanged)
|
2016-07-06 16:37:22 +01:00
|
|
|
Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged)
|
2013-06-25 17:08:34 +01:00
|
|
|
|
2015-09-12 21:03:39 +01:00
|
|
|
public:
|
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
|
|
|
|
*/
|
2022-09-10 22:23:52 +01: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
|
|
|
|
*/
|
2022-09-10 22:23:52 +01: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;
|
2022-09-10 22:23:52 +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
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// Add and remove links
|
|
|
|
void addLink(const NetworkPacket &identityPacket, DeviceLink *);
|
|
|
|
void removeLink(DeviceLink *);
|
2015-05-18 07:28:58 +01:00
|
|
|
|
2023-06-01 01:25:37 +01:00
|
|
|
PairState pairState() const;
|
|
|
|
Q_SCRIPTABLE int pairStateAsInt() const; // Hack because qdbus doesn't like enums
|
|
|
|
Q_SCRIPTABLE bool isPaired() const;
|
|
|
|
Q_SCRIPTABLE bool isPairRequested() const;
|
|
|
|
Q_SCRIPTABLE bool isPairRequestedByPeer() 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;
|
2022-09-10 22:23:52 +01:00
|
|
|
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;
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
KdeConnectPlugin *plugin(const QString &pluginName) const;
|
|
|
|
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
|
|
|
|
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:
|
2022-09-10 22:23:52 +01:00
|
|
|
/// sends a @p np packet to the device
|
|
|
|
/// virtual for testing purposes.
|
|
|
|
virtual bool sendPacket(NetworkPacket &np);
|
2013-07-23 16:50:09 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// Dbus operations
|
2013-07-23 16:50:09 +01:00
|
|
|
public Q_SLOTS:
|
2023-06-01 01:25:37 +01:00
|
|
|
Q_SCRIPTABLE void requestPairing();
|
|
|
|
Q_SCRIPTABLE void unpair();
|
2022-09-10 22:23:52 +01:00
|
|
|
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();
|
2023-06-01 01:25:37 +01:00
|
|
|
Q_SCRIPTABLE void cancelPairing();
|
2017-01-24 23:22:22 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE QString pluginIconName(const QString &pluginName);
|
2013-07-03 02:52:44 +01:00
|
|
|
private Q_SLOTS:
|
2022-09-10 22:23:52 +01:00
|
|
|
void privateReceivedPacket(const NetworkPacket &np);
|
|
|
|
void linkDestroyed(QObject *o);
|
2023-06-01 01:25:37 +01:00
|
|
|
|
|
|
|
void pairingHandler_incomingPairRequest();
|
|
|
|
void pairingHandler_pairingFailed(const QString &errorMessage);
|
|
|
|
void pairingHandler_pairingSuccessful();
|
|
|
|
void pairingHandler_unpaired();
|
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);
|
2023-06-01 01:25:37 +01:00
|
|
|
Q_SCRIPTABLE void pairStateChanged(int pairState); // Hack because qdbus doesn't like enums
|
|
|
|
Q_SCRIPTABLE void pairingFailed(const QString &error);
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE void nameChanged(const QString &name);
|
|
|
|
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
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
private: // Methods
|
|
|
|
static DeviceType str2type(const QString &deviceType);
|
2015-09-12 21:03:39 +01:00
|
|
|
static QString type2str(DeviceType deviceType);
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void setName(const QString &name);
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_DECLARE_METATYPE(Device *)
|
2013-08-13 04:07:32 +01:00
|
|
|
|
2013-06-06 04:57:06 +01:00
|
|
|
#endif // DEVICE_H
|