aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/indicator-power.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/indicator-power.c b/src/indicator-power.c
index d97ecdd..701415d 100644
--- a/src/indicator-power.c
+++ b/src/indicator-power.c
@@ -688,38 +688,34 @@ build_menu (IndicatorPower *self)
static GVariant *
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;
+ gint primary_device_charging_index = -1;
+ gint primary_device_discharging_index = -1;
+ gint primary_device_index = -1;
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;
- n_devices = devices ? g_variant_n_children (devices) : 0;
+ const gsize n_devices = devices ? g_variant_n_children (devices) : 0;
g_debug ("Num devices: '%" G_GSIZE_FORMAT "'\n", n_devices);
for (i = 0; i < n_devices; i++)
{
- time = 0;
- device = g_variant_get_child_value (devices, i);
- g_variant_get (device,
- "(susdut)",
- &object_path,
- &kind,
- &device_icon,
- &percentage,
- &state,
- &time);
+ const gchar *object_path;
+ UpDeviceKind kind;
+ const gchar *device_icon;
+ gdouble percentage;
+ UpDeviceState state;
+ guint64 time = 0;
+
+ g_variant_get_child (devices, i, "(&su&sdut)",
+ &object_path,
+ &kind,
+ &device_icon,
+ &percentage,
+ &state,
+ &time);
g_debug ("%s: got data from object %s", G_STRFUNC, object_path);
@@ -738,7 +734,7 @@ get_primary_device (GVariant *devices)
if (time < min_discharging_time)
{
min_discharging_time = time;
- primary_device_discharging = device;
+ primary_device_discharging_index = i;
}
}
else if (state == UP_DEVICE_STATE_CHARGING)
@@ -746,33 +742,33 @@ get_primary_device (GVariant *devices)
charging = TRUE;
if (time == 0) /* Battery broken */
{
- primary_device_charging = device;
+ primary_device_charging_index = i;
}
if (time > max_charging_time)
{
max_charging_time = time;
- primary_device_charging = device;
+ primary_device_charging_index = i;
}
}
else
{
- primary_device = device;
+ primary_device_index = i;
}
-
- g_free (device_icon);
- g_free (object_path);
}
if (discharging)
{
- primary_device = primary_device_discharging;
+ primary_device_index = primary_device_discharging_index;
}
else if (charging)
{
- primary_device = primary_device_charging;
+ primary_device_index = primary_device_charging_index;
}
- return primary_device;
+ if (primary_device_index >= 0)
+ return g_variant_get_child_value (devices, primary_device_index);
+
+ return NULL;
}
static void