1 /*
2     SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "sensors_export.h"
10 #include <QObject>
11 #include <memory>
12 
13 namespace KSysGuard
14 {
15 class SensorInfo;
16 
17 /**
18  * An object to query the daemon for a list of sensors and their metadata.
19  *
20  * This class will request a list of sensors from the daemon, then filter them
21  * based on the supplied path. The path can include the wildcard "*" to get a
22  * list of all sensors matching the specified part of their path. In addition,
23  * if left empty, all sensors will be returned.
24  */
25 class SENSORS_EXPORT SensorQuery : public QObject
26 {
27     Q_OBJECT
28 
29 public:
30     SensorQuery(const QString &path = QString{}, QObject *parent = nullptr);
31     ~SensorQuery() override;
32 
33     QString path() const;
34     void setPath(const QString &path);
35 
36     /**
37      * A list of sensors ids that match the query.
38      */
39     QStringList sensorIds() const;
40     /**
41      * Sort the retrieved sensors by their user visible names.
42      */
43     void sortByName();
44 
45     /**
46      * Start processing the query.
47      */
48     bool execute();
49     /**
50      * Wait for the query to finish.
51      *
52      * Mostly useful for code that needs the result to be available before
53      * continuing. Ideally the finished() signal should be used instead.
54      */
55     bool waitForFinished();
56 
57     Q_SIGNAL void finished(const SensorQuery *query);
58 
59 private:
60     friend class Sensor;
61     friend class SensorTreeModel;
62     QVector<QPair<QString, SensorInfo>> result() const;
63 
64     class Private;
65     const std::unique_ptr<Private> d;
66 };
67 
68 } // namespace KSysGuard
69