From 23a2672a1a763cdef67ccc5cb9f8fec7daf021be Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 May 2012 09:22:28 -0500 Subject: use signals to decouple i-power and dbus-listener --- src/indicator-power.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index cf96619..6690f9b 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -116,9 +116,10 @@ indicator_power_init (IndicatorPower *self) priv->accessible_desc = NULL; - priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, - INDICATOR_POWER_DBUS_LISTENER_INDICATOR, self, - NULL); + priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL); + g_signal_connect_swapped (priv->dbus_listener, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(indicator_power_set_devices), self); + priv->settings = g_settings_new ("com.canonical.indicator.power"); g_signal_connect_swapped (priv->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); @@ -763,33 +764,22 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) } void -indicator_power_set_devices (IndicatorPower * self, - IndicatorPowerDevice ** devices, - gsize device_count) +indicator_power_set_devices (IndicatorPower * self, GSList * devices) { - gsize i; - GSList * new_devices; IndicatorPowerPrivate * priv; -/* LCOV_EXCL_START */ + /* LCOV_EXCL_START */ g_return_if_fail (IS_INDICATOR_POWER(self)); -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ priv = self->priv; - /* make a reff'ed list of the new devices */ - new_devices = NULL; - for (i=0; idevices = new_devices; + priv->devices = g_slist_copy (devices); priv->device = get_primary_device (priv->devices); - /* and update ourselves based on this new data */ + /* and our menus/visibility from the new device list */ if (priv->device != NULL) put_primary_device (self, priv->device); else -- cgit v1.2.3