Changeset View
Changeset View
Standalone View
Standalone View
libs/bolt/manager.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 - 2019 Daniel Vrátil <dvratil@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef MANAGER_H_ | ||||
22 | #define MANAGER_H_ | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QSharedPointer> | ||||
26 | | ||||
27 | #include <functional> | ||||
28 | #include <memory> | ||||
29 | | ||||
30 | #include "enum.h" | ||||
31 | #include "kbolt_export.h" | ||||
32 | | ||||
33 | class QDBusObjectPath; | ||||
34 | class OrgFreedesktopBolt1ManagerInterface; | ||||
35 | namespace Bolt | ||||
36 | { | ||||
37 | | ||||
38 | class Device; | ||||
39 | class KBOLT_EXPORT Manager : public QObject | ||||
40 | { | ||||
41 | Q_OBJECT | ||||
42 | | ||||
43 | Q_PROPERTY(bool isAvailable READ isAvailable CONSTANT) | ||||
44 | Q_PROPERTY(uint version READ version CONSTANT STORED false) | ||||
45 | Q_PROPERTY(bool isProbing READ isProbing CONSTANT STORED false) | ||||
46 | Q_PROPERTY(Bolt::Policy defaultPolicy READ defaultPolicy CONSTANT STORED false) | ||||
47 | Q_PROPERTY(Bolt::Security securityLevel READ securityLevel CONSTANT STORED false) | ||||
48 | Q_PROPERTY(Bolt::AuthMode authMode READ authMode WRITE setAuthMode STORED false) | ||||
49 | | ||||
50 | public: | ||||
51 | explicit Manager(QObject *parent = nullptr); | ||||
52 | ~Manager() override; | ||||
53 | | ||||
54 | bool isAvailable() const; | ||||
55 | | ||||
56 | uint version() const; | ||||
57 | bool isProbing() const; | ||||
58 | Policy defaultPolicy() const; | ||||
59 | Security securityLevel() const; | ||||
60 | AuthMode authMode() const; | ||||
61 | void setAuthMode(AuthMode mode); | ||||
62 | | ||||
63 | /** | ||||
64 | * Updates device authorization and stores it persistently. | ||||
65 | */ | ||||
66 | void enrollDevice(const QString &uid, Bolt::Policy policy, Bolt::AuthFlags flags, | ||||
67 | std::function<void()> successCallback = {}, | ||||
68 | std::function<void(const QString &)> errorCallback = {}); | ||||
69 | /** | ||||
70 | * Keeps device authorized but removes it from persistent store. | ||||
71 | * | ||||
72 | * Next time the device is plugged in, it will not be authorized. | ||||
73 | */ | ||||
74 | void forgetDevice(const QString &uid, | ||||
75 | std::function<void()> successCallback = {}, | ||||
76 | std::function<void(const QString &)> errorCallback = {}); | ||||
77 | | ||||
78 | public Q_SLOTS: | ||||
79 | QSharedPointer<Bolt::Device> device(const QString &uid) const; | ||||
80 | QSharedPointer<Bolt::Device> device(const QDBusObjectPath &path) const; | ||||
81 | QList<QSharedPointer<Bolt::Device>> devices() const; | ||||
82 | | ||||
83 | Q_SIGNALS: | ||||
84 | void deviceAdded(const QSharedPointer<Bolt::Device> &device); | ||||
85 | void deviceRemoved(const QSharedPointer<Bolt::Device> &device); | ||||
86 | | ||||
87 | private: | ||||
88 | QSharedPointer<Device> device(std::function<bool(const QSharedPointer<Device> &)> &&match) const; | ||||
89 | std::unique_ptr<OrgFreedesktopBolt1ManagerInterface> mInterface; | ||||
90 | | ||||
91 | uint mVersion = 0; | ||||
92 | Policy mPolicy = Policy::Unknown; | ||||
93 | Security mSecurity = Security::Unknown; | ||||
94 | AuthMode mAuthMode = AuthMode::Disabled; | ||||
95 | bool mIsProbing = false; | ||||
96 | | ||||
97 | QList<QSharedPointer<Device>> mDevices; | ||||
98 | }; | ||||
99 | | ||||
100 | } // namespace | ||||
101 | | ||||
102 | #endif |