[goobox] notify the event in an idle function to allow the player to update its state



commit 3f6b839e098526dd44dc9db4345e77a1f64c7e6c
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jun 5 17:33:11 2011 +0200

    notify the event in an idle function to allow the player to update its state

 src/goo-window.c |   40 +++++++++++++++++++++++++++++-----------
 src/main.c       |    3 +--
 src/main.h       |    1 -
 3 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/src/goo-window.c b/src/goo-window.c
index b3eee84..d9bfa82 100644
--- a/src/goo-window.c
+++ b/src/goo-window.c
@@ -113,6 +113,7 @@ struct _GooWindowPrivate {
 	GDBusProxy        *media_keys_proxy;
 	gulong             focus_in_event;
 	gulong             media_key_event;
+	gulong             notify_event;
 };
 
 enum {
@@ -478,6 +479,11 @@ goo_window_finalize (GObject *object)
 
 		g_object_unref (window->priv->list_store);
 
+		if (window->priv->notify_event != 0) {
+			g_source_remove (window->priv->notify_event);
+			window->priv->notify_event = 0;
+		}
+
 		if (window->priv->next_timeout_handle != 0) {
 			g_source_remove (window->priv->next_timeout_handle);
 			window->priv->next_timeout_handle = 0;
@@ -1291,17 +1297,23 @@ set_action_label_and_icon (GooWindow  *window,
 }
 
 
-static void
-notify_current_state (GooWindow       *window,
-		      GooPlayerAction  action)
+static gboolean
+notify_current_state_cb (gpointer user_data)
 {
+	GooWindow *window = user_data;
+
+	if (window->priv->notify_event != 0) {
+		g_source_remove (window->priv->notify_event);
+		window->priv->notify_event = 0;
+	}
+
 #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;
+		system_notify (window, "", "");
+		return FALSE;
 	}
 
 	if (window->priv->album->artist != NULL) {
@@ -1323,13 +1335,24 @@ notify_current_state (GooWindow       *window,
 	g_string_append (info, " ");
 
 	system_notify (window,
-		       action,
 		       window->priv->current_track->title,
 		       info->str);
 
 	g_string_free (info, TRUE);
 
 #endif /* ENABLE_NOTIFICATION */
+
+	return FALSE;
+}
+
+
+static void
+notify_current_state (GooWindow       *window,
+		      GooPlayerAction  action)
+{
+	if (window->priv->notify_event != 0)
+		g_source_remove (window->priv->notify_event);
+	window->priv->notify_event = g_idle_add (notify_current_state_cb, window);
 }
 
 
@@ -1352,11 +1375,6 @@ player_start_cb (GooPlayer       *player,
 		notify_current_state (window, action);
 		break;
 
-	case GOO_PLAYER_ACTION_PAUSE:
-	case GOO_PLAYER_ACTION_STOP:
-		notify_current_state (window, action);
-		break;
-
 	default:
 		break;
 	}
diff --git a/src/main.c b/src/main.c
index e3d5a74..e08b0ad 100644
--- a/src/main.c
+++ b/src/main.c
@@ -670,7 +670,6 @@ notification_has_persistence (void)
 
 void
 system_notify (GooWindow       *window,
-	       GooPlayerAction  action,
 	       const char      *summary,
 	       const char      *body)
 {
@@ -712,7 +711,7 @@ system_notify (GooWindow       *window,
 	if (notification_supports_actions) {
 		notify_notification_clear_actions (notification);
 
-		if (action == GOO_PLAYER_ACTION_PLAY)
+		if (goo_player_get_state (goo_window_get_player (window)) == GOO_PLAYER_STATE_PLAYING)
 			notify_notification_add_action (notification,
 							GOO_STOCK_PAUSE,
 							_("Pause"),
diff --git a/src/main.h b/src/main.h
index 4bfca6d..b329ec4 100644
--- a/src/main.h
+++ b/src/main.h
@@ -36,7 +36,6 @@ 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);
 



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