From 0948eec26c5ed75ddac22f22e978e0a599bb5651 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Sun, 18 Jun 2017 20:06:41 -0400 Subject: [PATCH] metadata: Add back cached position values in NemoFile. Be sure to clear the timestamp metadata on files being moved/copied to or from the desktop. This ensures the lazy flag operates correctly. With the desktop becoming a separate process, transfers that include position info need to be handled slightly differently, as the old way of just setting metadata and reacting to it from a new container won't work - the file gets debuted in the other process sooner than (or not reliably after, at least) the metadata is written, resulting in inconsistent positioning. --- libnemo-private/nemo-directory.c | 14 +---- libnemo-private/nemo-file-operations.c | 72 ++++++++++++++++++-------- libnemo-private/nemo-file-private.h | 2 + libnemo-private/nemo-file.c | 37 ++++++++----- src/nemo-icon-view-grid-container.c | 18 +++++++ 5 files changed, 97 insertions(+), 46 deletions(-) diff --git a/libnemo-private/nemo-directory.c b/libnemo-private/nemo-directory.c index 1e93d052a..f49e49329 100644 --- a/libnemo-private/nemo-directory.c +++ b/libnemo-private/nemo-directory.c @@ -1412,24 +1412,14 @@ nemo_directory_schedule_position_set (GList *position_setting_list) nemo_file_set_position (file, -1, -1); } - if (item->set) { - nemo_file_set_time_metadata - (file, - NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, - now); - } else { - nemo_file_set_time_metadata - (file, - NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, - UNDEFINED_TIME); - } - if (item->set) { nemo_file_set_monitor_number (file, item->monitor); } else { nemo_file_set_monitor_number (file, -1); } + nemo_file_set_time_metadata (file, NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, UNDEFINED_TIME); + nemo_file_unref (file); } } diff --git a/libnemo-private/nemo-file-operations.c b/libnemo-private/nemo-file-operations.c index 478a1137c..a6b9cdf7f 100644 --- a/libnemo-private/nemo-file-operations.c +++ b/libnemo-private/nemo-file-operations.c @@ -4195,7 +4195,7 @@ copy_move_file (CopyMoveJob *copy_job, gboolean res; int unique_name_nr; gboolean handled_invalid_filename; - gboolean target_is_desktop; + gboolean target_is_desktop, source_is_desktop; job = (CommonJob *)copy_job; @@ -4207,6 +4207,17 @@ copy_move_file (CopyMoveJob *copy_job, target_is_desktop = (copy_job->desktop_location != NULL && g_file_equal (copy_job->desktop_location, dest_dir)); + source_is_desktop = FALSE; + + if (src != NULL) { + GFile *parent = g_file_get_parent (src); + + if (parent != NULL && g_file_equal (copy_job->desktop_location, parent)) { + source_is_desktop = TRUE; + g_object_unref (parent); + } + } + unique_name_nr = 1; /* another file in the same directory might have handled the invalid @@ -4328,13 +4339,11 @@ copy_move_file (CopyMoveJob *copy_job, report_copy_progress (copy_job, source_info, transfer_info); if (debuting_files) { - if (target_is_desktop) { - if (position) { - nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num); - } else { - nemo_file_changes_queue_schedule_position_remove (dest); - } - } + if (target_is_desktop && position) { + nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num); + } else if (source_is_desktop) { + nemo_file_changes_queue_schedule_position_remove (dest); + } g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE)); } @@ -4915,11 +4924,22 @@ move_file_prepare (CopyMoveJob *move_job, GFileCopyFlags flags; MoveFileCopyFallback *fallback; gboolean handled_invalid_filename; - gboolean target_is_desktop; + gboolean target_is_desktop, source_is_desktop; target_is_desktop = (move_job->desktop_location != NULL && g_file_equal (move_job->desktop_location, dest_dir)); + source_is_desktop = FALSE; + + if (src != NULL) { + GFile *parent = g_file_get_parent (src); + + if (parent != NULL && g_file_equal (move_job->desktop_location, parent)) { + source_is_desktop = TRUE; + g_object_unref (parent); + } + } + overwrite = FALSE; handled_invalid_filename = *dest_fs_type != NULL; @@ -4983,12 +5003,10 @@ move_file_prepare (CopyMoveJob *move_job, nemo_file_changes_queue_file_moved (src, dest); - if (target_is_desktop) { - if (position) { - nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num); - } else { - nemo_file_changes_queue_schedule_position_remove (dest); - } + if (target_is_desktop && position) { + nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num); + } else if (source_is_desktop) { + nemo_file_changes_queue_schedule_position_remove (dest); } if (job->undo_info != NULL) { @@ -5344,6 +5362,7 @@ nemo_file_operations_move (GList *files, job = op_job_new (CopyMoveJob, parent_window); job->is_move = TRUE; + job->desktop_location = nemo_get_desktop_location (); job->done_callback = done_callback; job->done_callback_data = done_callback_data; job->files = eel_g_object_list_copy (files); @@ -5442,11 +5461,22 @@ link_file (CopyMoveJob *job, char *primary, *secondary, *details; int response; gboolean handled_invalid_filename; - gboolean target_is_desktop; + gboolean target_is_desktop, source_is_desktop; target_is_desktop = (job->desktop_location != NULL && g_file_equal (job->desktop_location, dest_dir)); + source_is_desktop = FALSE; + + if (src != NULL) { + GFile *parent = g_file_get_parent (src); + + if (parent != NULL && g_file_equal (job->desktop_location, parent)) { + source_is_desktop = TRUE; + g_object_unref (parent); + } + } + common = (CommonJob *)job; count = 0; @@ -5485,12 +5515,10 @@ link_file (CopyMoveJob *job, nemo_file_changes_queue_file_added (dest); - if (target_is_desktop) { - if (position) { - nemo_file_changes_queue_schedule_position_set (dest, *position, common->monitor_num); - } else { - nemo_file_changes_queue_schedule_position_remove (dest); - } + if (target_is_desktop && position) { + nemo_file_changes_queue_schedule_position_set (dest, *position, common->monitor_num); + } else if (source_is_desktop) { + nemo_file_changes_queue_schedule_position_remove (dest); } g_object_unref (dest); diff --git a/libnemo-private/nemo-file-private.h b/libnemo-private/nemo-file-private.h index 5ebccc427..25e35a84e 100644 --- a/libnemo-private/nemo-file-private.h +++ b/libnemo-private/nemo-file-private.h @@ -221,6 +221,8 @@ struct NemoFileDetails time_t free_space_read; /* The time free_space was updated, or 0 for never */ gint desktop_monitor; + gint cached_position_x; + gint cached_position_y; }; typedef struct { diff --git a/libnemo-private/nemo-file.c b/libnemo-private/nemo-file.c index fba4b7d20..5248f5978 100644 --- a/libnemo-private/nemo-file.c +++ b/libnemo-private/nemo-file.c @@ -178,6 +178,8 @@ nemo_file_init (NemoFile *file) file->details = G_TYPE_INSTANCE_GET_PRIVATE ((file), NEMO_TYPE_FILE, NemoFileDetails); file->details->desktop_monitor = -1; + file->details->cached_position_x = -1; + file->details->cached_position_y = -1; nemo_file_clear_info (file); nemo_file_invalidate_extension_info_internal (file); @@ -7571,22 +7573,30 @@ nemo_file_get_position (NemoFile *file, GdkPoint *point) { gint x, y; - char *position_string; - gboolean position_good; - char c; + if (file->details->cached_position_x == -1) { + char *position_string; + gboolean position_good; + char c; - /* Get the current position of this icon from the metadata. */ - position_string = nemo_file_get_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, ""); + /* Get the current position of this icon from the metadata. */ + position_string = nemo_file_get_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, ""); - position_good = sscanf (position_string, " %d , %d %c", &x, &y, &c) == 2; - g_free (position_string); + position_good = sscanf (position_string, " %d , %d %c", &x, &y, &c) == 2; + g_free (position_string); - if (position_good) { - point->x = x; - point->y = y; + if (position_good) { + point->x = x; + point->y = y; + } else { + point->x = -1; + point->y = -1; + } + + file->details->cached_position_x = x; + file->details->cached_position_y = y; } else { - point->x = -1; - point->y = -1; + point->x = file->details->cached_position_x; + point->y = file->details->cached_position_y; } } @@ -7602,6 +7612,9 @@ nemo_file_set_position (NemoFile *file, gint x, gint y) } nemo_file_set_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, NULL, position_string); + file->details->cached_position_x = x; + file->details->cached_position_y = y; + g_free (position_string); } diff --git a/src/nemo-icon-view-grid-container.c b/src/nemo-icon-view-grid-container.c index becb71323..e11a1efc8 100644 --- a/src/nemo-icon-view-grid-container.c +++ b/src/nemo-icon-view-grid-container.c @@ -901,6 +901,8 @@ nemo_icon_view_grid_container_update_icon (NemoIconContainer *container, gboolean embedded_text_needs_loading; gboolean has_open_window; gint scale_factor; + EelIRect old_size, new_size; + gint old_width, new_width; if (icon == NULL) { return; @@ -908,6 +910,8 @@ nemo_icon_view_grid_container_update_icon (NemoIconContainer *container, details = container->details; + nemo_icon_canvas_item_get_icon_canvas_rectangle (icon->item, &old_size); + /* Get the appropriate images for the file. */ icon_size = container->details->forced_icon_size; @@ -967,6 +971,20 @@ nemo_icon_view_grid_container_update_icon (NemoIconContainer *container, nemo_icon_canvas_item_set_image (icon->item, pixbuf); nemo_icon_canvas_item_set_attach_points (icon->item, attach_points, n_attach_points); + nemo_icon_canvas_item_get_icon_canvas_rectangle (icon->item, &new_size); + + old_width = old_size.x1 - old_size.x0; + new_width = new_size.x1 - new_size.x0; + + if (old_width != 0 && old_width != new_width) { + nemo_icon_container_request_update (container, icon->data); + + icon->has_lazy_position = TRUE; + container->details->new_icons = g_list_prepend (container->details->new_icons, icon); + nemo_icon_container_redo_layout (container); + nemo_icon_container_icon_raise (container, icon); + } + /* Let the pixbufs go. */ g_object_unref (pixbuf);