[Xfce4-commits] <parole:master> Use GtkAction in plugins

Sean Davis noreply at xfce.org
Fri Oct 11 11:52:50 CEST 2013


Updating branch refs/heads/master
         to 03e61de7415054e1e79c9162622570a9873d08ab (commit)
       from ac3ea42c1c8d78177c87b0ec23944cae5b4224d8 (commit)

commit 03e61de7415054e1e79c9162622570a9873d08ab
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Thu Oct 3 19:13:53 2013 -0400

    Use GtkAction in plugins

 src/misc/parole-provider-player.c    |   14 ++++++++
 src/misc/parole-provider-player.h    |    3 ++
 src/parole-player.c                  |   27 ++++++++++++++--
 src/parole-player.h                  |   10 ++++++
 src/plugins/notify/notify-provider.c |   11 +++++++
 src/plugins/tray/tray-provider.c     |   58 ++++++----------------------------
 6 files changed, 72 insertions(+), 51 deletions(-)

diff --git a/src/misc/parole-provider-player.c b/src/misc/parole-provider-player.c
index 9c3d537..0dff22d 100644
--- a/src/misc/parole-provider-player.c
+++ b/src/misc/parole-provider-player.c
@@ -420,3 +420,17 @@ void parole_provider_player_open_media_chooser (ParoleProviderPlayer *player)
         (*PAROLE_PROVIDER_PLAYER_GET_INTERFACE (player)->open_media_chooser) (player);
     }
 }
+
+/**
+ * parole_provider_player_get_action:
+ * @player: a #ParoleProviderPlayer
+ * @action: the #ParolePlayerAction to retrieve
+ * 
+ * Get GtkAction from Parole.
+ * 
+ * Since: 0.6
+ **/
+GtkAction *parole_provider_player_get_action(ParoleProviderPlayer *player, ParolePlayerAction action)
+{
+    return parole_player_get_action(action);
+}
diff --git a/src/misc/parole-provider-player.h b/src/misc/parole-provider-player.h
index 06af0ed..98bee2d 100644
--- a/src/misc/parole-provider-player.h
+++ b/src/misc/parole-provider-player.h
@@ -29,6 +29,7 @@
 
 #include <gtk/gtk.h>
 #include "parole-stream.h"
+#include "parole-player.h"
 
 G_BEGIN_DECLS 
 
