From 0ab79aced178b97e878432be4e716f23b4520d09 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Sep 2014 10:39:58 -0500 Subject: on phone, add nonexpiring snap-decision popup on low battery events. --- src/notifier.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/notifier.c b/src/notifier.c index 81cd6f1..8242292 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -21,11 +21,13 @@ #include "dbus-shared.h" #include "notifier.h" +#include + #include #include -#define HINT_INTERACTIVE "x-canonical-switch-to-application" +#include /* UINT32_MAX */ typedef enum { @@ -53,6 +55,8 @@ static GParamSpec * properties[LAST_PROP]; static int instance_count = 0; +static gboolean actions_supported = FALSE; + /** *** **/ @@ -162,12 +166,30 @@ notification_clear (IndicatorPowerNotifier * self) } } +static void +on_battery_settings_clicked(NotifyNotification * nn G_GNUC_UNUSED, + char * action G_GNUC_UNUSED, + gpointer user_data G_GNUC_UNUSED) +{ + url_dispatch_send("settings:///system/battery", NULL, NULL); +} + +static void +on_dismiss_clicked(NotifyNotification * nn G_GNUC_UNUSED, + char * action G_GNUC_UNUSED, + gpointer user_data G_GNUC_UNUSED) +{ + /* no-op; libnotify warns if we have a NULL action callback */ +} + static void notification_show(IndicatorPowerNotifier * self) { priv_t * const p = get_priv(self); gdouble pct; char * body; + GStrv icon_names; + const char * icon_name; NotifyNotification * nn; GError * error; @@ -176,9 +198,23 @@ notification_show(IndicatorPowerNotifier * self) /* create the notification */ pct = indicator_power_device_get_percentage(p->battery); body = g_strdup_printf(_("%.0f%% charge remaining"), pct); - nn = notify_notification_new(_("Battery Low"), body, NULL); + icon_names = indicator_power_device_get_icon_names(p->battery); + if (icon_names && *icon_names) + icon_name = icon_names[0]; + else + icon_name = NULL; + nn = notify_notification_new(_("Battery Low"), body, icon_name); + if (actions_supported) + { + notify_notification_set_hint(nn, "x-canonical-snap-decisions", g_variant_new_boolean(TRUE)); + notify_notification_set_hint(nn, "x-canonical-non-shaped-icon", g_variant_new_boolean(TRUE)); + notify_notification_set_hint(nn, "x-canonical-snap-decisions-timeout", g_variant_new_int32(INT32_MAX)); + notify_notification_set_timeout(nn, NOTIFY_EXPIRES_NEVER); + notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); + notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL); + } + g_strfreev (icon_names); g_free (body); - /*notify_notification_set_hint(nn, HINT_INTERACTIVE, g_variant_new_boolean(TRUE));*/ /* if we can show it, keep it */ error = NULL; @@ -322,10 +358,21 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) if (!instance_count++) { + GList * caps; + GList * l; + if (!notify_init("indicator-power-service")) { g_critical("Unable to initialize libnotify! Notifications might not be shown."); } + + /* see if actions are supported */ + actions_supported = FALSE; + caps = notify_get_server_caps(); + for (l=caps; l!=NULL && !actions_supported; l=l->next) + if (!g_strcmp0(l->data, "actions")) + actions_supported = TRUE; + g_list_free_full(caps, g_free); } } -- cgit v1.2.3 From b06dda0e74e93e107b0be4158bd82ba1e8853bc4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Sep 2014 11:43:56 -0500 Subject: in notifier.c, reverse the order in which we add the actions so they'll look right on the phone --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/notifier.c b/src/notifier.c index 8242292..ed079e5 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -210,8 +210,8 @@ notification_show(IndicatorPowerNotifier * self) notify_notification_set_hint(nn, "x-canonical-non-shaped-icon", g_variant_new_boolean(TRUE)); notify_notification_set_hint(nn, "x-canonical-snap-decisions-timeout", g_variant_new_int32(INT32_MAX)); notify_notification_set_timeout(nn, NOTIFY_EXPIRES_NEVER); - notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL); + notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); } g_strfreev (icon_names); g_free (body); -- cgit v1.2.3 From 48b162d72dc3e470e95de8259901e9689d229668 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Sep 2014 11:45:00 -0500 Subject: in notifier.c, don't call notify_get_server_caps() if notify_init() failed. --- src/notifier.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/notifier.c b/src/notifier.c index ed079e5..a059447 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -361,18 +361,21 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) GList * caps; GList * l; + actions_supported = FALSE; + if (!notify_init("indicator-power-service")) { g_critical("Unable to initialize libnotify! Notifications might not be shown."); } - - /* see if actions are supported */ - actions_supported = FALSE; - caps = notify_get_server_caps(); - for (l=caps; l!=NULL && !actions_supported; l=l->next) - if (!g_strcmp0(l->data, "actions")) - actions_supported = TRUE; - g_list_free_full(caps, g_free); + else + { + /* see if actions are supported */ + caps = notify_get_server_caps(); + for (l=caps; l!=NULL && !actions_supported; l=l->next) + if (!g_strcmp0(l->data, "actions")) + actions_supported = TRUE; + g_list_free_full(caps, g_free); + } } } -- cgit v1.2.3 From 24b9a28725106d1762fcefb0652f2cb06ad9aa4c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Sep 2014 15:35:19 -0500 Subject: in notifier's snap decisions, distinguish in the title between low battery and critical battery --- src/notifier.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/notifier.c b/src/notifier.c index a059447..f4c8950 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -187,15 +187,22 @@ notification_show(IndicatorPowerNotifier * self) { priv_t * const p = get_priv(self); gdouble pct; + const char * title; char * body; GStrv icon_names; const char * icon_name; NotifyNotification * nn; GError * error; + const PowerLevel power_level = get_battery_power_level(p->battery); notification_clear(self); + g_return_if_fail(power_level != POWER_LEVEL_OK); + /* create the notification */ + title = power_level == POWER_LEVEL_LOW + ? _("Battery Low") + : _("Battery Critical"); pct = indicator_power_device_get_percentage(p->battery); body = g_strdup_printf(_("%.0f%% charge remaining"), pct); icon_names = indicator_power_device_get_icon_names(p->battery); @@ -203,7 +210,10 @@ notification_show(IndicatorPowerNotifier * self) icon_name = icon_names[0]; else icon_name = NULL; - nn = notify_notification_new(_("Battery Low"), body, icon_name); + nn = notify_notification_new(title, body, icon_name); + g_strfreev (icon_names); + g_free (body); + if (actions_supported) { notify_notification_set_hint(nn, "x-canonical-snap-decisions", g_variant_new_boolean(TRUE)); @@ -213,8 +223,6 @@ notification_show(IndicatorPowerNotifier * self) notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL); notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); } - g_strfreev (icon_names); - g_free (body); /* if we can show it, keep it */ error = NULL; -- cgit v1.2.3 From ee6e07ff8b0765a584b8424dc4801833ac86317e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Sep 2014 16:19:37 -0500 Subject: sync with lp-1330037-add-upower-099-support to resolve merge conflicts --- src/notifier.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/notifier.c b/src/notifier.c index f4c8950..1767146 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -103,7 +103,7 @@ power_level_to_dbus_string (const PowerLevel power_level) } } -PowerLevel +static PowerLevel get_battery_power_level (IndicatorPowerDevice * battery) { static const double percent_critical = 2.0; @@ -366,9 +366,6 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) if (!instance_count++) { - GList * caps; - GList * l; - actions_supported = FALSE; if (!notify_init("indicator-power-service")) @@ -377,6 +374,9 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) } else { + GList * caps; + GList * l; + /* see if actions are supported */ caps = notify_get_server_caps(); for (l=caps; l!=NULL && !actions_supported; l=l->next) -- cgit v1.2.3