changeset 9495:960e3fd1da94

[gaim-migrate @ 10321] I think this all works. Test it for me. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 09 Jul 2004 22:33:06 +0000
parents 42d6650bcdac
children 27a595d413ff
files ChangeLog src/gtkblist.c src/gtkconv.c
diffstat 3 files changed, 65 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jul 09 13:41:15 2004 +0000
+++ b/ChangeLog	Fri Jul 09 22:33:06 2004 +0000
@@ -3,6 +3,8 @@
 version 0.80cvs:
 	New Features:
 	* Ability to send files from the conversation window (Daniel Atallah)
+	* Drag a file into the buddy list or a conversation to send it to that
+	  buddy
 	* Yet more new commands and features for SILC (Stu Tomlinson)
 	* Gaim uses the new file chooser when compiled for GTK+ 2.4
 	  (Fernando Herrera)
--- a/src/gtkblist.c	Fri Jul 09 13:41:15 2004 +0000
+++ b/src/gtkblist.c	Fri Jul 09 22:33:06 2004 +0000
@@ -2004,6 +2004,41 @@
 		result = parse_vcard(sd->data, group);
 
 		gtk_drag_finish(dc, result, (dc->action == GDK_ACTION_MOVE), t);
+	} else if (sd->target == gdk_atom_intern("text/plain", FALSE) && sd->data) {
+		GtkTreePath *path = NULL;
+		GtkTreeViewDropPosition position;
+
+		if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget),
+						      x, y, &path, &position))
+			{
+				GtkTreeIter iter;
+				GaimBlistNode *node;
+				GValue val = {0};
+				
+				gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel),
+							&iter, path);
+				gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel),
+							  &iter, NODE_COLUMN, &val);
+				node = g_value_get_pointer(&val);
+				
+				if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CONTACT(node)) {
+					GaimBuddy *b = GAIM_BLIST_NODE_IS_BUDDY(node) ? (GaimBuddy*)node : gaim_contact_get_priority_buddy((GaimContact*)node);
+					if (!g_ascii_strncasecmp(sd->data, "file://", 7)) {
+						GError *converr = NULL;
+						gchar *file;
+						if(!(file = g_filename_from_uri(sd->data, NULL, &converr))) {
+							gaim_debug(GAIM_DEBUG_ERROR, "conv dnd", "%s\n",
+								   (converr ? converr->message :
+								    "g_filename_from_uri error"));
+							return;
+						}
+						file = g_strchomp(file);
+						/* XXX - Handle dragging more than one file.  Make ft API support creating a transfer with more than one file */
+						serv_send_file(gaim_account_get_connection(b->account), b->name, file);
+						g_free(file);
+					}
+				}
+			}	
 	}
 }
 
@@ -2966,7 +3001,7 @@
 	}
 }
 
-enum {DRAG_BUDDY, DRAG_ROW, DRAG_VCARD};
+enum {DRAG_BUDDY, DRAG_ROW, DRAG_VCARD, DRAG_TEXT, NUM_TARGETS};
 
 static char *
 item_factory_translate_func (const char *path, gpointer func_data)
@@ -3006,7 +3041,8 @@
 	GtkTreeSelection *selection;
 	GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW},
 				{"application/x-im-contact", 0, DRAG_BUDDY},
-				{"text/x-vcard", 0, DRAG_VCARD }};
+				{"text/x-vcard", 0, DRAG_VCARD },
+	                        {"text/plain", 0, DRAG_TEXT}};
 
 	if (gtkblist && gtkblist->window) {
 		gtk_widget_show(gtkblist->window);
@@ -3076,11 +3112,11 @@
 
 	/* Set up dnd */
 	gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview),
-										   GDK_BUTTON1_MASK, gte, 3,
-										   GDK_ACTION_COPY);
+					       GDK_BUTTON1_MASK, gte, NUM_TARGETS,
+					       GDK_ACTION_COPY);
 	gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview),
-										 gte, 3,
-										 GDK_ACTION_COPY | GDK_ACTION_MOVE);
+					     gte, NUM_TARGETS,
+					     GDK_ACTION_COPY | GDK_ACTION_MOVE);
 
   	g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL);
 	g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL);
--- a/src/gtkconv.c	Fri Jul 09 13:41:15 2004 +0000
+++ b/src/gtkconv.c	Fri Jul 09 22:33:06 2004 +0000
@@ -4365,7 +4365,27 @@
 
 		gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
 	}
-		gtk_drag_finish(dc, FALSE, FALSE, t);
+	else if (sd->target == gdk_atom_intern("text/plain", FALSE)) {
+		if (!g_ascii_strncasecmp(sd->data, "file://", 7)) {
+			GError *converr = NULL;
+			gchar *file;
+			if(!(file = g_filename_from_uri(sd->data, NULL, &converr))) {
+				gaim_debug(GAIM_DEBUG_ERROR, "conv dnd", "%s\n",
+					   (converr ? converr->message :
+					    "g_filename_from_uri error"));
+				return;
+			}
+			file = g_strchomp(file);
+			/* XXX - Handle dragging more than one file.  Make ft API support creating a transfer with more than one file */
+			/* XXX - Attempt to load this file into gdk_pixbuf, or otherwise determine if it is an image.  If it is, offer
+			 * the choice of a) sending this file b) inserting this file as an IM image or c) setting this file as a custom
+			 * buddy icon for this buddy */
+			if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
+				serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), file);
+			g_free(file);
+		}
+	}
+	gtk_drag_finish(dc, FALSE, FALSE, t);
 }
 
 /**************************************************************************