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>
|
2013-08-30 18:10:43 +01:00
|
|
|
#include <QSslKey>
|
|
|
|
#include <QTimer>
|
2013-08-31 12:04:00 +01:00
|
|
|
#include <QtCrypto>
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2013-08-13 04:15:57 +01:00
|
|
|
#include "networkpackage.h"
|
|
|
|
|
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")
|
2014-06-14 18:09:31 +01:00
|
|
|
Q_PROPERTY(QString id READ id CONSTANT)
|
|
|
|
Q_PROPERTY(QString iconName READ iconName CONSTANT)
|
2015-03-14 03:28:54 +00:00
|
|
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
2015-03-14 03:09:14 +00:00
|
|
|
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
|
2013-06-25 17:08:34 +01:00
|
|
|
|
2013-08-31 12:04:00 +01:00
|
|
|
enum PairStatus {
|
|
|
|
NotPaired,
|
2013-09-03 21:11:13 +01:00
|
|
|
Requested,
|
|
|
|
RequestedByPeer,
|
2013-08-31 12:04:00 +01:00
|
|
|
Paired,
|
|
|
|
};
|
|
|
|
|
2013-11-06 20:31:37 +00:00
|
|
|
enum DeviceType {
|
|
|
|
Unknown,
|
|
|
|
Desktop,
|
|
|
|
Laptop,
|
|
|
|
Phone,
|
|
|
|
Tablet,
|
|
|
|
};
|
|
|
|
static DeviceType str2type(QString deviceType);
|
|
|
|
static QString type2str(DeviceType deviceType);
|
|
|
|
|
2013-06-06 04:57:06 +01:00
|
|
|
public:
|
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
|
|
|
|
*/
|
2014-01-22 22:31:27 +00:00
|
|
|
Device(QObject* parent, const NetworkPackage& np, DeviceLink* dl);
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2013-08-16 08:27:32 +01:00
|
|
|
virtual ~Device();
|
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(); }
|
2014-06-14 18:09:31 +01:00
|
|
|
QString iconName() const;
|
2013-07-26 15:21:19 +01:00
|
|
|
|
2013-07-04 18:17:22 +01:00
|
|
|
//Add and remove links
|
2013-10-01 02:11:22 +01:00
|
|
|
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
|
2013-07-03 02:52:44 +01:00
|
|
|
void removeLink(DeviceLink*);
|
2014-01-17 08:57:07 +00:00
|
|
|
|
2013-08-31 12:04:00 +01:00
|
|
|
Q_SCRIPTABLE bool isPaired() const { return m_pairStatus==Device::Paired; }
|
2013-09-03 21:11:13 +01:00
|
|
|
Q_SCRIPTABLE bool pairRequested() const { return m_pairStatus==Device::Requested; }
|
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;
|
|
|
|
|
2013-07-03 02:52:44 +01:00
|
|
|
public Q_SLOTS:
|
2013-10-11 14:19:23 +01:00
|
|
|
///sends a @p np package to the device
|
2013-09-01 21:13:03 +01:00
|
|
|
virtual bool sendPackage(NetworkPackage& 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:
|
2013-08-30 18:10:43 +01:00
|
|
|
Q_SCRIPTABLE void requestPair();
|
|
|
|
Q_SCRIPTABLE void unpair();
|
|
|
|
Q_SCRIPTABLE void reloadPlugins(); //From kconf
|
|
|
|
void acceptPairing();
|
|
|
|
void rejectPairing();
|
2013-07-03 02:52:44 +01:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2013-08-30 18:10:43 +01:00
|
|
|
void privateReceivedPackage(const NetworkPackage& np);
|
2013-09-03 21:11:13 +01:00
|
|
|
void linkDestroyed(QObject* o);
|
2013-08-30 18:10:43 +01:00
|
|
|
void pairingTimeout();
|
2013-06-06 04:57:06 +01:00
|
|
|
|
2013-08-13 22:23:32 +01:00
|
|
|
Q_SIGNALS:
|
2013-08-16 05:26:40 +01:00
|
|
|
Q_SCRIPTABLE void reachableStatusChanged();
|
|
|
|
Q_SCRIPTABLE void pluginsChanged();
|
2013-08-30 18:10:43 +01:00
|
|
|
Q_SCRIPTABLE void pairingSuccesful();
|
|
|
|
Q_SCRIPTABLE void pairingFailed(const QString& error);
|
2013-09-16 15:52:40 +01:00
|
|
|
Q_SCRIPTABLE void unpaired();
|
2015-03-14 03:28:54 +00:00
|
|
|
Q_SCRIPTABLE void nameChanged(const QString& name);
|
2013-08-13 22:23:32 +01:00
|
|
|
|
2013-06-06 04:57:06 +01:00
|
|
|
private:
|
2015-03-14 03:28:54 +00:00
|
|
|
void setName(const QString &name);
|
2015-03-16 02:13:54 +00:00
|
|
|
void unpairInternal();
|
2015-03-14 03:28:54 +00:00
|
|
|
|
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-08-31 12:04:00 +01:00
|
|
|
QCA::PublicKey m_publicKey;
|
|
|
|
PairStatus m_pairStatus;
|
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;
|
2014-06-14 19:35:00 +01:00
|
|
|
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
|
|
|
|
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
|
2013-07-03 02:52:44 +01:00
|
|
|
|
2014-04-14 20:57:34 +01:00
|
|
|
QTimer m_pairingTimeut;
|
2015-03-14 01:44:21 +00:00
|
|
|
const QSet<QString> m_incomingCapabilities;
|
|
|
|
const QSet<QString> m_outgoingCapabilities;
|
2013-09-01 21:13:03 +01:00
|
|
|
|
2013-11-06 20:34:06 +00:00
|
|
|
void setAsPaired();
|
|
|
|
bool sendOwnPublicKey();
|
|
|
|
|
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
|