[goobox] don't use the status icon with GNOME Shell



commit bdd14c6ae1eb4e6dce829120e17c5c009fe25ab8
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jun 5 17:01:44 2011 +0200

    don't use the status icon with GNOME Shell

 src/goo-window.c |  135 +++++++++++++++++++++++++++++++-------------------
 src/goo-window.h |    1 +
 src/main.c       |  145 +++++++++++++++++++++++++++++++++++------------------
 src/main.h       |   15 +++--
 4 files changed, 190 insertions(+), 106 deletions(-)
---
diff --git a/src/goo-window.c b/src/goo-window.c
index 7d54b6d..b3eee84 100644
--- a/src/goo-window.c
+++ b/src/goo-window.c
@@ -109,7 +109,6 @@ struct _GooWindowPrivate {
 	GtkWidget         *preview;
 	int                pos_x, pos_y;
 	gboolean           hibernate;
-	gboolean           notify_action;
 
 	GDBusProxy        *media_keys_proxy;
 	gulong             focus_in_event;
@@ -845,8 +844,6 @@ static void
 play_track (GooWindow *window,
 	    int        track_number)
 {
-	if (! gtk_widget_get_visible (GTK_WIDGET (window)))
-		window->priv->notify_action = TRUE;
 	goo_player_seek_track (window->priv->player, track_number);
 }
 
@@ -1080,12 +1077,17 @@ goo_window_class_init (GooWindowClass *class)
 }
 
 
-static void
+static gboolean
 window_delete_event_cb (GtkWidget  *caller,
 			GdkEvent   *event,
 			GooWindow  *window)
 {
-	activate_action_quit (NULL, window);
+	if (goo_player_get_state (window->priv->player) == GOO_PLAYER_STATE_PLAYING)
+		gtk_window_iconify (GTK_WINDOW (window));
+	else
+		activate_action_quit (NULL, window);
+
+	return TRUE;
 }
 
 
@@ -1290,6 +1292,48 @@ set_action_label_and_icon (GooWindow  *window,
 
 
 static void
+notify_current_state (GooWindow       *window,
+		      GooPlayerAction  action)
+{
+#ifdef ENABLE_NOTIFICATION
+
+	GString *info = g_string_new ("");
+
+	if ((window->priv->album == NULL) || (window->priv->current_track == NULL)) {
+		system_notify (window, GOO_PLAYER_ACTION_NONE, "", "");
+		return;
+	}
+
+	if (window->priv->album->artist != NULL) {
+		char *e_artist = g_markup_escape_text (window->priv->album->artist, -1);
+
+		g_string_append_printf (info, "%s", e_artist);
+		g_free (e_artist);
+	}
+
+	if (window->priv->album->title != NULL) {
+		char *e_album = g_markup_escape_text (window->priv->album->title, -1);
+
+		g_string_append (info, "\n");
+
+		g_string_append_printf (info, "<i>%s</i>", e_album);
+		g_free (e_album);
+	}
+
+	g_string_append (info, " ");
+
+	system_notify (window,
+		       action,
+		       window->priv->current_track->title,
+		       info->str);
+
+	g_string_free (info, TRUE);
+
+#endif /* ENABLE_NOTIFICATION */
+}
+
+
+static void
 player_start_cb (GooPlayer       *player,
 		 GooPlayerAction  action,
 		 GooWindow       *window)
@@ -1305,35 +1349,14 @@ player_start_cb (GooPlayer       *player,
 					   GOO_STOCK_PAUSE,
 					   "/MenuBar/CDMenu/",
 					   NULL);
+		notify_current_state (window, action);
+		break;
 
-#ifdef ENABLE_NOTIFICATION
-
-		if (window->priv->notify_action) {
-			GString *info = g_string_new ("");
-
-			if (window->priv->album->title != NULL) {
-				char *e_album = g_markup_escape_text (window->priv->album->title, -1);
-
-				g_string_append_printf (info, "<i>%s</i>", e_album);
-				g_free (e_album);
-			}
-			g_string_append (info, "\n");
-			if (window->priv->album->artist != NULL) {
-				char *e_artist = g_markup_escape_text (window->priv->album->artist, -1);
-
-				g_string_append_printf (info, "<big>%s</big>", e_artist);
-				g_free (e_artist);
-			}
-			system_notify (window,
-				       window->priv->current_track->title,
-				       info->str);
-			g_string_free (info, TRUE);
-			window->priv->notify_action = FALSE;
-		}
-
-#endif /* ENABLE_NOTIFICATION */
-
+	case GOO_PLAYER_ACTION_PAUSE:
+	case GOO_PLAYER_ACTION_STOP:
+		notify_current_state (window, action);
 		break;
+
 	default:
 		break;
 	}
