[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/01: Initial playlist support

noreply at xfce.org noreply at xfce.org
Wed Nov 29 12:45:10 CET 2017


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-pulseaudio-plugin.

commit 5cbe27be4be9552755c5463c2b8ad68358e7dc29
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Wed Nov 29 06:45:04 2017 -0500

    Initial playlist support
---
 panel-plugin/pulseaudio-menu.c         |  65 ++++++++++++++++++--
 panel-plugin/pulseaudio-mpris-player.c | 105 ++++++++++++++++++++++++++++++++-
 panel-plugin/pulseaudio-mpris-player.h |   4 ++
 panel-plugin/pulseaudio-mpris.c        |  30 +++++++++-
 panel-plugin/pulseaudio-mpris.h        |  11 +++-
 5 files changed, 203 insertions(+), 12 deletions(-)

diff --git a/panel-plugin/pulseaudio-menu.c b/panel-plugin/pulseaudio-menu.c
index 8fb73b5..383a6ec 100644
--- a/panel-plugin/pulseaudio-menu.c
+++ b/panel-plugin/pulseaudio-menu.c
@@ -274,6 +274,26 @@ pulseaudio_menu_run_audio_mixer (PulseaudioMenu   *menu,
 
 
 static void
+pulseaudio_menu_activate_playlist (PulseaudioMenu *menu,
+                                   GtkMenuItem    *menu_item)
+{
+  gchar *player;
+  gchar *playlist;
+
+  g_return_if_fail(IS_PULSEAUDIO_MENU(menu));
+
+  player = g_strdup (g_object_get_data (G_OBJECT (menu_item), "player"));
+  playlist = g_strdup (g_object_get_data (G_OBJECT (menu_item), "playlist"));
+
+  pulseaudio_mpris_activate_playlist (menu->mpris, player, playlist);
+
+  g_free (player);
+  g_free (playlist);
+}
+
+
+
+static void
 pulseaudio_menu_volume_changed (PulseaudioMenu   *menu,
                                 gboolean          should_notify,
                                 PulseaudioVolume *volume)
@@ -339,6 +359,7 @@ mpris_update_cb (PulseaudioMpris *mpris,
   gboolean        can_go_previous;
   gboolean        can_go_next;
   gboolean        can_raise;
+  GList          *playlists;
 
   g_return_if_fail (IS_PULSEAUDIO_MPRIS (mpris));
   g_return_if_fail (IS_MPRIS_MENU_ITEM (menu_item));
@@ -359,7 +380,8 @@ mpris_update_cb (PulseaudioMpris *mpris,
                                                 &can_pause,
                                                 &can_go_previous,
                                                 &can_go_next,
-                                                &can_raise))
+                                                &can_raise,
+                                                &playlists))
         {
           mpris_menu_item_set_is_running (menu_item, is_running);
           mpris_menu_item_set_title (menu_item, title);
@@ -379,6 +401,8 @@ mpris_update_cb (PulseaudioMpris *mpris,
         g_free (title);
       if (artist != NULL)
         g_free (artist);
+      if (playlists != NULL)
+        g_list_free (playlists);
     }
 }
 
@@ -416,7 +440,7 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
   guint           i = 0;
 
 #ifdef HAVE_MPRIS2
-      gchar **players;
+  gchar         **players;
   gchar          *title = NULL;
   gchar          *artist = NULL;
   gboolean        is_running;
@@ -427,6 +451,8 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
   gboolean        can_go_previous;
   gboolean        can_go_next;
   gboolean        can_raise;
+  GList          *playlists;
+  GtkWidget      *submenu = NULL;
 #endif
 
   g_return_val_if_fail (IS_PULSEAUDIO_VOLUME (volume), NULL);
@@ -554,7 +580,8 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
                                                             &can_pause,
                                                             &can_go_previous,
                                                             &can_go_next,
