summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Viktor Semykin <thesame.ml@gmail.com>2010-01-04 21:21:11 +0200
committerGravatar Viktor Semykin <thesame.ml@gmail.com>2010-01-04 21:21:11 +0200
commit1d9340c4852cea9328219a1b9a3104f5772e0904 (patch)
tree568149a7c3bdb756d8cbd3676c5ec18e35c7f38a
parentfa519319f3c31f7ca63740c953c35dd4dc9e4b4a (diff)
Initial notification implementation
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac11
-rw-r--r--plugins/notification/Makefile.am6
-rw-r--r--plugins/notification/notification.c55
4 files changed, 73 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 18aecca8..854de1da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,6 +9,7 @@ SUBDIRS = gme/Game_Music_Emu-0.5.2\
plugins/nullout\
plugins/vtx\
plugins/adplug\
+ ${NOTIFICATION_DIR}\
${ALSA_DIR}\
${LFM_DIR}\
${MPGMAD_DIR}\
diff --git a/configure.ac b/configure.ac
index eb34044b..ff4ad333 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,7 @@ PKG_CHECK_MODULES(DEPS, samplerate)
PKG_CHECK_MODULES(GTKUI_DEPS, gtk+-2.0 >= 2.12 gthread-2.0 glib-2.0, HAVE_GTK=1, NO_GTK=1)
PKG_CHECK_MODULES(ALSA_DEPS, alsa, HAVE_ALSA=1, NO_ALSA=1)
PKG_CHECK_MODULES(FFMPEG_DEPS, libavcodec libavutil libavformat >= 52.0.0, HAVE_FFMPEG=1, NO_FFMPEG=1)
+PKG_CHECK_MODULES(NOTIFICATION_DEPS, libnotify, HAVE_LIBNOTIFY=1, NO_LIBNOTIFY=1)
AC_CHECK_LIB([pthread], [main])
AC_CHECK_LIB([dl], [main])
@@ -172,6 +173,14 @@ if test ${HAVE_FFMPEG}; then
AC_SUBST(FFMPEG_DIR)
fi
+AM_CONDITIONAL(HAVE_LIBNOTIFY, test $HAVE_LIBNOTIFY)
+if test ${HAVE_LIBNOTIFY}; then
+ NOTIFICATION_DIR="plugins/notification"
+ AC_SUBST(NOTIFICATION_DEPS_CFLAGS)
+ AC_SUBST(NOTIFICATION_DEPS_LIBS)
+ AC_SUBST(NOTIFICATION_DIR)
+fi
+
dnl print summary
echo
echo "plugin summary:"
@@ -207,6 +216,7 @@ dnl PRINT_PLUGIN_INFO([faad2],[aac/mp4 player],[test $HAVE_FAAD && test $HAVE_MP
PRINT_PLUGIN_INFO([cdda],[cd audio player],[test $HAVE_CDIO && test $HAVE_CDDB])
PRINT_PLUGIN_INFO([gtkui],[GTK user interface],[test $HAVE_GTK])
PRINT_PLUGIN_INFO([ffmpeg],[ffmpeg codecs],[test $HAVE_FFMPEG])
+PRINT_PLUGIN_INFO([notification],[Current track notification],[true])
echo
AC_OUTPUT([
@@ -233,6 +243,7 @@ plugins/nullout/Makefile
plugins/vtx/Makefile
plugins/adplug/Makefile
plugins/ffmpeg/Makefile
+plugins/notification/Makefile
deadbeef.desktop
])
diff --git a/plugins/notification/Makefile.am b/plugins/notification/Makefile.am
new file mode 100644
index 00000000..9bae994f
--- /dev/null
+++ b/plugins/notification/Makefile.am
@@ -0,0 +1,6 @@
+notificationdir = $(libdir)/$(PACKAGE)
+pkglib_LTLIBRARIES = notification.la
+notification_la_SOURCES = notification.c
+notification_la_LDFLAGS = -module
+notification_la_LIBADD = $(LDADD) $(NOTIFICATION_DEPS_LIBS)
+AM_CFLAGS = -std=c99 $(NOTIFICATION_DEPS_CFLAGS)
diff --git a/plugins/notification/notification.c b/plugins/notification/notification.c
new file mode 100644
index 00000000..28df06fc
--- /dev/null
+++ b/plugins/notification/notification.c
@@ -0,0 +1,55 @@
+#include "../../deadbeef.h"
+
+#include <stdio.h>
+#include <libnotify/notify.h>
+
+static DB_misc_t plugin;
+static DB_functions_t *deadbeef;
+
+static int
+songchanged (DB_event_trackchange_t *ev, uintptr_t data) {
+ DB_playItem_t *track = deadbeef->pl_get_for_idx (ev->to);
+ const char *artist = deadbeef->pl_find_meta (track, "artist");
+ const char *album = deadbeef->pl_find_meta (track, "album");
+ const char *title = deadbeef->pl_find_meta (track, "title");
+ char body [1024];
+ GError *err;
+ snprintf (body, sizeof (body), "%s - %s", artist, album);
+ NotifyNotification *ntf = notify_notification_new (title, body, NULL, NULL);
+ notify_notification_set_timeout (ntf, NOTIFY_EXPIRES_DEFAULT);
+ notify_notification_show (ntf, NULL);
+ return 0;
+}
+
+static int
+notification_stop (void) {
+ deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0);
+}
+
+static int
+notification_start (void) {
+ notify_init ("deadbeef");
+
+ deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0);
+ return 1;
+}
+
+DB_plugin_t *
+notification_load (DB_functions_t *api) {
+ deadbeef = api;
+ return DB_PLUGIN (&plugin);
+}
+
+// define plugin interface
+static DB_misc_t plugin = {
+ DB_PLUGIN_SET_API_VERSION
+ .plugin.type = DB_PLUGIN_MISC,
+ .plugin.name = "Current track notification",
+ .plugin.descr = "Displays notification when current track is changed",
+ .plugin.author = "Viktor Semykin",
+ .plugin.email = "thesame.ml@gmail.com",
+ .plugin.website = "http://deadbeef.sf.net",
+ .plugin.start = notification_start,
+ .plugin.stop = notification_stop
+};
+