@@ -126,6 +127,8 @@ gboolean    parole_provider_player_seek         (ParoleProviderPlayer *player,
 void        
 parole_provider_player_open_media_chooser       (ParoleProviderPlayer *player);
 
+GtkAction *parole_provider_player_get_action(ParoleProviderPlayer *player, ParolePlayerAction action);
+
 G_END_DECLS
 
 #endif /* __PAROLE_PLUGIN_IFACE_H__ */
diff --git a/src/parole-player.c b/src/parole-player.c
index fb0aeaa..bf6134c 100644
--- a/src/parole-player.c
+++ b/src/parole-player.c
@@ -74,6 +74,10 @@
 
 int GTK_ICON_SIZE_ARTWORK_FALLBACK;
 
+GtkAction *playpause_action;
+GtkAction *previous_action;
+GtkAction *next_action;
+
 static void
 get_time_string (gchar *timestring, gint total_seconds)
 {
@@ -1681,6 +1685,24 @@ void parole_player_previous_action_cb (GtkAction *action, ParolePlayer *player)
     parole_player_play_prev (player);
 }
 
+GtkAction *parole_player_get_action(ParolePlayerAction action)
+{
+    switch(action)
+    {
+        case PAROLE_PLAYER_ACTION_PLAYPAUSE:
+            return playpause_action;
+            break;
+        case PAROLE_PLAYER_ACTION_PREVIOUS:
+            return previous_action;
+            break;
+        case PAROLE_PLAYER_ACTION_NEXT:
+            return next_action;
+            break;
+        default:
+            return NULL;
+    }
+}
+
 void parole_player_seekf_cb (GtkWidget *widget, ParolePlayer *player, gdouble seek)
 {
     seek = parole_gst_get_stream_position (PAROLE_GST (player->priv->gst) ) + seek;
@@ -2976,6 +2998,7 @@ parole_player_init (ParolePlayer *player)
      */
     /* Play/Pause */
     player->priv->media_playpause_action = gtk_action_new("playpause_action", _("_Play"), _("Play"), NULL);
+    playpause_action = player->priv->media_playpause_action;
     gtk_action_set_icon_name(player->priv->media_playpause_action, "media-playback-start-symbolic");
     gtk_action_set_always_show_image(player->priv->media_playpause_action, TRUE);
     g_signal_connect(G_OBJECT(player->priv->media_playpause_action), "activate", G_CALLBACK(parole_player_playpause_action_cb), player);
@@ -2983,6 +3006,7 @@ parole_player_init (ParolePlayer *player)
     
     /* Previous Track */
     player->priv->media_previous_action = gtk_action_new("previous_action", _("P_revious Track"), _("Previous Track"), NULL);
+    previous_action = player->priv->media_previous_action;
     gtk_action_set_icon_name(player->priv->media_previous_action, "media-skip-backward-symbolic");
     gtk_action_set_always_show_image(player->priv->media_previous_action, TRUE);
     g_signal_connect(G_OBJECT(player->priv->media_previous_action), "activate", G_CALLBACK(parole_player_previous_action_cb), player);
@@ -2990,13 +3014,12 @@ parole_player_init (ParolePlayer *player)
     
     /* Next Track */
     player->priv->media_next_action = gtk_action_new("next_action", _("_Next Track"), _("Next Track"), NULL);
+    next_action = player->priv->media_next_action;
     gtk_action_set_icon_name(player->priv->media_next_action, "media-skip-forward-symbolic");
     gtk_action_set_always_show_image(player->priv->media_next_action, TRUE);
     g_signal_connect(G_OBJECT(player->priv->media_next_action), "activate", G_CALLBACK(parole_player_next_action_cb), player);
     gtk_action_set_sensitive(player->priv->media_next_action, FALSE);
-    
 
-    
     /* Fullscreen */
     player->priv->media_fullscreen_action = gtk_action_new("fullscreen_action", _("_Fullscreen"), _("Fullscreen"), NULL);
     gtk_action_set_icon_name(player->priv->media_fullscreen_action, "view-fullscreen-symbolic");
diff --git a/src/parole-player.h b/src/parole-player.h
index 0e8503e..390ecb3 100644
--- a/src/parole-player.h
+++ b/src/parole-player.h
@@ -56,6 +56,13 @@ typedef struct
 
 } ParolePlayerClass;
 
+typedef enum
+{
+    PAROLE_PLAYER_ACTION_PREVIOUS,
+    PAROLE_PLAYER_ACTION_NEXT,
+    PAROLE_PLAYER_ACTION_PLAYPAUSE
+} ParolePlayerAction;
+
 GType                           parole_player_get_type          (void) G_GNUC_CONST;
 ParolePlayer                   *parole_player_new               (const gchar *client_id);
 
@@ -71,6 +78,9 @@ void                            parole_player_embedded          (ParolePlayer *p
 
 void                            parole_player_full_screen       (ParolePlayer *player, 
                                                                  gboolean fullscreen);
+                                                                 
+GtkAction                      *parole_player_get_action(ParolePlayerAction action);
+
 
 G_END_DECLS
 
diff --git a/src/plugins/notify/notify-provider.c b/src/plugins/notify/notify-provider.c
index 20da833..1b7cda1 100644
--- a/src/plugins/notify/notify-provider.c
+++ b/src/plugins/notify/notify-provider.c
@@ -99,6 +99,7 @@ notify_playing (NotifyProvider *notify, const ParoleStream *stream)
     gchar *title, *album, *artist, *year, *stream_uri;
     gchar *message;
     ParoleMediaType media_type;
+    GtkAction *action;
     
     g_object_get (G_OBJECT (stream), 
                   "title", &title,
@@ -190,15 +191,25 @@ notify_playing (NotifyProvider *notify, const ParoleStream *stream)
     notify_notification_set_urgency (notify->notification, NOTIFY_URGENCY_LOW);
     notify_notification_set_timeout (notify->notification, 5000);
     
+    /* Only show Previous Track item if clicking previous is possible */
+    action = parole_provider_player_get_action(PAROLE_PROVIDER_PLAYER(notify->player), PAROLE_PLAYER_ACTION_PREVIOUS);
+    if (gtk_action_get_sensitive(action))
+    {
     notify_notification_add_action (notify->notification, 
                                     "play-previous", _("Previous Track"), 
                                     NOTIFY_ACTION_CALLBACK(on_previous_clicked),
                                     notify, NULL);
+    }
 
+    /* Only show Next Track item if clicking next is possible */
+    action = parole_provider_player_get_action(PAROLE_PROVIDER_PLAYER(notify->player), PAROLE_PLAYER_ACTION_NEXT);
+    if (gtk_action_get_sensitive(action))
+    {
     notify_notification_add_action (notify->notification, 
                                     "play-next", _("Next Track"), 
                                     NOTIFY_ACTION_CALLBACK(on_next_clicked),
                                     notify, NULL);
+    }
     
     notify_notification_show (notify->notification, NULL);
     g_signal_connect (notify->notification, "closed",
diff --git a/src/plugins/tray/tray-provider.c b/src/plugins/tray/tray-provider.c
index 7ad83bc..57b685c 100644
--- a/src/plugins/tray/tray-provider.c
+++ b/src/plugins/tray/tray-provider.c
@@ -84,33 +84,6 @@ exit_activated_cb (TrayProvider *tray)
 }
 
 static void
-play_pause_activated_cb (TrayProvider *tray)
-{
-    menu_selection_done_cb (tray);
-    
-    if ( tray->state == PAROLE_STATE_PLAYING )
-        parole_provider_player_pause (tray->player);
-    else if ( tray->state == PAROLE_STATE_PAUSED )
-        parole_provider_player_resume (tray->player);
-}
-
-static void
-previous_activated_cb (TrayProvider *tray)
-{
-    menu_selection_done_cb (tray);
-    
-    parole_provider_player_play_previous (tray->player);
-}
-
-static void
-next_activated_cb (TrayProvider *tray)
-{
-    menu_selection_done_cb (tray);
-    
-    parole_provider_player_play_next (tray->player);
-}
-
-static void
 open_activated_cb (TrayProvider *tray)
 {
     parole_provider_player_open_media_chooser (tray->player);
@@ -121,46 +94,33 @@ popup_menu_cb (GtkStatusIcon *icon, guint button,
                guint activate_time, TrayProvider *tray)
 {
     GtkWidget *menu, *mi, *image;
+    GtkAction *action;
     
     menu = gtk_menu_new ();
 
     /*
-     * Play pause.
+     * Play pause
      */
-    image = gtk_image_new_from_icon_name(tray->state == PAROLE_STATE_PLAYING ? "media-playback-pause-symbolic" : 
-                                             "media-playback-start-symbolic", GTK_ICON_SIZE_MENU);
-    mi = gtk_image_menu_item_new_with_mnemonic(tray->state == PAROLE_STATE_PLAYING ? _("_Pause") : 
-                                             _("_Play"));
-    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), image);
-    gtk_widget_set_sensitive (mi, TRUE);
-    gtk_widget_show (mi);
-    g_signal_connect_swapped (mi, "activate", G_CALLBACK (play_pause_activated_cb), tray);
+    action = parole_provider_player_get_action(PAROLE_PROVIDER_PLAYER(tray->player), PAROLE_PLAYER_ACTION_PLAYPAUSE);
+    mi = gtk_action_create_menu_item(action);
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
     
     /*
      * Previous Track
      */
-    image = gtk_image_new_from_icon_name("media-skip-backward-symbolic", GTK_ICON_SIZE_MENU);
-    mi = gtk_image_menu_item_new_with_mnemonic(_("P_revious Track"));
-    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), image);
-    gtk_widget_set_sensitive (mi, TRUE);
-    gtk_widget_show (mi);
-    g_signal_connect_swapped (mi, "activate", G_CALLBACK (previous_activated_cb), tray);
+    action = parole_provider_player_get_action(PAROLE_PROVIDER_PLAYER(tray->player), PAROLE_PLAYER_ACTION_PREVIOUS);
+    mi = gtk_action_create_menu_item(action);
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
     
     /*
      * Next Track
      */
-    image = gtk_image_new_from_icon_name("media-skip-forward-symbolic", GTK_ICON_SIZE_MENU);
-    mi = gtk_image_menu_item_new_with_mnemonic(_("_Next Track"));
-    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), image);
-    gtk_widget_set_sensitive (mi, TRUE);
-    gtk_widget_show (mi);
-    g_signal_connect_swapped (mi, "activate", G_CALLBACK (next_activated_cb), tray);
+    action = parole_provider_player_get_action(PAROLE_PROVIDER_PLAYER(tray->player), PAROLE_PLAYER_ACTION_NEXT);
+    mi = gtk_action_create_menu_item(action);
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
     
     /*
-     * Separator.
+     * Separator
      */
     mi = gtk_separator_menu_item_new ();
     gtk_widget_show (mi);


More information about the Xfce4-commits mailing list