[Muine] [PATCH] Repeat the current song only



Attached is a patch that may be of more immediate use for mainline than my previous one. The patch adds a menu item in the playlist menu to repeat the current song. This functionality can currently be achieved by loading a playlist of length 1 and using the existing repeat menu item however --

The use case at our house is that we'll have a rather large and accumulated playlist loaded, and have a sudden need to get the baby to sleep (this need seems to occur every night...go figure). There are a few choice songs that he has to hear multiple times to fall asleep sometimes...and so we'll often add one of those to the playlist, and just hit repeat current to listen to it until he's asleep. Then we'll uncheck it and continue on.

The patch is straightforward, and I'd love some feedback on both the code and the perceived usefulness of the patch.

Thanks,

.dave

--
Dave Barry
dave psax org
? repeat_current.diff
? libmuine/.deps
? libmuine/.libs
? libmuine/db.lo
? libmuine/gsequence.lo
? libmuine/libmuine.la
? libmuine/metadata.lo
? libmuine/mm-keys.lo
? libmuine/ogg-helper.lo
? libmuine/player-gst.lo
? libmuine/pointer-list-model.lo
? libmuine/rb-cell-renderer-pixbuf.lo
? libmuine/id3-vfs/.deps
? libmuine/id3-vfs/.libs
? libmuine/id3-vfs/id3-vfs.lo
? libmuine/id3-vfs/libid3-vfs.la
? libmuine/id3-vfs/mp3bitrate.lo
? plugins/.deps
? plugins/.libs
? plugins/inotify-glue.lo
? plugins/libinotifyglue.la
? po/.intltool-merge-cache
? po/stamp-it
? src/.Actions.cs.swp
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	2 Apr 2006 16:14:02 -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	2 Apr 2006 16:14:02 -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	2 Apr 2006 16:14:04 -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)");
 
 		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
@@ -1353,6 +1375,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 +1457,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 +1698,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]