Libksysguard

SensorFaceController_p.h
1/*
2 SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <KConfigGroup>
10#include <KConfigLoader>
11#include <KConfigPropertyMap>
12#include <KLocalizedContext>
13#include <KPackage/PackageLoader>
14#include <QJsonArray>
15#include <QQuickItem>
16#include <QStandardItemModel>
17
18#include <functional>
19
20#include "sensorfaces_export.h"
21
22class QQmlEngine;
23
24namespace KSysGuard
25{
26class SensorFaceController;
27class SensorFace;
28class SensorQuery;
29
30class FacesModel : public QStandardItemModel
31{
33public:
34 enum AdditionalRoles {
35 PluginIdRole = Qt::UserRole + 1,
36 };
37 Q_ENUM(AdditionalRoles)
38
39 FacesModel(QObject *parent = nullptr);
40 ~FacesModel() override = default;
41
42 Q_INVOKABLE void reload();
43 Q_INVOKABLE QString pluginId(int row);
44
45 QHash<int, QByteArray> roleNames() const override;
46};
47
48class PresetsModel : public QStandardItemModel
49{
51public:
52 enum AdditionalRoles { PluginIdRole = Qt::UserRole + 1, ConfigRole, WritableRole };
53 Q_ENUM(AdditionalRoles)
54
55 PresetsModel(QObject *parent = nullptr);
56 ~PresetsModel() override = default;
57
58 Q_INVOKABLE void reload();
59
60 QHash<int, QByteArray> roleNames() const override;
61};
62
63struct SensorResolver {
64 SensorResolver(SensorFaceController *_controller, const QJsonArray &_expected);
65 void execute();
66
67 SensorFaceController *controller = nullptr;
68
69 QJsonArray expected;
70 QJsonArray found;
71 QJsonArray missing;
72
74
75 std::function<void(SensorResolver *)> callback;
76};
77
78// This is exported so we can use it in autotests
79class SENSORFACES_EXPORT SensorFaceControllerPrivate
80{
81public:
82 SensorFaceControllerPrivate();
83
84 QJsonArray readSensors(const KConfigGroup &config, const QString &entryName);
85 QJsonArray readAndUpdateSensors(KConfigGroup &config, const QString &entryName);
86 QString replaceDiskId(const QString &entryname) const;
87 QString replacePartitionId(const QString &entryname) const;
88 void resolveSensors(const QJsonArray &partialEntries, std::function<void(SensorResolver *)>);
89 SensorFace *createGui(const QString &qmlPath);
90 QQuickItem *createConfigUi(const QString &file, const QVariantMap &initialProperties);
91
92 SensorFaceController *q;
93 QString title;
94 QQmlEngine *engine;
95 QQmlEngine *configEngine;
96
97 KConfigGroup faceProperties;
98 KConfigPropertyMap *faceConfiguration = nullptr;
99 KConfigLoader *faceConfigLoader = nullptr;
100
101 bool configNeedsSave = false;
102 KPackage::Package facePackage;
103 QString faceId;
104 KLocalizedContext *contextObj = nullptr;
105 KConfigGroup configGroup;
106 KConfigGroup appearanceGroup;
107 KConfigGroup sensorsGroup;
108 KConfigGroup colorsGroup;
109 KConfigGroup labelsGroup;
110 QPointer<SensorFace> fullRepresentation;
111 QPointer<SensorFace> compactRepresentation;
112 QPointer<QQuickItem> faceConfigUi;
113 QPointer<QQuickItem> appearanceConfigUi;
114 QPointer<QQuickItem> sensorsConfigUi;
115
116 QJsonArray totalSensors;
117 QJsonArray highPrioritySensorIds;
118 QJsonArray lowPrioritySensorIds;
119 QJsonArray missingSensors;
120
121 QTimer *syncTimer;
122 bool shouldSync = true;
123 FacesModel *availableFacesModel = nullptr;
124 PresetsModel *availablePresetsModel = nullptr;
125
126 static QList<QPair<QRegularExpression, QString>> sensorIdReplacements;
127 static QRegularExpression oldDiskSensor;
128 static QRegularExpression oldPartitionSensor;
129};
130
131}
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.