API Documentation
Documentation for developing SailfishOS applicationsBatteryInfo Class
(Sailfish::Mdm::BatteryInfo)The BatteryInfo class provides battery charge information. More...
Header: | #include <mdm-batteryinfo.h> |
Public Types
enum | ChargerStatus { Connected, Disconnected, ChargerStatusUnknown } |
enum | Status { Full, Normal, Low, Empty } |
Public Functions
BatteryInfo(QObject *parent = 0) | |
int | chargePercentage() const |
ChargerStatus | chargerStatus() const |
Status | status() const |
Signals
void | chargePercentageChanged(int percentage) |
void | chargerStatusChanged(ChargerStatus status) |
void | statusChanged(Status status) |
Detailed Description
The BatteryInfo class provides battery charge information.
To use this class, clients must add the following to their qmake project:
CONFIG += link_pkgconfig PKGCONFIG += sailfishmdm
and then #include <mdm-batteryinfo.h>
.
Example of usage:
#include <mdm-batteryinfo.h> void listenForBatteryChanges(QObject *parent) { Sailfish::Mdm::BatteryInfo *info = new Sailfish::Mdm::BatteryInfo(parent); connect(info, &Sailfish::Mdm::BatteryInfo::chargerStatusChanged, [info] { qInfo() << "Charger status now:" << info->chargerStatus(); }); connect(info, &Sailfish::Mdm::BatteryInfo::statusChanged, [info] { qInfo() << "Battery status now:" << info->status(); }); connect(info, &Sailfish::Mdm::BatteryInfo::chargePercentageChanged, [info] { qInfo() << "Battery charge now:" << info->chargePercentage() << "%"; }); }
Member Type Documentation
enum BatteryInfo::ChargerStatus
This enum type specifies the possible status of the battery charger.
Constant | Value | Description |
---|---|---|
Sailfish::Mdm::BatteryInfo::Connected | 0 | The charger is connected to and charging the device. |
Sailfish::Mdm::BatteryInfo::Disconnected | 1 | The charger is not connected to the device. |
Sailfish::Mdm::BatteryInfo::ChargerStatusUnknown | 2 | It is not known if the charger is connected to the device. |
enum BatteryInfo::Status
This enum type specifies the possible categories of battery charge status. The mapping of range of charge percentages to battery charge status can be customised by the vendor.
Constant | Value | Description |
---|---|---|
Sailfish::Mdm::BatteryInfo::Full | 0 | The battery is fully charged (usually > 95% charge). |
Sailfish::Mdm::BatteryInfo::Normal | 1 | The battery has a good amount of charge (usually >= 50% charge). |
Sailfish::Mdm::BatteryInfo::Low | 2 | The battery is running low on charge (usually >= 10% charge). |
Sailfish::Mdm::BatteryInfo::Empty | 3 | The battery is empty or almost empty (usually < 10% charge). |
Member Function Documentation
BatteryInfo::BatteryInfo(QObject *parent = 0)
Default constructs an instance of BatteryInfo.
int BatteryInfo::chargePercentage() const
Returns the current battery charge as a percentage.
A fully charged battery will be reported as 100
while a completely drained battery will be reported as 0
percent. If the battery charge percentage is not known (e.g., due to communication with the system service which provides the data taking some time, or if the calling application doesn't have permission to access that information) then -1
will be returned.
The chargePercentageChanged() signal will be emitted if it changes.
[signal]
void BatteryInfo::chargePercentageChanged(int percentage)
This signal is emitted when the battery charge percentage changes. The percentage describes the new battery charge percentage.
See also chargePercentage().
ChargerStatus BatteryInfo::chargerStatus() const
Returns the status of the battery charger.
The battery charger may either be Connected
, Disconnected
, or ChargerStatusUnknown
.
The chargerStatusChanged() signal will be emitted if it changes.
[signal]
void BatteryInfo::chargerStatusChanged(ChargerStatus status)
This signal is emitted when the charger is plugged into or unplugged from the device. The status describes the new charger status.
See also chargerStatus().
Status BatteryInfo::status() const
Returns the status of the battery charge.
The status may be one of Full
, Normal
, Low
, Empty
, or BatteryStatusUnknown
.
The statusChanged() signal will be emitted if it changes.
[signal]
void BatteryInfo::statusChanged(Status status)
This signal is emitted when the battery level status changes. The status describes the new battery level status.
See also status().