@@ -1677,7 +1700,7 @@ player_done_cb (GooPlayer       *player,
 		}
 		else if (action == GOO_PLAYER_ACTION_STOP)
 			set_current_track_icon (window, GOO_STOCK_STOP);
-
+		notify_current_state (window, action);
 		break;
 
 	case GOO_PLAYER_ACTION_PAUSE:
@@ -1689,6 +1712,7 @@ player_done_cb (GooPlayer       *player,
 					   GOO_STOCK_PLAY,
 					   "/MenuBar/CDMenu/",
 					   NULL);
+		notify_current_state (window, action);
 		break;
 
 	default:
@@ -2490,27 +2514,29 @@ goo_window_construct (GooWindow    *window,
 
 	/* The status icon. */
 
-	window->priv->status_icon = gtk_status_icon_new_from_icon_name ("goobox");
-	gtk_status_icon_set_has_tooltip (window->priv->status_icon, TRUE);
-	gtk_status_icon_set_title (window->priv->status_icon, _("CD Player"));
+	if (! notification_has_persistence ()) {
+		window->priv->status_icon = gtk_status_icon_new_from_icon_name ("goobox");
+		gtk_status_icon_set_has_tooltip (window->priv->status_icon, TRUE);
+		gtk_status_icon_set_title (window->priv->status_icon, _("CD Player"));
 
-	window->priv->status_tooltip_content = goo_player_info_new (window, FALSE);
-	gtk_container_set_border_width (GTK_CONTAINER (window->priv->status_tooltip_content), 0);
+		window->priv->status_tooltip_content = goo_player_info_new (window, FALSE);
+		gtk_container_set_border_width (GTK_CONTAINER (window->priv->status_tooltip_content), 0);
 
-	g_signal_connect (G_OBJECT (window->priv->status_icon),
-			  "activate",
-			  G_CALLBACK (status_icon_activate_cb),
-			  window);
-	g_signal_connect (G_OBJECT (window->priv->status_icon),
-			  "query-tooltip",
-			  G_CALLBACK (status_icon_query_tooltip_cb),
-			  window);
-	g_signal_connect (G_OBJECT (window->priv->status_icon),
-			  "popup-menu",
-			  G_CALLBACK (status_icon_popup_menu_cb),
-			  window);
+		g_signal_connect (G_OBJECT (window->priv->status_icon),
+				  "activate",
+				  G_CALLBACK (status_icon_activate_cb),
+				  window);
+		g_signal_connect (G_OBJECT (window->priv->status_icon),
+				  "query-tooltip",
+				  G_CALLBACK (status_icon_query_tooltip_cb),
+				  window);
+		g_signal_connect (G_OBJECT (window->priv->status_icon),
+				  "popup-menu",
+				  G_CALLBACK (status_icon_popup_menu_cb),
+				  window);
 
-	window->priv->status_icon_popup_menu = gtk_ui_manager_get_widget (ui, "/TrayPopupMenu");
+		window->priv->status_icon_popup_menu = gtk_ui_manager_get_widget (ui, "/TrayPopupMenu");
+	}
 
 	/* Add notification callbacks. */
 
@@ -2833,6 +2859,13 @@ goo_window_get_player (GooWindow *window)
 }
 
 
+GtkWidget *
+goo_window_get_player_info (GooWindow *window)
+{
+	return window->priv->info;
+}
+
+
 void
 goo_window_set_cover_image_from_pixbuf (GooWindow *window,
 					GdkPixbuf *image)
