[banshee] Mpris: Add and implement the PlaylistChanged signal



commit 13a1c296166d3f7213b52d8f2a19a0cfe377d8c7
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sat Jan 29 15:25:16 2011 +0100

    Mpris: Add and implement the PlaylistChanged signal
    
    This is a recent addition to the MPRIS spec, and allows client to be
    notified when a playlist is renamed.
    The signal is also fired when the content of the playlist is updated
    (track added, etc.) but this shouldn't be a problem for clients.

 .../Banshee.Mpris/Banshee.Mpris/IPlaylists.cs      |    4 ++++
 .../Banshee.Mpris/Banshee.Mpris/MediaPlayer.cs     |   14 ++++++++++++++
 .../Banshee.Mpris/Banshee.Mpris/MprisService.cs    |   10 ++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/Extensions/Banshee.Mpris/Banshee.Mpris/IPlaylists.cs b/src/Extensions/Banshee.Mpris/Banshee.Mpris/IPlaylists.cs
index f739851..99bb68a 100644
--- a/src/Extensions/Banshee.Mpris/Banshee.Mpris/IPlaylists.cs
+++ b/src/Extensions/Banshee.Mpris/Banshee.Mpris/IPlaylists.cs
@@ -29,6 +29,8 @@ using NDesk.DBus;
 
 namespace Banshee.Mpris
 {
+    public delegate void PlaylistChangedHandler (Playlist playlist);
+
     public struct Playlist
     {
         public ObjectPath Id;
@@ -45,6 +47,8 @@ namespace Banshee.Mpris
     [Interface ("org.mpris.MediaPlayer2.Playlists")]
     public interface IPlaylists
     {
+        event PlaylistChangedHandler PlaylistChanged;
+
         uint PlaylistCount { get; }
         string [] Orderings { get; }
         MaybePlaylist ActivePlaylist { get; }
diff --git a/src/Extensions/Banshee.Mpris/Banshee.Mpris/MediaPlayer.cs b/src/Extensions/Banshee.Mpris/Banshee.Mpris/MediaPlayer.cs
index 5b86685..d433482 100644
--- a/src/Extensions/Banshee.Mpris/Banshee.Mpris/MediaPlayer.cs
+++ b/src/Extensions/Banshee.Mpris/Banshee.Mpris/MediaPlayer.cs
@@ -73,6 +73,12 @@ namespace Banshee.Mpris
             remove { dbus_seeked -= value; }
         }
 
+        private event PlaylistChangedHandler playlist_changed;
+        event PlaylistChangedHandler IPlaylists.PlaylistChanged {
+            add { playlist_changed += value; }
+            remove { playlist_changed -= value; }
+        }
+
         public MediaPlayer ()
         {
             playback_service = ServiceManager.PlaybackController;
@@ -455,6 +461,14 @@ namespace Banshee.Mpris
             }
         }
 
+        public void HandlePlaylistChange (AbstractPlaylistSource source)
+        {
+            PlaylistChangedHandler playlist_handler = playlist_changed;
+            if (playlist_handler != null) {
+                playlist_handler (BuildPlaylistFromSource (source));
+            }
+        }
+
         public void AddPropertyChange (params PlayerProperties [] properties)
         {
             lock (changed_properties) {
diff --git a/src/Extensions/Banshee.Mpris/Banshee.Mpris/MprisService.cs b/src/Extensions/Banshee.Mpris/Banshee.Mpris/MprisService.cs
index b251080..576b124 100644
--- a/src/Extensions/Banshee.Mpris/Banshee.Mpris/MprisService.cs
+++ b/src/Extensions/Banshee.Mpris/Banshee.Mpris/MprisService.cs
@@ -67,6 +67,7 @@ namespace Banshee.Mpris
 
             ServiceManager.SourceManager.SourceAdded += OnSourceCountChanged;
             ServiceManager.SourceManager.SourceRemoved += OnSourceCountChanged;
+            ServiceManager.SourceManager.SourceUpdated += OnSourceUpdated;
             ServiceManager.PlaybackController.SourceChanged += OnPlayingSourceChanged;
 
             player = new MediaPlayer();
@@ -88,6 +89,7 @@ namespace Banshee.Mpris
 
             ServiceManager.SourceManager.SourceAdded -= OnSourceCountChanged;
             ServiceManager.SourceManager.SourceRemoved -= OnSourceCountChanged;
+            ServiceManager.SourceManager.SourceUpdated -= OnSourceUpdated;
             ServiceManager.PlaybackController.SourceChanged -= OnPlayingSourceChanged;
 
             Bus.Session.ReleaseName (bus_name);
@@ -129,6 +131,14 @@ namespace Banshee.Mpris
             }
         }
 
+        private void OnSourceUpdated (SourceEventArgs args)
+        {
+            var source = args.Source as AbstractPlaylistSource;
+            if (source != null) {
+                player.HandlePlaylistChange (source);
+            }
+        }
+
         private void OnPlayingSourceChanged (object o, EventArgs args)
         {
             player.AddPropertyChange (PlaylistProperties.ActivePlaylist);



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