[nautilus/gnome-3-22] general: only set icon position metadata when in desktop



commit 9b686c807f0a0db990f992f25fff7af33ea816d0
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Dec 9 22:23:06 2016 +0100

    general: only set icon position metadata when in desktop
    
    We were setting the icon position metadata for any operation in any file
    due to legacy code where nautilus was able to have a
    freedom-of-placement canvas in the regular windows.
    
    However that changed and we can only have freedom-of-placement in the
    desktop window.
    
    Setting the metadata is a extremely expensive operation, and was causing
    issues, outlined in https://bugzilla.gnome.org/show_bug.cgi?id=757747,
    summarizing copy and move operations where really slow when using drag
    and drop, operations when we need to store the icon position when using
    a freedom-of-placement canvas view.
    
    This patch tries to only set the metadata when necessary, which is when
    using the desktop window. However the code is pretty integrated with the
    rest of Nautilus, so the patch was able to isolate the part when the
    metadata is set and only provide metadata when the target is the desktop.
    However, for unsetting the metadata the patch need to check if it's
    the desktop inside the file-operations, which is less than ideal.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=775910

 src/nautilus-canvas-dnd.c      |   11 +++++++----
 src/nautilus-file-operations.c |   16 ++++++++++++----
 src/nautilus-file.c            |   24 ++++++++++++++++++++++++
 src/nautilus-file.h            |    1 +
 src/nautilus-files-view-dnd.c  |   19 ++++++++++++-------
 src/nautilus-files-view.c      |   20 ++++++++++++++------
 6 files changed, 70 insertions(+), 21 deletions(-)
