File: device.h

package info (click to toggle)
kdeconnect 25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,584 kB
  • sloc: cpp: 22,922; xml: 520; python: 92; sh: 25; makefile: 5
file content (141 lines) | stat: -rw-r--r-- 4,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#ifndef DEVICE_H
#define DEVICE_H

#include <QHostAddress>
#include <QObject>
#include <QString>

#include "backends/devicelink.h"
#include "deviceinfo.h"
#include "networkpacket.h"
#include "pairstate.h"

class DeviceLink;
class KdeConnectPlugin;

class KDECONNECTCORE_EXPORT Device : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device")
    Q_PROPERTY(QString type READ typeAsString NOTIFY typeChanged)
    Q_PROPERTY(QString name READ name NOTIFY nameChanged)
    Q_PROPERTY(QString iconName READ iconName CONSTANT)
    Q_PROPERTY(QString verificationKey READ verificationKey NOTIFY pairStateChanged)
    Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged)
    Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChanged)
    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)
    Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged)

public:
    /**
     * Restores the @p device from the saved configuration
     *
     * We already know it but we need to wait for an incoming DeviceLink to communicate
     */
    Device(QObject *parent, const QString &id);

    /**
     * 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, DeviceLink *link);

    ~Device() override;

    QString id() const;
    QString name() const;
    QString dbusPath() const
    {
        return QStringLiteral("/modules/kdeconnect/devices/") + id();
    }
    DeviceType type() const;
    QString typeAsString() const
    {
        return type().toString();
    };
    QString iconName() const;
    QString statusIconName() const;
    Q_SCRIPTABLE QString verificationKey() const;
    Q_SCRIPTABLE QString encryptionInfo() const;

    // Add and remove links
    void addLink(DeviceLink *link);
    void removeLink(DeviceLink *link);

    bool updateDeviceInfo(const DeviceInfo &deviceInfo);

    bool hasInvalidCertificate();
    QSslCertificate certificate() const;

    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;
    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;

    int protocolVersion();
    QStringList supportedPlugins() const;

    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:
    Q_SCRIPTABLE void requestPairing();
    Q_SCRIPTABLE void unpair();
    Q_SCRIPTABLE void reloadPlugins(); // from kconf

    Q_SCRIPTABLE void acceptPairing();
    Q_SCRIPTABLE void cancelPairing();

    Q_SCRIPTABLE QString pluginIconName(const QString &pluginName);
private Q_SLOTS:
    void privateReceivedPacket(const NetworkPacket &np);
    void linkDestroyed(QObject *o);

    void pairingHandler_incomingPairRequest();
    void pairingHandler_pairingFailed(const QString &errorMessage);
    void pairingHandler_pairingSuccessful();
    void pairingHandler_unpaired();

Q_SIGNALS:
    Q_SCRIPTABLE void pluginsChanged();
    Q_SCRIPTABLE void reachableChanged(bool reachable);
    Q_SCRIPTABLE void pairStateChanged(int pairState); // Hack because qdbus doesn't like enums
    Q_SCRIPTABLE void pairingFailed(const QString &error);
    Q_SCRIPTABLE void nameChanged(const QString &name);
    Q_SCRIPTABLE void typeChanged(const QString &type);
    Q_SCRIPTABLE void statusIconNameChanged();

private:
    class DevicePrivate;
    DevicePrivate *d;
};

Q_DECLARE_METATYPE(Device *)

#endif // DEVICE_H