Merge lp:~charlesk/indicator-power/lp-1296431-low-power-snap-decisions into lp:indicator-power/14.10

Proposed by Charles Kerr on 2014-09-08
Status: Merged
Approved by: Ted Gould on 2014-09-08
Approved revision: 261
Merged at revision: 260
Proposed branch: lp:~charlesk/indicator-power/lp-1296431-low-power-snap-decisions
Merge into: lp:indicator-power/14.10
Diff against target: 148 lines (+69/-8)
2 files modified
src/notifier.c (+62/-4)
tests/indicator-power-service-cmdline-battery.cc (+7/-4)
To merge this branch: bzr merge lp:~charlesk/indicator-power/lp-1296431-low-power-snap-decisions
Reviewer Review Type Date Requested Status
Ted Gould (community) 2014-09-08 Approve on 2014-09-08
PS Jenkins bot (community) continuous-integration Approve on 2014-09-08
Review via email: mp+233744@code.launchpad.net

Commit message

When the phone's battery goes down past a certain level, pop up a snap decision to warn the user.

Description of the change

== Description of the Change

When the battery charge level goes down past the predefined thresholds,

show this on the phone: https://launchpadlibrarian.net/183295784/battery%20low%20notification.jpg

and this on the desktop: https://wiki.ubuntu.com/Power?action=AttachFile&do=get&target=battery-low-pc.png

NB: the phone warnings wireframe at https://wiki.ubuntu.com/Power#Warnings is not up-to-date. Phone warnings should look like the wireframe above wrt being a snap decision with options to dismiss or to launch battery settings.

== Checklist

> Are there any related MPs required for this MP to build/function as expected? Please list.

No

> Is your branch in sync with latest trunk? (e.g. bzr pull lp:trunk -> no changes)

Yes

> Did the code build without warnings?

Yes

> Did the tests run successfully?

Yes

> Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

> If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

> Did your component test plan pass? If on a device, what image number?

mako + rtm r29

> Did you provide a link to this page https://wiki.ubuntu.com/Process/Merges/Checklists/indicator-power

Yes

> Please list which manual tests are germane for the reviewer in this MR.

New test: indicator-power/low-power-notifications

To post a comment you must log in.
259. By Charles Kerr on 2014-09-08

in notifier.c, reverse the order in which we add the actions so they'll look right on the phone

260. By Charles Kerr on 2014-09-08

in notifier.c, don't call notify_get_server_caps() if notify_init() failed.

Ted Gould (ted) wrote :

Bad design, but eh, I guess we can't fix that here.

We're going to need to track the notification and close it when the next one comes in. Probably that's the standard case, people aren't using their phone and just getting notifications that aren't useful, we don't want them to stack up.

review: Needs Fixing
261. By Charles Kerr on 2014-09-08

in notifier's snap decisions, distinguish in the title between low battery and critical battery

Ted Gould (ted) wrote :

Cool, explained to me on IRC.

review: Approve
262. By Charles Kerr on 2014-09-08

