Re: [Muine] [PATCH] Repeat the current song only



Joachim Beckers wrote:
On Sun, 2006-04-09 at 11:28 +0200, Keywan Najafi Tonekaboni wrote:
Just use "Playlist (Repeating X Minutes)" Just like when you repeating a complete playlist.

Maybe, it's all a matter of taste after all. I'm CCing the patch author.
We'll let him decide.


Hey-o,

Good to hear that this patch has some usefulness beyond mine. I've opted to keep a similar format to the existing muine repeat summary, however, I think it's important to distinguish between repeating and repeating the current track/song, so I've gone with:

Playlist (Repeating Current Song - x minutes)

It does the right thing if the song is under a minute or longer than an hour as well.

Patch attached.

-daveb

--
Dave Barry
dave psax org

Index: data/ui/PlaylistWindow.xml
===================================================================
RCS file: /cvs/gnome/muine/data/ui/PlaylistWindow.xml,v
retrieving revision 1.6
diff -u -r1.6 PlaylistWindow.xml
--- data/ui/PlaylistWindow.xml	4 May 2005 19:05:43 -0000	1.6
+++ data/ui/PlaylistWindow.xml	9 Apr 2006 15:10:49 -0000
@@ -30,6 +30,7 @@
       <menuitem action="Clear" />
       <separator />
       <menuitem action="ToggleRepeat" />
+      <menuitem action="ToggleRepeatCurrent" />
       <menuitem action="Shuffle" />
     </menu>
     <menu action="HelpMenu">
Index: src/Actions.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Actions.cs,v
retrieving revision 1.17
diff -u -r1.17 Actions.cs
--- src/Actions.cs	21 Mar 2006 07:04:26 -0000	1.17
+++ src/Actions.cs	9 Apr 2006 15:10:49 -0000
@@ -94,6 +94,9 @@
 
 		private static readonly string string_toggle_repeat =
 			Catalog.GetString ("R_epeat");
+		
+		private static readonly string string_toggle_repeat_current =
+			Catalog.GetString ("Repeat Curren_t");
 
 		private static readonly string string_shuffle =
 			Catalog.GetString ("Shu_ffle");
@@ -174,6 +177,9 @@
 
 			new ToggleActionEntry ("ToggleRepeat", null, string_toggle_repeat,
 			       "<control>R", null, null, false),
+			
+			new ToggleActionEntry ("ToggleRepeatCurrent", null, string_toggle_repeat_current,
+			       "<control>T", null, null, false),
 
 			new ToggleActionEntry ("ToggleVisible", null, string_toggle_visible,
 				"Escape", null, null, true),
@@ -240,6 +246,7 @@
                         this ["About"        ].Activated += new EventHandler (OnAbout        );
                         this ["TogglePlay"   ].Activated += new EventHandler (OnTogglePlay   );
                         this ["ToggleRepeat" ].Activated += new EventHandler (OnToggleRepeat );
+                        this ["ToggleRepeatCurrent" ].Activated += new EventHandler (OnToggleRepeatCurrent );
 		}
 
 		// Properties
@@ -625,6 +632,29 @@
 				return;
 
 			Global.Playlist.Repeat = a.Active;
+		}
+		// Handlers :: OnToggleRepeatCurrent
+		/// <summary>
+		/// 	Handler called when the ToggleRepeatCurrent action is activated.
+		/// </summary>
+		/// <remarks>
+		///	This sets <see cref="PlaylistWindow.RepeatCurrent" /> to the
+		///	state of the ToggleRepeat action.
+		/// </remarks>
+		/// <param name="o">
+		///	The calling object.
+		/// </param>
+		/// <param name="args">
+		///	The <see cref="EventArgs" />.
+		/// </param>
+		private void OnToggleRepeatCurrent (object o, EventArgs args)
+		{
+			ToggleAction a = (ToggleAction) o;
+
+			if (a.Active == Global.Playlist.RepeatCurrent)
+				return;
+
+			Global.Playlist.RepeatCurrent = a.Active;
 		}
 	}
 }
Index: src/PlaylistWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/PlaylistWindow.cs,v
retrieving revision 1.244
diff -u -r1.244 PlaylistWindow.cs
--- src/PlaylistWindow.cs	21 Mar 2006 08:26:06 -0000	1.244
+++ src/PlaylistWindow.cs	9 Apr 2006 15:10:51 -0000
@@ -62,6 +62,9 @@
 
 		private const string GConfKeyRepeat = "/apps/muine/repeat";
 		private const bool   GConfDefaultRepeat = false;
+		
+		private const string GConfKeyRepeatCurrent = "/apps/muine/repeat_current";
+		private const bool   GConfDefaultRepeatCurrent = false;
 
 		// Strings
 		private static readonly string string_program = 
