From 0027e9422fa7205d0a50b995fbe172c35c9ce379 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 21 Jan 2013 16:09:02 -0500 Subject: add support for libnotify based notifier --- notify.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'notify.h') diff --git a/notify.h b/notify.h index 03f6775..4718f20 100644 --- a/notify.h +++ b/notify.h @@ -2,6 +2,10 @@ #include +#ifdef HAVE_NOTIFY +#include +#endif + enum NotificationType { NOTIFY_VOLUME, NOTIFY_BALANCE, @@ -35,4 +39,52 @@ class CommandLineNotifier : public Notifier { } }; +#ifdef HAVE_NOTIFY +class LibnotifyNotifier : public Notifier { + public: + LibnotifyNotifier() { + notify_init("ponymix"); + } + + virtual ~LibnotifyNotifier() { + notify_uninit(); + } + + virtual void Notify(enum NotificationType type, long value, bool mute) { + switch (type) { + case NOTIFY_BALANCE: + break; + case NOTIFY_VOLUME: + case NOTIFY_UNMUTE: + case NOTIFY_MUTE: + volchange(value, mute); + break; + } + } + + private: + void volchange(long vol, bool mute) { + const char* icon = "notification-audio-volume-muted"; + + if (!mute) { + if (vol > 67) { + icon = "notification-audio-volume-high"; + } else if (vol > 33) { + icon = "notification-audio-volume-medium"; + } else if (vol > 0) { + icon = "notification-audio-volume-low"; + } + } + + NotifyNotification* notification = notify_notification_new("ponymix", "", icon); + notify_notification_set_timeout(notification, 1000); + notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); + notify_notification_set_hint_int32(notification, "value", vol); + notify_notification_set_hint_string(notification, "synchronous", "volume"); + notify_notification_show(notification, NULL); + g_object_unref(G_OBJECT(notification)); + } +}; +#endif + // vim: set et ts=2 sw=2: -- cgit v1.2.3