File indexing completed on 2024-04-21 05:31:42

0001 /*
0002     SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "sensors_export.h"
0010 #include <QObject>
0011 #include <memory>
0012 
0013 namespace KSysGuard
0014 {
0015 class SensorInfo;
0016 
0017 /**
0018  * An object to query the daemon for a list of sensors and their metadata.
0019  *
0020  * This class will request a list of sensors from the daemon, then filter them
0021  * based on the supplied path. The path can include the wildcard "*" to get a
0022  * list of all sensors matching the specified part of their path. In addition,
0023  * if left empty, all sensors will be returned.
0024  */
0025 class SENSORS_EXPORT SensorQuery : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     SensorQuery(const QString &path = QString{}, QObject *parent = nullptr);
0031     ~SensorQuery() override;
0032 
0033     QString path() const;
0034     void setPath(const QString &path);
0035 
0036     /**
0037      * A list of sensors ids that match the query.
0038      */
0039     QStringList sensorIds() const;
0040     /**
0041      * Sort the retrieved sensors by their user visible names.
0042      */
0043     void sortByName();
0044 
0045     /**
0046      * Start processing the query.
0047      */
0048     bool execute();
0049     /**
0050      * Wait for the query to finish.
0051      *
0052      * Mostly useful for code that needs the result to be available before
0053      * continuing. Ideally the finished() signal should be used instead.
0054      */
0055     bool waitForFinished();
0056 
0057     Q_SIGNAL void finished(SensorQuery *query);
0058 
0059 private:
0060     friend class Sensor;
0061     friend class SensorTreeModel;
0062     QList<QPair<QString, SensorInfo>> result() const;
0063 
0064     class Private;
0065     const std::unique_ptr<Private> d;
0066 };
0067 
0068 } // namespace KSysGuard