BluezQt

battery.cpp
1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "battery.h"
10#include "battery_p.h"
11#include "macros.h"
12#include "utils.h"
13
14#include <QVariantMap>
15
16namespace BluezQt
17{
18BatteryPrivate::BatteryPrivate(const QString &path, const QVariantMap &properties)
19 : QObject()
20 , m_path(path)
21{
22 // Init properties
23 m_percentage = properties.value(QStringLiteral("Percentage")).toInt();
24}
25
26void BatteryPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated)
27{
28 Q_UNUSED(invalidated)
29
30 if (interface != Strings::orgBluezBattery1()) {
31 return;
32 }
33
34 QVariantMap::const_iterator i;
35 for (i = changed.constBegin(); i != changed.constEnd(); ++i) {
36 const QVariant &value = i.value();
37 const QString &property = i.key();
38
39 if (property == QLatin1String("Percentage")) {
40 PROPERTY_CHANGED2(m_percentage, value.toInt(), percentageChanged)
41 }
42 }
43}
44
45Battery::Battery(const QString &path, const QVariantMap &properties)
46 : d(new BatteryPrivate(path, properties))
47{
48}
49
50Battery::~Battery() = default;
51
52BatteryPtr Battery::toSharedPtr() const
53{
54 return d->q.toStrongRef();
55}
56
57int Battery::percentage() const
58{
59 return d->m_percentage;
60}
61
62} // namespace BluezQt
63
64#include "moc_battery.cpp"
65#include "moc_battery_p.cpp"
QString path(const QString &relativePath)
KGuiItem properties()
int toInt(bool *ok) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.