[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmms-devel
Subject:    [xmms-devel] Dnd in the playlist window
From:       Philip Van Hoof <spamfrommailing () freax ! org>
Date:       2004-02-06 0:15:03
Message-ID: 1076026503.5813.16.camel () pluisje
[Download RAW message or body]

Hi there fellow geeks,

Somebody should have done this a long time ago, however :-)

This patch adds drag and drop support to the playlistwin

When holding control you can also drag and drop multiple songs from the
playlist to for example nautilus.

ps. Please please do add this in some release, I would like to use "yum
install xmms" and not have to patch it's sources for this dnd support
:)!

I even don't care about author credits or somebody changing this patch
or rewriting it so that it 'fits better' in the code or whatever, just
make sure that I can drag an mp3 from xmms to for example nautilus (this
patch does that). I REALLYYY need that feature!! :-), Yeah REAALLYY. I
tried waiting for another mp3-player that does that and just "WORKS"
just like xmms just "works". And well, the result is that (after waiting
some years) I started doing this patch myself, damned .. hehe


What are you waiting for? And stop reading my b*llshit! commit!! :-)


-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
work: Philip dot VanHoof at cronos dot be
http://www.freax.be, http://www.freax.eu.org

["xmms_playlistwin_dnd_support.diff" (xmms_playlistwin_dnd_support.diff)]

Index: playlist_list.c
===================================================================
RCS file: /cvs/xmms/xmms/playlist_list.c,v
retrieving revision 1.24
diff -u -r1.24 playlist_list.c
--- playlist_list.c	8 Jun 2003 21:52:02 -0000	1.24
+++ playlist_list.c	6 Feb 2004 00:05:00 -0000
@@ -23,7 +23,6 @@
 #include <wchar.h>
 #endif
 #include <X11/Xatom.h>
-
 static GdkFont *playlist_list_font = NULL;
 
 static int playlist_list_auto_drag_down_func(gpointer data)
@@ -117,6 +116,7 @@
 	if (pl->pl_prev_max != -1)
 		pl->pl_prev_max++;
 }
+
 
 void playlist_list_button_press_cb(GtkWidget * widget, GdkEventButton * event, \
PlayList_List * pl)  {
Index: playlistwin.c
===================================================================
RCS file: /cvs/xmms/xmms/playlistwin.c,v
retrieving revision 1.88
diff -u -r1.88 playlistwin.c
--- playlistwin.c	28 Jan 2004 00:11:25 -0000	1.88
+++ playlistwin.c	6 Feb 2004 00:05:04 -0000
@@ -33,6 +33,17 @@
 static int playlistwin_resizing, playlistwin_resize_x, playlistwin_resize_y;
 static int playlistwin_save_type;
 
+enum {
+        TARGET_PLAIN,
+        TARGET_URILIST,
+};
+static GtkTargetEntry target_table[] = {
+        { "text/uri-list", 0, TARGET_URILIST },
+        { "text/plain",    0, TARGET_PLAIN }
+};
+
+GList *filestodrag = NULL;
+
 gboolean playlistwin_focus = FALSE;
 
 PlayList_List *playlistwin_list = NULL;
@@ -1842,6 +1853,108 @@
 	textbox_set_text(playlistwin_time_sec, text);
 	g_free(text);
 }
