2013-06-06 04:57:06 +01:00
|
|
|
/**
|
|
|
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2015-03-14 03:07:55 +00:00
|
|
|
#include <QVector>
|
2014-11-04 18:12:29 +00:00
|
|
|
#include <QSet>
|
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")
|
2015-05-18 07:28:58 +01:00
|
|
|
Q_PROPERTY(QString type READ type CONSTANT)
|
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)
|
|
|
|
Q_PROPERTY(QString statusIconName READ statusIconName)
|
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
|
|
|
|
2013-08-13 04:14:46 +01:00
|
|
|
QString id() const { return m_deviceId; }
|
2013-07-26 15:21:19 +01:00
|
|
|
QString name() const { return m_deviceName; }
|
2013-08-20 12:52:25 +01:00
|
|
|
QString dbusPath() const { return "/modules/kdeconnect/devices/"+id(); }
|
2015-07-09 22:51:08 +01:00
|
|
|
QString type() const { return type2str(m_deviceType); }
|
2014-06-14 18:09:31 +01:00
|
|
|
QString iconName() const;
|
2015-05-18 07:28:58 +01:00
|
|
|
QString statusIconName() 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;
|
2015-03-14 03:09:14 +00:00
|
|
|
bool isReachable() const { return !m_deviceLinks.isEmpty(); }
|
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
|
|
|
|
2016-04-15 02:52:31 +01:00
|
|
|
int protocolVersion() { return m_protocolVersion; }
|
2016-07-06 16:37:22 +01:00
|
|
|
QStringList supportedPlugins() const { return m_supportedPlugins.toList(); }
|
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
|
|
|
|
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);
|
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);
|
2015-05-18 07:28:58 +01:00
|
|
|
QString iconForStatus(bool reachable, bool paired) const;
|
2015-03-14 03:28:54 +00:00
|
|
|
|
2015-05-18 07:28:58 +01:00
|
|
|
private: //Fields (TODO: dPointer!)
|
2013-10-11 14:19:23 +01:00
|
|
|
const QString m_deviceId;
|
2013-07-03 02:52:44 +01:00
|
|
|
QString m_deviceName;
|
2013-11-06 20:31:37 +00:00
|
|
|
DeviceType m_deviceType;
|
2013-10-01 00:09:20 +01:00
|
|
|
int m_protocolVersion;
|
2013-08-30 18:10:43 +01:00
|
|
|
|
2015-03-14 03:07:55 +00:00
|
|
|
QVector<DeviceLink*> m_deviceLinks;
|
|
|
|
QHash<QString, KdeConnectPlugin*> m_plugins;
|
2015-12-01 18:45:14 +00:00
|
|
|
|
|
|
|
//Capabilities stuff
|
2016-07-06 16:37:22 +01:00
|
|
|
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingCapability;
|
|
|
|
QSet<QString> m_supportedPlugins;
|
2017-01-24 23:22:22 +00:00
|
|
|
QSet<PairingHandler*> m_pairRequests;
|
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
|