| 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 |
|
| 50 |
Battery::~Battery() = default; |
| 51 |
|
| 52 |
BatteryPtr Battery::toSharedPtr() const |
| 53 |
{ |
| 54 |
return d->q.toStrongRef(); |
| 55 |
} |
| 56 |
|
| 57 |
int 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" |