Skip to content

Commit

Permalink
metadata: Add back cached position values in NemoFile. Be sure to clear
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtwebster committed Jun 19, 2017
1 parent a765074 commit 0948eec
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 46 deletions.
14 changes: 2 additions & 12 deletions libnemo-private/nemo-directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
72 changes: 50 additions & 22 deletions libnemo-private/nemo-file-operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions libnemo-private/nemo-file-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 25 additions & 12 deletions libnemo-private/nemo-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
}

Expand Down
18 changes: 18 additions & 0 deletions src/nemo-icon-view-grid-container.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,13 +901,17 @@ 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;
}

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;

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0948eec

Please sign in to comment.