diff options
Diffstat (limited to 'src/service.c')
-rw-r--r-- | src/service.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/service.c b/src/service.c index 73fcf46..07f1106 100644 --- a/src/service.c +++ b/src/service.c @@ -52,6 +52,7 @@ enum PROP_0, PROP_BUS, PROP_DEVICE_PROVIDER, + PROP_NOTIFIER, LAST_PROP }; @@ -976,7 +977,8 @@ on_bus_acquired (GDBusConnection * connection, g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_BUS]); /* export the battery properties */ - indicator_power_notifier_set_bus (p->notifier, connection); + if (p->notifier != NULL) + indicator_power_notifier_set_bus (p->notifier, connection); /* export the actions */ if ((id = g_dbus_connection_export_action_group (connection, @@ -1118,6 +1120,10 @@ my_get_property (GObject * o, g_value_set_object (value, p->device_provider); break; + case PROP_NOTIFIER: + g_value_set_object (value, p->notifier); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -1137,6 +1143,10 @@ my_set_property (GObject * o, indicator_power_service_set_device_provider (self, g_value_get_object (value)); break; + case PROP_NOTIFIER: + indicator_power_service_set_notifier (self, g_value_get_object (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -1179,6 +1189,7 @@ my_dispose (GObject * o) g_clear_object (&p->conn); indicator_power_service_set_device_provider (self, NULL); + indicator_power_service_set_notifier (self, NULL); G_OBJECT_CLASS (indicator_power_service_parent_class)->dispose (o); } @@ -1200,8 +1211,6 @@ indicator_power_service_init (IndicatorPowerService * self) p->settings = g_settings_new ("org.ayatana.indicator.power"); - p->notifier = indicator_power_notifier_new (); - p->brightness = indicator_power_brightness_new(); g_signal_connect_swapped(p->brightness, "notify::percentage", G_CALLBACK(update_brightness_action_state), self); @@ -1269,10 +1278,12 @@ indicator_power_service_class_init (IndicatorPowerServiceClass * klass) ***/ IndicatorPowerService * -indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider) +indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider, + IndicatorPowerNotifier * notifier) { GObject * o = g_object_new (INDICATOR_TYPE_POWER_SERVICE, "device-provider", device_provider, + "notifier", notifier, NULL); return INDICATOR_POWER_SERVICE (o); @@ -1311,6 +1322,25 @@ indicator_power_service_set_device_provider (IndicatorPowerService * self, } } +void +indicator_power_service_set_notifier (IndicatorPowerService * self, + IndicatorPowerNotifier * notifier) +{ + priv_t * p; + + g_return_if_fail (INDICATOR_IS_POWER_SERVICE (self)); + g_return_if_fail (!notifier || INDICATOR_IS_POWER_NOTIFIER (notifier)); + p = self->priv; + + if (p->notifier != notifier) + { + g_clear_object (&p->notifier); + p->notifier = g_object_ref (notifier); + indicator_power_notifier_set_bus (p->notifier, p->conn); + } +} + + /* If a device has multiple batteries and uses only one of them at a time, they should be presented as separate items inside the battery menu, but everywhere else they should be aggregated (bug 880881). |