summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-04-19 03:08:48 +0200
committerBastien Nocera <hadess@hadess.net>2018-04-19 03:40:40 +0200
commit0e6cc20ca922a2985a43ec342eeeefe21082c348 (patch)
tree10577e2eb50e5ecd07521c8ea107543760a98de0
parent096121740f7a1c9c1e23915505536021245829f1 (diff)
downloadupower-0e6cc20ca922a2985a43ec342eeeefe21082c348.tar.gz
lib: Mention that battery level is preferred when present14-lib-add-a-new-version-of-up_client_get_devices-which-unrefs-contents
And print "should be ignored" next to the percentage. https://bugs.freedesktop.org/show_bug.cgi?id=97484
-rw-r--r--libupower-glib/up-device.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c
index 23a84ed..8bfd98a 100644
--- a/libupower-glib/up-device.c
+++ b/libupower-glib/up-device.c
@@ -270,6 +270,7 @@ up_device_to_text (UpDevice *device)
const gchar *serial;
UpDeviceKind kind;
gboolean is_display;
+ UpDeviceLevel battery_level;
g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
@@ -324,8 +325,9 @@ 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)));
+ battery_level = up_exported_device_get_battery_level (priv->proxy_device);
+ if (battery_level != UP_DEVICE_LEVEL_NONE)
+ g_string_append_printf (string, " battery-level: %s\n", up_device_level_to_string (battery_level));
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)
@@ -368,8 +370,12 @@ up_device_to_text (UpDevice *device)
kind == UP_DEVICE_KIND_COMPUTER ||
kind == UP_DEVICE_KIND_MEDIA_PLAYER ||
kind == UP_DEVICE_KIND_UPS ||
- kind == UP_DEVICE_KIND_GAMING_INPUT)
- g_string_append_printf (string, " percentage: %g%%\n", up_exported_device_get_percentage (priv->proxy_device));
+ kind == UP_DEVICE_KIND_GAMING_INPUT) {
+ if (battery_level == UP_DEVICE_LEVEL_NONE)
+ g_string_append_printf (string, " percentage: %g%%\n", up_exported_device_get_percentage (priv->proxy_device));
+ else
+ g_string_append_printf (string, " percentage: %g%% (should be ignored)\n", up_exported_device_get_percentage (priv->proxy_device));
+ }
if (kind == UP_DEVICE_KIND_BATTERY) {
if (up_exported_device_get_temperature (priv->proxy_device) > 0)
g_string_append_printf (string, " temperature: %g degrees C\n", up_exported_device_get_temperature (priv->proxy_device));
@@ -1128,7 +1134,9 @@ up_device_class_init (UpDeviceClass *klass)
/**
* UpDevice:percentage:
*
- * The percentage charge of the device.
+ * The percentage charge of the device. Note that if the battery level property
+ * is something other than %UP_DEVICE_LEVEL_NONE, then this percentage is an
+ * approximation, and should not be used a number to display to the user.
*
* Since: 0.9.0
**/
@@ -1168,7 +1176,9 @@ up_device_class_init (UpDeviceClass *klass)
/**
* UpDevice:battery-level:
*
- * The battery level, e.g. %UP_DEVICE_LEVEL_CRITICAL.
+ * The battery level, e.g. %UP_DEVICE_LEVEL_CRITICAL. If this is something
+ * other than %UP_DEVICE_LEVEL_NONE, then User Interfaces should use this
+ * approximate level instead of percentages.
*
* Since: 1.0
**/