[banshee] Disable repeat and shuffle controls when the play queue is active (bgo#577681)



commit c67e13985a9e97d80560204d7c34f711de68b996
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date:   Fri May 15 11:59:16 2009 +1000

    Disable repeat and shuffle controls when the play queue is active (bgo#577681)
    
    This commit adds CanRepeat and CanShuffle properties to ITrackModelSource and
    uses them to enable/disable Playback(Repeat|Shuffle)Actions when the current
    playback source is changed.
---
 .../Banshee.Sources/DatabaseSource.cs              |    8 +++++
 .../Banshee.Sources/ITrackModelSource.cs           |    5 ++-
 .../Banshee.Gui/PlaybackRepeatActions.cs           |   21 ++++++++++++-
 .../Banshee.Gui/PlaybackShuffleActions.cs          |   21 ++++++++++++-
 .../Banshee.AudioCd/AudioCdSource.cs               |   10 +++++-
 .../Banshee.Lastfm.Radio/LastfmActions.cs          |   33 +-------------------
 .../Banshee.Lastfm.Radio/StationSource.cs          |   10 +++++-
 .../Banshee.PlayQueue/PlayQueueSource.cs           |   10 +++++-
 8 files changed, 80 insertions(+), 38 deletions(-)

diff --git a/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs b/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
index 4d801db..d18906c 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
@@ -260,6 +260,14 @@ namespace Banshee.Sources
             get { return true; }
         }
 
+        public virtual bool CanRepeat {
+            get { return true; }
+        }
+
+        public virtual bool CanShuffle {
+            get { return true; }
+        }
+
         public override string TrackModelPath {
             get { return DBusServiceManager.MakeObjectPath (DatabaseTrackModel); }
         }
diff --git a/src/Core/Banshee.Services/Banshee.Sources/ITrackModelSource.cs b/src/Core/Banshee.Services/Banshee.Sources/ITrackModelSource.cs
index 5e7f7bf..4bc88a3 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/ITrackModelSource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/ITrackModelSource.cs
@@ -49,7 +49,10 @@ namespace Banshee.Sources
         bool CanRemoveTracks { get; }
         bool CanDeleteTracks { get; }
         bool ConfirmRemoveTracks { get; }
-        
+
+        bool CanRepeat { get; }
+        bool CanShuffle { get; }
+
         bool ShowBrowser { get; }
         bool Indexable { get; }
     }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs
index d445c7a..22f4c37 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs
@@ -43,6 +43,7 @@ namespace Banshee.Gui
     public class PlaybackRepeatActions : BansheeActionGroup, IEnumerable<RadioAction>
     {
         private RadioAction active_action;
+        private RadioAction saved_action;
         
         public RadioAction Active {
             get { return active_action; }
@@ -94,6 +95,7 @@ namespace Banshee.Gui
             this["RepeatSingleAction"].IconName = "media-repeat-single";
 
             ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged;
+            ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged;
 
             Gtk.Action action = this[ConfigIdToActionName (RepeatMode.Get ())];
             if (action is RadioAction) {
@@ -118,10 +120,27 @@ namespace Banshee.Gui
                 }
             }
 
-            RepeatMode.Set (ActionNameToConfigId (active_action.Name));
+            if (saved_action == null) {
+                RepeatMode.Set (ActionNameToConfigId (active_action.Name));
+            }
             OnChanged();
         }
 
