aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-05-25 17:10:52 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-05-25 17:10:52 -0500
commit7ac2b78246e26f354453935301ed322eb6870c3a (patch)
treebce4e9e03f1bc3597d567da4040619568f396320 /src
parent73d31da1baed181dee9cead8a710444f4a4363a6 (diff)
downloadayatana-indicator-power-7ac2b78246e26f354453935301ed322eb6870c3a.tar.gz
ayatana-indicator-power-7ac2b78246e26f354453935301ed322eb6870c3a.tar.bz2
ayatana-indicator-power-7ac2b78246e26f354453935301ed322eb6870c3a.zip
make indicator_power_set_devices() safe for passing in the same devices more than once
Diffstat (limited to 'src')
-rw-r--r--src/indicator-power.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/indicator-power.c b/src/indicator-power.c
index 768504d..6eb6904 100644
--- a/src/indicator-power.c
+++ b/src/indicator-power.c
@@ -145,9 +145,9 @@ dispose_devices (IndicatorPower * self)
{
IndicatorPowerPrivate * priv = self->priv;
+ g_clear_object (&priv->device);
g_slist_free_full (priv->devices, g_object_unref);
priv->devices = NULL;
- g_clear_object (&priv->device);
}
static void
indicator_power_dispose (GObject *object)
@@ -748,8 +748,6 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device)
const gchar * device_icon = indicator_power_device_get_icon (device);
const gdouble percentage = indicator_power_device_get_percentage (device);
-g_message ("new primary device: %s", indicator_power_device_get_object_path(device));
-
/* set icon */
device_gicons = get_device_icon (kind, state, time, device_icon);
gtk_image_set_from_gicon (priv->status_image,
@@ -780,26 +778,30 @@ indicator_power_set_devices (IndicatorPower * self,
gsize device_count)
{
gsize i;
+ GSList * new_devices;
IndicatorPowerPrivate * priv;
g_return_if_fail (IS_INDICATOR_POWER(self));
priv = self->priv;
- /* clear out the previous values */
- dispose_devices (self);
-
- /* get the new devices */
+ /* make a reff'ed list of the new devices */
+ new_devices = NULL;
for (i=0; i<device_count; ++i)
- priv->devices = g_slist_prepend (priv->devices, g_object_ref(devices[i]));
- priv->devices = g_slist_reverse (priv->devices);
+ new_devices = g_slist_prepend (new_devices, g_object_ref(devices[i]));
+ new_devices = g_slist_reverse (new_devices);
- /* get the new primary device */
+ /* clear out the old devices */
+ dispose_devices (self);
+
+ /* add the new ones */
+ priv->devices = new_devices;
priv->device = get_primary_device (priv->devices);
- if (priv->device)
+
+ /* and update ourselves based on this new data */
+ if (priv->device != NULL)
put_primary_device (self, priv->device);
else
g_message ("Couldn't find primary device");
-
build_menu (self);
update_visibility (self);
}