-                                                            &can_raise))
+                                                            &can_raise,
+                                                            &playlists))
                     {
                       mpris_menu_item_set_is_running (MPRIS_MENU_ITEM (mi), is_running);
                       mpris_menu_item_set_title (MPRIS_MENU_ITEM (mi), title);
@@ -586,8 +613,36 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
                   g_signal_connect (menu->mpris, "update", G_CALLBACK (mpris_update_cb), mi);
                   g_signal_connect (mi, "destroy", G_CALLBACK(item_destroy_cb), menu);
 
-                  gtk_widget_show (mi);
-                  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+                  gtk_widget_show(mi);
+                  gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+
+                  if (playlists != NULL)
+                    {
+                      if (g_list_length(playlists) > 0)
+                      {
+                        mi = gtk_menu_item_new_with_label(_("Choose Playlist"));
+                        gtk_widget_show(mi);
+                        gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+
+                        submenu = gtk_menu_new();
+                        gtk_menu_item_set_submenu(GTK_MENU_ITEM(mi), submenu);
+
+                        for (list = playlists; list != NULL; list = g_list_next(list))
+                        {
+                          mi = gtk_menu_item_new_with_label((gchar *)list->data);
+                          gtk_widget_show(mi);
+                          gtk_menu_shell_append(GTK_MENU_SHELL(submenu), mi);
+
+                          g_object_set_data (G_OBJECT(mi), "player", g_strdup (players[i]));
+                          g_object_set_data (G_OBJECT(mi), "playlist", g_strdup ((gchar *)list->data));
+
+                          g_signal_connect_swapped(G_OBJECT(mi), "activate", G_CALLBACK (pulseaudio_menu_activate_playlist), menu);
+                        }
+                      }
+
+                      g_list_free(playlists);
+                      playlists = NULL;
+                    }
 
                   /* separator */
                   mi = gtk_separator_menu_item_new ();
diff --git a/panel-plugin/pulseaudio-mpris-player.c b/panel-plugin/pulseaudio-mpris-player.c
index 677b905..da4d7ef 100644
--- a/panel-plugin/pulseaudio-mpris-player.c
+++ b/panel-plugin/pulseaudio-mpris-player.c
@@ -57,6 +57,8 @@ struct _PulseaudioMprisPlayer
   PlaybackStatus    playback_status;
 
   guint             watch_id;
+
+  GHashTable       *playlists;
 };
 
 struct _PulseaudioMprisPlayerClass
