changeset 1488:30f121eb17a6 trunk

[svn] - add libnotify plugin
author nenolod
date Thu, 03 Aug 2006 22:32:07 -0700
parents 9d234fcfc72d
children df4b1ed6b717
files ChangeLog Plugins/General/notify/Makefile Plugins/General/notify/notify.c
diffstat 3 files changed, 134 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Aug 03 01:40:18 2006 -0700
+++ b/ChangeLog	Thu Aug 03 22:32:07 2006 -0700
@@ -1,3 +1,11 @@
+2006-08-03 08:40:18 +0000  Tony Vroon <chainsaw@gentoo.org>
+  revision [1888]
+  Updated dutch translation. 990 translated messages.
+
+  Changes:        Modified:
+  +16 -418        trunk/po/nl.po  
+
+
 2006-08-03 08:05:52 +0000  William Pitcock <nenolod@nenolod.net>
   revision [1886]
   - do virtual playlists properly in 1.2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/General/notify/Makefile	Thu Aug 03 22:32:07 2006 -0700
@@ -0,0 +1,16 @@
+include ../../../mk/rules.mk
+include ../../../mk/objective.mk
+
+OBJECTIVE_LIBS = libnotify.so
+
+LIBDIR = $(plugindir)/$(GENERAL_PLUGIN_DIR)
+
+SOURCES = notify.c
+
+OBJECTS = ${SOURCES:.c=.o}
+
+CFLAGS += -fPIC -DPIC $(GTK_CFLAGS) $(ARCH_DEFINES) -I../../../intl -I../../.. -DDATA_DIR=\"$(datadir)\"
+
+CXXFLAGS = $(CFLAGS)
+
+LIBADD = $(GTK_LIBS) -lnotify
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/General/notify/notify.c	Thu Aug 03 22:32:07 2006 -0700
@@ -0,0 +1,110 @@
+/*
+ * libnotify plugin for audacious 1.1+
+ * http://nenolod.net/code/audacious-notify
+ *
+ * See `COPYING' in the directory root for license details.
+ */
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <libnotify/notify.h>
+#include "audacious/plugin.h"
+#include "audacious/playlist.h"
+
+#include "config.h"
+
+static void init(void);
+static void cleanup(void);
+static gboolean watchdog_func(gpointer unused);
+static gint timeout_tag = 0;
+
+static gint notify_playlist_pos = -1;
+
+/* our API. */
+static void do_notification(gchar *summary, gchar *message, gchar *icon_uri);
+
+GeneralPlugin notify_gp =
+{
+        NULL,                   /* handle */
+        NULL,                   /* filename */
+        -1,                     /* xmms_session */
+        NULL,                   /* Description */
+        init,
+        NULL,
+        NULL,
+        cleanup,
+};
+
+GeneralPlugin *get_gplugin_info(void)
+{
+	notify_gp.description = g_strdup_printf(_("libnotify Plugin %s"), PACKAGE_VERSION);
+	return &notify_gp;
+}
+
+static void init(void) 
+{
+	timeout_tag = gtk_timeout_add(100, watchdog_func, NULL);
+}
+
+static void cleanup(void)
+{
+	gtk_timeout_remove(timeout_tag);
+}
+
+static gboolean watchdog_func(gpointer unused)
+{
+	gint pos = playlist_get_position();
+
+	if (pos != notify_playlist_pos)
+	{
+		do_notification("Audacious", playlist_get_songtitle(pos), DATA_DIR "/pixmaps/audacious.png");
+	}
+
+	notify_playlist_pos = pos;
+
+	return TRUE;
+}
+
+static void do_notification(gchar *summary, gchar *message, gchar *icon_uri)
+{
+	NotifyNotification *n;  
+	gint ret;
+
+	/* Initialise libnotify if we haven't done so yet. */
+	notify_init(PACKAGE);
+
+	n = notify_notification_new(summary, 
+ 	                            message,
+        	                    NULL, NULL);
+
+	/* make sure we have a notify object before continuing,
+	 * for paranoia's sake anyhow. -nenolod
+	 */
+	if (n == NULL)
+		return;
+
+	notify_notification_set_timeout(n, 5000);	/* todo: configurable? */
+
+	if (icon_uri != NULL)
+	{
+		GdkPixbuf *gp = gdk_pixbuf_new_from_file(icon_uri, NULL);
+
+		if (gp != NULL)
+		{
+			notify_notification_set_icon_from_pixbuf(n, GDK_PIXBUF(gp));
+			g_object_unref(G_OBJECT(gp));
+		}
+	}
+
+	ret = notify_notification_show(n, NULL);
+
+#if 0
+	/* rainy day: handle this condition below -nenolod */
+	if (ret == 0)
+	{
+		/* do something */
+	}
+#endif
+
+	g_object_unref(G_OBJECT(n));
+}