From 522fdc6abbfee52dec5c6b0194cf87ffcc0f3dcd Mon Sep 17 00:00:00 2001 From: Marc Deslauriers Date: Tue, 2 Jun 2015 19:18:22 -0400 Subject: Don't prioritize discharging items with no time estimate that have more than 10% power remaining. Devices with no time estimates are most likely low-power devices that have long-lasting batteries, such as a mouse with AA batteries. For those type of devices that contain batteries that last weeks, there is no value in displaying their status in preference to devices that have a rapid charge/discharge cycle. However, there is value in knowing if the device has a battery that needs replacing imminently, so only display it if it falls to a 10% charge or under. --- src/service.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index c93c4b6..73fcf46 100644 --- a/src/service.c +++ b/src/service.c @@ -162,12 +162,12 @@ get_device_kind_weight (const IndicatorPowerDevice * device) } /* sort devices from most interesting to least interesting on this criteria: - 1. device that supplied the power to the system - 2. discharging items from least time remaining until most time remaining - 3. charging items from most time left to charge to least time left to charge - 4. charging items with an unknown time remaining - 5. discharging items with an unknown time remaining - 6. batteries, then non-line power, then line-power */ + 1. discharging items from least time remaining until most time remaining + 2. charging items from most time left to charge to least time left to charge + 3. charging items with an unknown time remaining + 4. discharging items with an unknown time remaining, but 10% or below + 5. batteries, then non-line power, then line-power + 6. discharging items with an unknown time remaining, but above 10% */ static gint device_compare_func (gconstpointer ga, gconstpointer gb) { @@ -199,6 +199,14 @@ device_compare_func (gconstpointer ga, gconstpointer gb) } state = UP_DEVICE_STATE_DISCHARGING; + + /* discharging items with more than 10% remaining always lose */ + if (!ret && (((a_state == state) && !a_time && (a_percentage > 10)))) + ret = 1; + + if (!ret && (((b_state == state) && !b_time && (b_percentage > 10)))) + ret = -1; + if (!ret && (((a_state == state) && a_time) || ((b_state == state) && b_time))) { -- cgit v1.2.3 From a8fd3f49bf6509bd4545aec3292d2fc022d847ca Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 15:58:55 -0600 Subject: make a SoundPlayer interface so we can mock it in the tests this requires an annoying amount of scaffolding: 1. implement gst and mock classes to implement the SoundPlayer interface 2. modify notifier to take a SoundPlayer argument in its ctor 3. modify service to take a Notifier argument in its ctor instead of instantiating it on its own 4. change main to update the startup steps for player/notifier/service --- src/service.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/service.c') 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). -- cgit v1.2.3 From 61327b52f353c829ed10b452d17fec3d36b8c601 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 16:26:35 -0600 Subject: fix notifier property in service --- src/service.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 07f1106..a6c3432 100644 --- a/src/service.c +++ b/src/service.c @@ -1270,6 +1270,13 @@ indicator_power_service_class_init (IndicatorPowerServiceClass * klass) G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + properties[PROP_NOTIFIER] = g_param_spec_object ( + "notifier", + "Notifier", + "Notifies user of important battery changes", + G_TYPE_OBJECT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, LAST_PROP, properties); } -- cgit v1.2.3 From deca915372eddd1e0a1fa219cb26d7f6541d1f80 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 20:14:14 -0600 Subject: update copyright dates on changed files (again) --- src/service.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index a6c3432..17414c7 100644 --- a/src/service.c +++ b/src/service.c @@ -1,12 +1,7 @@ /* - * Copyright 2013 Canonical Ltd. + * Copyright 2013-2016 Canonical Ltd. * Copytight 2021 AyatanaIndicators * - * Authors: - * Charles Kerr - * Ted Gould - * Robert Tari - * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. @@ -18,6 +13,11 @@ * * You should have received a copy of the GNU General Public License along * with this program. If not, see . + * + * Authors: + * Charles Kerr + * Ted Gould + * Robert Tari */ #include -- cgit v1.2.3 From 5d038638f58765ec3859797704c5d0e1c0fa7903 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 20:19:45 -0600 Subject: handle service_set_notifier(NULL) gracefully --- src/service.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 17414c7..c04122f 100644 --- a/src/service.c +++ b/src/service.c @@ -1339,9 +1339,13 @@ indicator_power_service_set_notifier (IndicatorPowerService * self, g_return_if_fail (!notifier || INDICATOR_IS_POWER_NOTIFIER (notifier)); p = self->priv; - if (p->notifier != notifier) + if (p->notifier == notifier) + return; + + g_clear_object (&p->notifier); + + if (notifier != NULL) { - g_clear_object (&p->notifier); p->notifier = g_object_ref (notifier); indicator_power_notifier_set_bus (p->notifier, p->conn); } -- cgit v1.2.3 From 948a5107c479a72a2940316674fae6a3b55534ff Mon Sep 17 00:00:00 2001 From: Rodney <6557070+dobey@users.noreply.github.com> Date: Sun, 28 Oct 2018 13:54:40 -0400 Subject: Pull in many fixes from the bionic branch. (#7) * Pay attention to $SNAP prefix * Releasing 12.10.6+17.04.20161201-0ubuntu1 * give sorting priority to devices with power supplies * Releasing 12.10.6+17.04.20170116-0ubuntu1 * Remove old autostart files. * Use gmock module from cmake-extras. * Use coverage support from cmake-extras. * Add gcovr and lcov dependencies. * Use intltool support from cmake-extras. * Remove usage of extra GCOV variables. * Remove hard-coded -g compiler flag. * Releasing 12.10.6+17.04.20170210-0ubuntu1 * no change rebuild * Releasing 12.10.6+17.04.20170322-0ubuntu1 * Start indicator in systemd when indicators.target is started * Build for bionic * This is still xenial. * Update translations from launchpad too. --- src/service.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index c04122f..9b99a05 100644 --- a/src/service.c +++ b/src/service.c @@ -163,12 +163,12 @@ get_device_kind_weight (const IndicatorPowerDevice * device) } /* sort devices from most interesting to least interesting on this criteria: - 1. discharging items from least time remaining until most time remaining - 2. charging items from most time left to charge to least time left to charge - 3. charging items with an unknown time remaining - 4. discharging items with an unknown time remaining, but 10% or below - 5. batteries, then non-line power, then line-power - 6. discharging items with an unknown time remaining, but above 10% */ + 1. device that supplied the power to the system + 2. discharging items from least time remaining until most time remaining + 3. charging items from most time left to charge to least time left to charge + 4. charging items with an unknown time remaining + 5. discharging items with an unknown time remaining + 6. batteries, then non-line power, then line-power */ static gint device_compare_func (gconstpointer ga, gconstpointer gb) { @@ -600,7 +600,7 @@ create_brightness_menu_item(void) GMenuItem * item; item = g_menu_item_new(NULL, "indicator.brightness"); - g_menu_item_set_attribute(item, "x-ayatana-type", "s", "org.ayatana.unity.slider"); + g_menu_item_set_attribute(item, "x-ayatana-type", "s", "org.ayatana.indicator.slider"); g_menu_item_set_attribute(item, "min-value", "d", 0.0); g_menu_item_set_attribute(item, "max-value", "d", 1.0); -- cgit v1.2.3