banshee r5172 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.PlaybackController src/Core/Banshee.ThickClient/Banshee.Gui



Author: alexk
Date: Sun Mar 29 22:41:32 2009
New Revision: 5172
URL: http://svn.gnome.org/viewvc/banshee?rev=5172&view=rev

Log:
2009-03-29  Alexander Kojevnikov  <alexander kojevnikov com>

	* src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs:
	* src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackRepeatMode.cs:
	* src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackShuffleMode.cs:
	* src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs:
	* src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs:
	Update the UI when repeat and shuffle mode is changed using DBus
	(BGO #575383).

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackRepeatMode.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackShuffleMode.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	Sun Mar 29 22:41:32 2009
@@ -79,6 +79,8 @@
         public event EventHandler NextSourceChanged;
         public event EventHandler TrackStarted;
         public event EventHandler Transition;
+        public event EventHandler<ShuffleModeChangedEventArgs> ShuffleModeChanged;
+        public event EventHandler<RepeatModeChangedEventArgs> RepeatModeChanged;
         
         public PlaybackControllerService ()
         {
@@ -447,12 +449,24 @@
         
         public PlaybackShuffleMode ShuffleMode {
             get { return shuffle_mode; }
-            set { shuffle_mode = value; }
+            set {
+                shuffle_mode = value;
+                EventHandler<ShuffleModeChangedEventArgs> handler = ShuffleModeChanged;
+                if (handler != null) {
+                    handler (this, new ShuffleModeChangedEventArgs (shuffle_mode));
+                }
+            }
         }
         
         public PlaybackRepeatMode RepeatMode {
             get { return repeat_mode; }
-            set { repeat_mode = value; }
+            set {
+                repeat_mode = value;
+                EventHandler<RepeatModeChangedEventArgs> handler = RepeatModeChanged;
+                if (handler != null) {
+                    handler (this, new RepeatModeChangedEventArgs (repeat_mode));
+                }
+            }
         }
         
         public bool StopWhenFinished {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackRepeatMode.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackRepeatMode.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackRepeatMode.cs	Sun Mar 29 22:41:32 2009
@@ -36,4 +36,17 @@
         RepeatAll,
         RepeatSingle
     }
+
+    public class RepeatModeChangedEventArgs : EventArgs
+    {
+        private PlaybackRepeatMode repeat_mode;
+        public PlaybackRepeatMode RepeatMode {
+            get { return repeat_mode; }
+        }
+
+        public RepeatModeChangedEventArgs (PlaybackRepeatMode repeat_mode)
+        {
+            this.repeat_mode = repeat_mode;
+        }
+    }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackShuffleMode.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackShuffleMode.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackShuffleMode.cs	Sun Mar 29 22:41:32 2009
@@ -37,4 +37,17 @@
         Artist,
         Album
     }
+
+    public class ShuffleModeChangedEventArgs : EventArgs
+    {
+        private PlaybackShuffleMode shuffle_mode;
+        public PlaybackShuffleMode ShuffleMode {
+            get { return shuffle_mode; }
+        }
+
+        public ShuffleModeChangedEventArgs (PlaybackShuffleMode shuffle_mode)
+        {
+            this.shuffle_mode = shuffle_mode;
+        }
+    }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackRepeatActions.cs	Sun Mar 29 22:41:32 2009
@@ -48,9 +48,7 @@
             get { return active_action; }
             set {
                 active_action = value;
-                RepeatMode.Set (active_action == null ? String.Empty : ActionNameToConfigId (active_action.Name));
                 ServiceManager.PlaybackController.RepeatMode = (PlaybackRepeatMode)active_action.Value;
-                OnChanged ();
             }
         }
         
@@ -95,6 +93,8 @@
             this["RepeatAllAction"].IconName = "media-repeat-all";
             this["RepeatSingleAction"].IconName = "media-repeat-single";
 
+            ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged;
+
             Gtk.Action action = this[ConfigIdToActionName (RepeatMode.Get ())];
             if (action is RadioAction) {
                 active_action = (RadioAction)action;
@@ -105,6 +105,23 @@
             Active.Activate ();
         }
 
+        private void OnRepeatModeChanged (object o, RepeatModeChangedEventArgs args)
+        {
+            if (active_action.Value != (int)args.RepeatMode) {
+                // This happens only when changing the mode using DBus.
+                // In this case we need to locate the action by its value.
+                foreach (RadioAction action in this) {
+                    if (action.Value == (int)args.RepeatMode) {
+                        active_action = action;
+                        break;
+                    }
+                }
+            }
+
+            RepeatMode.Set (ActionNameToConfigId (active_action.Name));
+            OnChanged();
+        }
+
         private void OnActionChanged (object o, ChangedArgs args)
         {
             Active = args.Current;

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackShuffleActions.cs	Sun Mar 29 22:41:32 2009
@@ -49,9 +49,7 @@
             get { return active_action; }
             set {
                 active_action = value;
-                ShuffleMode.Set (active_action == null ? String.Empty : ActionNameToConfigId (active_action.Name));
                 ServiceManager.PlaybackController.ShuffleMode = (PlaybackShuffleMode)active_action.Value;
-                OnChanged ();
             }
         }
 
@@ -106,6 +104,8 @@
             this["ShuffleArtistAction"].Sensitive = false;
             this["ShuffleAlbumAction"].Sensitive = false;
 
+            ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged;
+
             Gtk.Action action = this[ConfigIdToActionName (ShuffleMode.Get ())];
             if (action is RadioAction) {
                 active_action = (RadioAction)action;
@@ -116,6 +116,23 @@
             Active.Activate ();
         }
 
+        private void OnShuffleModeChanged (object o, ShuffleModeChangedEventArgs args)
+        {
+            if (active_action.Value != (int)args.ShuffleMode) {
+                // This happens only when changing the mode using DBus.
+                // In this case we need to locate the action by its value.
+                foreach (RadioAction action in this) {
+                    if (action.Value == (int)args.ShuffleMode) {
+                        active_action = action;
+                        break;
+                    }
+                }
+            }
+
+            ShuffleMode.Set (ActionNameToConfigId (active_action.Name));
+            OnChanged();
+        }
+
         private void OnActionChanged (object o, ChangedArgs args)
         {
             Active = args.Current;



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