BluezQt

battery.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <[email protected]>
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 
16 namespace BluezQt
17 {
18 BatteryPrivate::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 
26 void 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 
45 Battery::Battery(const QString &path, const QVariantMap &properties)
46  : d(new BatteryPrivate(path, properties))
47 {
48 }
49 
51 {
52  delete d;
53 }
54 
56 {
57  return d->q.toStrongRef();
58 }
59 
60 int Battery::percentage() const
61 {
62  return d->m_percentage;
63 }
64 
65 } // namespace BluezQt
66 
67 #include "moc_battery.cpp"
68 #include "moc_battery_p.cpp"
T value() const const
KGuiItem properties()
~Battery() override
Destroys a Battery object.
Definition: battery.cpp:50
BatteryPtr toSharedPtr() const
Returns a shared pointer from this.
Definition: battery.cpp:55
int toInt(bool *ok) const const
QString path(const QString &relativePath)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:04:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.