aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/notifier.c53
-rw-r--r--tests/indicator-power-service-cmdline-battery.cc11
2 files changed, 57 insertions, 7 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);
}
}
diff --git a/tests/indicator-power-service-cmdline-battery.cc b/tests/indicator-power-service-cmdline-battery.cc
index a7a86a1..29ec87d 100644
--- a/tests/indicator-power-service-cmdline-battery.cc
+++ b/tests/indicator-power-service-cmdline-battery.cc
@@ -83,10 +83,13 @@ static gboolean on_command_stream_available (GIOChannel *source,
int
main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
{
- g_message ("This app is basically the same as indicator-power-service but,\n"
- "instead of the system's real devices, sees a single fake battery\n"
- "which can be manipulated by typing commands:\n"
- "'charging', 'discharging', a charge percentage, or ctrl-c.");
+ g_print("This test app has the same code as indicator-power-service\n"
+ "except instead of listening to UPower, it has a fake battery\n"
+ "which you can edit with keyboard inputs. Supported commands:\n"
+ "1. A number in [0..100] to set battery level\n"
+ "2. 'charging'\n"
+ "3. 'discharging'\n"
+ "4. ctrl-c to exit\n");
IndicatorPowerDeviceProvider * device_provider;
IndicatorPowerService * service;