diff --git a/src/goo-window.h b/src/goo-window.h
index b720ae4..86d7ac0 100644
--- a/src/goo-window.h
+++ b/src/goo-window.h
@@ -79,6 +79,7 @@ AlbumInfo * goo_window_get_album                 (GooWindow    *window);
 GList *     goo_window_get_tracks                (GooWindow    *window,
 						  gboolean      selection);
 GooPlayer * goo_window_get_player                (GooWindow    *window);
+GtkWidget * goo_window_get_player_info           (GooWindow    *window);
 void        goo_window_update_cover              (GooWindow    *window);
 void        goo_window_set_cover_image_from_pixbuf (GooWindow  *window,
 					          GdkPixbuf    *image);
diff --git a/src/main.c b/src/main.c
index ad17dd3..e3d5a74 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,6 +27,7 @@
 #include <glib/gprintf.h>
 #include <gtk/gtk.h>
 #include "eggsmclient.h"
+#include "goo-player-info.h"
 #include "goo-stock.h"
 #include "goo-window.h"
 #include "typedefs.h"
@@ -40,6 +41,8 @@
 #define NOTIFY_CHECK_VERSION(x,y,z) 0
 #endif
 static NotifyNotification *notification = NULL;
+gboolean                   notification_supports_persistence = FALSE;
+gboolean                   notification_supports_actions = FALSE;
 #endif /* ENABLE_NOTIFICATION */
 
 
@@ -592,6 +595,7 @@ play_next (gpointer user_data)
 	GooWindow *window = user_data;
 
 	goo_window_next (window);
+
 	return FALSE;
 }
 
