From 499d05b8370324f319933558bac590e98ad55927 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Apr 2017 18:20:27 +0200 Subject: all: Add BatteryLevel property Export approximate battery levels that devices can use, exported by the kernel as POWER_SUPPLY_CAPACITY_LEVEL_* values. This avoids bizarrely accurate values showing up in UIs when we only have ok/warning levels of accuracy in some cases. https://bugs.freedesktop.org/show_bug.cgi?id=100359 --- libupower-glib/up-device.c | 25 +++++++++++++++++++++++++ libupower-glib/up-types.h | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'libupower-glib') diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c index 7bce4e0..63ebe12 100644 --- a/libupower-glib/up-device.c +++ b/libupower-glib/up-device.c @@ -90,6 +90,7 @@ enum { PROP_PERCENTAGE, PROP_TEMPERATURE, PROP_WARNING_LEVEL, + PROP_BATTERY_LEVEL, PROP_ICON_NAME, PROP_LAST }; @@ -315,6 +316,8 @@ up_device_to_text (UpDevice *device) kind == UP_DEVICE_KIND_UPS) g_string_append_printf (string, " state: %s\n", up_device_state_to_string (up_exported_device_get_state (priv->proxy_device))); g_string_append_printf (string, " warning-level: %s\n", up_device_level_to_string (up_exported_device_get_warning_level (priv->proxy_device))); + if (up_exported_device_get_battery_level (priv->proxy_device) != UP_DEVICE_LEVEL_NONE) + g_string_append_printf (string, " battery-level: %s\n", up_device_level_to_string (up_exported_device_get_battery_level (priv->proxy_device))); if (kind == UP_DEVICE_KIND_BATTERY) { g_string_append_printf (string, " energy: %g Wh\n", up_exported_device_get_energy (priv->proxy_device)); if (!is_display) @@ -665,6 +668,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa case PROP_WARNING_LEVEL: up_exported_device_set_warning_level (device->priv->proxy_device, g_value_get_uint (value)); break; + case PROP_BATTERY_LEVEL: + up_exported_device_set_battery_level (device->priv->proxy_device, g_value_get_uint (value)); + break; case PROP_ICON_NAME: up_exported_device_set_icon_name (device->priv->proxy_device, g_value_get_string (value)); break; @@ -776,6 +782,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe case PROP_WARNING_LEVEL: g_value_set_uint (value, up_exported_device_get_warning_level (device->priv->proxy_device)); break; + case PROP_BATTERY_LEVEL: + g_value_set_uint (value, up_exported_device_get_battery_level (device->priv->proxy_device)); + break; case PROP_ICON_NAME: g_value_set_string (value, up_exported_device_get_icon_name (device->priv->proxy_device)); break; @@ -1149,6 +1158,22 @@ up_device_class_init (UpDeviceClass *klass) UP_DEVICE_LEVEL_UNKNOWN, G_PARAM_READWRITE)); + /** + * UpDevice:battery-level: + * + * The battery level. + * + * Since: 1.0 + **/ + g_object_class_install_property (object_class, + PROP_BATTERY_LEVEL, + g_param_spec_uint ("battery-level", + NULL, NULL, + UP_DEVICE_LEVEL_UNKNOWN, + UP_DEVICE_LEVEL_LAST, + UP_DEVICE_LEVEL_NONE, + G_PARAM_READWRITE)); + /** * UpDevice:icon-name: * diff --git a/libupower-glib/up-types.h b/libupower-glib/up-types.h index 3509537..6d34970 100644 --- a/libupower-glib/up-types.h +++ b/libupower-glib/up-types.h @@ -86,7 +86,8 @@ typedef enum { /** * UpDeviceLevel: * - * The level of a battery. + * The level of a battery. Some values are only relevant to the WarningLevel + * property, some others to the BatteryLevel property. **/ typedef enum { UP_DEVICE_LEVEL_UNKNOWN, -- cgit v1.2.3