aboutsummaryrefslogtreecommitdiff
path: root/src/notifier.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-09-08 10:39:58 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-09-08 10:39:58 -0500
commit0ab79aced178b97e878432be4e716f23b4520d09 (patch)
treeeda039e04d7b89bf2078ca37714725b7e77349a9 /src/notifier.c
parent059246d136ed8c24c5e78e6a966bf2dfc945fe4e (diff)
downloadayatana-indicator-power-0ab79aced178b97e878432be4e716f23b4520d09.tar.gz
ayatana-indicator-power-0ab79aced178b97e878432be4e716f23b4520d09.tar.bz2
ayatana-indicator-power-0ab79aced178b97e878432be4e716f23b4520d09.zip
on phone, add nonexpiring snap-decision popup on low battery events.
Diffstat (limited to 'src/notifier.c')
-rw-r--r--src/notifier.c53
1 files changed, 50 insertions, 3 deletions
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 <url-dispatcher.h>
+
#include <libnotify/notify.h>
#include <glib/gi18n.h>
-#define HINT_INTERACTIVE "x-canonical-switch-to-application"
+#include <stdint.h> /* UINT32_MAX */
typedef enum
{
@@ -53,6 +55,8 @@ static GParamSpec * properties[LAST_PROP];
static int instance_count = 0;
+static gboolean actions_supported = FALSE;
+
/**
***
**/
@@ -163,11 +167,29 @@ 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);
}
}