[nautilus/wip/ernestask/tasks: 15/15] file-name-widget-controller: port to task API



commit 6cd4fa0a249ebdb7c38141cc38d615522dc98ae8
Author: Ernestas Kulik <ernestask gnome org>
Date:   Wed Jun 28 15:32:25 2017 +0300

    file-name-widget-controller: port to task API
    
    Canceling in finalize() like that is pretty wonky, might want to explore
    that.

 src/nautilus-file-name-widget-controller.c |   68 ++++++++++++++++++---------
 1 files changed, 45 insertions(+), 23 deletions(-)
---
diff --git a/src/nautilus-file-name-widget-controller.c b/src/nautilus-file-name-widget-controller.c
index 0deff90..414d56e 100644
--- a/src/nautilus-file-name-widget-controller.c
+++ b/src/nautilus-file-name-widget-controller.c
@@ -20,7 +20,8 @@
 #include <glib/gi18n.h>
 
 #include "nautilus-file-name-widget-controller.h"
-
+#include "nautilus-task-manager.h"
+#include "tasks/nautilus-info-attribute-task.h"
 
 #define FILE_NAME_DUPLICATED_LABEL_TIMEOUT 500
 
@@ -34,6 +35,9 @@ typedef struct
 
     gboolean duplicated_is_folder;
     gint duplicated_label_timeout_id;
+
+    NautilusTask *on_changed_info_task;
+    NautilusTask *on_activate_info_task;
 } NautilusFileNameWidgetControllerPrivate;
 
 enum
@@ -194,9 +198,8 @@ file_name_widget_controller_process_new_name (NautilusFileNameWidgetController *
 }
 
 static void
-file_name_widget_controller_on_changed_directory_info_ready (NautilusDirectory *directory,
-                                                             GList             *files,
-                                                             gpointer           user_data)
+file_name_widget_controller_on_changed_directory_info_ready (NautilusTask *task,
+                                                             gpointer      user_data)
 {
     NautilusFileNameWidgetController *controller;
     NautilusFileNameWidgetControllerPrivate *priv;
@@ -220,6 +223,8 @@ file_name_widget_controller_on_changed_directory_info_ready (NautilusDirectory *
                                                            (GSourceFunc) duplicated_file_label_show,
                                                            controller);
     }
+
+    g_clear_object (&priv->on_changed_info_task);
 }
 
 static void
@@ -227,25 +232,27 @@ file_name_widget_controller_on_changed (gpointer user_data)
 {
     NautilusFileNameWidgetController *controller;
     NautilusFileNameWidgetControllerPrivate *priv;
+    g_autoptr (NautilusTaskManager) task_manager = NULL;
 
     controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
     priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+    task_manager = nautilus_task_manager_dup_singleton ();
+    priv->on_changed_info_task = nautilus_info_attribute_task_new_for_directory (priv->containing_directory);
 
-    nautilus_directory_call_when_ready (priv->containing_directory,
-                                        NAUTILUS_FILE_ATTRIBUTE_INFO,
-                                        TRUE,
-                                        file_name_widget_controller_on_changed_directory_info_ready,
-                                        controller);
+    nautilus_task_manager_queue_task (task_manager,
+                                      priv->on_changed_info_task,
+                                      file_name_widget_controller_on_changed_directory_info_ready,
+                                      controller);
 }
 
 static void
-file_name_widget_controller_on_activate_directory_info_ready (NautilusDirectory *directory,
-                                                              GList             *files,
-                                                              gpointer           user_data)
+file_name_widget_controller_on_activate_directory_info_ready (NautilusTask *task,
+                                                              gpointer      user_data)
 {
     NautilusFileNameWidgetController *controller;
     gboolean duplicated_name;
     gboolean valid_name;
+    NautilusFileNameWidgetControllerPrivate *priv;
 
     controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
 
@@ -268,6 +275,10 @@ file_name_widget_controller_on_activate_directory_info_ready (NautilusDirectory
             duplicated_file_label_show (controller);
         }
     }
+
+    priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+
+    g_clear_object (&priv->on_activate_info_task);
 }
 
 static void
@@ -275,20 +286,28 @@ file_name_widget_controller_on_activate (gpointer user_data)
 {
     NautilusFileNameWidgetController *controller;
     NautilusFileNameWidgetControllerPrivate *priv;
+    g_autoptr (NautilusTaskManager) task_manager = NULL;
 
     controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
     priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+    task_manager = nautilus_task_manager_dup_singleton ();
+    priv->on_activate_info_task = nautilus_info_attribute_task_new_for_directory 
(priv->containing_directory);
 
-    nautilus_directory_call_when_ready (priv->containing_directory,
-                                        NAUTILUS_FILE_ATTRIBUTE_INFO,
-                                        TRUE,
-                                        file_name_widget_controller_on_activate_directory_info_ready,
-                                        controller);
+    nautilus_task_manager_queue_task (task_manager,
+                                      priv->on_activate_info_task,
+                                      file_name_widget_controller_on_activate_directory_info_ready,
+                                      controller);
 }
 
 static void
 nautilus_file_name_widget_controller_init (NautilusFileNameWidgetController *self)
 {
+    NautilusFileNameWidgetControllerPrivate *priv;
+
+    priv = nautilus_file_name_widget_controller_get_instance_private (self);
+
+    priv->on_changed_info_task = NULL;
+    priv->on_activate_info_task = NULL;
 }
 
 static void
@@ -367,14 +386,17 @@ nautilus_file_name_widget_controller_finalize (GObject *object)
     self = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (object);
     priv = nautilus_file_name_widget_controller_get_instance_private (self);
 
+    if (priv->on_changed_info_task != NULL)
+    {
+        nautilus_task_cancel (priv->on_changed_info_task);
+    }
+    if (priv->on_activate_info_task != NULL)
+    {
+        nautilus_task_cancel (priv->on_activate_info_task);
+    }
+
     if (priv->containing_directory != NULL)
     {
-        nautilus_directory_cancel_callback (priv->containing_directory,
-                                            file_name_widget_controller_on_changed_directory_info_ready,
-                                            self);
-        nautilus_directory_cancel_callback (priv->containing_directory,
-                                            file_name_widget_controller_on_activate_directory_info_ready,
-                                            self);
         g_clear_object (&priv->containing_directory);
     }
 


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