aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2011-07-14 12:52:28 +0200
committerJavier Jardón <javier.jardon@codethink.co.uk>2011-07-14 12:52:28 +0200
commitd104cd9b6b891271785a61e0f6794fda893ced4a (patch)
tree8f53e8c60c0cb19c909515e06ecba81dccd15c55 /src
parent4bd654838bff866644358212a106dfff77c33c48 (diff)
downloadayatana-indicator-power-d104cd9b6b891271785a61e0f6794fda893ced4a.tar.gz
ayatana-indicator-power-d104cd9b6b891271785a61e0f6794fda893ced4a.tar.bz2
ayatana-indicator-power-d104cd9b6b891271785a61e0f6794fda893ced4a.zip
Show the apropiate icon depending of the status of the devices
Follow https://wiki.ubuntu.com/BatteryStatusMenu : - If anything is discharging, the menu title should represent the thing that is estimated to lose power first. - If no devices are discharging, the menu title should represent the device that is estimated to take longest to charge.
Diffstat (limited to 'src')
-rw-r--r--src/indicator-power.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/indicator-power.c b/src/indicator-power.c
index bbc653b..9280bdb 100644
--- a/src/indicator-power.c
+++ b/src/indicator-power.c
@@ -443,11 +443,18 @@ get_primary_device (GVariant *devices)
{
UpDeviceKind kind;
UpDeviceState state;
+ GVariant *device;
+ GVariant *primary_device_charging = NULL;
+ GVariant *primary_device_discharging = NULL;
GVariant *primary_device = NULL;
+ gboolean charging = FALSE;
+ gboolean discharging = FALSE;
gchar *object_path;
gchar *device_icon;
gdouble percentage;
guint64 time;
+ guint64 min_discharging_time = G_MAXUINT64;
+ guint64 max_charging_time = 0;
gsize n_devices;
guint i;
@@ -456,8 +463,8 @@ get_primary_device (GVariant *devices)
for (i = 0; i < n_devices; i++)
{
- primary_device = g_variant_get_child_value (devices, i);
- g_variant_get (primary_device,
+ device = g_variant_get_child_value (devices, i);
+ g_variant_get (device,
"(susdut)",
&object_path,
&kind,
@@ -467,6 +474,37 @@ get_primary_device (GVariant *devices)
&time);
g_debug ("%s: got data from object %s", G_STRFUNC, object_path);
+
+ if (primary_device == NULL && kind == UP_DEVICE_KIND_BATTERY)
+ primary_device = device;
+
+ if (state == UP_DEVICE_STATE_DISCHARGING)
+ {
+ discharging = TRUE;
+ if (time < min_discharging_time)
+ {
+ min_discharging_time = time;
+ primary_device_discharging = device;
+ }
+ }
+ else if (state == UP_DEVICE_STATE_CHARGING)
+ {
+ charging = TRUE;
+ if (time > max_charging_time)
+ {
+ max_charging_time = time;
+ primary_device_charging = device;
+ }
+ }
+ }
+
+ if (discharging)
+ {
+ primary_device = primary_device_discharging;
+ }
+ else if (charging)
+ {
+ primary_device = primary_device_charging;
}
return primary_device;