From c872e9dc6560b02447d7a0b43c42eb713e59da28 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Mon, 17 Jan 2005 16:52:39 +0000 Subject: [PATCH] 2005-01-17 [colin] 0.9.13cvs36.2 * src/compose.c Fix DnD inserting twice. While at it, add DnD support for text/plain in the body, and add support in the headers. --- ChangeLog-gtk2.claws | 7 +++ PATCHSETS | 1 + configure.ac | 2 +- src/compose.c | 123 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 116 insertions(+), 17 deletions(-) diff --git a/ChangeLog-gtk2.claws b/ChangeLog-gtk2.claws index c9267f294..856147e68 100644 --- a/ChangeLog-gtk2.claws +++ b/ChangeLog-gtk2.claws @@ -1,3 +1,10 @@ +2005-01-17 [colin] 0.9.13cvs36.2 + + * src/compose.c + Fix DnD inserting twice. While at it, + add DnD support for text/plain in the + body, and add support in the headers. + 2005-01-16 [colin] 0.9.13cvs36.1 * ChangeLog diff --git a/PATCHSETS b/PATCHSETS index 9f044ed08..30e5e8a31 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -322,3 +322,4 @@ ( cvs diff -u -r 1.12.2.4 -r 1.12.2.5 src/html.c; cvs diff -u -r 1.16.2.12 -r 1.16.2.13 src/msgcache.c; ) > 0.9.13cvs33.1.patchset ( cvs diff -u -r 1.30.2.7 -r 1.30.2.8 src/prefs_toolbar.c; ) > 0.9.13cvs33.2.patchset ( cvs diff -u -r 1.396.2.19 -r 1.396.2.20 ChangeLog; cvs diff -u -r 1.391.2.19 -r 1.391.2.20 ChangeLog.jp; cvs diff -u -r 1.2504.2.42 -r 1.2504.2.43 ChangeLog.claws; ) > 0.9.13cvs36.1.patchset +( cvs diff -u -r 1.382.2.85 -r 1.382.2.86 src/compose.c; ) > 0.9.13cvs36.2.patchset diff --git a/configure.ac b/configure.ac index 62544efdb..28b7e6e5e 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ INTERFACE_AGE=0 BINARY_AGE=0 EXTRA_VERSION=36 EXTRA_RELEASE= -EXTRA_GTK2_VERSION=.1 +EXTRA_GTK2_VERSION=.2 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION} diff --git a/src/compose.c b/src/compose.c index 3bfee2f2f..47c5ea8e0 100644 --- a/src/compose.c +++ b/src/compose.c @@ -452,7 +452,19 @@ static void compose_insert_drag_received_cb (GtkWidget *widget, guint info, guint time, gpointer user_data); +static void compose_header_drag_received_cb (GtkWidget *widget, + GdkDragContext *drag_context, + gint x, + gint y, + GtkSelectionData *data, + guint info, + guint time, + gpointer user_data); +static gboolean compose_drag_drop (GtkWidget *widget, + GdkDragContext *drag_context, + gint x, gint y, + guint time, gpointer user_data); #if 0 static void to_activated (GtkWidget *widget, Compose *compose); @@ -666,7 +678,9 @@ static GtkItemFactoryEntry compose_entries[] = static GtkTargetEntry compose_mime_types[] = { - {"text/uri-list", 0, 0} + {"text/uri-list", 0, 0}, + {"text/plain", 0, 0}, + {"STRING", 0, 0} }; static gboolean compose_put_existing_to_front(MsgInfo *info) @@ -4445,6 +4459,18 @@ static void compose_create_header_entry(Compose *compose) G_CALLBACK(compose_grab_focus_before_cb), compose); g_signal_connect_after(G_OBJECT(entry), "grab_focus", G_CALLBACK(compose_grab_focus_cb), compose); + + /* email dnd */ + gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types, + sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), + GDK_ACTION_COPY | GDK_ACTION_MOVE); + g_signal_connect(G_OBJECT(entry), "drag_data_received", + G_CALLBACK(compose_header_drag_received_cb), + entry); + g_signal_connect(G_OBJECT(entry), "drag-drop", + G_CALLBACK(compose_drag_drop), + compose); + address_completion_register_entry(GTK_ENTRY(entry)); headerentry->compose = compose; @@ -4662,11 +4688,15 @@ GtkWidget *compose_create_attach(Compose *compose) /* drag and drop */ gtk_drag_dest_set(attach_clist, - GTK_DEST_DEFAULT_ALL, compose_mime_types, 1, + GTK_DEST_DEFAULT_ALL, compose_mime_types, + sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect(G_OBJECT(attach_clist), "drag_data_received", G_CALLBACK(compose_attach_drag_received_cb), compose); + g_signal_connect(G_OBJECT(attach_clist), "drag-drop", + G_CALLBACK(compose_drag_drop), + compose); compose->attach_scrwin = attach_scrwin; compose->attach_clist = attach_clist; @@ -4940,11 +4970,15 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode) G_CALLBACK(text_inserted), compose); /* drag and drop */ - gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1, + gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, + sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect(G_OBJECT(text), "drag_data_received", G_CALLBACK(compose_insert_drag_received_cb), compose); + g_signal_connect(G_OBJECT(text), "drag-drop", + G_CALLBACK(compose_drag_drop), + compose); gtk_widget_show_all(vbox); /* pane between attach clist and text */ @@ -7132,15 +7166,27 @@ static void compose_attach_drag_received_cb (GtkWidget *widget, { Compose *compose = (Compose *)user_data; GList *list, *tmp; + + if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) { + list = uri_list_extract_filenames((const gchar *)data->data); + for (tmp = list; tmp != NULL; tmp = tmp->next) + compose_attach_append + (compose, (const gchar *)tmp->data, + (const gchar *)tmp->data, NULL); + if (list) compose_changed_cb(NULL, compose); + list_free_strings(list); + g_list_free(list); + } +} - list = uri_list_extract_filenames((const gchar *)data->data); - for (tmp = list; tmp != NULL; tmp = tmp->next) - compose_attach_append - (compose, (const gchar *)tmp->data, - (const gchar *)tmp->data, NULL); - if (list) compose_changed_cb(NULL, compose); - list_free_strings(list); - g_list_free(list); +static gboolean compose_drag_drop(GtkWidget *widget, + GdkDragContext *drag_context, + gint x, gint y, + guint time, gpointer user_data) +{ + /* not handling this signal makes compose_insert_drag_received_cb + * called twice */ + return TRUE; } static void compose_insert_drag_received_cb (GtkWidget *widget, @@ -7155,11 +7201,56 @@ static void compose_insert_drag_received_cb (GtkWidget *widget, Compose *compose = (Compose *)user_data; GList *list, *tmp; - list = uri_list_extract_filenames((const gchar *)data->data); - for (tmp = list; tmp != NULL; tmp = tmp->next) - compose_insert_file(compose, (const gchar *)tmp->data); - list_free_strings(list); - g_list_free(list); + /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE) + * does not work */ + if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) { + list = uri_list_extract_filenames((const gchar *)data->data); + for (tmp = list; tmp != NULL; tmp = tmp->next) { + compose_insert_file(compose, (const gchar *)tmp->data); + } + list_free_strings(list); + g_list_free(list); + gtk_drag_finish(drag_context, TRUE, FALSE, time); + return; + } else { + gchar *tmpfile = get_tmp_file(); + str_write_to_file((const gchar *)data->data, tmpfile); + compose_insert_file(compose, tmpfile); + unlink(tmpfile); + g_free(tmpfile); + gtk_drag_finish(drag_context, TRUE, FALSE, time); + return; + } + gtk_drag_finish(drag_context, TRUE, FALSE, time); +} + +static void compose_header_drag_received_cb (GtkWidget *widget, + GdkDragContext *drag_context, + gint x, + gint y, + GtkSelectionData *data, + guint info, + guint time, + gpointer user_data) +{ + GtkEditable *entry = (GtkEditable *)user_data; + gchar *email = (gchar *)data->data; + + /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE) + * does not work */ + + if (!strncmp(email, "mailto:", strlen("mailto:"))) { + gchar decoded[strlen(email)]; + int start = 0; + + email += strlen("mailto:"); + decode_uri(decoded, email); /* will fit */ + gtk_editable_delete_text(entry, 0, -1); + gtk_editable_insert_text(entry, decoded, strlen(decoded), &start); + gtk_drag_finish(drag_context, TRUE, FALSE, time); + return; + } + gtk_drag_finish(drag_context, TRUE, FALSE, time); } #if 0 /* NEW COMPOSE GUI */ -- 2.25.1