From 2947964b3d5119d5cd186c381df9f86e997c34df Mon Sep 17 00:00:00 2001 From: Steve Dodier-Lazaro Date: Thu, 9 Apr 2015 13:11:44 +0100 Subject: [PATCH] Towards support for libnotify (functions set up, but not used) --- configure.ac.in | 7 ++ panel-plugin/Makefile.am | 4 + panel-plugin/pulseaudio-notify.c | 153 +++++++++++++++++++++++++++++++++++++++ panel-plugin/pulseaudio-notify.h | 56 ++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 panel-plugin/pulseaudio-notify.c create mode 100644 panel-plugin/pulseaudio-notify.h diff --git a/configure.ac.in b/configure.ac.in index d420023..2d2d3c6 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -95,6 +95,12 @@ dnl ********************************** XDT_CHECK_OPTIONAL_PACKAGE([KEYBINDER], [keybinder-3.0], [0.2.2], [keybinder], [keybinder Support]) +dnl ********************************** +dnl *** Optional libnotify Support *** +dnl ********************************** +XDT_CHECK_OPTIONAL_PACKAGE([NOTIFY], [libnotify], [0.6.0], [libnotify], + [libnotify Support]) + AC_CHECK_LIBM AC_SUBST(LIBM) @@ -143,6 +149,7 @@ echo "Build Configuration:" echo echo "* Debug Support: $enable_debug" echo "* Use keybinder: ${KEYBINDER_FOUND:-no}" +echo "* Use notifications: ${NOTIFY_FOUND:-no}" echo "* Use IDO library: ${IDO_FOUND:-no}" echo "* Default Mixer command: $DEFAULT_MIXER_COMMAND" echo diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am index 1a540d3..f7cf06f 100644 --- a/panel-plugin/Makefile.am +++ b/panel-plugin/Makefile.am @@ -35,6 +35,8 @@ libpulseaudio_plugin_la_SOURCES = \ pulseaudio-dialog.h \ pulseaudio-menu.c \ pulseaudio-menu.h \ + pulseaudio-notify.c \ + pulseaudio-notify.h \ scalemenuitem.c \ scalemenuitem.h @@ -49,6 +51,7 @@ libpulseaudio_plugin_la_CFLAGS = \ $(XFCONF_CFLAGS) \ $(IDO_CFLAGS) \ $(KEYBINDER_CFLAGS) \ + $(NOTIFY_CFLAGS) \ $(PLATFORM_CFLAGS) libpulseaudio_plugin_la_LDFLAGS = \ @@ -68,6 +71,7 @@ libpulseaudio_plugin_la_LIBADD = \ $(XFCONF_LIBS) \ $(IDO_LIBS) \ $(KEYBINDER_LIBS) \ + $(NOTIFY_LIBS) \ $(LIBM) # diff --git a/panel-plugin/pulseaudio-notify.c b/panel-plugin/pulseaudio-notify.c new file mode 100644 index 0000000..91c3e71 --- /dev/null +++ b/panel-plugin/pulseaudio-notify.c @@ -0,0 +1,153 @@ +/* Copyright © 2009-2015 Steve Dodier-Lazaro + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + + +/* + * This file implements a notification class for the Xfce PulseAudio + * panel plugin + */ + + + +#ifdef HAVE_NOTIFY +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "pulseaudio-debug.h" +#include "pulseaudio-notify.h" +#include "pulseaudio-volume.h" + +typedef struct _PulseaudioNotify { + /* Volume vars */ + guint current_vol; + gboolean muted; + + /* Libnotify vars */ + gboolean gauge_notifications; + NotifyNotification* notification; +} PulseaudioNotify; + +void +pulseaudio_notify_notification (PulseaudioNotify *pan, + gchar *icon, + gint value) +{ + gchar* title = NULL; + + if ((icon != NULL) && (g_strcmp0 (icon, PAN_MUTED) == 0)) + { + // TRANSLATORS: this is the body of the ATK interface of the volume notifications. This is the case when volume is muted + title = g_strdup ("Volume is muted"); + } + else + { + // TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug. + title = g_strdup_printf ("Volume is at %d%c", value, '%'); + } + + notify_notification_update (pan->notification, title, NULL, icon); + g_free (title); + + if (pan->gauge_notifications) + { + notify_notification_set_hint_int32 (pan->notification, "value", value); + notify_notification_set_hint_string (pan->notification, PAN_SYNCHRONOUS, ""); + } + + GError *error = NULL; + if (!notify_notification_show (pan->notification, &error)) + { + g_warning ("Error while sending notification : %s\n", error->message); + g_error_free (error); + } +} + +void +pulseaudio_notify_volume_notification (PulseaudioNotify *pan) +{ + if (pan->current_vol == 0) + pulseaudio_notify_notification (pan, PAN_MUTED, 0); + else if (pan->current_vol < 34) + pulseaudio_notify_notification (pan, (pan->muted) ? PAN_MUTED : PAN_LOW, pan->current_vol); + else if (pan->current_vol < 67) + pulseaudio_notify_notification (pan, (pan->muted) ? PAN_MUTED : PAN_MEDIUM, pan->current_vol); + else + pulseaudio_notify_notification (pan, (pan->muted) ? PAN_MUTED : PAN_HIGH, pan->current_vol); +} + +void +pulseaudio_notify_overshoot_notification (PulseaudioNotify *pan) +{ + pulseaudio_notify_notification (pan, + (pan->muted) ? PAN_MUTED : PAN_MUTED_HIGH, + (pan->gauge_notifications) ? 101 : 100); +} + +void +pulseaudio_notify_undershoot_notification (PulseaudioNotify *pan) +{ + pulseaudio_notify_notification (pan, + PAN_MUTED, + (pan->gauge_notifications) ? -1 : 0); +} + +void +pulseaudio_notify_init (PulseaudioNotify *pan, + const gchar *appname) +{ + pan->gauge_notifications = TRUE; + notify_init (appname); + + GList *caps_list = notify_get_server_caps (); + if (caps_list) + { + GList *node; + + node = g_list_find_custom (caps_list, PAN_LAYOUT_ICON_ONLY, (GCompareFunc) g_strcmp0); + if (!node) + pan->gauge_notifications = FALSE; + + node = g_list_find_custom (caps_list, PAN_SYNCHRONOUS, (GCompareFunc) g_strcmp0); + if (!node) + pan->gauge_notifications = FALSE; + + g_list_free (caps_list); + } + +#ifdef NOTIFY_CHECK_VERSION +#if NOTIFY_CHECK_VERSION (0, 7, 0) + pan->notification = notify_notification_new (appname, NULL, NULL); +#else + pan->notification = notify_notification_new (appname, NULL, NULL, NULL); +#endif +#else + pan->notification = notify_notification_new (appname, NULL, NULL, NULL); +#endif + + notify_notification_set_timeout (pan->notification, 1000); +} + +void +pulseaudio_notify_uninit (PulseaudioNotify *pan) +{ + g_object_unref (G_OBJECT (pan->notification)); + pan->notification = NULL; + notify_uninit (); +} +#endif /* !__HAVE_NOTIFY__ */ diff --git a/panel-plugin/pulseaudio-notify.h b/panel-plugin/pulseaudio-notify.h new file mode 100644 index 0000000..2d0ca48 --- /dev/null +++ b/panel-plugin/pulseaudio-notify.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2014 Andrzej + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_NOTIFY +#ifndef __PULSEAUDIO_NOTIFY_H__ +#define __PULSEAUDIO_NOTIFY_H__ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#define PAN_MUTED "audio-volume-muted-symbolic" +#define PAN_LOW "audio-volume-low-symbolic" +#define PAN_MEDIUM "audio-volume-medium-symbolic" +#define PAN_HIGH "audio-volume-high-symbolic" + +#define PAN_SYNCHRONOUS "x-canonical-private-synchronous" +#define PAN_LAYOUT_ICON_ONLY "x-canonical-private-icon-only" + +typedef struct _PulseaudioNotify PulseaudioNotify; + +void pulseaudio_notify_notification (PulseaudioNotify *pan, + gchar *icon, + gint value); + +void pulseaudio_notify_volume_notification (PulseaudioNotify *pan); + +void pulseaudio_notify_overshoot_notification (PulseaudioNotify *pan); + +void pulseaudio_notify_undershoot_notification (PulseaudioNotify *pan); + +void pulseaudio_notify_init (PulseaudioNotify *pan, + const gchar *appname); + +void pulseaudio_notify_uninit (PulseaudioNotify *pan); + +#endif /* !__PULSEAUDIO_NOTIFY_H__ */ +#endif /* !__HAVE_NOTIFY__ */ -- 2.3.5