kdeconnect-kde/core/device.h

144 lines
4.3 KiB
C
Raw Normal View History

2013-06-06 04:57:06 +01:00
/**
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
2013-06-06 04:57:06 +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>
#include <QHostAddress>
#include "networkpacket.h"
#include "backends/devicelink.h"
2013-08-13 04:15:57 +01:00
class DeviceLink;
2013-08-13 04:14:46 +01:00
class KdeConnectPlugin;
2013-06-06 04:57:06 +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
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)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString iconName READ iconName CONSTANT)
Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged)
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChanged)
2015-12-01 18:45:14 +00:00
Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChanged)
Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged)
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:
enum DeviceType {
Unknown,
Desktop,
Laptop,
Phone,
Tablet,
Tv,
};
/**
* Restores the @p device from the saved configuration
*
* 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
/**
* Device known via an incoming connection sent to us via a devicelink.
*
* We know everything but we don't trust it yet
*/
Device(QObject* parent, const NetworkPacket& np, DeviceLink* dl);
~Device() override;
QString id() const;
QString name() const;
QString dbusPath() const { return QStringLiteral("/modules/kdeconnect/devices/") + id(); }
QString type() const;
QString iconName() const;
QString statusIconName() const;
2015-12-01 15:25:34 +00:00
Q_SCRIPTABLE QString encryptionInfo() const;
//Add and remove links
void addLink(const NetworkPacket& identityPacket, DeviceLink*);
void removeLink(DeviceLink*);
2015-12-01 18:45:14 +00:00
Q_SCRIPTABLE bool isTrusted() const;
Q_SCRIPTABLE QStringList availableLinks() const;
2019-06-05 03:42:06 +01:00
virtual bool isReachable() const;
Q_SCRIPTABLE QStringList loadedPlugins() const;
Q_SCRIPTABLE bool hasPlugin(const QString& name) const;
Q_SCRIPTABLE QString pluginsConfigFile() const;
KdeConnectPlugin* plugin(const QString& pluginName) const;
Q_SCRIPTABLE void setPluginEnabled(const QString& pluginName, bool enabled);
Q_SCRIPTABLE bool isPluginEnabled(const QString& pluginName) const;
void cleanUnneededLinks();
int protocolVersion();
QStringList supportedPlugins() const;
2016-04-15 02:52:31 +01:00
QHostAddress getLocalIpAddress() const;
public Q_SLOTS:
///sends a @p np packet to the device
///virtual for testing purposes.
virtual bool sendPacket(NetworkPacket& np);
//Dbus operations
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
Q_SCRIPTABLE void acceptPairing();
Q_SCRIPTABLE void rejectPairing();
2017-02-20 20:00:26 +00:00
Q_SCRIPTABLE bool hasPairingRequests() const;
Q_SCRIPTABLE QString pluginIconName(const QString& pluginName);
private Q_SLOTS:
void privateReceivedPacket(const NetworkPacket& np);
void linkDestroyed(QObject* o);
2015-12-01 18:45:14 +00:00
void pairStatusChanged(DeviceLink::PairStatus current);
void addPairingRequest(PairingHandler* handler);
void removePairingRequest(PairingHandler* handler);
2015-07-27 16:28:58 +01:00
Q_SIGNALS:
Q_SCRIPTABLE void pluginsChanged();
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);
Q_SCRIPTABLE void nameChanged(const QString& name);
2020-08-02 12:57:58 +01:00
Q_SCRIPTABLE void typeChanged(const QString& type);
Q_SCRIPTABLE void statusIconNameChanged();
Q_SCRIPTABLE void hasPairingRequestsChanged(bool hasPairingRequests);
private: //Methods
static DeviceType str2type(const QString& deviceType);
2015-09-12 21:03:39 +01:00
static QString type2str(DeviceType deviceType);
void setName(const QString& name);
2020-08-02 12:57:58 +01:00
void setType(const QString& strtype);
QString iconForStatus(bool reachable, bool paired) const;
private:
class DevicePrivate;
DevicePrivate *d;
2013-06-06 04:57:06 +01:00
};
Q_DECLARE_METATYPE(Device*)
2013-06-06 04:57:06 +01:00
#endif // DEVICE_H