+        private void OnPlaybackSourceChanged (object o, EventArgs args)
+        {
+            var source = ServiceManager.PlaybackController.Source;
+
+            if (saved_action == null && !source.CanRepeat) {
+                saved_action = Active;
+                Active = this["RepeatNoneAction"] as RadioAction;
+                Sensitive = false;
+            } else if (saved_action != null && source.CanRepeat) {
+                Active = saved_action;
+                saved_action = null;
+                Sensitive = true;
+            }
+        }
+
         private void OnActionChanged (object o, ChangedArgs args)
         {
             Active = args.Current;
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs
index d14e803..faeec9c 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs
@@ -43,6 +43,7 @@ namespace Banshee.Gui
     public class PlaybackShuffleActions : BansheeActionGroup, IEnumerable<RadioAction>
     {
         private RadioAction active_action;
+        private RadioAction saved_action;
         private PlaybackActions playback_actions;
 
         public RadioAction Active {
@@ -105,6 +106,7 @@ namespace Banshee.Gui
             this["ShuffleAlbumAction"].Sensitive = false;
 
             ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged;
+            ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged;
 
             Gtk.Action action = this[ConfigIdToActionName (ShuffleMode.Get ())];
             if (action is RadioAction) {
@@ -129,10 +131,27 @@ namespace Banshee.Gui
                 }
             }
 
-            ShuffleMode.Set (ActionNameToConfigId (active_action.Name));
+            if (saved_action == null) {
+                ShuffleMode.Set (ActionNameToConfigId (active_action.Name));
+            }
             OnChanged();
         }
 
+        private void OnPlaybackSourceChanged (object o, EventArgs args)
+        {
+            var source = ServiceManager.PlaybackController.Source;
+
+            if (saved_action == null && !source.CanShuffle) {
+                saved_action = Active;
+                Active = this["ShuffleOffAction"] as RadioAction;
+                Sensitive = false;
+            } else if (saved_action != null && source.CanShuffle) {
+                Active = saved_action;
+                saved_action = null;
+                Sensitive = true;
+            }
+        }
+
         private void OnActionChanged (object o, ChangedArgs args)
         {
             Active = args.Current;
diff --git a/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdSource.cs b/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdSource.cs
index 02b2ec0..fdbab2c 100644
--- a/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdSource.cs
+++ b/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdSource.cs
@@ -321,7 +321,15 @@ namespace Banshee.AudioCd
         public bool ConfirmRemoveTracks {
             get { return false; }
         }
-        
+
+        public virtual bool CanRepeat {
+            get { return true; }
+        }
+
+        public virtual bool CanShuffle {
+            get { return true; }
+        }
+
         public bool ShowBrowser {
             get { return false; }
         }
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmActions.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmActions.cs
index c566fb8..7465dba 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmActions.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmActions.cs
@@ -179,7 +179,6 @@ namespace Banshee.Lastfm.Radio
         {
             Actions.UIManager.RemoveUi (actions_id);
             Actions.RemoveActionGroup (this);
-            RestoreShuffleRepeat ();
             ServiceManager.PlayerEngine.DisconnectEvent (OnPlayerEvent);
             base.Dispose ();
         }
@@ -410,8 +409,6 @@ namespace Banshee.Lastfm.Radio
         }
 
         private uint track_actions_id;
-        private RadioAction old_shuffle;
-        private RadioAction old_repeat;
         private bool was_lastfm = false;
         private void OnPlaybackSourceChanged (object o, EventArgs args)
         {
@@ -422,26 +419,7 @@ namespace Banshee.Lastfm.Radio
 
             bool is_lastfm = ServiceManager.PlaybackController.Source is StationSource;
             Actions.PlaybackActions["PreviousAction"].Sensitive = !is_lastfm;
-            PlaybackRepeatActions repeat_actions = Actions.PlaybackActions.RepeatActions;
-            PlaybackShuffleActions shuffle_actions = Actions.PlaybackActions.ShuffleActions;
-
-            // Save/clear shuffle/repeat values when we first switch to a Last.fm station
-            if (is_lastfm && !was_lastfm) {
-                old_repeat = repeat_actions.Active;
-                repeat_actions.Active = repeat_actions["RepeatNoneAction"] as RadioAction;
-                
-                old_shuffle = shuffle_actions.Active;
-                shuffle_actions.Active = shuffle_actions["ShuffleOffAction"] as RadioAction;
-            }
-            // Restore shuffle/repeat values when we switch from a Last.fm station to a non Last.fm source
-            if (!is_lastfm && was_lastfm) {
-                RestoreShuffleRepeat ();
-            }
-            
-            // Set sensitivity
-            shuffle_actions.Sensitive = !is_lastfm;
-            repeat_actions.Sensitive = !is_lastfm;
-            
+
             if (is_lastfm && !was_lastfm)
                 track_actions_id = Actions.UIManager.AddUiFromResource ("LastfmTrackActions.xml");
             else if (!is_lastfm && was_lastfm)
@@ -449,14 +427,5 @@ namespace Banshee.Lastfm.Radio
 
             was_lastfm = is_lastfm;
         }
-
-        private void RestoreShuffleRepeat ()
-        {
-            if (Actions != null && Actions.PlaybackActions != null && old_repeat != null) {
-                Actions.PlaybackActions.RepeatActions.Active = old_repeat;
-                Actions.PlaybackActions.ShuffleActions.Active = old_shuffle;
-            }
-            old_repeat = old_shuffle = null;
-        }
     }
 }
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
index c6133d5..e74426f 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
@@ -492,7 +492,15 @@ namespace Banshee.Lastfm.Radio
         public bool ConfirmRemoveTracks {
             get { return false; }
         }
-        
+
+        public virtual bool CanRepeat {
+            get { return false; }
+        }
+
+        public virtual bool CanShuffle {
+            get { return false; }
+        }
+
         public bool ShowBrowser {
             get { return false; }
         }
diff --git a/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs b/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
index d2e1dc9..2b2b380 100644
--- a/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
+++ b/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
@@ -299,7 +299,15 @@ namespace Banshee.PlayQueue
         public override bool ConfirmRemoveTracks {
             get { return false; }
         }
-        
+
+        public override bool CanRepeat {
+            get { return false; }
+        }
+
+        public override bool CanShuffle {
+            get { return false; }
+        }
+
         public override bool CanUnmap {
             get { return false; }
         }



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