Libksysguard

SensorFaceController_p.h
1 /*
2  Copyright (C) 2020 Marco Martin <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #pragma once
21 
22 #include <QQuickItem>
23 #include <QStandardItemModel>
24 #include <QJsonArray>
25 #include <KLocalizedContext>
26 #include <KPackage/PackageLoader>
27 #include <KConfigGroup>
28 #include <KConfigLoader>
29 #include <KDeclarative/ConfigPropertyMap>
30 
31 #include <functional>
32 
33 #include "sensorfaces_export.h"
34 
35 class QQmlEngine;
36 
37 namespace KSysGuard {
38 
39 class SensorFaceController;
40 class SensorFace;
41 
42 class FacesModel : public QStandardItemModel
43 {
44  Q_OBJECT
45 public:
46  enum AdditionalRoles {
47  PluginIdRole = Qt::UserRole + 1,
48  };
49  Q_ENUM(AdditionalRoles)
50 
51  FacesModel(QObject *parent = nullptr);
52  ~FacesModel() = default;
53 
54  Q_INVOKABLE void reload();
55  Q_INVOKABLE QString pluginId(int row);
56 
57  QHash<int, QByteArray> roleNames() const override;
58 };
59 
60 class PresetsModel : public QStandardItemModel
61 {
62  Q_OBJECT
63 public:
64  enum AdditionalRoles {
65  PluginIdRole = Qt::UserRole + 1,
66  ConfigRole,
67  WritableRole
68  };
69  Q_ENUM(AdditionalRoles)
70 
71  PresetsModel(QObject *parent = nullptr);
72  ~PresetsModel() = default;
73 
74  Q_INVOKABLE void reload();
75 
76  QHash<int, QByteArray> roleNames() const override;
77 };
78 
79 // This is exported so we can use it in autotests
80 class SENSORFACES_EXPORT SensorFaceControllerPrivate
81 {
82 public:
83  SensorFaceControllerPrivate();
84 
85  QJsonArray readSensors(const KConfigGroup &config, const QString &entryName);
86  QJsonArray readAndUpdateSensors(KConfigGroup &config, const QString &entryName);
87  QString replaceDiskId(const QString &entryname) const;
88  QString replacePartitionId(const QString &entryname) const;
89  void resolveSensors(const QJsonArray &partialEntries, std::function<void(const QJsonArray&)> callback);
90  SensorFace *createGui(const QString &qmlPath);
91  QQuickItem *createConfigUi(const QString &file, const QVariantMap &initialProperties);
92 
93  SensorFaceController *q;
94  QString title;
95  QQmlEngine *engine;
96 
97  KConfigGroup faceProperties;
98  KDeclarative::ConfigPropertyMap *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  QPointer <SensorFace> fullRepresentation;
110  QPointer <SensorFace> compactRepresentation;
111  QPointer <QQuickItem> faceConfigUi;
112  QPointer <QQuickItem> appearanceConfigUi;
113  QPointer <QQuickItem> sensorsConfigUi;
114 
115  QJsonArray totalSensors;
116  QJsonArray highPrioritySensorIds;
117  QJsonArray lowPrioritySensorIds;
118 
119  QTimer *syncTimer;
120  bool shouldSync = true;
121  FacesModel *availableFacesModel = nullptr;
122  PresetsModel *availablePresetsModel = nullptr;
123 
124  static QVector<QPair<QRegularExpression, QString>> sensorIdReplacements;
125  static QRegularExpression oldDiskSensor;
126  static QRegularExpression oldPartitionSensor;
127 };
128 
129 }
Q_ENUM(...)
Q_OBJECTQ_OBJECT
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 02:46:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.