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/notifier.c') 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