[rhythmbox] status-icon: add 'next' action to notification popups (bug #331272)



commit 363ef6c9af734ff1d34e15e4fc9a4efccfe3bb65
Author: Szilveszter �rdög <slipszi gmail com>
Date:   Mon Jun 1 12:28:40 2009 +1000

    status-icon: add 'next' action to notification popups (bug #331272)
---
 plugins/status-icon/rb-status-icon-plugin.c |   40 +++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/plugins/status-icon/rb-status-icon-plugin.c b/plugins/status-icon/rb-status-icon-plugin.c
index c0c8100..0f5bbb0 100644
--- a/plugins/status-icon/rb-status-icon-plugin.c
+++ b/plugins/status-icon/rb-status-icon-plugin.c
@@ -114,6 +114,7 @@ struct _RBStatusIconPluginPrivate
 	GdkPixbuf *notify_pixbuf;
 #ifdef HAVE_NOTIFY
 	NotifyNotification *notification;
+	gboolean notify_supports_actions;
 #endif
 
 	GtkWidget *config_dialog;
@@ -302,20 +303,42 @@ notification_closed_cb (NotifyNotification *notification,
 }
 
 static void
+notification_next_cb (NotifyNotification *notification,
+		      const char *action,
+		      RBStatusIconPlugin *plugin)
+{
+	rb_debug ("notification action: %s", action);
+	rb_shell_player_do_next (plugin->priv->shell_player, NULL);
+}
+
+static void
 do_notify (RBStatusIconPlugin *plugin,
 	   guint timeout,
 	   const char *primary,
 	   const char *secondary,
-	   GdkPixbuf *pixbuf)
+	   GdkPixbuf *pixbuf,
+	   gboolean show_action)
 {
 	const char *icon_name;
 	GError *error = NULL;
 
 	if (notify_is_initted () == FALSE) {
+		GList *caps;
+
 		if (notify_init ("rhythmbox") == FALSE) {
 			g_warning ("libnotify initialization failed");
 			return;
 		}
+
+		/* ask the notification server if it supports actions */
+		caps = notify_get_server_caps ();
+		if (g_list_find_custom (caps, "actions", (GCompareFunc)g_strcmp0) != NULL) {
+			rb_debug ("notification server supports actions");
+			plugin->priv->notify_supports_actions = TRUE;
+		} else {
+			rb_debug ("notification server does not support actions");
+		}
+		rb_list_deep_free (caps);
 	}
 
 	update_status_icon_visibility (plugin, TRUE);
@@ -363,6 +386,16 @@ do_notify (RBStatusIconPlugin *plugin,
 		notify_notification_set_icon_from_pixbuf (plugin->priv->notification, pixbuf);
 	}
 
+	notify_notification_clear_actions (plugin->priv->notification);
+	if (show_action && plugin->priv->notify_supports_actions) {
+		notify_notification_add_action (plugin->priv->notification,
+						"media-next",
+						_("Next"),
+						(NotifyActionCallback) notification_next_cb,
+						plugin,
+						NULL);
+	}
+
 	if (notify_notification_show (plugin->priv->notification, &error) == FALSE) {
 		g_warning ("Failed to send notification (%s): %s", primary, error->message);
 		g_error_free (error);
@@ -430,7 +463,8 @@ notify_playing_entry (RBStatusIconPlugin *plugin, gboolean requested)
 		   PLAYING_ENTRY_NOTIFY_TIME * 1000,
 		   plugin->priv->current_title,
 		   plugin->priv->current_album_and_artist,
-		   plugin->priv->notify_pixbuf);
+		   plugin->priv->notify_pixbuf,
+		   TRUE);
 }
 
 static void
@@ -440,7 +474,7 @@ notify_custom (RBStatusIconPlugin *plugin, guint timeout, const char *primary, c
 		return;
 	}
 
-	do_notify (plugin, timeout, primary, secondary, pixbuf);
+	do_notify (plugin, timeout, primary, secondary, pixbuf, FALSE);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]