[Muine] added forward/backward behavior to next/previous buttons



Hi all.
i made a patch for Muine that allow you to forward/backward a song
keeping pressed the next/previous button and mantain the original
behavior (previous/next song) if you just click them.
Take a look and please give me some feedback. :)

You can see it online at http://monoport.com/3927 or attached to this mail.

c-u.
-- 
D.
diff -urw muine.orig/src/PlaylistWindow.cs muine/src/PlaylistWindow.cs
--- muine.orig/src/PlaylistWindow.cs	2007-08-03 19:44:43.000000000 -0300
+++ muine/src/PlaylistWindow.cs	2007-08-03 19:54:22.000000000 -0300
@@ -20,6 +20,7 @@
 using System;
 using System.Collections;
 using System.IO;
+using System.Threading;
 
 using Gtk;
 using GLib;
@@ -51,6 +52,14 @@
 		//	Seconds over which to show remaining time in minutes
 		private const int MinShowMinutes = 60;
 		
+		// Constants :: MaxClickTime
+		//  Milliseconds for start forwarding/backwarding the song
+		private const int MaxClickTime = 1000;
+
+		// Constants :: RepeatSkipTime
+		//  Milliseconds to wait between each forwarding/backwarding when the button is pressed
+		private const int RepeatSkipTime = 500;
+		
 		// GConf
 		// GConf :: Width
 		private const string GConfKeyWidth = "/apps/muine/playlist_window/width";
@@ -230,6 +239,7 @@
 		private Hashtable random_sort_keys;
 
 		private bool repeat;
+		private AdvanceState skip_state;
 
 		// Constructor
 		public PlaylistWindow () : base (WindowType.Toplevel)
@@ -863,8 +873,10 @@
 		{
 			// Callbacks
 			toggle_play_button.Clicked += OnTogglePlayButtonClicked;
-			previous_button   .Clicked += OnPreviousButtonClicked;
-			next_button       .Clicked += OnNextButtonClicked;
+			previous_button   .Pressed  += OnPreviousButtonPressed;
+			previous_button   .Released += OnPreviousButtonReleased;	
+			next_button	  .Pressed  += OnNextButtonPressed;
+			next_button	  .Released += OnNextButtonReleased;			
 			add_song_button   .Clicked += OnAddSongButtonClicked;
 			add_album_button  .Clicked += OnAddAlbumButtonClicked;
 
@@ -2128,18 +2140,52 @@
 			Playing = toggle_play_button.Active;
 		}
 		
-		// Handlers :: OnPreviousButtonClicked
-		private void OnPreviousButtonClicked (object o, EventArgs args)
+		// Handlers :: OnNextButtonPressed
+		private void OnNextButtonPressed (object o, EventArgs args)
 		{
-			Previous ();
+			this.skip_state = new AdvanceState ();
+			TimerCallback forwardCallback = new TimerCallback (ChangeStateAndForward);
+			Timer skip_timer = new Timer (forwardCallback, null, MaxClickTime, RepeatSkipTime);
+			this.skip_state.timer = skip_timer;
 		}
 		
-		// Handlers :: OnNextButtonClicked
-		private void OnNextButtonClicked (object o, EventArgs args)
+		// Handlers :: OnNextButtonReleased
+		private void OnNextButtonReleased (object o, EventArgs args)
 		{
+			this.skip_state.timer.Dispose ();
+			if (this.skip_state.change_song)
 			Next ();
 		}
 		
+		private void ChangeStateAndForward (object state)
+		{
+			this.skip_state.change_song = false;
+			SkipForward ();
+		}
+
+		// Handlers :: OnPreviousButtonPressed
+		private void OnPreviousButtonPressed (object o, EventArgs args)
+		{
+			this.skip_state = new AdvanceState ();
+			TimerCallback backwardCallback = new TimerCallback (ChangeStateAndBackward);
+			Timer skip_timer = new Timer (backwardCallback, null, MaxClickTime, RepeatSkipTime);
+			this.skip_state.timer = skip_timer;
+		}
+
+		// Handlers :: OnPreviousButtonReleased
+		private void OnPreviousButtonReleased (object o, EventArgs args)
+		{
+			this.skip_state.timer.Dispose ();
+			if (this.skip_state.change_song)
+				Previous ();
+		}
+
+		private void ChangeStateAndBackward (object state)
+		{
+			this.skip_state.change_song = false;
+			SkipBackwards ();
+		}
+
 		// Handlers :: OnAddSongButtonClicked
 		private void OnAddSongButtonClicked (object o, EventArgs args)
 		{
@@ -2306,5 +2352,11 @@
 			public TreeViewDropPosition Position;
 			public bool                 First   ;
 		}
+		
+		private class AdvanceState
+		{
+			public Timer timer;
+			public bool  change_song = true;
+		}
 	}
 }


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