+/* Note from dnd author: Kill me, I stole code from the gthumb project ! */
+GString*
+make_url_list (GList    *list,
+               int       target)
+{
+        GList      *scan;
+        GString    *result;
+        const gchar *url_sep="";
+        const gchar *prefix="";
+                                                                                     \
 +        if (list == NULL)
+                return NULL;
+                                                                                     \
 +        switch (target) {
+        case TARGET_PLAIN:
+        case TARGET_URILIST:
+                prefix = "file://";
+                url_sep = "\r\n";
+                break;
+        }
+                                                                                     \
 +        result = g_string_new (NULL);
+        for (scan = list; scan; scan = scan->next) {
+                g_string_append (result, prefix);
+                g_string_append (result, scan->data);
+                g_string_append (result, url_sep);
+        }
+                                                                                     \
 +        return result;
+}
+
+void
+playlistwin_drag_begin (GtkWidget          *widget,
+                     	  GdkDragContext     *context,
+                     	  gpointer            extra_data)
+{                                                                                    \
 +	GList *list;
+
+	PL_LOCK();
+	if ((list = get_playlist()) == NULL)
+	{
+		PL_UNLOCK();
+		return;
+	}
+	if (((PlaylistEntry *) list->data)->selected)
+	{
+		/* We are at the top */
+		PL_UNLOCK();
+		return;
+	}
+	while (list)
+	{
+		if (((PlaylistEntry *) list->data)->selected)
+		{
+			filestodrag = g_list_append (filestodrag, ((PlaylistEntry *) \
list->data)->filename); +		}
+		list = g_list_next(list);
+	}
+	PL_UNLOCK();
+}
+
+void
+playlistwin_drag_end (GtkWidget          *widget,
+                   		GdkDragContext     *context,
+                   		gpointer            extra_data)
+{
+        if (filestodrag != NULL)
+                g_list_free (filestodrag);
+        filestodrag = NULL;
+}
+
+void
+playlistwin_drag_data_get  (GtkWidget        *widget,
+                       		  GdkDragContext   *context,
+                       		  GtkSelectionData *selection_data,
+                       		  guint             info,
+                       		  guint             time,
+                       		  gpointer          data)
+{
+        gint      target_id=0;
+		gchar    *target = gdk_atom_name (selection_data->target);
+		GString *url_list;
+
+        if (strcmp (target, "text/uri-list") == 0)
+                target_id = TARGET_URILIST;
+        else if (strcmp (target, "text/plain") == 0)
+                target_id = TARGET_PLAIN;
+        g_free (target);
+                                                                                     \
 +        url_list = make_url_list (filestodrag, target_id);
+
+        if (url_list == NULL)
+                return;
+
+        gtk_selection_data_set (selection_data,
+                                selection_data->target,
+                                8,
+                                url_list->str,
+                                url_list->len);
+
+        g_string_free (url_list, TRUE);
+}
 
 static void playlistwin_drag_data_received(GtkWidget * widget,
 					   GdkDragContext * context,
@@ -1946,8 +2059,23 @@
 	gtk_signal_connect(GTK_OBJECT(playlistwin), "key-press-event", \
GTK_SIGNAL_FUNC(playlistwin_keypress), NULL);  \
gtk_signal_connect(GTK_OBJECT(playlistwin), "selection_received", \
GTK_SIGNAL_FUNC(selection_received), NULL);  
+	gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_begin", \
GTK_SIGNAL_FUNC(playlistwin_drag_begin), NULL); \
+	gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_end", \
GTK_SIGNAL_FUNC(playlistwin_drag_end), NULL); \
+	gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_data_get", \
GTK_SIGNAL_FUNC(playlistwin_drag_data_get), NULL); +
 	if (!cfg.show_wm_decorations)
 		gdk_window_set_decorations(playlistwin->window, 0);
+	
+	gtk_drag_dest_set (GTK_WIDGET(playlistwin),
+                           GTK_DEST_DEFAULT_ALL,
+                           target_table, 2,
+                           GDK_ACTION_COPY);
+	
+	gtk_drag_source_set (GTK_WIDGET(playlistwin),
+                             GDK_BUTTON1_MASK,
+                             target_table, 2,
+                             GDK_ACTION_MOVE | GDK_ACTION_COPY);
+
 
 	gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0);
 	playlistwin_create_mask();



_______________________________________________
xmms-devel mailing list
xmms-devel@lists.xmms.org
http://lists.xmms.org/mailman/listinfo/xmms-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic