[Muine] Patch to add DND importing



Hi

Attached is a patch against CVS HEAD that adds the ability to drag a
folder into the Muine main window and have it be imported into Muine.
I'm not totally sure how the best way to do this fully would be, should
there be a "This folder needs to be imported, Yes, No" dialog, or should
it just automatically import like its doing now? Should the newly
imported files be added to the playlist?

There's also a change that I find very useful and it adds a "# of
tracks" text to the Play Album window, which shows how many tracks there
are in each album. Maybe only I find it useful because I have albums
where I didn't rip all the tracks.

iain
? PlaylistWindow.cs.silly
Index: AddAlbumWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/AddAlbumWindow.cs,v
retrieving revision 1.36
diff -u -p -r1.36 AddAlbumWindow.cs
--- AddAlbumWindow.cs	6 May 2004 10:02:12 -0000	1.36
+++ AddAlbumWindow.cs	20 May 2004 23:59:53 -0000
@@ -174,7 +174,7 @@ public class AddAlbumWindow : Window
 		if (album.Performers.Length > 0)
 			performers = String.Format (Muine.Catalog.GetString ("Performed by {0}"), StringUtils.JoinHumanReadable (album.Performers, 2));
 
-		r.Text = album.Name + "\n" + StringUtils.JoinHumanReadable (album.Artists, 3) + "\n\n" + performers;
+		r.Text = album.Name + "\n" + StringUtils.JoinHumanReadable (album.Artists, 3) + "\n" + album.Songs.Count + " " + Muine.Catalog.GetPluralString ("track", "tracks", album.Songs.Count) + "\n" + performers;
 
 		MarkupUtils.CellSetMarkup (r, 0, StringUtils.GetByteLength (album.Name),
 					   false, true, false);
Index: PlaylistWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/PlaylistWindow.cs,v
retrieving revision 1.120
diff -u -p -r1.120 PlaylistWindow.cs
--- PlaylistWindow.cs	9 May 2004 20:16:49 -0000	1.120
+++ PlaylistWindow.cs	20 May 2004 23:59:53 -0000
@@ -90,6 +90,15 @@ public class PlaylistWindow : Window
 	/* Multimedia Key handler */
 	private MmKeys mmkeys;
 
+	/* Drag and drop targets. */
+	private enum TargetType {
+		UriList
+	};
+
+	private static TargetEntry [] drag_entries = new TargetEntry [] {
+		new TargetEntry ("text/uri-list", 0, (uint) TargetType.UriList)
+	};
+
 	public PlaylistWindow () : base (WindowType.Toplevel)
 	{
 		/* build the interface */
@@ -102,6 +111,9 @@ public class PlaylistWindow : Window
 
 		WindowStateEvent += new WindowStateEventHandler (HandleWindowStateEvent);
 		DeleteEvent += new DeleteEventHandler (HandleDeleteEvent);
+		DragDataReceived += new DragDataReceivedHandler (HandleDragDataReceived);
+		Gtk.Drag.DestSet (this, DestDefaults.All,
+				  drag_entries, Gdk.DragAction.Copy);
 
 		/* keep track of window visibility */
 		VisibilityNotifyEvent += new VisibilityNotifyEventHandler (HandleWindowVisibilityNotifyEvent);
@@ -149,6 +161,43 @@ public class PlaylistWindow : Window
 			Main.Iteration ();
 	}
 
+	private void HandleDragDataReceived (object o, DragDataReceivedArgs args)
+	{
+		string data = StringUtils.SelectionDataToString (args.SelectionData);
+		Uri uri;
+		string [] uri_list;
+		string fn;
+
+		switch (args.Info) {
+		case (uint) TargetType.UriList:
+			uri_list = Regex.Split (data, "\r\n");
+			fn = uri_list [0];
+
+			uri = new Uri (fn);
+			
+			if (!(uri.Scheme == "file")) {
+				Drag.Finish (args.Context, false, false, args.Time);
+				return;
+			}
+				
+			break;
+
+		default:
+			Drag.Finish (args.Context, false, false, args.Time);
+			return;
+		}
+
+		DirectoryInfo dinfo = new DirectoryInfo (uri.LocalPath);
+		ProgressWindow pw = new ProgressWindow (this, dinfo.Name);
+		
+		Muine.DB.AddWatchedFolder (dinfo.FullName);
+		HandleDirectory (dinfo, pw);
+		
+		pw.Done ();
+
+		Drag.Finish (args.Context, true, false, args.Time);
+	}
+
 	public void CheckFirstStartUp () 
  	{
 		bool first_start;


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