[nautilus/wip/ernestask/tasks: 2/2] Add info attribute task class



commit d855b6dc728a2b46ecfd2c174f0ca144caf38b5b
Author: Ernestas Kulik <ernestask gnome org>
Date:   Tue Jun 27 20:52:58 2017 +0300

    Add info attribute task class

 src/meson.build                          |    4 +-
 src/tasks/nautilus-info-attribute-task.c |  109 ++++++++++++++++++++++++++++++
 src/tasks/nautilus-info-attribute-task.h |   36 ++++++++++
 test/meson.build                         |    5 ++
 test/test-info-attribute-task.c          |   54 +++++++++++++++
 5 files changed, 207 insertions(+), 1 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index d526797..9d0c478 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -272,7 +272,9 @@ libnautilus_sources = [
     'tasks/nautilus-deep-count-task.c',
     'tasks/nautilus-deep-count-task.h',
     'tasks/nautilus-attribute-task.c',
-    'tasks/nautilus-attribute-task.h'
+    'tasks/nautilus-attribute-task.h',
+    'tasks/nautilus-info-attribute-task.c',
+    'tasks/nautilus-info-attribute-task.h'
 ]
 
 if get_option ('enable-tracker')
diff --git a/src/tasks/nautilus-info-attribute-task.c b/src/tasks/nautilus-info-attribute-task.c
new file mode 100644
index 0000000..0740366
--- /dev/null
+++ b/src/tasks/nautilus-info-attribute-task.c
@@ -0,0 +1,109 @@
+/* Copyright (C) 2017 Ernestas Kulik <ernestask gnome org>
+ *
+ * This file is part of Nautilus.
+ *
+ * Nautilus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Nautilus.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "nautilus-info-attribute-task.h"
+
+#include "nautilus-directory-private.h"
+#include "nautilus-file-private.h"
+
+struct _NautilusInfoAttributeTask
+{
+    NautilusAttributeTask parent_instance;
+};
+
+G_DEFINE_TYPE (NautilusInfoAttributeTask, nautilus_info_attribute_task,
+               NAUTILUS_TYPE_ATTRIBUTE_TASK)
+
+static gboolean
+is_cache_invalid (NautilusAttributeTask *attribute_task,
+                  NautilusFile          *file)
+{
+    return !file->details->file_info_is_up_to_date
+           && !file->details->is_gone;
+}
+
+static void
+update_cache (NautilusAttributeTask *task,
+              NautilusFile          *file,
+              GFileInfo             *info,
+              GError                *error)
+{
+    if (info == NULL)
+    {
+        if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)
+        {
+            /* mark file as gone */
+            nautilus_file_mark_gone (file);
+        }
+        file->details->file_info_is_up_to_date = TRUE;
+        nautilus_file_clear_info (file);
+        file->details->get_info_failed = TRUE;
+        file->details->get_info_error = error;
+    }
+    else
+    {
+        nautilus_file_update_info (file, info);
+        g_object_unref (info);
+    }
+}
+
+static void
+nautilus_info_attribute_task_class_init (NautilusInfoAttributeTaskClass *klass)
+{
+    NautilusAttributeTaskClass *attribute_class;
+
+    attribute_class = NAUTILUS_ATTRIBUTE_TASK_CLASS (klass);
+
+    attribute_class->is_cache_invalid = is_cache_invalid;
+    attribute_class->update_cache = update_cache;
+}
+
+static void
+nautilus_info_attribute_task_init (NautilusInfoAttributeTask *self)
+{
+}
+
+NautilusTask *
+nautilus_info_attribute_task_new_for_file (NautilusFile *file)
+{
+    g_autoptr (GList) list = NULL;
+
+    g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+
+    list = g_list_append (list, file);
+
+    return g_object_new (NAUTILUS_TYPE_INFO_ATTRIBUTE_TASK,
+                         "files", list,
+                         "attributes", NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+                         NULL);
+}
+
+NautilusTask *
+nautilus_info_attribute_task_new_for_directory (NautilusDirectory *directory)
+{
+    g_autoptr (GList) list = NULL;
+
+    g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+
+    list = g_list_copy (directory->details->file_list);
+
+    return g_object_new (NAUTILUS_TYPE_INFO_ATTRIBUTE_TASK,
+                         "files", list,
+                         "attributes", NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+                         NULL);
+}
diff --git a/src/tasks/nautilus-info-attribute-task.h b/src/tasks/nautilus-info-attribute-task.h
new file mode 100644
index 0000000..55840c0
--- /dev/null
+++ b/src/tasks/nautilus-info-attribute-task.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 2017 Ernestas Kulik <ernestask gnome org>
+ *
+ * This file is part of Nautilus.
+ *
+ * Nautilus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Nautilus.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NAUTILUS_INFO_ATTRIBUTE_TASK_H
+#define NAUTILUS_INFO_ATTRIBUTE_TASK_H
+
+#include "nautilus-attribute-task.h"
+
+#include "nautilus-directory.h"
+#include "nautilus-file.h"
+
+#define NAUTILUS_TYPE_INFO_ATTRIBUTE_TASK (nautilus_info_attribute_task_get_type ())
+
+G_DECLARE_FINAL_TYPE (NautilusInfoAttributeTask, nautilus_info_attribute_task,
+                      NAUTILUS, INFO_ATTRIBUTE_TASK,
+                      NautilusAttributeTask)
+
+NautilusTask *nautilus_info_attribute_task_new_for_file (NautilusFile *file);
+NautilusTask *nautilus_info_attribute_task_new_for_directory (NautilusDirectory *directory);
+
+#endif
diff --git a/test/meson.build b/test/meson.build
index 0c7d830..fbe8ddd 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -24,8 +24,13 @@ test_eel_string_get_common_prefix = executable ('test-eel-string-get-common-pref
                                                 'test-eel-string-get-common-prefix.c',
                                                 dependencies: libnautilus_dep)
 
