[Xfce4-commits] <parole:master> Move notifications from system tray plugin to Notify plugin.
Sean Davis
noreply at xfce.org
Fri Dec 21 15:54:01 CET 2012
Updating branch refs/heads/master
to b1e4b182cc382fe3255f2fbddb1505cae62e0a74 (commit)
from cea167214947a17582cd1147201c65a16969195e (commit)
commit b1e4b182cc382fe3255f2fbddb1505cae62e0a74
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Fri Dec 21 09:53:51 2012 -0500
Move notifications from system tray plugin to Notify plugin.
configure.ac.in | 68 +++--
src/plugins/Makefile.am | 4 +
src/plugins/{tray => notify}/Makefile.am | 20 +-
.../{tray/tray-plugin.c => notify/notify-plugin.c} | 8 +-
src/plugins/notify/notify-provider.c | 351 ++++++++++++++++++++
src/plugins/notify/notify-provider.h | 44 +++
src/plugins/notify/notify.desktop.in | 6 +
src/plugins/tray/Makefile.am | 6 +-
src/plugins/tray/tray-provider.c | 205 +------------
9 files changed, 460 insertions(+), 252 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index 5331f4a..44d5a8a 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -179,6 +179,22 @@ fi
# Check plugins to build #
#=======================================================#
+# Notify plugin.
+#--------------------------
+AC_ARG_ENABLE([notify-plugin], AC_HELP_STRING([--disable-notify-plugin], [Don't build parole notification plugin]),
+ [ac_notify_plugin=$enableval], [ac_notify_plugin=yes])
+AC_MSG_CHECKING([whether to build the notification plugin])
+AM_CONDITIONAL([PAROLE_NOTIFY_PLUGIN], [test x"$ac_notify_plugin" = x"yes"])
+AC_MSG_RESULT([$ac_notify_plugin])
+# Depends on Libnotify - if not found cannot build
+LIBNOTIFY_FOUND="no"
+if test x"$ac_notify_plugin" = x"yes"; then
+ XDT_CHECK_PACKAGE([LIBNOTIFY],
+ [libnotify], [libnotify_minimum_version],
+ [libnotify],
+ [libnotify library], [yes])
+fi
+
# Tray plugin.
#--------------------------
AC_ARG_ENABLE([tray-plugin], AC_HELP_STRING([--disable-tray-plugin], [Don't build parole tray icon plugin]),
@@ -186,14 +202,6 @@ AC_ARG_ENABLE([tray-plugin], AC_HELP_STRING([--disable-tray-plugin], [Don't buil
AC_MSG_CHECKING([whether to build the system tray plugin])
AM_CONDITIONAL([PAROLE_TRAY_PLUGIN], [test x"$ac_tray_plugin" = x"yes"])
AC_MSG_RESULT([$ac_tray_plugin])
-# Should we build the tray icon with notification support?
-LIBNOTIFY_FOUND="no"
-if test x"$ac_tray_plugin" = x"yes"; then
- XDT_CHECK_OPTIONAL_PACKAGE([LIBNOTIFY],
- [libnotify], [libnotify_minimum_version],
- [libnotify],
- [libnotify library], [yes])
-fi
# Power Manager
#--------------------------
@@ -234,6 +242,7 @@ src/gst/Makefile
src/dbus/Makefile
src/plugins/Makefile
src/plugins/sample/Makefile
+src/plugins/notify/Makefile
src/plugins/tray/Makefile
src/plugins/power-manager/Makefile
docs/Makefile
@@ -246,28 +255,27 @@ echo "
------------------------------------------------------
Parole Media Player $VERSION
====================================
-
- Installation:
- =============
- prefix: $prefix
- pixmapsdir: $pixmapsdir
- Debug: $enable_debug
- Building plugin api docs: ${enable_gtk_doc}
-
- Optional dependencies:
- ======================
- Libnotify: $LIBNOTIFY_FOUND
- Taglib: $TAGLIB_FOUND
-
- Plugins to build:
- =================
- System Tray icon: ${ac_tray_plugin}"
- if test x${ac_tray_plugin} = x"yes"; then
- echo " (With notification $LIBNOTIFY_FOUND)"
- fi
-
- echo "
- Power Manager: ${ac_power_manager_plugin}
+
+ Installation:
+ =============
+ prefix: $prefix
+ pixmapsdir: $pixmapsdir
+ Debug: $enable_debug
+ Building plugin api docs: ${enable_gtk_doc}
+
+ Optional dependencies:
+ ======================
+ Taglib: $TAGLIB_FOUND
+
+ Plugins to build:
+ =================
+ Notify: ${ac_notify_plugin}"
+
+ echo "
+ System Tray icon: ${ac_tray_plugin}"
+
+ echo "
+ Power Manager: ${ac_power_manager_plugin}
------------------------------------------------------
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 753feaf..14fa33c 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -4,6 +4,10 @@ if PAROLE_TRAY_PLUGIN
SUBDIRS+=tray
endif
+if PAROLE_NOTIFY_PLUGIN
+SUBDIRS+=notify
+endif
+
if POWER_MANAGER_PLUGIN
SUBDIRS+=power-manager
endif
diff --git a/src/plugins/tray/Makefile.am b/src/plugins/notify/Makefile.am
similarity index 73%
copy from src/plugins/tray/Makefile.am
copy to src/plugins/notify/Makefile.am
index fd85826..1b9a679 100644
--- a/src/plugins/tray/Makefile.am
+++ b/src/plugins/notify/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = \
-I$(top_builddir) \
-I$(top_srcdir) \
-I$(top_srcdir)/src \
- -DG_LOG_DOMAIN=\"parole_tray\" \
+ -DG_LOG_DOMAIN=\"parole_notify\" \
-DLIBEXECDIR=\"$(libexecdir)\" \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
@@ -10,27 +10,27 @@ pluginsdir = \
$(libdir)/parole-$(PAROLE_VERSION_API)
plugins_LTLIBRARIES = \
- tray-icon.la
+ parole-notify.la
-tray_icon_la_SOURCES = \
- tray-plugin.c \
- tray-provider.c \
- tray-provider.h
+parole_notify_la_SOURCES = \
+ notify-plugin.c \
+ notify-provider.c \
+ notify-provider.h
-tray_icon_la_CFLAGS = \
+parole_notify_la_CFLAGS = \
$(PLATFORM_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(LIBNOTIFY_CFLAGS)
-tray_icon_la_LDFLAGS = \
+parole_notify_la_LDFLAGS = \
-avoid-version \
-export-dynamic \
-module \
$(PLATFORM_LDFLAGS)
-tray_icon_la_LIBADD = \
+parole_notify_la_LIBADD = \
$(top_builddir)/src/misc/libparole.la \
$(GTK_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
@@ -39,7 +39,7 @@ tray_icon_la_LIBADD = \
#
# .desktop file
#
-desktop_in_files = system-tray.desktop.in
+desktop_in_files = notify.desktop.in
desktopdir = $(datadir)/parole/parole-plugins-$(PAROLE_VERSION_API)
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
diff --git a/src/plugins/tray/tray-plugin.c b/src/plugins/notify/notify-plugin.c
similarity index 88%
copy from src/plugins/tray/tray-plugin.c
copy to src/plugins/notify/notify-plugin.c
index 402427b..643c513 100644
--- a/src/plugins/tray/tray-plugin.c
+++ b/src/plugins/notify/notify-plugin.c
@@ -1,5 +1,5 @@
/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2012 Sean Davis <smd.seandavis at gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -24,7 +24,7 @@
#include <libxfce4util/libxfce4util.h>
-#include "tray-provider.h"
+#include "notify-provider.h"
G_MODULE_EXPORT GType parole_plugin_initialize (ParoleProviderPlugin *plugin);
@@ -35,9 +35,9 @@ parole_plugin_initialize (ParoleProviderPlugin *plugin)
{
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
- tray_provider_register_type (plugin);
+ notify_provider_register_type (plugin);
- return TRAY_TYPE_PROVIDER;
+ return NOTIFY_TYPE_PROVIDER;
}
G_MODULE_EXPORT void
diff --git a/src/plugins/notify/notify-provider.c b/src/plugins/notify/notify-provider.c
new file mode 100644
index 0000000..a65625a
--- /dev/null
+++ b/src/plugins/notify/notify-provider.c
@@ -0,0 +1,351 @@
+/*
+ * * Copyright (C) 2012 Sean Davis <smd.seandavis at gmail.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include <src/misc/parole.h>
+
+#include <libnotify/notify.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+
+#include "notify-provider.h"
+
+#define RESOURCE_FILE "xfce4/src/misc/parole-plugins/notify.rc"
+
+static void notify_provider_iface_init (ParoleProviderPluginIface *iface);
+static void notify_provider_finalize (GObject *object);
+
+
+struct _NotifyProviderClass
+{
+ GObjectClass parent_class;
+};
+
+struct _NotifyProvider
+{
+ GObject parent;
+ ParoleProviderPlayer *player;
+ GtkWidget *window;
+
+ NotifyNotification *notification;
+ gboolean enabled;
+};
+
+PAROLE_DEFINE_TYPE_WITH_CODE (NotifyProvider,
+ notify_provider,
+ G_TYPE_OBJECT,
+ PAROLE_IMPLEMENT_INTERFACE (PAROLE_TYPE_PROVIDER_PLUGIN,
+ notify_provider_iface_init));
+
+static void
+notification_closed_cb (NotifyNotification *n, NotifyProvider *notify)
+{
+ g_object_unref (notify->notification);
+ notify->notification = NULL;
+}
+
+static void
+close_notification (NotifyProvider *notify)
+{
+ if ( notify->notification )
+ {
+ GError *error = NULL;
+ notify_notification_close (notify->notification, &error);
+ if ( error )
+ {
+ g_warning ("Failed to close notification : %s", error->message);
+ g_error_free (error);
+ }
+ g_object_unref (notify->notification);
+ notify->notification = NULL;
+ }
+}
+
+static void
+notify_playing (NotifyProvider *notify, const ParoleStream *stream)
+{
+ GdkPixbuf *pix;
+ gboolean has_video;
+ gchar *title, *album, *artist, *year;
+ gchar *message;
+ ParoleMediaType media_type;
+
+ g_object_get (G_OBJECT (stream),
+ "title", &title,
+ "album", &album,
+ "artist", &artist,
+ "year", &year,
+ "has-video", &has_video,
+ "media-type", &media_type,
+ NULL);
+
+ if ( has_video )
+ return;
+
+ if ( !title )
+ {
+ gchar *uri;
+ gchar *filename;
+ g_object_get (G_OBJECT (stream),
+ "uri", &uri,
+ NULL);
+
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ g_free (uri);
+ if ( filename )
+ {
+ title = g_path_get_basename (filename);
+ g_free (filename);
+ if ( !title )
+ return;
+ }
+ }
+
+ if (!album)
+ album = g_strdup( _("Unknown Album") );
+ if (!artist)
+ artist = g_strdup( _("Unknown Artist") );
+
+ if (!year)
+ message = g_strdup_printf ("%s %s\n%s %s", _("<i>on</i>"), album, _("<i>by</i>"), artist);
+ else
+ {
+ message = g_strdup_printf ("%s %s (%s)\n%s %s", _("<i>on</i>"), album, year, _("<i>by</i>"), artist);
+ g_free(year);
+ }
+
+ g_free(artist);
+ g_free(album);
+
+#ifdef NOTIFY_CHECK_VERSION
+#if NOTIFY_CHECK_VERSION (0, 7, 0)
+ notify->notification = notify_notification_new (title, message, NULL);
+#else
+ notify->notification = notify_notification_new (title, message, NULL, NULL);
+#endif
+#else
+ notify->notification = notify_notification_new (title, message, NULL, NULL);
+#endif
+ g_free (title);
+ g_free (message);
+
+ if (media_type == PAROLE_MEDIA_TYPE_CDDA)
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "media-cdrom-audio",
+ 48,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
+ else
+ pix = parole_stream_get_image(G_OBJECT(stream));
+
+ if (!pix)
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "audio-x-generic",
+ 48,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
+
+ if ( pix )
+ {
+ notify_notification_set_icon_from_pixbuf (notify->notification, pix);
+ g_object_unref (pix);
+ }
+ notify_notification_set_urgency (notify->notification, NOTIFY_URGENCY_LOW);
+ notify_notification_set_timeout (notify->notification, 5000);
+
+ notify_notification_show (notify->notification, NULL);
+ g_signal_connect (notify->notification, "closed",
+ G_CALLBACK (notification_closed_cb), notify);
+
+ notify->enabled = FALSE;
+}
+
+static void
+state_changed_cb (ParoleProviderPlayer *player, const ParoleStream *stream, ParoleState state, NotifyProvider *notify)
+{
+ if ( state == PAROLE_STATE_PLAYING )
+ notify_playing (notify, stream);
+
+ else if ( state <= PAROLE_STATE_PAUSED )
+ close_notification (notify);
+
+ if ( state < PAROLE_STATE_PAUSED )
+ notify->enabled = TRUE;
+}
+
+static gboolean
+read_entry_bool (const gchar *entry, gboolean fallback)
+{
+ gboolean ret_val = fallback;
+ gchar *file;
+ XfceRc *rc;
+
+ file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, RESOURCE_FILE, TRUE);
+ rc = xfce_rc_simple_open (file, TRUE);
+ g_free (file);
+
+ if ( rc )
+ {
+ ret_val = xfce_rc_read_bool_entry (rc, entry, fallback);
+ xfce_rc_close (rc);
+ }
+
+ return ret_val;
+}
+
+static void
+write_entry_bool (const gchar *entry, gboolean value)
+{
+ gchar *file;
+ XfceRc *rc;
+
+ file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, RESOURCE_FILE, TRUE);
+ rc = xfce_rc_simple_open (file, FALSE);
+ g_free (file);
+
+ xfce_rc_write_bool_entry (rc, entry, value);
+ xfce_rc_close (rc);
+}
+
+static gboolean
+notify_enabled (void)
+{
+ gboolean ret_val = read_entry_bool ("NOTIFY", TRUE);
+
+ return ret_val;
+}
+
+static void
+notify_toggled_cb (GtkToggleButton *bt, NotifyProvider *notify)
+{
+ gboolean active;
+ active = gtk_toggle_button_get_active (bt);
+ notify->enabled = active;
+
+ write_entry_bool ("NOTIFY", active);
+}
+
+static void
+configure_plugin (NotifyProvider *notify, GtkWidget *widget)
+{
+ GtkWidget *dialog;
+ GtkWidget *content_area;
+
+ GtkWidget *check;
+
+ GtkWidget *hide_on_delete;
+ gboolean hide_on_delete_b;
+
+ dialog = gtk_dialog_new_with_buttons (_("Tray icon plugin"),
+ GTK_WINDOW (widget),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ NULL);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+ check = gtk_check_button_new_with_label (_("Enable notification"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), notify->enabled);
+ g_signal_connect (check, "toggled",
+ G_CALLBACK (notify_toggled_cb), notify);
+ gtk_box_pack_start_defaults (GTK_BOX (content_area), check) ;
+
+ hide_on_delete_b = read_entry_bool ("MINIMIZE_TO_TRAY", TRUE);
+ hide_on_delete = gtk_check_button_new_with_label (_("Always minimize to tray when window is closed"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (hide_on_delete), hide_on_delete_b);
+
+ gtk_box_pack_start_defaults (GTK_BOX (content_area), hide_on_delete);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show_all (dialog);
+}
+
+static gboolean notify_provider_is_configurable (ParoleProviderPlugin *plugin)
+{
+ return TRUE;
+}
+
+static void
+notify_provider_set_player (ParoleProviderPlugin *plugin, ParoleProviderPlayer *player)
+{
+ NotifyProvider *notify;
+
+ notify = NOTIFY_PROVIDER (plugin);
+
+ notify->window = parole_provider_player_get_main_window (player);
+
+ notify->player = player;
+
+ notify->notification = NULL;
+ notify_init ("parole-notify");
+ notify->enabled = notify_enabled ();
+
+ g_signal_connect (player, "state_changed",
+ G_CALLBACK (state_changed_cb), notify);
+}
+
+static void
+notify_provider_configure (ParoleProviderPlugin *provider, GtkWidget *parent)
+{
+ NotifyProvider *notify;
+ notify = NOTIFY_PROVIDER (provider);
+ configure_plugin (notify, parent);
+}
+
+static void
+notify_provider_iface_init (ParoleProviderPluginIface *iface)
+{
+ iface->set_player = notify_provider_set_player;
+ iface->configure = notify_provider_configure;
+ iface->get_is_configurable = notify_provider_is_configurable;
+}
+
+static void notify_provider_class_init (NotifyProviderClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = notify_provider_finalize;
+}
+
+static void notify_provider_init (NotifyProvider *provider)
+{
+ provider->player = NULL;
+}
+
+static void notify_provider_finalize (GObject *object)
+{
+ NotifyProvider *notify;
+
+ notify = NOTIFY_PROVIDER (object);
+
+ close_notification (notify);
+
+ G_OBJECT_CLASS (notify_provider_parent_class)->finalize (object);
+}
diff --git a/src/plugins/notify/notify-provider.h b/src/plugins/notify/notify-provider.h
new file mode 100644
index 0000000..1c6cb1b
--- /dev/null
+++ b/src/plugins/notify/notify-provider.h
@@ -0,0 +1,44 @@
+/*
+ * * Copyright (C) 2012 Sean Davis <smd.seandavis at gmail.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ */
+
+#ifndef NOTIFY_PROVIDER_H_
+#define NOTIFY_PROVIDER_H_
+
+#include <src/misc/parole.h>
+
+G_BEGIN_DECLS
+
+typedef struct _NotifyProviderClass NotifyProviderClass;
+typedef struct _NotifyProvider NotifyProvider;
+
+#define NOTIFY_TYPE_PROVIDER (notify_provider_get_type ())
+#define NOTIFY_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFY_TYPE_PROVIDER, NotifyProvider))
+#define NOTIFY_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFY_TYPE_PROVIDER, NotifyProviderClass))
+#define NOTIFY_IS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFY_TYPE_PROVIDER))
+#define NOTIFY_IS_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFY_TYPE_PROVIDER))
+#define NOTIFY_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NOTIFY_TYPE_PROVIDER, NotifyProviderClass))
+
+GType notify_provider_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
+
+void notify_provider_register_type (ParoleProviderPlugin *provider);
+
+G_END_DECLS
+
+#endif /*NOTIFY_PROVIDER_H_*/
diff --git a/src/plugins/notify/notify.desktop.in b/src/plugins/notify/notify.desktop.in
new file mode 100644
index 0000000..11c3e84
--- /dev/null
+++ b/src/plugins/notify/notify.desktop.in
@@ -0,0 +1,6 @@
+[Parole Plugin]
+Module=parole-notify
+_Name=Notify
+_Description=Show notifications currently playing tracks
+Authors=Sean Davis smd.seandavis at gmail.com
+Website=http://goodies.xfce.org/projects/applications/parole
diff --git a/src/plugins/tray/Makefile.am b/src/plugins/tray/Makefile.am
index fd85826..d7f2fac 100644
--- a/src/plugins/tray/Makefile.am
+++ b/src/plugins/tray/Makefile.am
@@ -21,8 +21,7 @@ tray_icon_la_CFLAGS = \
$(PLATFORM_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
- $(LIBXFCE4UTIL_CFLAGS) \
- $(LIBNOTIFY_CFLAGS)
+ $(LIBXFCE4UTIL_CFLAGS)
tray_icon_la_LDFLAGS = \
-avoid-version \
@@ -33,8 +32,7 @@ tray_icon_la_LDFLAGS = \
tray_icon_la_LIBADD = \
$(top_builddir)/src/misc/libparole.la \
$(GTK_LIBS) \
- $(LIBXFCE4UTIL_LIBS) \
- $(LIBNOTIFY_LIBS)
+ $(LIBXFCE4UTIL_LIBS)
#
# .desktop file
diff --git a/src/plugins/tray/tray-provider.c b/src/plugins/tray/tray-provider.c
index 0fa0c9d..91865e8 100644
--- a/src/plugins/tray/tray-provider.c
+++ b/src/plugins/tray/tray-provider.c
@@ -27,11 +27,6 @@
#include <src/misc/parole.h>
-#ifdef HAVE_LIBNOTIFY
-#include <libnotify/notify.h>
-#endif
-
-
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
@@ -56,11 +51,6 @@ struct _TrayProvider
GtkWidget *window;
gulong sig;
-#ifdef HAVE_LIBNOTIFY
- NotifyNotification *n;
- gboolean notify;
- gboolean enabled;
-#endif
ParoleState state;
GtkWidget *menu;
};
@@ -187,139 +177,6 @@ tray_activate_cb (GtkStatusIcon *tray_icon, TrayProvider *tray)
gtk_widget_show (tray->window);
}
-#ifdef HAVE_LIBNOTIFY
-static void
-notification_closed_cb (NotifyNotification *n, TrayProvider *tray)
-{
- g_object_unref (tray->n);
- tray->n = NULL;
-}
-
-static void
-close_notification (TrayProvider *tray)
-{
- if ( tray->n )
- {
- GError *error = NULL;
- notify_notification_close (tray->n, &error);
- if ( error )
- {
- g_warning ("Failed to close notification : %s", error->message);
- g_error_free (error);
- }
- g_object_unref (tray->n);
- tray->n = NULL;
- }
-}
-
-static void
-notify_playing (TrayProvider *tray, const ParoleStream *stream)
-{
- GdkPixbuf *pix;
- gboolean has_video;
- gchar *title, *album, *artist, *year;
- gchar *message;
- ParoleMediaType media_type;
-
- if ( !tray->notify || !tray->enabled)
- return;
-
- g_object_get (G_OBJECT (stream),
- "title", &title,
- "album", &album,
- "artist", &artist,
- "year", &year,
- "has-video", &has_video,
- "media-type", &media_type,
- NULL);
-
- if ( has_video )
- return;
-
- if ( !title )
- {
- gchar *uri;
- gchar *filename;
- g_object_get (G_OBJECT (stream),
- "uri", &uri,
- NULL);
-
- filename = g_filename_from_uri (uri, NULL, NULL);
- g_free (uri);
- if ( filename )
- {
- title = g_path_get_basename (filename);
- g_free (filename);
- if ( !title )
- return;
- }
- }
-
- if (!album)
- album = g_strdup( _("Unknown Album") );
- if (!artist)
- artist = g_strdup( _("Unknown Artist") );
-
- if (!year)
- message = g_strdup_printf ("%s %s\n%s %s", _("<i>on</i>"), album, _("<i>by</i>"), artist);
- else
- {
- message = g_strdup_printf ("%s %s (%s)\n%s %s", _("<i>on</i>"), album, year, _("<i>by</i>"), artist);
- g_free(year);
- }
-
- g_free(artist);
- g_free(album);
-
-#ifdef NOTIFY_CHECK_VERSION
-#if NOTIFY_CHECK_VERSION (0, 7, 0)
- tray->n = notify_notification_new (title, message, NULL);
-#else
- tray->n = notify_notification_new (title, message, NULL, NULL);
-#endif
-#else
- tray->n = notify_notification_new (title, message, NULL, NULL);
-#endif
- g_free (title);
- g_free (message);
-
-#ifdef NOTIFY_CHECK_VERSION
-#if !NOTIFY_CHECK_VERSION (0, 7, 0)
- notify_notification_attach_to_status_icon (tray->n, tray->tray);
-#endif
-#endif
- if (media_type == PAROLE_MEDIA_TYPE_CDDA)
- pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- "media-cdrom-audio",
- 48,
- GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
- else
- pix = parole_stream_get_image(G_OBJECT(stream));
-
- if (!pix)
- pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- "audio-x-generic",
- 48,
- GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
-
- if ( pix )
- {
- notify_notification_set_icon_from_pixbuf (tray->n, pix);
- g_object_unref (pix);
- }
- notify_notification_set_urgency (tray->n, NOTIFY_URGENCY_LOW);
- notify_notification_set_timeout (tray->n, 5000);
-
- notify_notification_show (tray->n, NULL);
- g_signal_connect (tray->n, "closed",
- G_CALLBACK (notification_closed_cb), tray);
-
- tray->notify = FALSE;
-}
-#endif
-
static void
state_changed_cb (ParoleProviderPlayer *player, const ParoleStream *stream, ParoleState state, TrayProvider *tray)
{
@@ -331,20 +188,6 @@ state_changed_cb (ParoleProviderPlayer *player, const ParoleStream *stream, Paro
tray->menu = NULL;
g_signal_emit_by_name (G_OBJECT (tray->tray), "popup-menu", 0, gtk_get_current_event_time ());
}
-
-#ifdef HAVE_LIBNOTIFY
-
- if ( state == PAROLE_STATE_PLAYING )
- {
- notify_playing (tray, stream);
- }
- else if ( state <= PAROLE_STATE_PAUSED )
- {
- close_notification (tray);
- if ( state < PAROLE_STATE_PAUSED )
- tray->notify = TRUE;
- }
-#endif
}
static gboolean
@@ -381,26 +224,6 @@ write_entry_bool (const gchar *entry, gboolean value)
xfce_rc_close (rc);
}
-#ifdef HAVE_LIBNOTIFY
-static gboolean
-notify_enabled (void)
-{
- gboolean ret_val = read_entry_bool ("NOTIFY", TRUE);
-
- return ret_val;
-}
-
-static void
-notify_toggled_cb (GtkToggleButton *bt, TrayProvider *tray)
-{
- gboolean active;
- active = gtk_toggle_button_get_active (bt);
- tray->enabled = active;
-
- write_entry_bool ("NOTIFY", active);
-}
-#endif /*HAVE_LIBNOTIFY*/
-
static void
hide_on_delete_toggled_cb (GtkWidget *widget, gpointer tray)
{
@@ -414,9 +237,7 @@ configure_plugin (TrayProvider *tray, GtkWidget *widget)
{
GtkWidget *dialog;
GtkWidget *content_area;
-#ifdef HAVE_LIBNOTIFY
- GtkWidget *check;
-#endif
+
GtkWidget *hide_on_delete;
gboolean hide_on_delete_b;
@@ -428,15 +249,6 @@ configure_plugin (TrayProvider *tray, GtkWidget *widget)
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
-#ifdef HAVE_LIBNOTIFY
- check = gtk_check_button_new_with_label (_("Enable notification"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), tray->enabled);
- g_signal_connect (check, "toggled",
- G_CALLBACK (notify_toggled_cb), tray);
- gtk_box_pack_start_defaults (GTK_BOX (content_area), check) ;
-
-#endif /*HAVE_LIBNOTIFY*/
hide_on_delete_b = read_entry_bool ("MINIMIZE_TO_TRAY", TRUE);
hide_on_delete = gtk_check_button_new_with_label (_("Always minimize to tray when window is closed"));
@@ -549,11 +361,7 @@ delete_event_cb (GtkWidget *widget, GdkEvent *ev, TrayProvider *tray)
static gboolean tray_provider_is_configurable (ParoleProviderPlugin *plugin)
{
-#ifdef HAVE_LIBNOTIFY
return TRUE;
-#else
- return FALSE;
-#endif
}
static void
@@ -574,13 +382,6 @@ tray_provider_set_player (ParoleProviderPlugin *plugin, ParoleProviderPlayer *pl
tray->player = player;
tray->menu = NULL;
-#ifdef HAVE_LIBNOTIFY
- tray->n = NULL;
- notify_init ("parole-tray-icon");
- tray->enabled = notify_enabled ();
- tray->notify = TRUE;
-#endif
-
pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"parole",
48,
@@ -643,10 +444,6 @@ static void tray_provider_finalize (GObject *object)
if ( GTK_IS_WIDGET (tray->window) && g_signal_handler_is_connected (tray->window, tray->sig) )
g_signal_handler_disconnect (tray->window, tray->sig);
-#ifdef HAVE_LIBNOTIFY
- close_notification (tray);
-#endif
-
g_object_unref (G_OBJECT (tray->tray));
G_OBJECT_CLASS (tray_provider_parent_class)->finalize (object);
More information about the Xfce4-commits
mailing list