--- ../notify.orig/osd.c	2012-09-23 15:05:12.000000000 +0200
+++ osd.c	2012-11-22 12:21:27.045430740 +0100
@@ -18,57 +18,179 @@
  */
 
 #include <glib.h>
+#include <libaudcore/hook.h>
 #include <audacious/debug.h>
+#include <audacious/i18n.h>
+#include <audacious/drct.h>
+#include <audacious/misc.h>
 #include <libnotify/notify.h>
-
 #include "osd.h"
 
-NotifyNotification *notification = NULL;
-
-gboolean osd_init() {
-    notification = NULL;
-    return notify_init ("Audacious");
-}
-
-void osd_uninit (void)
+static void clean (void * unused, void * notif)
 {
+    NotifyNotification *notification = (NotifyNotification *) notif;
     if (notification)
     {
+        GError *error = NULL;
+        if (notify_notification_close (notification, &error) == FALSE)
+            AUDDBG("%s!\n", error->message);
         g_object_unref (notification);
-        notification = NULL;
     }
 
     notify_uninit();
 }
 
-void osd_closed_handler(NotifyNotification *notification2, gpointer data) {
-    if(notification != NULL) {
-        g_object_unref(notification);
-        notification = NULL;
-        AUDDBG("notification unrefed!\n");
+void* osd_init() {
+    if (notify_is_initted())
+        return NULL;
+    if (notify_init("Audacious"))
+    {
+        NotifyNotification *notif = notify_notification_new("Notification", NULL, NULL);
+
+        hook_associate ("notify shutdown", (HookFunction) clean, notif);
+
+        notify_notification_set_urgency (notif, NOTIFY_URGENCY_LOW);
+        notify_notification_set_hint (notif, "desktop-entry", g_variant_new_string ("audacious"));
+
+        GList *server_caps;
+        server_caps = notify_get_server_caps ();
+        if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0))
+        {
+            if (g_list_find_custom (server_caps, "action-icons", (GCompareFunc)g_strcmp0))
+                notify_notification_set_hint (notif, "action-icons", g_variant_new_boolean (TRUE));
+        }
+        g_list_free_full(server_caps, g_free);
+        return notif;
     }
+    
+    return NULL;
 }
 
+void osd_uninit (void)
+{
+    hook_call("notify shutdown", NULL);
+    hook_dissociate ("notify shutdown", (HookFunction) clean);
+}
+
+
+static void
+goprevious (NotifyNotification *notification,
+            const char *action,
+            gpointer user_data)
+{
+    aud_drct_pl_prev();
+}
+
+static void
+gonext (NotifyNotification *notification,
+        const char *action,
+        gpointer user_data)
+{
+    aud_drct_pl_next();
+}
+
+static void
+show_audacious (NotifyNotification *notification,
+        const char *action,
+        gpointer user_data)
+{
+    aud_interface_show(TRUE);
+}
+
+static void
+playpause (NotifyNotification *notification,
+           const char *action,
+           gpointer user_data)
+{
+    if(aud_drct_get_playing())
+    {aud_drct_pause();}
+    else
+    {aud_drct_play();}
+}
+
+
 void osd_show (const gchar * title, const gchar * _message, const gchar * icon,
- GdkPixbuf * pb)
+ GdkPixbuf * pb, void *notif)
 {
+    NotifyNotification *notification = (NotifyNotification *) notif;
     gchar * message = g_markup_escape_text (_message, -1);
     GError *error = NULL;
 
-    if(notification == NULL) {
-        notification = notify_notification_new(title, message, pb == NULL ? icon : NULL);
-        g_signal_connect(notification, "closed", G_CALLBACK(osd_closed_handler), NULL);
-        AUDDBG("new osd created! (notification=%p)\n", (void *) notification);
-    } else {
-        if(notify_notification_update(notification, title, message, pb == NULL ? icon : NULL)) {
-            AUDDBG("old osd updated! (notification=%p)\n", (void *) notification);
-        } else {
-            AUDDBG("could not update old osd! (notification=%p)\n", (void *) notification);
+    if(notify_notification_update(notification, title, message, pb == NULL ? icon : NULL)) {
+        AUDDBG("Osd updated!\n");
+     } else {
+         AUDDBG("Could not update osd!\n");
+    }
+
+
+    GList *server_caps;
+    server_caps = notify_get_server_caps ();
+    if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0))
+    {
+        gboolean playing = FALSE;
+        if (aud_drct_get_playing()) {playing = !aud_drct_get_paused();}
+
+        notify_notification_clear_actions (notification);
+
+        if(aud_get_bool ("notify", "actions")){
+            notify_notification_add_action (notification,
+                        "media-skip-backward",
+                        N_("Previous"),
+                        (NotifyActionCallback) goprevious,
+                        NULL,
+                        NULL);
+
+            notify_notification_add_action (notification,
+                            playing ? "media-playback-pause" : "media-playback-start",
+                            playing ? N_("Pause") : N_("Play"),
+                            (NotifyActionCallback) playpause,
+                            NULL,
+                            NULL);
+
+            notify_notification_add_action (notification,
+                        "media-skip-forward",
+                        N_("Next"),
+                        (NotifyActionCallback) gonext,
+                        NULL,
+                        NULL);
+
+            notify_notification_add_action (notification,
+                        "default",
+                        N_("Afficher Audacious"),
+                        (NotifyActionCallback) show_audacious,
+                        NULL,
+                        NULL);
+            notify_notification_set_timeout(notification, 1);
         }
     }
 
-    if(pb != NULL)
-        notify_notification_set_icon_from_pixbuf(notification, pb);
+    if(aud_get_bool ("notify", "silent"))
+        notify_notification_set_hint (notif, "transient", g_variant_new_boolean (TRUE));
+    else
+        notify_notification_set_hint (notif, "transient", g_variant_new_boolean (FALSE));
+
+    if (g_list_find_custom (server_caps, "persistence", (GCompareFunc)g_strcmp0))
+        {
+            AUDDBG("Notification server supports persistence\n");
+            if (aud_get_bool ("notify", "actions"))
+                notify_notification_set_hint (notif, "resident", g_variant_new_boolean (TRUE));
+            else
+                notify_notification_set_hint (notif, "resident", g_variant_new_boolean (FALSE));
+        }
+
+    g_list_free_full(server_caps, g_free);
+
+
+/*    if(pb != NULL)*/
+/*    {*/
+/*        notify_notification_set_icon_from_pixbuf(notification, pb);*/
+/*        notify_notification_set_image_from_pixbuf(notification, pb);*/
+/*    }*/
+
+/*    notify_notification_set_hint (notification,*/
+/*                      "image_path",*/
+/*                      g_variant_new_string ("/home/oxayotl/.cache/rhythmbox/album-art/00000065"));*/
+
 
     if(!notify_notification_show(notification, &error))
         AUDDBG("%s!\n", error->message);