sync with lp-1330037-add-upower-099-support to resolve merge conflicts

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/notifier.c'
2--- src/notifier.c 2014-07-25 05:34:59 +0000
3+++ src/notifier.c 2014-09-08 21:23:16 +0000
4@@ -21,11 +21,13 @@
5 #include "dbus-shared.h"
6 #include "notifier.h"
7
8+#include <url-dispatcher.h>
9+
10 #include <libnotify/notify.h>
11
12 #include <glib/gi18n.h>
13
14-#define HINT_INTERACTIVE "x-canonical-switch-to-application"
15+#include <stdint.h> /* UINT32_MAX */
16
17 typedef enum
18 {
19@@ -53,6 +55,8 @@
20
21 static int instance_count = 0;
22
23+static gboolean actions_supported = FALSE;
24+
25 /**
26 ***
27 **/
28@@ -99,7 +103,7 @@
29 }
30 }
31
32-PowerLevel
33+static PowerLevel
34 get_battery_power_level (IndicatorPowerDevice * battery)
35 {
36 static const double percent_critical = 2.0;
37@@ -163,22 +167,62 @@
38 }
39
40 static void
41+on_battery_settings_clicked(NotifyNotification * nn G_GNUC_UNUSED,
42+ char * action G_GNUC_UNUSED,
43+ gpointer user_data G_GNUC_UNUSED)
44+{
45+ url_dispatch_send("settings:///system/battery", NULL, NULL);
46+}
47+
48+static void
49+on_dismiss_clicked(NotifyNotification * nn G_GNUC_UNUSED,
50+ char * action G_GNUC_UNUSED,
51+ gpointer user_data G_GNUC_UNUSED)
52+{
53+ /* no-op; libnotify warns if we have a NULL action callback */
54+}
55+
56+static void
57 notification_show(IndicatorPowerNotifier * self)
58 {
59 priv_t * const p = get_priv(self);
60 gdouble pct;
61+ const char * title;
62 char * body;
63+ GStrv icon_names;
64+ const char * icon_name;
65 NotifyNotification * nn;
66 GError * error;
67+ const PowerLevel power_level = get_battery_power_level(p->battery);
68
69 notification_clear(self);
70
71+ g_return_if_fail(power_level != POWER_LEVEL_OK);
72+
73 /* create the notification */
74+ title = power_level == POWER_LEVEL_LOW
75+ ? _("Battery Low")
76+ : _("Battery Critical");
77 pct = indicator_power_device_get_percentage(p->battery);
78 body = g_strdup_printf(_("%.0f%% charge remaining"), pct);
79- nn = notify_notification_new(_("Battery Low"), body, NULL);
80+ icon_names = indicator_power_device_get_icon_names(p->battery);
81+ if (icon_names && *icon_names)
82+ icon_name = icon_names[0];
83+ else
84+ icon_name = NULL;
85+ nn = notify_notification_new(title, body, icon_name);
86+ g_strfreev (icon_names);
87 g_free (body);
88- /*notify_notification_set_hint(nn, HINT_INTERACTIVE, g_variant_new_boolean(TRUE));*/
89+
90+ if (actions_supported)
91+ {
92+ notify_notification_set_hint(nn, "x-canonical-snap-decisions", g_variant_new_boolean(TRUE));
93+ notify_notification_set_hint(nn, "x-canonical-non-shaped-icon", g_variant_new_boolean(TRUE));
94+ notify_notification_set_hint(nn, "x-canonical-snap-decisions-timeout", g_variant_new_int32(INT32_MAX));
95+ notify_notification_set_timeout(nn, NOTIFY_EXPIRES_NEVER);
96+ notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL);
97+ notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL);
98+ }
99
100 /* if we can show it, keep it */
101 error = NULL;
102@@ -322,10 +366,24 @@
103
104 if (!instance_count++)
105 {
106+ actions_supported = FALSE;
107+
108 if (!notify_init("indicator-power-service"))
109 {
110 g_critical("Unable to initialize libnotify! Notifications might not be shown.");
111 }
112+ else
113+ {
114+ GList * caps;
115+ GList * l;
116+
117+ /* see if actions are supported */
118+ caps = notify_get_server_caps();
119+ for (l=caps; l!=NULL && !actions_supported; l=l->next)
120+ if (!g_strcmp0(l->data, "actions"))
121+ actions_supported = TRUE;
122+ g_list_free_full(caps, g_free);
123+ }
124 }
125 }
126
127
128=== modified file 'tests/indicator-power-service-cmdline-battery.cc'
129--- tests/indicator-power-service-cmdline-battery.cc 2014-07-22 14:58:29 +0000
130+++ tests/indicator-power-service-cmdline-battery.cc 2014-09-08 21:23:16 +0000
131@@ -83,10 +83,13 @@
132 int
133 main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
134 {
135- g_message ("This app is basically the same as indicator-power-service but,\n"
136- "instead of the system's real devices, sees a single fake battery\n"
137- "which can be manipulated by typing commands:\n"
138- "'charging', 'discharging', a charge percentage, or ctrl-c.");
139+ g_print("This test app has the same code as indicator-power-service\n"
140+ "except instead of listening to UPower, it has a fake battery\n"
141+ "which you can edit with keyboard inputs. Supported commands:\n"
142+ "1. A number in [0..100] to set battery level\n"
143+ "2. 'charging'\n"
144+ "3. 'discharging'\n"
145+ "4. ctrl-c to exit\n");
146
147 IndicatorPowerDeviceProvider * device_provider;
148 IndicatorPowerService * service;

Subscribers

People subscribed via source and target branches