[Muine] Drag 'n' drop for album covers



The patch linked below enables drag 'n' drop of album covers to the Add
Album dialog.

I'm not sure whether the code I've added should check the drop type or
not (Drag 'n' drop confuses me!)

http://www.leewillis.co.uk/muine/dnd.patch

Thanks
Lee
Index: libmuine/pointer-list-view.c
===================================================================
RCS file: /cvs/gnome/muine/libmuine/pointer-list-view.c,v
retrieving revision 1.22
diff -u -r1.22 pointer-list-view.c
--- libmuine/pointer-list-view.c	26 Feb 2004 12:39:12 -0000	1.22
+++ libmuine/pointer-list-view.c	7 Apr 2004 20:59:56 -0000
@@ -206,7 +206,7 @@
 		CellDataFuncData *data)
 {
 	data->func (data->view, cell,
-	            pointer_list_model_get_pointer ((PointerListModel *) model, iter));
+		    pointer_list_model_get_pointer ((PointerListModel *) model, iter));
 }
 
 void
@@ -286,6 +286,18 @@
 	return pointer_list_model_get_pointers (view->model);
 }
 
+gpointer 
+pointer_list_get_handle_from_path (PointerListView *view, 
+		                   GtkTreePath *path)
+{
+	GtkTreeIter iter;
+
+	gtk_tree_model_get_iter ((GtkTreeModel *) view->model,
+				 &iter, path);
+
+	return pointer_list_model_get_pointer (view->model, &iter);
+}
+
 int
 pointer_list_view_get_length (PointerListView *view)
 {
Index: libmuine/pointer-list-view.h
===================================================================
RCS file: /cvs/gnome/muine/libmuine/pointer-list-view.h,v
retrieving revision 1.13
diff -u -r1.13 pointer-list-view.h
--- libmuine/pointer-list-view.h	26 Feb 2004 12:39:12 -0000	1.13
+++ libmuine/pointer-list-view.h	7 Apr 2004 20:59:56 -0000
@@ -36,14 +36,14 @@
 
 struct _PointerListView
 {
-  GtkTreeView parent;
-  PointerListModel *model;
-  GList *data;
+	GtkTreeView parent;
+	PointerListModel *model;
+	GList *data;
 };
 
 struct _PointerListViewClass
 {
-  GtkTreeViewClass parent_class;
+	GtkTreeViewClass parent_class;
 };
 
 typedef void (*CellDataFunc) (PointerListView *view,
@@ -53,44 +53,46 @@
 GType            pointer_list_view_get_type      (void);
 PointerListView *pointer_list_view_new           (void);
 
-void             pointer_list_view_add_column    (PointerListView *view,
-						  GtkCellRenderer *renderer,
-						  CellDataFunc func,
-						  gboolean expand);
-void             pointer_list_view_append        (PointerListView *view,
-				                  gpointer pointer);
-void             pointer_list_view_changed       (PointerListView *view,
-			                          gpointer pointer);
-void             pointer_list_view_remove        (PointerListView *view,
-			                          gpointer pointer);
-void             pointer_list_view_remove_delta  (PointerListView *view,
-				                  GList *delta);
-void             pointer_list_view_clear         (PointerListView *view);
-GList *          pointer_list_view_get_contents  (PointerListView *view);
-int              pointer_list_view_get_length    (PointerListView *view);
-gboolean         pointer_list_view_contains      (PointerListView *view,
-				                  gpointer pointer);
-GList *          pointer_list_view_get_selection (PointerListView *view);
-void             pointer_list_view_select_first  (PointerListView *view);
-gboolean         pointer_list_view_select_next   (PointerListView *view,
-						  gboolean center,
-						  gboolean scroll);
-gboolean         pointer_list_view_select_prev   (PointerListView *view,
-						  gboolean center,
-						  gboolean scroll);
-void             pointer_list_view_select        (PointerListView *view,
-						  gpointer pointer);
-void             pointer_list_view_set_sort_func (PointerListView *view,
-				                  GCompareFunc sort_func);
-void             pointer_list_view_set_playing   (PointerListView *view,
-				                  gpointer pointer);
-gpointer         pointer_list_view_get_playing   (PointerListView *view);
-gboolean         pointer_list_view_has_first     (PointerListView *view);
-gboolean         pointer_list_view_has_prev      (PointerListView *view);
-gboolean         pointer_list_view_has_next      (PointerListView *view);
-gpointer         pointer_list_view_first         (PointerListView *view);
-gpointer	 pointer_list_view_last		 (PointerListView *view);
-gpointer         pointer_list_view_prev          (PointerListView *view);
-gpointer         pointer_list_view_next          (PointerListView *view);
+void             pointer_list_view_add_column      (PointerListView *view,
+						    GtkCellRenderer *renderer,
+						    CellDataFunc func,
+						    gboolean expand);
+void             pointer_list_view_append          (PointerListView *view,
+				                    gpointer pointer);
+void             pointer_list_view_changed         (PointerListView *view,
+			                            gpointer pointer);
+void             pointer_list_view_remove          (PointerListView *view,
+			                            gpointer pointer);
+void             pointer_list_view_remove_delta    (PointerListView *view,
+				                    GList *delta);
+void             pointer_list_view_clear           (PointerListView *view);
+GList *          pointer_list_view_get_contents    (PointerListView *view);
+gpointer	 pointer_list_get_handle_from_path (PointerListView *view,
+						    GtkTreePath *path);
+int              pointer_list_view_get_length      (PointerListView *view);
+gboolean         pointer_list_view_contains        (PointerListView *view,
+				                    gpointer pointer);
+GList *          pointer_list_view_get_selection   (PointerListView *view);
+void             pointer_list_view_select_first    (PointerListView *view);
+gboolean         pointer_list_view_select_next     (PointerListView *view,
+						    gboolean center,
+						    gboolean scroll);
+gboolean         pointer_list_view_select_prev     (PointerListView *view,
+						    gboolean center,
+						    gboolean scroll);
+void             pointer_list_view_select          (PointerListView *view,
+						    gpointer pointer);
+void             pointer_list_view_set_sort_func   (PointerListView *view,
+				                    GCompareFunc sort_func);
+void             pointer_list_view_set_playing     (PointerListView *view,
+				                    gpointer pointer);
+gpointer         pointer_list_view_get_playing     (PointerListView *view);
+gboolean         pointer_list_view_has_first       (PointerListView *view);
+gboolean         pointer_list_view_has_prev        (PointerListView *view);
+gboolean         pointer_list_view_has_next        (PointerListView *view);
+gpointer         pointer_list_view_first           (PointerListView *view);
+gpointer	 pointer_list_view_last		   (PointerListView *view);
+gpointer         pointer_list_view_prev            (PointerListView *view);
+gpointer         pointer_list_view_next            (PointerListView *view);
 
 #endif /* __POINTER_LIST_VIEW_H__ */
Index: src/AddAlbumWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/AddAlbumWindow.cs,v
retrieving revision 1.30
diff -u -r1.30 AddAlbumWindow.cs
--- src/AddAlbumWindow.cs	27 Feb 2004 21:29:06 -0000	1.30
+++ src/AddAlbumWindow.cs	7 Apr 2004 20:59:56 -0000
@@ -44,6 +44,17 @@
 	private CellRenderer pixbuf_renderer;
 	private Gdk.Pixbuf nothing_pixbuf;
 	
+	private enum TargetType {
+		UriList,
+		Uri
+	}
+
+	private static TargetEntry [] cover_drag_entries = new TargetEntry [] {
+		new TargetEntry ("text/uri-list", 0, (uint) TargetType.UriList),
+		new TargetEntry ("x-special/gnome-icon-list", 0, (uint) TargetType.UriList),
+		new TargetEntry ("_NETSCAPE_URL", 0, (uint) TargetType.Uri)
+	};
+
 	public AddAlbumWindow ()
 	{
 		Glade.XML gxml = new Glade.XML (null, "AddWindow.glade", "window", null);
@@ -101,6 +112,11 @@
 		foreach (Album a in Muine.DB.Albums.Values) 
 			view.Append (a.Handle);
 		view.SelectFirst ();
+
+		DragDataReceived += new DragDataReceivedHandler (HandleDragDataReceived);
+		DragMotion+= new DragMotionHandler (HandleDragMotion);
+		Gtk.Drag.DestSet (this, DestDefaults.All,
+				  cover_drag_entries, Gdk.DragAction.Copy);
 	}
 
 	public void Run ()
@@ -303,4 +319,32 @@
 
 		SelectFirstIfNeeded ();
 	}
+
+	private void HandleDragDataReceived (object o, DragDataReceivedArgs args)
+	{
+		Album album;
+		IntPtr album_ptr;
+		CoverImage cover_image;
+		TreePath path = new TreePath();
+
+		view.GetPathAtPos(args.X, args.Y, out path, null);
+
+		album_ptr = view.GetHandleFromPath (path);
+		album = Album.FromHandle (album_ptr);
+
+		cover_image = new CoverImage ();
+		cover_image.Song = (Song) album.Songs [0];
+		cover_image.HandleDragDataReceived (cover_image, args);
+
+		Drag.Finish (args.Context, true, false, args.Time);
+	}
+
+	private void HandleDragMotion(object o, DragMotionArgs args)
+	{
+		TreePath path = new TreePath();
+
+		view.GetPathAtPos (args.X, args.Y, out path, null);
+		view.SetDragDestRow (path, Gtk.TreeViewDropPosition.IntoOrAfter);
+		return ;
+	}
 }
