# HG changeset patch # User Sean Egan # Date 1073962979 0 # Node ID 56b74730715ff85cb243ab9ba335d7bf385611e3 # Parent fb0eab758560c7788bdf3669044955aa316a0f08 [gaim-migrate @ 8790] A drag-and-drop URL patch. It seems to get the drop signal twice, but I'm going to commit this now and fix it later so that Dan can claim the bounty and hopefully have it accepted. committer: Tailor Script diff -r fb0eab758560 -r 56b74730715f COPYRIGHT --- a/COPYRIGHT Tue Jan 13 02:15:46 2004 +0000 +++ b/COPYRIGHT Tue Jan 13 03:02:59 2004 +0000 @@ -107,6 +107,7 @@ Bjoern Voigt Nathan Walp Eric Warmenhoven +Dan Willemsen Jason Willis Matt Wilson Ximian diff -r fb0eab758560 -r 56b74730715f src/gtkconv.c --- a/src/gtkconv.c Tue Jan 13 02:15:46 2004 +0000 +++ b/src/gtkconv.c Tue Jan 13 03:02:59 2004 +0000 @@ -4181,10 +4181,8 @@ G_CALLBACK(conv_dnd_recv), conv); g_signal_connect(G_OBJECT(gtkconv->imhtml), "drag_data_received", G_CALLBACK(conv_dnd_recv), conv); -#if 0 - g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received", - G_CALLBACK(conv_dnd_recv), conv); -#endif +/* g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received", + G_CALLBACK(conv_dnd_recv), conv);*/ /* Setup the container for the tab. */ gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 5); diff -r fb0eab758560 -r 56b74730715f src/gtkimhtml.c --- a/src/gtkimhtml.c Tue Jan 13 02:15:46 2004 +0000 +++ b/src/gtkimhtml.c Tue Jan 13 03:02:59 2004 +0000 @@ -24,6 +24,7 @@ #ifdef HAVE_CONFIG_H #include #endif +#include "util.h" #include "gtkimhtml.h" #include "gtksourceiter.h" #include @@ -63,6 +64,7 @@ static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); void gtk_imhtml_close_tags(GtkIMHtml *imhtml); +static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ @@ -78,6 +80,10 @@ TARGET_TEXT }; +enum { + DRAG_URL +}; + GtkTargetEntry selection_targets[] = { { "text/html", 0, TARGET_HTML }, { "UTF8_STRING", 0, TARGET_UTF8_STRING }, @@ -85,6 +91,12 @@ { "STRING", 0, TARGET_STRING }, { "TEXT", 0, TARGET_TEXT}}; +GtkTargetEntry link_drag_drop_targets[] = { + {"x-url/ftp", 0, DRAG_URL}, + {"x-url/http", 0, DRAG_URL}, + {"text/uri-list", 0, DRAG_URL}, + {"_NETSCAPE_URL", 0, DRAG_URL}}; + static GtkSmileyTree* gtk_smiley_tree_new () { @@ -561,6 +573,12 @@ g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); + + gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, + link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), + GDK_ACTION_COPY); + g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); + #if GTK_CHECK_VERSION(2,2,0) g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); @@ -734,6 +752,35 @@ return FALSE; /* Let clicks go through if we didn't catch anything */ } +static void +gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, + GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) +{ + if(gtk_imhtml_get_editable(imhtml) && sd->data){ + gchar **links; + gchar *link; + + gaim_str_strip_cr(sd->data); + + links = g_strsplit(sd->data, "\n", 0); + while((link = *links++) != NULL){ + if(gaim_str_has_prefix(link, "http://") || + gaim_str_has_prefix(link, "https://") || + gaim_str_has_prefix(link, "ftp://")){ + gtk_imhtml_insert_link(imhtml, link, link); + } else if (link=='\0') { + //Ignore blank lines + } else { + //Special reasons, aka images being put in via other tag, etc. + } + } + + gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); + } else { + gtk_drag_finish(dc, FALSE, FALSE, t); + } +} + /* this isn't used yet static void gtk_smiley_tree_remove (GtkSmileyTree *tree,