[nautilus/wip/ernestask/tasks: 19/27] Add attribute task class



commit 63e02ff92bdbb1f2eb51af260642bcf4b4286ef6
Author: Ernestas Kulik <ernestask gnome org>
Date:   Tue Jun 27 20:52:34 2017 +0300

    Add attribute task class

 src/meson.build                     |    2 +
 src/tasks/nautilus-attribute-task.c |  179 +++++++++++++++++++++++++++++++++++
 src/tasks/nautilus-attribute-task.h |   37 +++++++
 3 files changed, 218 insertions(+), 0 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index d01d034..848de3e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -277,6 +277,8 @@ libnautilus_sources = [
     'tasks/nautilus-extract-task.c',
 #    'tasks/nautilus-deep-count-task.c',
 #    'tasks/nautilus-deep-count-task.h'
+    'tasks/nautilus-attribute-task.c',
+    'tasks/nautilus-attribute-task.h'
 ]
 
 nautilus_deps = [glib,
diff --git a/src/tasks/nautilus-attribute-task.c b/src/tasks/nautilus-attribute-task.c
new file mode 100644
index 0000000..a5d2f53
--- /dev/null
+++ b/src/tasks/nautilus-attribute-task.c
@@ -0,0 +1,179 @@
+/* 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-attribute-task.h"
+
+struct _NautilusAttributeTask
+{
+    GObject parent_instance;
+
+    GCancellable *cancellable;
+
+    GFile *file;
+    const char *attributes;
+
+    GFileQueryInfoFlags query_flags;
+
+    GFileAttributeMatcher *filesystem_attribute_matcher;
+} NautilusAttributeTaskPrivate;
+
+G_DEFINE_TYPE (NautilusAttributeTask, nautilus_attribute_task,
+               NAUTILUS_TYPE_TASK)
+
+enum
+{
+    PROP_FILE = 1,
+    PROP_ATTRIBUTES,
+    PROP_QUERY_FLAGS,
+    N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
+static void
+set_property (GObject      *object,
+              guint         property_id,
+              const GValue *value,
+              GParamSpec   *pspec)
+{
+    NautilusAttributeTask *self;
+
+    self = NAUTILUS_ATTRIBUTE_TASK (object);
+
+    switch (property_id)
+    {
+        case PROP_FILE:
+        {
+            if (G_UNLIKELY (self->file != NULL))
+            {
+                g_clear_object (&self->file);
+            }
+
+            self->file = g_value_dup_object (value);
+        }
+        break;
+
+        case PROP_ATTRIBUTES:
+        {
+            g_free ((gpointer) self->attributes);
+
+            self->attributes = g_value_dup_string (value);
+        }
+        break;
+
+        case PROP_QUERY_FLAGS:
+        {
+            self->query_flags = g_value_get_int (value);
+        }
+        break;
+
+        default:
+        {
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        }
+    }
+}
+
+static void
+finalize (GObject *object)
+{
+    NautilusAttributeTask *self;
+
+    self = NAUTILUS_ATTRIBUTE_TASK (object);
+
+    g_clear_pointer (&self->file, nautilus_file_unref);
+    g_clear_pointer (&self->attributes, g_free);
+
+    G_OBJECT_CLASS (nautilus_attribute_task_parent_class)->finalize (object);
+}
+
+static void
+execute (NautilusTask *task)
+{
+    NautilusAttributeTask *self;
+    g_autoptr (GCancellable) cancellable = NULL;
+    GError *error = NULL;
+    GFileInfo *info;
+
+    self = NAUTILUS_ATTRIBUTE_TASK (task);
+
+    cancellable = nautilus_task_get_cancellable (NAUTILUS_TASK (self));
+    info = g_file_query_info (self->file, self->attributes,
+                              self->query_flags,
+                              cancellable,
+                              &error);
+}
+
+static void
+nautilus_attribute_task_class_init (NautilusAttributeTaskClass *klass)
+{
+    GObjectClass *object_class;
+    NautilusTaskClass *task_class;
+
+    object_class = G_OBJECT_CLASS (klass);
+    task_class = NAUTILUS_TASK_CLASS (klass);
+
+    object_class->set_property = set_property;
+    object_class->finalize = finalize;
+
+    task_class->execute = execute;
+
+    properties[PROP_FILE] =
+        g_param_spec_object ("file", "File", "File",
+                             G_TYPE_FILE,
+                             G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME);
+
+    properties[PROP_ATTRIBUTES] =
+        g_param_spec_string ("attributes", "Attributes", "Attributes",
+                             NULL,
+                             G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME);
+
+    properties[PROP_QUERY_FLAGS] =
+        g_param_spec_int ("query-flags", "Query flags", "Query flags",
+                          G_FILE_QUERY_INFO_NONE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                          G_FILE_QUERY_INFO_NONE,
+                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME);
+
+    g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+nautilus_attribute_task_init (NautilusAttributeTask *self)
+{
+    self->file = NULL;
+    self->attributes = NULL;
+}
+
+NautilusTask *
+nautilus_attribute_task_new (NautilusFile *file,
+                             const char   *attributes,
+                             gboolean      follow_symlinks,
+                             GCancellable *cancellable)
+{
+    GFileQueryInfoFlags query_flags;
+
+    query_flags = follow_symlinks? G_FILE_QUERY_INFO_NONE :
+                                   G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
+
+    return g_object_new (NAUTILUS_TYPE_ATTRIBUTE_TASK,
+                         "file", file,
+                         "attributes", attributes,
+                         "query-flags", query_flags,
+                         "cancellable", cancellable,
+                         NULL);
+}
diff --git a/src/tasks/nautilus-attribute-task.h b/src/tasks/nautilus-attribute-task.h
new file mode 100644
index 0000000..91bd8e7
--- /dev/null
+++ b/src/tasks/nautilus-attribute-task.h
@@ -0,0 +1,37 @@
+/* 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 2 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_ATTRIBUTE_TASK_H
+#define NAUTILUS_ATTRIBUTE_TASK_H
+
+#include "nautilus-task.h"
+
+#include "nautilus-file.h"
+
+#define NAUTILUS_TYPE_ATTRIBUTE_TASK (nautilus_attribute_task_get_type ())
+
+G_DECLARE_FINAL_TYPE (NautilusAttributeTask, nautilus_attribute_task,
+                      NAUTILUS, ATTRIBUTE_TASK,
+                      NautilusTask)
+
+NautilusTask *nautilus_attribute_task_new (NautilusFile *file,
+                                           const char   *attributes,
+                                           gboolean      follow_symlinks,
+                                           GCancellable *cancellable);
+
+#endif


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