diff options
author | Ernestas Kulik <ernestask@gnome.org> | 2017-06-27 20:52:34 +0300 |
---|---|---|
committer | Ernestas Kulik <ernestask@gnome.org> | 2017-08-11 14:28:01 +0300 |
commit | f31b2c1a2659e06d6fe07153d7520017ef1b9778 (patch) | |
tree | 29aae1985ca5dee7a992e4f6d262138cd5bede45 | |
parent | 6f0246651df44bcd7a196ff2c9f568e28c871a26 (diff) | |
download | nautilus-f31b2c1a2659e06d6fe07153d7520017ef1b9778.tar.gz |
Add attribute task class
-rw-r--r-- | src/meson.build | 2 | ||||
-rw-r--r-- | src/tasks/nautilus-attribute-task.c | 179 | ||||
-rw-r--r-- | 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 73c555f86..579e34e62 100644 --- a/src/meson.build +++ b/src/meson.build @@ -275,6 +275,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 000000000..a5d2f5365 --- /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 000000000..91bd8e7a6 --- /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 |