aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-21 13:48:18 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-21 13:48:18 -0500
commitf5bf7f99724796a21dc05676d613ed47c624bfd1 (patch)
tree56f7a58e0c0e4136830b453382bf1c322c3be3ca
parent125f6f6d02e195a668704ac8f8c7ca87940432b9 (diff)
downloadayatana-indicator-power-f5bf7f99724796a21dc05676d613ed47c624bfd1.tar.gz
ayatana-indicator-power-f5bf7f99724796a21dc05676d613ed47c624bfd1.tar.bz2
ayatana-indicator-power-f5bf7f99724796a21dc05676d613ed47c624bfd1.zip
don't show clickable actions if the Notify server doesn't support them.
-rw-r--r--src/notifier.c60
-rw-r--r--src/notifier.h11
2 files changed, 51 insertions, 20 deletions
diff --git a/src/notifier.c b/src/notifier.c
index 1d9428c..06ab119 100644
--- a/src/notifier.c
+++ b/src/notifier.c
@@ -53,8 +53,6 @@ static GParamSpec * properties[LAST_PROP];
***
**/
-static int n_notifiers = 0;
-
struct _IndicatorPowerNotifierPrivate
{
/* The battery we're currently watching.
@@ -110,22 +108,22 @@ static void
notification_show(IndicatorPowerNotifier * self)
{
priv_t * p;
- IndicatorPowerDevice * battery;
char * body;
NotifyNotification * nn;
notification_clear (self);
+ /* only show clickable notifications if the Notify server supports them */
+ if (!INDICATOR_POWER_NOTIFIER_GET_CLASS(self)->interactive)
+ return;
+
p = self->priv;
- battery = p->battery;
- g_return_if_fail (battery != NULL);
/* create the notification */
- body = g_strdup_printf(_("%d%% charge remaining"),
- (int)indicator_power_device_get_percentage(battery));
- p->notify_notification = nn = notify_notification_new(_("Battery Low"),
- body,
- NULL);
+ body = g_strdup_printf(_("%.0f%% charge remaining"),
+ indicator_power_device_get_percentage(p->battery));
+ nn = notify_notification_new(_("Battery Low"), body, NULL);
+ p->notify_notification = nn;
notify_notification_set_hint(nn, "x-canonical-snap-decisions",
g_variant_new_boolean(TRUE));
notify_notification_set_hint(nn, "x-canonical-private-button-tint",
@@ -272,9 +270,11 @@ my_dispose (GObject * o)
}
static void
-my_finalize (GObject * o G_GNUC_UNUSED)
+my_finalize (GObject * o)
{
- if (!--n_notifiers)
+ IndicatorPowerNotifierClass * klass = INDICATOR_POWER_NOTIFIER_GET_CLASS(o);
+
+ if (!--klass->instance_count)
notify_uninit();
}
@@ -285,9 +285,12 @@ my_finalize (GObject * o G_GNUC_UNUSED)
static void
indicator_power_notifier_init (IndicatorPowerNotifier * self)
{
- priv_t * p = G_TYPE_INSTANCE_GET_PRIVATE (self,
- INDICATOR_TYPE_POWER_NOTIFIER,
- IndicatorPowerNotifierPrivate);
+ priv_t * p;
+ IndicatorPowerNotifierClass * klass;
+
+ p = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ INDICATOR_TYPE_POWER_NOTIFIER,
+ IndicatorPowerNotifierPrivate);
self->priv = p;
p->dbus_battery = dbus_battery_skeleton_new ();
@@ -304,8 +307,28 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self)
POWER_LEVEL_NAME,
G_BINDING_SYNC_CREATE);
- if (!n_notifiers++ && !notify_init("indicator-power-service"))
- g_critical("Unable to initialize libnotify! Notifications might not be shown.");
+ klass = INDICATOR_POWER_NOTIFIER_GET_CLASS(self);
+
+ if (!klass->instance_count++)
+ {
+ if (!notify_init("indicator-power-service"))
+ {
+ g_critical("Unable to initialize libnotify! Notifications might not be shown.");
+ }
+ else
+ {
+ /* See if the notification server supports clickable actions... */
+ GList * caps;
+ GList * l;
+ klass->interactive = FALSE;
+ caps = notify_get_server_caps();
+ for (l=caps; l!=NULL && !klass->interactive; l=l->next)
+ if (!g_strcmp0 ("actions", (const char*)l->data))
+ klass->interactive = TRUE;
+ g_message ("%s klass->interactive is %d", G_STRLOC, (int)klass->interactive);
+ g_list_free_full (caps, g_free);
+ }
+ }
}
static void
@@ -346,6 +369,9 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ klass->instance_count = 0;
+ klass->interactive = FALSE;
}
/***
diff --git a/src/notifier.h b/src/notifier.h
index c1c5a1b..cab053f 100644
--- a/src/notifier.h
+++ b/src/notifier.h
@@ -29,9 +29,10 @@
G_BEGIN_DECLS
/* standard GObject macros */
-#define INDICATOR_POWER_NOTIFIER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_POWER_NOTIFIER, IndicatorPowerNotifier))
-#define INDICATOR_TYPE_POWER_NOTIFIER (indicator_power_notifier_get_type())
-#define INDICATOR_IS_POWER_NOTIFIER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_POWER_NOTIFIER))
+#define INDICATOR_POWER_NOTIFIER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_POWER_NOTIFIER, IndicatorPowerNotifier))
+#define INDICATOR_TYPE_POWER_NOTIFIER (indicator_power_notifier_get_type())
+#define INDICATOR_IS_POWER_NOTIFIER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_POWER_NOTIFIER))
+#define INDICATOR_POWER_NOTIFIER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_POWER_NOTIFIER, IndicatorPowerNotifierClass))
typedef struct _IndicatorPowerNotifier IndicatorPowerNotifier;
typedef struct _IndicatorPowerNotifierClass IndicatorPowerNotifierClass;
@@ -59,6 +60,10 @@ struct _IndicatorPowerNotifier
struct _IndicatorPowerNotifierClass
{
GObjectClass parent_class;
+
+ /*< private >*/
+ gint instance_count;
+ gboolean interactive;
};
/***