---
diff --git a/src/nautilus-canvas-dnd.c b/src/nautilus-canvas-dnd.c
index 27d6aac..338b61d 100644
--- a/src/nautilus-canvas-dnd.c
+++ b/src/nautilus-canvas-dnd.c
@@ -987,7 +987,7 @@ handle_nonlocal_move (NautilusCanvasContainer *container,
                       gboolean                 icon_hit)
 {
     GList *source_uris, *p;
-    GArray *source_item_locations;
+    GArray *source_item_locations = NULL;
     gboolean free_target_uri, is_rtl;
     int index, item_x;
     GtkAllocation allocation;
@@ -1007,12 +1007,12 @@ handle_nonlocal_move (NautilusCanvasContainer *container,
 
     is_rtl = nautilus_canvas_container_is_layout_rtl (container);
 
-    source_item_locations = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
-    if (!icon_hit)
+    if (!icon_hit && eel_uri_is_desktop (target_uri))
     {
         /* Drop onto a container. Pass along the item points to allow placing
          * the items in their same relative positions in the new container.
          */
+        source_item_locations = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
         source_item_locations = g_array_set_size (source_item_locations,
                                                   g_list_length 
(container->details->dnd_info->drag_info.selection_list));
 
@@ -1058,7 +1058,10 @@ handle_nonlocal_move (NautilusCanvasContainer *container,
     }
 
     g_list_free (source_uris);
-    g_array_free (source_item_locations, TRUE);
+    if (source_item_locations != NULL)
+    {
+        g_array_free (source_item_locations, TRUE);
+    }
 }
 
 static char *
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index eaf8cd4..301e2d0 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -5085,6 +5085,7 @@ copy_move_file (CopyMoveJob   *copy_job,
                 gboolean       readonly_source_fs)
 {
     GFile *dest, *new_dest;
+    g_autofree gchar *dest_uri = NULL;
     GError *error;
     GFileCopyFlags flags;
     char *primary, *secondary, *details;
@@ -5267,11 +5268,12 @@ retry:
 
         if (debuting_files)
         {
+            dest_uri = g_file_get_uri (dest);
             if (position)
             {
                 nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
             }
-            else
+            else if (eel_uri_is_desktop (dest_uri))
             {
                 nautilus_file_changes_queue_schedule_position_remove (dest);
             }
@@ -5948,6 +5950,7 @@ move_file_prepare (CopyMoveJob  *move_job,
                    int           files_left)
 {
     GFile *dest, *new_dest;
+    g_autofree gchar *dest_uri = NULL;
     GError *error;
     CommonJob *job;
     gboolean overwrite;
@@ -6030,11 +6033,12 @@ retry:
 
         nautilus_file_changes_queue_file_moved (src, dest);
 
+        dest_uri = g_file_get_uri (dest);
         if (position)
         {
             nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
         }
-        else
+        else if (eel_uri_is_desktop (dest_uri))
         {
             nautilus_file_changes_queue_schedule_position_remove (dest);
         }
@@ -6542,6 +6546,7 @@ link_file (CopyMoveJob  *job,
            int           files_left)
 {
     GFile *src_dir, *dest, *new_dest;
+    g_autofree gchar *dest_uri = NULL;
     int count;
     char *path;
     gboolean not_local;
@@ -6593,11 +6598,12 @@ retry:
         }
 
         nautilus_file_changes_queue_file_added (dest);
+        dest_uri = g_file_get_uri (dest);
         if (position)
         {
             nautilus_file_changes_queue_schedule_position_set (dest, *position, common->screen_num);
         }
-        else
+        else if (eel_uri_is_desktop (dest_uri))
         {
             nautilus_file_changes_queue_schedule_position_remove (dest);
         }
@@ -7257,6 +7263,7 @@ create_task_thread_func (GTask        *task,
     CommonJob *common;
     int count;
     GFile *dest;
+    g_autofree gchar *dest_uri = NULL;
     char *basename;
     char *filename, *filename2, *new_filename;
     char *filename_base, *suffix;
@@ -7471,11 +7478,12 @@ retry:
     {
         job->created_file = g_object_ref (dest);
         nautilus_file_changes_queue_file_added (dest);
+        dest_uri = g_file_get_uri (dest);
         if (job->has_position)
         {
             nautilus_file_changes_queue_schedule_position_set (dest, job->position, common->screen_num);
         }
-        else
+        else if (eel_uri_is_desktop (dest_uri))
         {
             nautilus_file_changes_queue_schedule_position_remove (dest);
         }
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index ccda3b4..106ebbc 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -1622,6 +1622,30 @@ nautilus_file_is_desktop_directory (NautilusFile *file)
     return nautilus_is_desktop_directory_file (dir, eel_ref_str_peek (file->details->name));
 }
 
+/**
+ * nautilus_file_is_child_of_desktop_directory:
+ *
+ * Check whether this file is a direct child of the desktop directory.
+ *
+ * @file: The file to check.
+ *
+ * Return value: TRUE if this file is a direct child of the desktop directory.
+ */
+gboolean
+nautilus_file_is_child_of_desktop_directory (NautilusFile *file)
+{
+    GFile *dir;
+
+    dir = file->details->directory->details->location;
+
+    if (dir == NULL)
+    {
+        return FALSE;
+    }
+
+    return nautilus_is_desktop_directory (dir);
+}
+
 static gboolean
 is_desktop_file (NautilusFile *file)
 {
diff --git a/src/nautilus-file.h b/src/nautilus-file.h
index 96654e4..c44ffb0 100644
--- a/src/nautilus-file.h
+++ b/src/nautilus-file.h
@@ -218,6 +218,7 @@ gboolean                nautilus_file_is_remote                         (Nautilu
 gboolean                nautilus_file_is_other_locations                (NautilusFile                   
*file);
 gboolean               nautilus_file_is_home                           (NautilusFile                   
*file);
 gboolean                nautilus_file_is_desktop_directory              (NautilusFile                   
*file);
+gboolean                nautilus_file_is_child_of_desktop_directory     (NautilusFile                   
*file);
 GError *                nautilus_file_get_file_info_error               (NautilusFile                   
*file);
 gboolean                nautilus_file_get_directory_item_count          (NautilusFile                   
*file,
                                                                         guint                          
*count,
diff --git a/src/nautilus-files-view-dnd.c b/src/nautilus-files-view-dnd.c
index b34e00f..6562297 100644
--- a/src/nautilus-files-view-dnd.c
+++ b/src/nautilus-files-view-dnd.c
@@ -32,6 +32,7 @@
 
 #include <eel/eel-stock-dialogs.h>
 #include <eel/eel-string.h>
+#include <eel/eel-vfs-extensions.h>
 
 #include <glib/gi18n.h>
 
@@ -166,7 +167,7 @@ nautilus_files_view_handle_netscape_url_drop (NautilusFilesView *view,
 {
     char *url, *title;
     char *link_name;
-    GArray *points;
+    GArray *points = NULL;
     char **bits;
     GList *uri_list = NULL;
     GFile *f;
@@ -257,10 +258,12 @@ nautilus_files_view_handle_netscape_url_drop (NautilusFilesView *view,
     {
         GdkPoint tmp_point = { 0, 0 };
 
-        /* pass in a 1-item array of icon positions, relative to x, y */
-        points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
-        g_array_append_val (points, tmp_point);
-
+        if (eel_uri_is_desktop (target_uri))
+        {
+            /* pass in a 1-item array of icon positions, relative to x, y */
+            points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+            g_array_append_val (points, tmp_point);
+        }
         uri_list = g_list_append (uri_list, url);
 
         nautilus_files_view_move_copy_items (view, uri_list, points,
@@ -286,6 +289,7 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
     gchar **uri_list;
     GList *real_uri_list = NULL;
     char *container_uri;
+    const char *real_target_uri;
     int n_uris, i;
     GArray *points;
 
@@ -343,7 +347,8 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
         return;
     }
 
-    if (n_uris == 1)
+    real_target_uri = target_uri != NULL ? target_uri : container_uri;
+    if (n_uris == 1 && eel_uri_is_desktop (real_target_uri))
     {
         GdkPoint tmp_point = { 0, 0 };
 
@@ -359,7 +364,7 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
     view_widget_to_file_operation_position_xy (view, &x, &y);
 
     nautilus_files_view_move_copy_items (view, real_uri_list, points,
-                                         target_uri != NULL ? target_uri : container_uri,
+                                         real_target_uri,
                                          action, x, y);
 
     g_list_free_full (real_uri_list, g_free);
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 0d94e7c..721682f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1726,9 +1726,12 @@ new_folder_done (GFile    *new_folder,
 
 
     file = nautilus_file_get (new_folder);
-    nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_SCREEN,
-                                NULL,
-                                screen_string);
+    if (nautilus_file_is_child_of_desktop_directory (file))
+    {
+        nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_SCREEN,
+                                    NULL,
+                                    screen_string);
+    }
 
     if (data->selection != NULL)
     {
@@ -1902,9 +1905,10 @@ new_folder_dialog_controller_on_name_accepted (NautilusFileNameWidgetController
 {
     NautilusFilesView *view;
     NewFolderData *data;
-    GdkPoint *position;
+    GdkPoint *position = NULL;
     g_autofree gchar *parent_uri = NULL;
     g_autofree gchar *name = NULL;
+    NautilusFile *parent;
     gboolean with_selection;
 
     view = NAUTILUS_FILES_VIEW (user_data);
@@ -1922,14 +1926,18 @@ new_folder_dialog_controller_on_name_accepted (NautilusFileNameWidgetController
                            (GClosureNotify) NULL,
                            G_CONNECT_AFTER);
 
-    position = context_menu_to_file_operation_position (view);
-
     parent_uri = nautilus_files_view_get_backing_uri (view);
+    parent = nautilus_file_get_by_uri (parent_uri);
+    if (nautilus_file_is_desktop_directory (parent))
+    {
+        position = context_menu_to_file_operation_position (view);
+    }
     nautilus_file_operations_new_folder (GTK_WIDGET (view),
                                          position, parent_uri, name,
                                          new_folder_done, data);
 
     g_clear_object (&view->details->new_folder_controller);
+    g_object_unref (parent);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]