@@ -603,99 +607,142 @@ notify_action_next_cb (NotifyNotification *notification,
 {
 	GooWindow *window = user_data;
 
-	notify_notification_close (notification, NULL);
+	if (! notification_supports_persistence)
+		notify_notification_close (notification, NULL);
+
 	g_idle_add (play_next, window);
 }
 
 
+static gboolean
+toggle_play (gpointer user_data)
+{
+	GooWindow *window = user_data;
+
+	goo_window_toggle_play (window);
+
+	return FALSE;
+}
+
+
 static void
-notify_action_stop_cb (NotifyNotification *notification,
-                       char               *action,
-                       gpointer            user_data)
+notify_action_toggle_play_cb (NotifyNotification *notification,
+			      char               *action,
+			      gpointer            user_data)
 {
 	GooWindow *window = user_data;
 
-	goo_window_stop (window);
-	notify_notification_close (notification, NULL);
+	if (! notification_supports_persistence)
+		notify_notification_close (notification, NULL);
+
+	g_idle_add (toggle_play, window);
 }
 
 
 #endif /* ENABLE_NOTIFICATION */
 
 
+gboolean
+notification_has_persistence (void)
+{
+#ifdef ENABLE_NOTIFICATION
+
+	gboolean  supports_persistence = FALSE;
+	GList    *caps;
+
+	caps = notify_get_server_caps ();
+	if (caps != NULL) {
+		supports_persistence = g_list_find_custom (caps, "persistence", (GCompareFunc) strcmp) != NULL;
+
+		g_list_foreach (caps, (GFunc)g_free, NULL);
+		g_list_free (caps);
+	}
+
+	return supports_persistence;
+
+#else
+
+	return false;
+
+#endif /* ENABLE_NOTIFICATION */
+}
+
+
 void
-system_notify (GooWindow  *window,
-	       const char *title,
-	       const char *msg)
+system_notify (GooWindow       *window,
+	       GooPlayerAction  action,
+	       const char      *summary,
+	       const char      *body)
 {
 #ifdef ENABLE_NOTIFICATION
 
-	GtkStatusIcon *status_icon;
-	GdkScreen     *screen = NULL;
-	int            x = -1, y = -1;
+	GdkPixbuf *cover;
 
 	if (! notify_is_initted ())
 		return;
 
-	status_icon = goo_window_get_status_icon (window);
-	if (status_icon != NULL) {
-		GdkRectangle area;
-
-		if (gtk_status_icon_get_geometry (status_icon, &screen, &area, NULL)) {
-			y = area.y + area.height;
-			x = area.x + (area.width / 2);
-		}
-	}
-
 	if (notification == NULL) {
-		gboolean  supports_actions;
-		GList    *caps;
+		GList *caps;
+
+		notification_supports_actions = FALSE;
+		notification_supports_persistence = FALSE;
 
-		supports_actions = FALSE;
 		caps = notify_get_server_caps ();
 		if (caps != NULL) {
-			GList *c;
-
-			for (c = caps; c != NULL; c = c->next) {
-				if (strcmp ((char*)c->data, "actions") == 0) {
-					supports_actions = TRUE;
-					break;
-				}
-			}
+			notification_supports_actions = g_list_find_custom (caps, "actions", (GCompareFunc) strcmp) != NULL;
+			notification_supports_persistence = g_list_find_custom (caps, "persistence", (GCompareFunc) strcmp) != NULL;
 
 			g_list_foreach (caps, (GFunc)g_free, NULL);
 			g_list_free (caps);
 		}
 
 #if NOTIFY_CHECK_VERSION (0, 7, 0)
-		notification = notify_notification_new (title, msg, "goobox");
+		notification = notify_notification_new (summary, body, "goobox");
 #else
-		notification = notify_notification_new_with_status_icon (title, msg, "goobox", status_icon);
+		notification = notify_notification_new_with_status_icon (summary, body, "goobox", status_icon);
 #endif
 		notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+	}
+	else
+		notify_notification_update (notification, summary, body, "goobox");
+
+	cover = goo_player_info_get_cover (GOO_PLAYER_INFO (goo_window_get_player_info (window)));
+	notify_notification_set_image_from_pixbuf (notification, cover);
+
+	if (notification_supports_actions) {
+		notify_notification_clear_actions (notification);
 
-		if (supports_actions) {
+		if (action == GOO_PLAYER_ACTION_PLAY)
 			notify_notification_add_action (notification,
-							GTK_STOCK_MEDIA_NEXT,
-							_("Next"),
-							notify_action_next_cb,
+							GOO_STOCK_PAUSE,
+							_("Pause"),
+							notify_action_toggle_play_cb,
 							window,
 							NULL);
+		else
 			notify_notification_add_action (notification,
-							GTK_STOCK_MEDIA_STOP,
-							_("Stop"),
-							notify_action_stop_cb,
+							GOO_STOCK_PLAY,
+							_("Play"),
+							notify_action_toggle_play_cb,
 							window,
 							NULL);
-		}
+
+		notify_notification_add_action (notification,
+						GOO_STOCK_NEXT,
+						_("Next"),
+						notify_action_next_cb,
+						window,
+						NULL);
+
+		notify_notification_set_hint_byte (notification,
+						   "action-icons",
+						   TRUE);
 	}
-	else
-		notify_notification_update (notification, title, msg, "goobox");
 
-	/*if ((x >= 0) && (y >= 0))
-		notify_notification_set_geometry_hints (notification,
-							screen,
-							x, y);*/
+	if (notification_supports_persistence)
+		notify_notification_set_hint_byte (notification,
+						    "resident" /* "transient" */,
+						    TRUE);
 
 	notify_notification_show (notification, NULL);
 
diff --git a/src/main.h b/src/main.h
index 9767f5a..4bfca6d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -24,17 +24,20 @@
 #define MAIN_H
 
 #include <brasero3/brasero-drive.h>
+#include "goo-player.h"
 #include "goo-window.h"
 
 extern GtkApplication *main_application;
 extern int             arg_auto_play;
 extern int             arg_toggle_visibility;
 
-GtkWidget *     main_get_window_from_device (const char *device);
-BraseroDrive *  main_get_most_likely_drive  (void);
-BraseroDrive *  main_get_drive_for_device   (const char *device);
-void            system_notify               (GooWindow  *window,
-	       			             const char *title,
-	       			             const char *msg);
+GtkWidget *     main_get_window_from_device  (const char      *device);
+BraseroDrive *  main_get_most_likely_drive   (void);
+BraseroDrive *  main_get_drive_for_device    (const char      *device);
+gboolean        notification_has_persistence (void);
+void            system_notify                (GooWindow       *window,
+					      GooPlayerAction  action,
+					      const char      *title,
+					      const char      *msg);
 
 #endif /* MAIN_H */



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