diff options
author | Milan Crha <mcrha@redhat.com> | 2022-06-01 22:17:53 +0200 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2022-06-01 22:18:44 +0200 |
commit | f498b9ccaa9c7061e809e0f530c209e102fd02c4 (patch) | |
tree | 7563c62fdb10a322fbe08fba8f86a3825c04c8ee | |
parent | cf74639d52dbab0a4eea53ca59f71e343247e3a1 (diff) | |
download | evolution-f498b9ccaa9c7061e809e0f530c209e102fd02c4.tar.gz |
I#1919 - Drag&Drop creates many identical temporary files
Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1919
-rw-r--r-- | src/e-util/e-attachment-view.c | 14 | ||||
-rw-r--r-- | src/mail/em-folder-tree.c | 2 | ||||
-rw-r--r-- | src/mail/em-utils.c | 29 | ||||
-rw-r--r-- | src/mail/em-utils.h | 2 | ||||
-rw-r--r-- | src/mail/message-list.c | 2 |
5 files changed, 41 insertions, 8 deletions
diff --git a/src/e-util/e-attachment-view.c b/src/e-util/e-attachment-view.c index da89238e3f..210fad648e 100644 --- a/src/e-util/e-attachment-view.c +++ b/src/e-util/e-attachment-view.c @@ -1674,6 +1674,13 @@ e_attachment_view_drag_data_get (EAttachmentView *view, g_return_if_fail (GDK_IS_DRAG_CONTEXT (context)); g_return_if_fail (selection != NULL); + status.uris = g_object_get_data (G_OBJECT (context), "evo-attach-urilist"); + + if (status.uris) { + gtk_selection_data_set_uris (selection, status.uris); + return; + } + status.uris = NULL; status.done = FALSE; @@ -1693,10 +1700,13 @@ e_attachment_view_drag_data_get (EAttachmentView *view, if (gtk_main_iteration ()) break; - if (status.uris != NULL) + if (status.uris) { gtk_selection_data_set_uris (selection, status.uris); - g_strfreev (status.uris); + /* Remember it, to not regenerate it, when the target widget asks for the data again */ + g_object_set_data_full (G_OBJECT (context), "evo-attach-urilist", + status.uris, (GDestroyNotify) g_strfreev); + } } void diff --git a/src/mail/em-folder-tree.c b/src/mail/em-folder-tree.c index 6583489f24..8fc3fa8437 100644 --- a/src/mail/em-folder-tree.c +++ b/src/mail/em-folder-tree.c @@ -2149,7 +2149,7 @@ tree_drag_data_get (GtkWidget *widget, GPtrArray *uids = camel_folder_get_uids (folder); - em_utils_selection_set_urilist (selection, folder, uids); + em_utils_selection_set_urilist (context, selection, folder, uids); camel_folder_free_uids (folder, uids); g_object_unref (folder); } diff --git a/src/mail/em-utils.c b/src/mail/em-utils.c index 876fce7f4e..e149100aaa 100644 --- a/src/mail/em-utils.c +++ b/src/mail/em-utils.c @@ -964,6 +964,7 @@ em_utils_build_export_basename (CamelFolder *folder, /** * em_utils_selection_set_urilist: + * @context: * @data: * @folder: * @uids: @@ -973,7 +974,8 @@ em_utils_build_export_basename (CamelFolder *folder, * up when the application quits. **/ void -em_utils_selection_set_urilist (GtkSelectionData *data, +em_utils_selection_set_urilist (GdkDragContext *context, + GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids) { @@ -993,6 +995,20 @@ em_utils_selection_set_urilist (GtkSelectionData *data, if (!uids->len) return; + /* Use cached value from the last call, if exists */ + tmpdir = g_object_get_data (G_OBJECT (context), "evo-urilist"); + if (tmpdir) { + GdkAtom type; + + type = gtk_selection_data_get_target (data); + gtk_selection_data_set ( + data, type, 8, + (guchar *) tmpdir, + strlen (tmpdir)); + + return; + } + tmpdir = e_mkdtemp ("drag-n-drop-XXXXXX"); if (tmpdir == NULL) return; @@ -1052,7 +1068,9 @@ em_utils_selection_set_urilist (GtkSelectionData *data, data, type, 8, (guchar *) uri_crlf, strlen (uri_crlf)); - g_free (uri_crlf); + + /* Remember it, to not regenerate it, when the target widget asks for the data again */ + g_object_set_data_full (G_OBJECT (context), "evo-urilist", uri_crlf, g_free); } g_object_unref (fstream); } else @@ -1102,7 +1120,12 @@ em_utils_selection_set_urilist (GtkSelectionData *data, g_free (filename); } - gtk_selection_data_set_uris (data, uris); + if (gtk_selection_data_set_uris (data, uris)) { + /* Remember it, to not regenerate it, when the target widget asks for the data again */ + g_object_set_data_full (G_OBJECT (context), "evo-urilist", + g_strndup ((const gchar *) gtk_selection_data_get_data (data), gtk_selection_data_get_length (data)), + g_free); + } g_strfreev (uris); } diff --git a/src/mail/em-utils.h b/src/mail/em-utils.h index e000ef43d6..dedf83b84b 100644 --- a/src/mail/em-utils.h +++ b/src/mail/em-utils.h @@ -55,7 +55,7 @@ void em_utils_selection_get_mailbox (GtkSelectionData *data, CamelFolder *folder void em_utils_selection_get_message (GtkSelectionData *data, CamelFolder *folder); void em_utils_selection_set_uidlist (GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids); void em_utils_selection_get_uidlist (GtkSelectionData *data, EMailSession *session, CamelFolder *dest, gint move, GCancellable *cancellable, GError **error); -void em_utils_selection_set_urilist (GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids); +void em_utils_selection_set_urilist (GdkDragContext *context, GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids); void em_utils_selection_get_urilist (GtkSelectionData *data, CamelFolder *folder); /* Return TRUE to continue, FALSE to stop further processing */ diff --git a/src/mail/message-list.c b/src/mail/message-list.c index d60c064c20..51e3fd79e0 100644 --- a/src/mail/message-list.c +++ b/src/mail/message-list.c @@ -2627,7 +2627,7 @@ ml_tree_drag_data_get (ETree *tree, em_utils_selection_set_uidlist (data, folder, uids); break; case DND_TEXT_URI_LIST: - em_utils_selection_set_urilist (data, folder, uids); + em_utils_selection_set_urilist (context, data, folder, uids); break; } } |