summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-01 20:39:54 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-01 20:39:54 +0100
commit1cc65f741a53ad608a9a150d4076a883002f0738 (patch)
tree7a6c168f2887de0029a498efbd03f7fb4ffe9ff2 /plugins
parentfe78eb6e6171c45cd3500bfd8cd35ded4f548c1d (diff)
moved libnotify support into gtkui using --enable-libnotify
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtkui/Makefile.am4
-rw-r--r--plugins/gtkui/gtkui.c51
-rw-r--r--plugins/notification/Makefile.am5
-rw-r--r--plugins/notification/notification.c63
4 files changed, 52 insertions, 71 deletions
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am
index aaf9c56a..146e76db 100644
--- a/plugins/gtkui/Makefile.am
+++ b/plugins/gtkui/Makefile.am
@@ -13,6 +13,6 @@ gtkui_la_SOURCES = gtkui.c gtkui.h\
gtkui_la_LDFLAGS = -module
-gtkui_la_LIBADD = $(LDADD) $(GTKUI_DEPS_LIBS)
-AM_CFLAGS = -std=c99 $(GTKUI_DEPS_CFLAGS)
+gtkui_la_LIBADD = $(LDADD) $(GTKUI_DEPS_LIBS) $(NOTIFY_DEPS_LIBS)
+AM_CFLAGS = -std=c99 $(GTKUI_DEPS_CFLAGS) $(NOTIFY_DEPS_CFLAGS)
endif
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index c4aacb95..279d281f 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -18,6 +18,12 @@
*/
#include "../../deadbeef.h"
#include <gtk/gtk.h>
+#ifdef HAVE_CONFIG_H
+#include "../../config.h"
+#endif
+#if HAVE_NOTIFY
+#include <libnotify/notify.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include <math.h>
@@ -52,6 +58,11 @@ static int sb_context_id = -1;
static char sb_text[512];
static float last_songpos = -1;
+#if HAVE_NOTIFY
+#define NOTIFY_DEFAULT_FORMAT "%a - %t"
+static NotifyNotification* notification;
+#endif
+
static gboolean
update_songinfo (gpointer ctx) {
char sbtext_new[512] = "-";
@@ -250,6 +261,27 @@ gtkui_on_activate (DB_event_t *ev, uintptr_t data) {
static int
gtkui_on_songchanged (DB_event_trackchange_t *ev, uintptr_t data) {
gtkpl_songchanged_wrapper (ev->from, ev->to);
+#if HAVE_NOTIFY
+ if (deadbeef->conf_get_int ("libnotify.enable", 0)) {
+ DB_playItem_t *track = deadbeef->pl_get_for_idx (ev->to);
+ if (track) {
+ char cmd [1024];
+ deadbeef->pl_format_title (track, -1, cmd, sizeof (cmd), -1, deadbeef->conf_get_str ("libnotify.format", NOTIFY_DEFAULT_FORMAT));
+ if (notify_is_initted ()) {
+ if (notification) {
+ notify_notification_close (notification, NULL);
+ }
+ else {
+ notification = notify_notification_new ("DeaDBeeF", cmd, NULL, NULL);
+ }
+ if (notification) {
+ notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+ notify_notification_show (notification, NULL);
+ }
+ }
+ }
+ }
+#endif
return 0;
}
@@ -365,6 +397,10 @@ gtkui_thread (void *ctx) {
gdk_threads_init ();
gdk_threads_enter ();
gtk_set_locale ();
+#if HAVE_NOTIFY
+ notify_init ("DeaDBeeF");
+#endif
+
int argc = 1;
const char **argv = alloca (sizeof (char *));
argv[0] = "deadbeef";
@@ -439,6 +475,9 @@ gtkui_thread (void *ctx) {
gtk_widget_show (mainwin);
gtk_main ();
+#if HAVE_NOTIFY
+ notify_uninit ();
+#endif
gdk_threads_leave ();
}
@@ -495,6 +534,13 @@ gtkui_load (DB_functions_t *api) {
return DB_PLUGIN (&plugin);
}
+#if HAVE_NOTIFY
+static const char settings_dlg[] =
+ "property \"Enable OSD notifications\" checkbox libnotify.enable 0;\n"
+ "property \"Notification format\" entry libnotify.format \"" NOTIFY_DEFAULT_FORMAT "\";\n"
+;
+#endif
+
// define plugin interface
static DB_gui_t plugin = {
DB_PLUGIN_SET_API_VERSION
@@ -508,5 +554,8 @@ static DB_gui_t plugin = {
.plugin.email = "waker@users.sourceforge.net",
.plugin.website = "http://deadbeef.sf.net",
.plugin.start = gtkui_start,
- .plugin.stop = gtkui_stop
+ .plugin.stop = gtkui_stop,
+#if HAVE_NOTIFY
+ .plugin.configdialog = settings_dlg,
+#endif
};
diff --git a/plugins/notification/Makefile.am b/plugins/notification/Makefile.am
deleted file mode 100644
index 5a9f7f65..00000000
--- a/plugins/notification/Makefile.am
+++ /dev/null
@@ -1,5 +0,0 @@
-notificationdir = $(libdir)/$(PACKAGE)
-pkglib_LTLIBRARIES = notification.la
-notification_la_SOURCES = notification.c
-notification_la_LDFLAGS = -module
-AM_CFLAGS = -std=c99
diff --git a/plugins/notification/notification.c b/plugins/notification/notification.c
deleted file mode 100644
index dc5b669f..00000000
--- a/plugins/notification/notification.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "../../deadbeef.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-static DB_misc_t plugin;
-static DB_functions_t *deadbeef;
-
-#define DEFAULT_COMMAND "notify-send '%t' '%a - %b'"
-
-static const char settings_dlg[] =
- "property Command entry notification.command \"" DEFAULT_COMMAND "\";\n"
-;
-
-static void
-show_notification (DB_playItem_t *track)
-{
- char cmd [1024];
- deadbeef->pl_format_title (track, -1, cmd, sizeof (cmd), -1, deadbeef->conf_get_str ("notification.command", DEFAULT_COMMAND));
- //system (cmd);
-}
-
-static int
-songchanged (DB_event_trackchange_t *ev, uintptr_t data) {
- DB_playItem_t *track = deadbeef->pl_get_for_idx (ev->to);
- if (track) {
- show_notification (track);
- }
- return 0;
-}
-
-static int
-notification_stop (void) {
- deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0);
- return 0;
-}
-
-static int
-notification_start (void) {
- deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0);
- return 0;
-}
-
-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,
- .plugin.configdialog = settings_dlg
-};
-