From 0c4e27a7a170cf3f982ab2a5a979860605745323 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Sun, 23 Dec 2012 22:13:27 -0500 Subject: [PATCH] Show UPS state Unless system has a battery, the UPS state will not display. Allow the UPS to represent the primary power device if the system does not have batteries and display its state in the indicator. Any battery will continue to be preferred as the primary device. Signed-off-by: Peter Hurley --- src/indicator-power.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index 9829839..b0e1d97 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -354,8 +354,6 @@ static IndicatorPowerDevice* get_primary_device (GSList * devices) { IndicatorPowerDevice * primary_device = NULL; - IndicatorPowerDevice * primary_device_charging = NULL; - IndicatorPowerDevice * primary_device_discharging = NULL; gboolean charging = FALSE; gboolean discharging = FALSE; guint64 min_discharging_time = G_MAXUINT64; @@ -375,6 +373,16 @@ get_primary_device (GSList * devices) percentage == 0) continue; + /* allow ups as primary device if no primary device already */ + if (kind == UP_DEVICE_KIND_UPS) + { + if (!primary_device) + { + primary_device = device; + } + continue; + } + /* not battery */ if (kind != UP_DEVICE_KIND_BATTERY) continue; @@ -385,37 +393,28 @@ get_primary_device (GSList * devices) if (time < min_discharging_time) { min_discharging_time = time; - primary_device_discharging = device; + primary_device = device; } } - else if (state == UP_DEVICE_STATE_CHARGING) + else if (!discharging && state == UP_DEVICE_STATE_CHARGING) { charging = TRUE; if (time == 0) /* Battery broken */ { - primary_device_charging = device; + primary_device = device; } if (time > max_charging_time) { max_charging_time = time; - primary_device_charging = device; + primary_device = device; } } - else + else if (!discharging && !charging) { primary_device = device; } } - if (discharging) - { - primary_device = primary_device_discharging; - } - else if (charging) - { - primary_device = primary_device_charging; - } - if (primary_device != NULL) g_object_ref (primary_device); @@ -543,15 +542,17 @@ get_name_hint (IndicatorObject *io) ***/ static void -count_batteries (GSList * devices, int *total, int *inuse) +count_batteries (GSList * devices, int *total, int *inuse, int *ups) { GSList * l; + UpDeviceKind kind; for (l=devices; l!=NULL; l=l->next) { const IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE(l->data); - if (indicator_power_device_get_kind(device) == UP_DEVICE_KIND_BATTERY) + kind = indicator_power_device_get_kind(device); + if (kind == UP_DEVICE_KIND_BATTERY) { ++*total; @@ -559,9 +560,14 @@ count_batteries (GSList * devices, int *total, int *inuse) if ((state == UP_DEVICE_STATE_CHARGING) || (state == UP_DEVICE_STATE_DISCHARGING)) ++*inuse; } + else if (kind == UP_DEVICE_KIND_UPS) + { + ++*ups; + } } g_debug("count_batteries found %d batteries (%d are charging/discharging)", *total, *inuse); + g_debug("count_batteries found %d ups", *ups); } static gboolean @@ -580,12 +586,12 @@ should_be_visible (IndicatorPower * self) } else { - int batteries=0, inuse=0; - count_batteries (priv->devices, &batteries, &inuse); + int batteries=0, inuse=0, ups=0; + count_batteries (priv->devices, &batteries, &inuse, &ups); if (icon_policy == POWER_INDICATOR_ICON_POLICY_PRESENT) { - visible = batteries > 0; + visible = batteries > 0 || ups > 0; } else if (icon_policy == POWER_INDICATOR_ICON_POLICY_CHARGE) { -- 1.8.0.2