kdeconnect-kde/core/device.h

185 lines
6 KiB
C
Raw Normal View History

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>
#include <QVector>
#include <QSet>
#include <QSslKey>
#include <QtCrypto>
#include <QSslCertificate>
#include <QTimer>
2013-08-13 04:15:57 +01:00
#include "networkpackage.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;
class PairingHandler;
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")
Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString iconName READ iconName CONSTANT)
Q_PROPERTY(QString statusIconName READ statusIconName)
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChanged)
Q_PROPERTY(QStringList unsupportedPlugins READ unsupportedPlugins NOTIFY pluginsChanged)
2013-06-25 17:08:34 +01:00
2015-09-12 21:03:39 +01:00
public:
enum PairStatus {
NotPaired,
Paired,
};
enum DeviceType {
Unknown,
Desktop,
Laptop,
Phone,
Tablet,
};
/**
* 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
*/
2014-01-22 22:31:27 +00:00
Device(QObject* parent, const NetworkPackage& np, DeviceLink* dl);
2013-08-16 08:27:32 +01:00
virtual ~Device();
2013-08-13 04:14:46 +01:00
QString id() const { return m_deviceId; }
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); }
QCA::PublicKey publicKey() const { return m_publicKey; }
QSslCertificate certificate() const { return m_certificate; }
2015-07-19 15:55:28 +01:00
Q_SCRIPTABLE QByteArray certificate(int format) const { return (format == QSsl::Pem) ? m_certificate.toPem() : m_certificate.toDer() ;} // To expose certificate through dbus for cli
QString iconName() const;
QString statusIconName() const;
QStringList unsupportedPlugins() const { return m_unsupportedPlugins; }
//Add and remove links
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
void removeLink(DeviceLink*);
2015-07-09 22:51:08 +01:00
// Setter for public key after pairing, since it is handled by pairinghandler now
void setPublicKey(QCA::PublicKey publicKey) { m_publicKey = publicKey; }
Q_SCRIPTABLE bool isPaired() const { return m_pairStatus==Device::Paired; }
2015-07-27 16:28:58 +01:00
Q_SCRIPTABLE bool pairRequested() const;
Q_SCRIPTABLE QStringList availableLinks() const;
bool isReachable() const { return !m_deviceLinks.isEmpty(); }
Q_SCRIPTABLE QStringList loadedPlugins() const;
Q_SCRIPTABLE bool hasPlugin(const QString& name) const;
Q_SCRIPTABLE QString pluginsConfigFile() const;
void pairingTimeout();
KdeConnectPlugin* plugin(const QString& pluginName) const;
void setPluginEnabled(const QString& pluginName, bool enabled);
bool isPluginEnabled(const QString& pluginName) const;
2015-09-12 21:03:39 +01:00
PairStatus pairStatus() const;
DeviceLink::ConnectionStarted connectionSource() const;
public Q_SLOTS:
///sends a @p np package to the device
virtual bool sendPackage(NetworkPackage& np);
//Dbus operations
public Q_SLOTS:
Q_SCRIPTABLE void requestPair();
Q_SCRIPTABLE void unpair();
Q_SCRIPTABLE void reloadPlugins(); //From kconf
void acceptPairing();
void rejectPairing();
private Q_SLOTS:
void privateReceivedPackage(const NetworkPackage& np);
void linkDestroyed(QObject* o);
void destroyPairingHandler();
2013-06-06 04:57:06 +01:00
2015-07-27 16:28:58 +01:00
void setAsPaired();
void unpairInternal();
Q_SIGNALS:
Q_SCRIPTABLE void pluginsChanged();
2015-06-22 03:39:04 +01:00
Q_SCRIPTABLE void reachableStatusChanged();
Q_SCRIPTABLE void pairingChanged(bool paired);
Q_SCRIPTABLE void pairingFailed(const QString& error);
Q_SCRIPTABLE void nameChanged(const QString& name);
QT_DEPRECATED Q_SCRIPTABLE void pairingSuccesful();
QT_DEPRECATED Q_SCRIPTABLE void unpaired();
private: //Methods
2015-09-12 21:03:39 +01:00
static DeviceType str2type(const QString &deviceType);
static QString type2str(DeviceType deviceType);
void setName(const QString &name);
QString iconForStatus(bool reachable, bool paired) const;
private: //Fields (TODO: dPointer!)
const QString m_deviceId;
QString m_deviceName;
DeviceType m_deviceType;
QCA::PublicKey m_publicKey;
2015-07-05 14:23:53 +01:00
QSslCertificate m_certificate;
PairStatus m_pairStatus;
int m_protocolVersion;
QVector<DeviceLink*> m_deviceLinks;
QHash<QString, KdeConnectPlugin*> m_plugins;
QMap<QString, PairingHandler*> m_pairingHandlers;
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
QTimer m_pairingTimeut;
QSet<QString> m_incomingCapabilities;
QSet<QString> m_outgoingCapabilities;
QStringList m_supportedIncomingInterfaces;
2015-09-12 16:48:24 +01:00
QStringList m_supportedOutgoingInterfaces;
QStringList m_unsupportedPlugins;
2013-06-06 04:57:06 +01:00
};
Q_DECLARE_METATYPE(Device*)
2013-06-06 04:57:06 +01:00
#endif // DEVICE_H