7#include "SensorQuery.h"
10#include <QDBusPendingCallWatcher>
12#include <QRegularExpression>
14#include "SensorDaemonInterface_p.h"
15#include "sensors_logging.h"
17using namespace KSysGuard;
19class SensorQuery::Private
22 enum class State { Initial, Running, Finished };
27 State state = State::Initial;
33KSysGuard::SensorQuery::SensorQuery(
const QString &path,
QObject *parent)
35 , d(std::make_unique<Private>())
40KSysGuard::SensorQuery::~SensorQuery()
44QString KSysGuard::SensorQuery::path()
const
49void KSysGuard::SensorQuery::setPath(
const QString &path)
51 if (path == d->path) {
55 if (d->state != Private::State::Initial) {
56 qCWarning(LIBKSYSGUARD_SENSORS) <<
"Cannot modify a running or finished query";
65 if (d->state != Private::State::Initial) {
69 d->state = Private::State::Running;
71 auto watcher = SensorDaemonInterface::instance()->allSensors();
74 watcher->deleteLater();
76 d->state = Private::State::Finished;
78 Q_EMIT finished(
this);
90 d->watcher->waitForFinished();
97 std::transform(d->result.cbegin(), d->result.cend(), std::back_inserter(ids), [](
auto entry) {
107 std::sort(d->result.begin(), d->result.end(), [&collator](
const QPair<QString, SensorInfo> &left,
const QPair<QString, SensorInfo> &right) {
108 return collator.compare(left.second.name, right.second.name) < 0;
122 result.append(qMakePair(it.key(), it.value()));
129 const auto sensorIds = reply.
value().keys();
130 for (
auto id : sensorIds) {
131 if (
id == path || regexp.match(
id).hasMatch()) {
132 result.append(qMakePair(
id, reply.
value().value(
id)));
bool waitForFinished()
Wait for the query to finish.
bool execute()
Start processing the query.
QStringList sensorIds() const
A list of sensors ids that match the query.
void sortByName()
Sort the retrieved sensors by their user visible names.
QString path(const QString &relativePath)
void setNumericMode(bool on)
void finished(QDBusPendingCallWatcher *self)
typename Select< 0 >::Type value() const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:45 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.