+test_info_attribute_task = executable ('test-info-attribute-task',
+                                       'test-info-attribute-task.c',
+                                       dependencies: libnautilus_dep)
+
 test ('test-nautilus-search-engine', test_nautilus_search_engine)
 test ('test-nautilus-directory-async', test_nautilus_directory_async)
 test ('test-file-utilities-get-common-filename-prefix', test_file_utilities_get_common_filename_prefix)
 test ('test-eel-string-rtrim-punctuation', test_eel_string_rtrim_punctuation)
 test ('test-eel-string-get-common-prefix', test_eel_string_get_common_prefix)
+test ('test-info-attribute-task', test_info_attribute_task)
diff --git a/test/test-info-attribute-task.c b/test/test-info-attribute-task.c
new file mode 100644
index 0000000..e89d684
--- /dev/null
+++ b/test/test-info-attribute-task.c
@@ -0,0 +1,54 @@
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+
+#include <nautilus-file-utilities.h>
+#include <nautilus-task-manager.h>
+#include <tasks/nautilus-info-attribute-task.h>
+
+#define ATTRIBUTE "owner"
+
+static void
+callback (NautilusTask *task,
+          gpointer      user_data)
+{
+    NautilusFile *file;
+
+    file = NAUTILUS_FILE (user_data);
+
+    g_message ("%s: %s",
+               ATTRIBUTE,
+               nautilus_file_get_string_attribute (file, ATTRIBUTE));
+
+    nautilus_file_unref (file);
+
+    gtk_main_quit ();
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+    NautilusFile *file;
+    g_autoptr (NautilusTaskManager) manager = NULL;
+    g_autoptr (NautilusTask) task = NULL;
+
+    gtk_init (&argc, &argv);
+
+    nautilus_ensure_extension_points ();
+
+    file = nautilus_file_get_by_uri ("file:///tmp");
+    manager = nautilus_task_manager_dup_singleton ();
+    task = nautilus_info_attribute_task_new_for_file (file);
+
+    g_message ("%s: %s",
+               ATTRIBUTE,
+               nautilus_file_get_string_attribute (file, ATTRIBUTE));
+    nautilus_task_manager_queue_task (manager, task, callback, file);
+
+    file = NULL;
+
+    gtk_main ();
+
+    return EXIT_SUCCESS;
+}


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