8#include "iokitbattery.h"
9#include "iokitdevice.h"
13using namespace Solid::Backends::IOKit;
15Battery::Battery(IOKitDevice *device)
16 : DeviceInterface(device)
70qlonglong Battery::timeToEmpty()
const
72 if (chargeState() != Solid::Battery::Charging) {
73 int t = m_device->property(QStringLiteral(
"AvgTimeToEmpty")).
toInt();
74 return t == 65535 ? -1 : t * 60;
79qlonglong Battery::timeToFull()
const
81 if (chargeState() == Solid::Battery::Charging) {
82 int t = m_device->property(QStringLiteral(
"AvgTimeToFull")).
toInt();
83 return t == 65535 ? -1 : t * 60;
88double Battery::voltage()
const
90 return m_device->property(QStringLiteral(
"Voltage")).
toInt() / 1000.0;
93double Battery::temperature()
const
95 return m_device->property(QStringLiteral(
"Temperature")).
toInt() / 100.0;
100 return m_device->property(QStringLiteral(
"BatterySerialNumber")).
toString();
103bool Battery::isPresent()
const
105 return m_device->property(QStringLiteral(
"ExternalConnected")).
toBool();
112 return Solid::Battery::PrimaryBattery;
115int Battery::chargePercent()
const
118 int maxCapacity = m_device->property(QStringLiteral(
"MaxCapacity")).
toInt();
119 if (maxCapacity == 0) {
122 return int(m_device->property(QStringLiteral(
"CurrentCapacity")).toInt() * 100.0 / maxCapacity + 0.5);
125int Battery::capacity()
const
127 if (m_device->iOKitPropertyExists(QStringLiteral(
"PermanentFailureStatus"))
128 && m_device->property(QStringLiteral(
"PermanentFailureStatus")).toInt()) {
134int Battery::cycleCount()
const
136 return m_device->property(QStringLiteral(
"CycleCount")).
toInt();
139bool Battery::isRechargeable()
const
141 return m_device->property(QStringLiteral(
"CycleCount")).
toInt() > 1;
144bool Battery::isPowerSupply()
const
147 return m_device->iOKitPropertyExists(QStringLiteral(
"BatteryInstalled"))
148 ? m_device->property(QStringLiteral(
"BatteryInstalled")).
toBool()
155 if (m_device->property(QStringLiteral(
"IsCharging")).toBool()) {
156 return Solid::Battery::Charging;
158 if (m_device->property(QStringLiteral(
"FullyCharged")).toBool()) {
159 return Solid::Battery::FullyCharged;
161 return Solid::Battery::Discharging;
164#include "moc_iokitbattery.cpp"
BatteryType
This enum type defines the type of the device holding the battery.
ChargeState
This enum type defines charge state of a battery.
bool toBool() const const
int toInt(bool *ok) const const
QString toString() const const