@@ -210,8 +212,40 @@ pulseaudio_mpris_player_call_player_method (PulseaudioMprisPlayer *player,
 
 
 
+GList *
+pulseaudio_mpris_player_get_playlists (PulseaudioMprisPlayer *player)
+{
+  return g_hash_table_get_keys (player->playlists);
+}
+
+
+
+void pulseaudio_mpris_player_activate_playlist (PulseaudioMprisPlayer *player,
+                                                const gchar           *playlist)
+{
+  gchar *path = g_hash_table_lookup (player->playlists, playlist);
+
+  if (path != NULL)
+    {
+      g_dbus_connection_call (player->dbus_connection,
+                              player->dbus_name,
+                              "/org/mpris/MediaPlayer2",
+                              "org.mpris.MediaPlayer2.Playlists",
+                              "ActivatePlaylist",
+                              g_variant_new("(o)", path),
+                              NULL,
+                              G_DBUS_CALL_FLAGS_NONE,
+                              -1,
+                              NULL,
+                              NULL,
+                              NULL);
+    }
+}
+
+
+
 static GVariant *
-pulseaudio_mpris_player_get_all_player_properties (PulseaudioMprisPlayer *player)
+pulseaudio_mpris_player_get_all_player_properties(PulseaudioMprisPlayer *player)
 {
   GVariantIter iter;
   GVariant *result, *child = NULL;
@@ -268,6 +302,35 @@ pulseaudio_mpris_player_get_all_media_player_properties (PulseaudioMprisPlayer *
 
 
 
+static GVariant *
+pulseaudio_mpris_player_playlists_get_playlists (PulseaudioMprisPlayer *player)
+{
+  GVariantIter iter;
+  GVariant *result, *child = NULL;
+
+  result = g_dbus_connection_call_sync(player->dbus_connection,
+                                       player->dbus_name,
+                                       "/org/mpris/MediaPlayer2",
+                                       "org.mpris.MediaPlayer2.Playlists",
+                                       "GetPlaylists",
+                                       g_variant_new("(uusb)", (guint32)0, (guint32)5, "Alphabetical", FALSE),
+                                       G_VARIANT_TYPE("(a(oss))"),
+                                       G_DBUS_CALL_FLAGS_NONE,
+                                       -1,
+                                       NULL,
+                                       NULL);
+
+  if (result)
+  {
+    g_variant_iter_init(&iter, result);
+    child = g_variant_iter_next_value(&iter);
+  }
+
+  return child;
+}
+
+
+
 static void
 pulseaudio_mpris_player_parse_playback_status (PulseaudioMprisPlayer *player,
                                                const gchar           *playback_status)
@@ -353,6 +416,28 @@ pulseaudio_mpris_player_parse_media_player_properties (PulseaudioMprisPlayer *pl
 
 
 static void
+pulseaudio_mpris_player_parse_playlists (PulseaudioMprisPlayer *player,
+                                         GVariant *playlists)
+{
+  GVariantIter iter;
+
+  gchar *path;
+  const gchar *name;
+  const gchar *icon;
+
+  g_hash_table_remove_all (player->playlists);
+
+  g_variant_iter_init(&iter, playlists);
+
+  while (g_variant_iter_loop(&iter, "(oss)", &path, &name, &icon))
+  {
+    g_hash_table_insert (player->playlists, g_strdup (name), g_strdup (path));
+  }
+}
+
+
+
+static void
 pulseaudio_mpris_player_on_dbus_property_signal (GDBusProxy *proxy,
                                                  gchar      *sender_name,
                                                  gchar      *signal_name,
@@ -397,11 +482,23 @@ pulseaudio_mpris_player_on_dbus_connected (GDBusConnection *connection,
   /* And informs the current status of the player */
   reply = pulseaudio_mpris_player_get_all_player_properties (player);
   pulseaudio_mpris_player_parse_player_properties (player, reply);
-  g_variant_unref (reply);
 
+  if (reply)
+    g_variant_unref (reply);
+
+  /* Media player properties */
   reply = pulseaudio_mpris_player_get_all_media_player_properties (player);
   pulseaudio_mpris_player_parse_media_player_properties (player, reply);
-  g_variant_unref (reply);
+
+  if (reply)
+    g_variant_unref (reply);
+
+  /* Playlists */
+  reply = pulseaudio_mpris_player_playlists_get_playlists (player);
+  pulseaudio_mpris_player_parse_playlists (player, reply);
+
+  if (reply)
+    g_variant_unref(reply);
 }
 
 
@@ -822,5 +919,7 @@ pulseaudio_mpris_player_new (gchar *name)
   pulseaudio_mpris_player_dbus_connect (player);
   pulseaudio_mpris_player_set_player (player, name);
 
+  player->playlists = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
+
   return player;
 }
diff --git a/panel-plugin/pulseaudio-mpris-player.h b/panel-plugin/pulseaudio-mpris-player.h
index b4e8b8a..935bb9f 100644
--- a/panel-plugin/pulseaudio-mpris-player.h
+++ b/panel-plugin/pulseaudio-mpris-player.h
@@ -74,6 +74,10 @@ gboolean                pulseaudio_mpris_player_is_equal           (PulseaudioMp
 void                    pulseaudio_mpris_player_call_player_method (PulseaudioMprisPlayer *player,
                                                                     const gchar           *method);
 
+GList                  *pulseaudio_mpris_player_get_playlists      (PulseaudioMprisPlayer *player);
+void                    pulseaudio_mpris_player_activate_playlist  (PulseaudioMprisPlayer *player,
+                                                                    const gchar           *playlist);
+
 G_END_DECLS
 
 #endif /* !__PULSEAUDIO_MPRIS_PLAYER_H__ */
diff --git a/panel-plugin/pulseaudio-mpris.c b/panel-plugin/pulseaudio-mpris.c
index 83b6578..5252d25 100644
--- a/panel-plugin/pulseaudio-mpris.c
+++ b/panel-plugin/pulseaudio-mpris.c
@@ -213,7 +213,8 @@ pulseaudio_mpris_get_player_snapshot (PulseaudioMpris  *mpris,
                                       gboolean         *can_pause,
                                       gboolean         *can_go_previous,
                                       gboolean         *can_go_next,
-                                      gboolean         *can_raise)
+                                      gboolean         *can_raise,
+                                      GList           **playlists)
 {
   PulseaudioMprisPlayer *player;
   player = PULSEAUDIO_MPRIS_PLAYER (g_hash_table_lookup (mpris->players, name));
@@ -233,6 +234,7 @@ pulseaudio_mpris_get_player_snapshot (PulseaudioMpris  *mpris,
           *can_go_previous    = pulseaudio_mpris_player_can_go_previous (player);
           *can_go_next        = pulseaudio_mpris_player_can_go_next (player);
           *can_raise          = pulseaudio_mpris_player_can_raise (player);
+          *playlists          = pulseaudio_mpris_player_get_playlists (player);
         }
       else
         {
@@ -247,6 +249,7 @@ pulseaudio_mpris_get_player_snapshot (PulseaudioMpris  *mpris,
           *can_go_previous    = FALSE;
           *can_go_next        = FALSE;
           *can_raise          = FALSE;
+          *playlists          = NULL;
         }
       if (*title == NULL || g_strcmp0 (*title, "") == 0)
         *title = g_strdup(pulseaudio_mpris_player_get_player_title (player));
@@ -312,6 +315,31 @@ pulseaudio_mpris_notify_any_player (PulseaudioMpris *mpris,
 
 
 
+gboolean
+pulseaudio_mpris_activate_playlist (PulseaudioMpris *mpris,
+                                    const gchar     *name,
+                                    const gchar     *playlist)
+{
+  PulseaudioMprisPlayer *player;
+
+  g_return_val_if_fail(IS_PULSEAUDIO_MPRIS(mpris), FALSE);
+
+  player = g_hash_table_lookup(mpris->players, name);
+
+  if (player != NULL)
+  {
+    if (pulseaudio_mpris_player_is_connected (player))
+    {
+      pulseaudio_mpris_player_activate_playlist (player, playlist);
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
+
+
 static void
 pulseaudio_mpris_init (PulseaudioMpris *mpris)
 {
diff --git a/panel-plugin/pulseaudio-mpris.h b/panel-plugin/pulseaudio-mpris.h
index 2e354a0..6ba6c17 100644
--- a/panel-plugin/pulseaudio-mpris.h
+++ b/panel-plugin/pulseaudio-mpris.h
@@ -52,15 +52,20 @@ gboolean                pulseaudio_mpris_get_player_snapshot   (PulseaudioMpris
                                                                 gboolean         *can_pause,
                                                                 gboolean         *can_go_previous,
                                                                 gboolean         *can_go_next,
-                                                                gboolean         *can_raise);
+                                                                gboolean         *can_raise,
+                                                                GList           **playlists);
 
 gboolean                pulseaudio_mpris_notify_player         (PulseaudioMpris  *mpris,
                                                                 const gchar      *name,
                                                                 const gchar      *message);
 
 gboolean                pulseaudio_mpris_notify_any_player     (PulseaudioMpris *mpris,
-                                                                const gchar *message);
+                                                                const gchar     *message);
 
-G_END_DECLS
+gboolean                pulseaudio_mpris_activate_playlist     (PulseaudioMpris *mpris,
+                                                                const gchar     *name,
+                                                                const gchar     *playlist);
+
+    G_END_DECLS
 
 #endif /* !__PULSEAUDIO_MPRIS_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list