Index: src/CoverImage.cs
===================================================================
RCS file: /cvs/gnome/muine/src/CoverImage.cs,v
retrieving revision 1.4
diff -u -r1.4 CoverImage.cs
--- src/CoverImage.cs	27 Feb 2004 21:29:06 -0000	1.4
+++ src/CoverImage.cs	7 Apr 2004 20:59:56 -0000
@@ -75,7 +75,7 @@
 		}
 	}
 
-	private void HandleDragDataReceived (object o, DragDataReceivedArgs args)
+	public void HandleDragDataReceived (object o, DragDataReceivedArgs args)
 	{
 		string data = StringUtils.SelectionDataToString (args.SelectionData);
 
Index: src/HandleView.cs
===================================================================
RCS file: /cvs/gnome/muine/src/HandleView.cs,v
retrieving revision 1.17
diff -u -r1.17 HandleView.cs
--- src/HandleView.cs	26 Feb 2004 10:46:10 -0000	1.17
+++ src/HandleView.cs	7 Apr 2004 20:59:56 -0000
@@ -152,6 +152,14 @@
 	}
 
 	[DllImport ("libmuine")]
+	private static extern IntPtr pointer_list_get_handle_from_path (IntPtr view,
+			                                                IntPtr path);
+
+	public IntPtr GetHandleFromPath (TreePath path) {
+		return pointer_list_get_handle_from_path (Raw, path.Handle);
+	}
+
+	[DllImport ("libmuine")]
 	private static extern int pointer_list_view_get_length (IntPtr view);
 
 	public int Length {


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