[nautilus/wip/ernestask/tasks: 46/49] Remove file change queueing



commit 97973f9a7a71f0f5655debff48b450ce566df1ad
Author: Ernestas Kulik <ernestask gnome org>
Date:   Mon Jul 24 21:33:26 2017 +0300

    Remove file change queueing

 src-ng/main.c                       |   18 +++++-
 src-ng/nautilus-directory.c         |    2 +-
 src-ng/nautilus-file-changes.c      |  115 +++++++++-------------------------
 src-ng/nautilus-file.c              |    2 +-
 src-ng/tasks/nautilus-rename-task.c |    8 +++
 5 files changed, 56 insertions(+), 89 deletions(-)
---
diff --git a/src-ng/main.c b/src-ng/main.c
index 086a250..df39bd4 100644
--- a/src-ng/main.c
+++ b/src-ng/main.c
@@ -106,11 +106,19 @@ perform_self_test_checks (const gchar *path)
 }
 
 static void
-rename (const gchar *target,
-        const gchar *name)
+on_children_changed (NautilusDirectory *directory,
+                     gpointer           user_data)
+{
+    g_main_loop_quit ((GMainLoop *) user_data);
+}
+
+static void
+_rename (const gchar *target,
+         const gchar *name)
 {
     g_autoptr (GFile) location = NULL;
     g_autoptr (NautilusFile) file = NULL;
+    g_autoptr (NautilusFile) parent = NULL;
     g_autoptr (NautilusTaskManager) manager = NULL;
     g_autoptr (NautilusTask) task = NULL;
     GMainLoop *loop;
@@ -119,12 +127,16 @@ rename (const gchar *target,
     g_message ("Constructed GFile %p for path %s",
                (gpointer) location, target);
     file = nautilus_file_new (location);
+    parent = nautilus_file_get_parent (file);
     g_message ("Constructed NautilusFile %p for location %p",
                (gpointer) file, (gpointer) location);
     manager = nautilus_task_manager_dup_singleton ();
     task = nautilus_rename_task_new ();
     loop = g_main_loop_new (NULL, TRUE);
 
+    g_signal_connect (parent, "children-changed",
+                      G_CALLBACK (on_children_changed), loop);
+
     nautilus_rename_task_add_target (NAUTILUS_RENAME_TASK (task),
                                      location, name);
 
@@ -189,7 +201,7 @@ main (int    argc,
 
     if (new_name != NULL && new_name[0] != '\0')
     {
-        rename (files[0], new_name);
+        _rename (files[0], new_name);
     }
 
     return EXIT_SUCCESS;
diff --git a/src-ng/nautilus-directory.c b/src-ng/nautilus-directory.c
index beab748..c125a39 100644
--- a/src-ng/nautilus-directory.c
+++ b/src-ng/nautilus-directory.c
@@ -59,7 +59,7 @@ nautilus_directory_class_init (NautilusDirectoryClass *klass)
 
     signals[CHILDREN_CHANGED] = g_signal_new ("children-changed",
                                               G_TYPE_FROM_CLASS (klass),
-                                              G_SIGNAL_RUN_LAST,
+                                              G_SIGNAL_RUN_FIRST,
                                               G_STRUCT_OFFSET (NautilusDirectoryClass, children_changed),
                                               NULL, NULL,
                                               g_cclosure_marshal_VOID__VOID,
diff --git a/src-ng/nautilus-file-changes.c b/src-ng/nautilus-file-changes.c
index 0f9752f..c912e63 100644
--- a/src-ng/nautilus-file-changes.c
+++ b/src-ng/nautilus-file-changes.c
@@ -38,9 +38,6 @@ static void move_change_free (MoveChange *change);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (MoveChange, move_change_free)
 
-static guint source = 0;
-static GMutex source_mutex;
-
 static void
 move_change_free (MoveChange *change)
 {
@@ -49,94 +46,48 @@ move_change_free (MoveChange *change)
     g_free (change);
 }
 
-static gpointer
-init_default_queue (gpointer data)
-{
-    return g_async_queue_new ();
-}
-
-static GAsyncQueue *
-get_default_queue (void)
-{
-    static GOnce once = G_ONCE_INIT;
-
-    g_once (&once, init_default_queue, NULL);
-
-    return once.retval;
-}
-
-static gboolean
-emit_signals (gpointer user_data)
+static void
+emit_signal_for_change (Change *change)
 {
-    GAsyncQueue *queue;
-    Change *change;
-
-    queue = user_data;
-
-    g_async_queue_lock (queue);
+    g_autoptr (NautilusFile) file = NULL;
+    g_autoptr (NautilusFile) parent = NULL;
 
-    while ((change = g_async_queue_try_pop_unlocked (queue)) != NULL)
+    file = nautilus_file_new (change->location);
+    if (file == NULL)
     {
-        g_autoptr (NautilusFile) file = NULL;
-        g_autoptr (NautilusFile) parent = NULL;
-
-        file = nautilus_file_new (change->location);
-        if (file == NULL)
-        {
-            continue;
-        }
-        parent = nautilus_file_get_parent (file);
+        return;
+    }
+    parent = nautilus_file_get_parent (file);
 
-        switch (change->type)
+    switch (change->type)
+    {
+        case NAUTILUS_FILE_CHANGE_RENAMED:
         {
-            case NAUTILUS_FILE_CHANGE_RENAMED:
-            {
-                g_autoptr (MoveChange) move_change = NULL;
+            g_autoptr (MoveChange) move_change = NULL;
 
-                move_change = (MoveChange *) change;
+            move_change = (MoveChange *) change;
 
-                nautilus_emit_signal_in_main_context_by_name (file,
-                                                              NULL,
-                                                              "renamed",
-                                                              move_change->location_to);
+            nautilus_emit_signal_in_main_context_by_name (file,
+                                                          NULL,
+                                                          "renamed",
+                                                          move_change->location_to);
 
-                if (parent == NULL)
-                {
-                    break;
-                }
-
-                nautilus_emit_signal_in_main_context_by_name (parent,
-                                                              NULL,
-                                                              "children-changed");
+            if (parent == NULL)
+            {
+                break;
             }
-            break;
-        }
-    }
-
-    g_async_queue_unlock (queue);
 
-    g_mutex_lock (&source_mutex);
-    source = 0;
-    g_mutex_unlock (&source_mutex);
-
-    return G_SOURCE_REMOVE;
-}
-
-static void
-schedule_signal_emission (void)
-{
-    g_mutex_lock (&source_mutex);
+            nautilus_emit_signal_in_main_context_by_name (parent,
+                                                          NULL,
+                                                          "children-changed");
+        }
+        break;
 
-    if (source == 0)
-    {
-        source = g_timeout_add (100, emit_signals, get_default_queue ());
-    }
-    else
-    {
-        g_source_remove (source);
+        case NAUTILUS_FILE_CHANGE_MOVED:
+        {
+        }
+        break;
     }
-
-    g_mutex_unlock (&source_mutex);
 }
 
 static void
@@ -145,19 +96,15 @@ notify_file_moved_or_renamed (GFile    *from,
                               gboolean  move_is_rename)
 {
     MoveChange *change;
-    GAsyncQueue *queue;
 
     change = g_new0 (MoveChange, 1);
-    queue = get_default_queue ();
 
     change->type = move_is_rename? NAUTILUS_FILE_CHANGE_RENAMED
                                  : NAUTILUS_FILE_CHANGE_MOVED;
     change->location_from = g_object_ref (from);
     change->location_to = g_object_ref (to);
 
-    g_async_queue_push (queue, change);
-
-    schedule_signal_emission ();
+    emit_signal_for_change ((Change *) change);
 }
 
 void
diff --git a/src-ng/nautilus-file.c b/src-ng/nautilus-file.c
index 763a2cf..fd51873 100644
--- a/src-ng/nautilus-file.c
+++ b/src-ng/nautilus-file.c
@@ -191,7 +191,7 @@ nautilus_file_class_init (NautilusFileClass *klass)
 
     signals[RENAMED] = g_signal_new ("renamed",
                                      G_TYPE_FROM_CLASS (klass),
-                                     G_SIGNAL_RUN_LAST,
+                                     G_SIGNAL_RUN_FIRST,
                                      G_STRUCT_OFFSET (NautilusFileClass, renamed),
                                      NULL, NULL,
                                      g_cclosure_marshal_VOID__OBJECT,
diff --git a/src-ng/tasks/nautilus-rename-task.c b/src-ng/tasks/nautilus-rename-task.c
index b210640..350d108 100644
--- a/src-ng/tasks/nautilus-rename-task.c
+++ b/src-ng/tasks/nautilus-rename-task.c
@@ -73,6 +73,8 @@ execute (NautilusTask *task)
         g_autoptr (GFile) location_to = NULL;
 
         location_from = G_FILE (key);
+        g_message ("Renaming GFile %p",
+                   (gpointer) location_from);
         location_to = g_file_set_display_name (location_from,
                                                (const gchar *) value,
                                                cancellable, &error);
@@ -84,6 +86,12 @@ execute (NautilusTask *task)
                        (gpointer) location_to);
             nautilus_notify_file_renamed (location_from, location_to);
         }
+        else
+        {
+            g_message ("Renaming GFile %p failed: %s",
+                       (gpointer) location_from,
+                       error->message);
+        }
     }
 
     /* This will typically be handled before the file and its parent


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