@@ -75,6 +78,9 @@
 
 		private static readonly string string_playlist_repeating =
 			Catalog.GetString ("<b>Playlist</b> (Repeating)");
+		
+		private static readonly string string_playlist_repeating_current =
+			Catalog.GetString ("<b>Playlist</b> (Repeating Current Song - < 1 minute)");
 
 		private static readonly string string_playlist_under_minute =
 			Catalog.GetString ("<b>Playlist</b> (Less than one minute remaining)");
@@ -224,6 +230,7 @@
 		private Hashtable random_sort_keys;
 
 		private bool repeat;
+		private bool repeat_current = false;
 
 		// Constructor
 		public PlaylistWindow () : base (WindowType.Toplevel)
@@ -407,6 +414,21 @@
 
 			get { return repeat; }
 		}
+		
+		// Properties :: RepeatCurrent (set; get;)
+		public bool RepeatCurrent {
+			set {
+				repeat_current = value;
+
+				((ToggleAction) Global.Actions ["ToggleRepeatCurrent"]).Active = value;
+
+				Config.Set (GConfKeyRepeatCurrent, value);			
+
+				PlaylistChanged ();
+			}
+
+			get { return repeat_current; }
+		}
 
 		// Methods
 		// Methods :: Public
@@ -1021,6 +1043,8 @@
 
 			if (this.repeat)
 				r_seconds = remaining_songs_time;
+         else if (this.repeat_current)
+            r_seconds = song.Duration;
 			else
 				r_seconds = remaining_songs_time + song.Duration - time;
 
@@ -1038,6 +1062,17 @@
 				"<b>Playlist</b> (Repeating {0} minutes)", 
 				minutes);
 
+			string string_repeat_one_hour = Catalog.GetPluralString (
+				"<b>Playlist</b> (Repeating Current Song - {0} hours)", 
+				"<b>Playlist</b> (Repeating Current Song - {0} hour)", 
+				hours);
+
+			string string_repeat_one_minute = Catalog.GetPluralString (
+				"<b>Playlist</b> (Repeating Current Song - {0} minute)", 
+				"<b>Playlist</b> (Repeating Current Song - {0} minutes)", 
+				minutes);
+            
+
 			string string_normal_hour = Catalog.GetPluralString (
 				"<b>Playlist</b> ({0} hour remaining)", 
 				"<b>Playlist</b> ({0} hours remaining)", 
@@ -1049,9 +1084,9 @@
 				minutes);
 
 			// Choose string for each scenario based on whether we are repeating or not
-			string string_hour   = (repeat) ? string_repeat_hour        : string_normal_hour;
-			string string_minute = (repeat) ? string_repeat_minute      : string_normal_minute;
-			string string_second = (repeat) ? string_playlist_repeating : string_playlist_under_minute;
+			string string_hour   = repeat ? string_repeat_hour        : repeat_current ? string_repeat_one_hour : string_normal_hour;
+			string string_minute = repeat ? string_repeat_minute      : repeat_current ? string_repeat_one_minute : string_normal_minute;
+			string string_second = repeat ? string_playlist_repeating : repeat_current ? string_playlist_repeating_current : string_playlist_under_minute;
 			
 			// Set the label
 			if (r_seconds > MinShowHours)
@@ -1353,6 +1388,11 @@
 		// Methods :: Private :: EndOfStream
 		private void EndOfStream (Song song, bool update_time)
 		{
+			if (repeat_current) {
+				playlist.Model.Playing = song.Handle;
+				PlaylistChanged ();
+				return;
+			}
 			// If we can, go to the next song
 			if (playlist.Model.HasNext) {
 				playlist.Model.Next ();
@@ -1430,6 +1470,12 @@
 
 			Config.AddNotify (GConfKeyRepeat,
 				new GConf.NotifyEventHandler (OnConfigRepeatChanged));
+			
+			// Repeat Current
+			RepeatCurrent = (bool) Config.Get (GConfKeyRepeatCurrent, GConfDefaultRepeatCurrent);
+
+			Config.AddNotify (GConfKeyRepeatCurrent,
+				new GConf.NotifyEventHandler (OnConfigRepeatCurrentChanged));
 		}
 
 		// Handlers
@@ -1665,6 +1711,19 @@
 				return;
 
 			this.Repeat = val;
+		}
+		
+		// Handlers :: OnConfigRepeatCurrentChanged
+		private void OnConfigRepeatCurrentChanged (object o, GConf.NotifyEventArgs args)
+		{
+			// Get new repeat setting from GConf
+			bool val = (bool) args.Value;
+
+			// If it changed, update.
+			if (val == this.repeat_current)
+				return;
+
+			this.RepeatCurrent = val;
 		}
 
 		// Handlers :: OnPlaylistRowActivated


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