summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2021-07-01 17:31:28 +0200
committerAntónio Fernandes <antoniof@gnome.org>2021-09-03 21:27:29 +0100
commit5de4c1fc74d89135100196d2a069c3797a04fc68 (patch)
tree9136f22aa0c8eaf1047bfbb521c96c548efe7de8
parentc82c31d994656c0cc72d7dde89546fc78da70b96 (diff)
downloadnautilus-5de4c1fc74d89135100196d2a069c3797a04fc68.tar.gz
files-view: Do not copy wallpaper unnecessarily
Previously, when an image was selected as wallpaper it would be copied unconditionally into the "Wallpapers" directory. The image would be copied even if it was already in the "Wallpapers" directory, resulting in copies of the image being created in the same directory. This made it incovenient to potentially store multiple backgrounds in the "Wallpapers" directory and switch between them due to the fact that each wallpaper change would result in the selected image being copied. To avoid this, introduce a check, and only copy the image if its parent is not the "Wallpapers" directory (as determined by `g_file_equal()`). For local files, `g_file_equal()` only compares the absolute paths - at least at the moment. Comparing paths is not enough to decide whether two entities are really the same in the presence of e.g. bind mounts. However, such configuration is arguably a very rare (if not non-existent). Nonetheless, users should not experience any regressions even in that case since when `g_file_equal()` returns a false negative, the old behaviour applies.
-rw-r--r--src/nautilus-files-view.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 17f397322..4e57ae61e 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -6854,26 +6854,38 @@ static void
set_wallpaper_fallback (NautilusFile *file,
gpointer user_data)
{
- g_autofree char *target_uri = NULL;
- GList *uris;
g_autoptr (GFile) target = NULL;
+ g_autofree char *file_uri = NULL;
+ g_autoptr (GFile) file_parent = NULL;
- /* Copy the item to Pictures/Wallpaper (internationalized) since it may be
- * remote. Then set it as the current wallpaper. */
+ /* Copy the item to Pictures/Wallpaper (internationalized),
+ * if it's not already there, since it may be remote.
+ * Then set it as the current wallpaper. */
target = g_file_new_build_filename (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
_("Wallpapers"),
NULL);
g_file_make_directory_with_parents (target, NULL, NULL);
- target_uri = g_file_get_uri (target);
- uris = g_list_prepend (NULL, nautilus_file_get_uri (file));
- nautilus_file_operations_copy_move (uris,
- target_uri,
- GDK_ACTION_COPY,
- GTK_WIDGET (user_data),
- NULL,
- wallpaper_copy_done_callback,
- NULL);
- g_list_free_full (uris, g_free);
+
+ file_parent = nautilus_file_get_parent_location (file);
+ file_uri = nautilus_file_get_uri (file);
+
+ if (!g_file_equal (file_parent, target))
+ {
+ g_autofree char *target_uri = g_file_get_uri (target);
+ g_autoptr (GList) uris = g_list_prepend (NULL, file_uri);
+
+ nautilus_file_operations_copy_move (uris,
+ target_uri,
+ GDK_ACTION_COPY,
+ GTK_WIDGET (user_data),
+ NULL,
+ wallpaper_copy_done_callback,
+ NULL);
+ }
+ else
+ {
+ set_uri_as_wallpaper (file_uri);
+ }
}
static void