[nautilus/wip/ernestask/tasks: 1/17] Add task class
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/ernestask/tasks: 1/17] Add task class
- Date: Sat, 8 Jul 2017 14:18:38 +0000 (UTC)
commit 76a24a49fd7f9bc480160762eb8d22ad9b620e45
Author: Ernestas Kulik <ernestask gnome org>
Date: Thu May 11 16:29:06 2017 +0300
Add task class
src/meson.build | 4 +-
src/nautilus-task.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/nautilus-task.h | 50 +++++++++++++++++
3 files changed, 205 insertions(+), 1 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 83723b9..5f4b22b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -255,7 +255,9 @@ libnautilus_sources = [
'nautilus-file-undo-operations.c',
'nautilus-file-undo-operations.h',
'nautilus-file-undo-manager.c',
- 'nautilus-file-undo-manager.h'
+ 'nautilus-file-undo-manager.h',
+ 'nautilus-task.c',
+ 'nautilus-task.h',
]
if get_option ('enable-tracker')
diff --git a/src/nautilus-task.c b/src/nautilus-task.c
new file mode 100644
index 0000000..81447ae
--- /dev/null
+++ b/src/nautilus-task.c
@@ -0,0 +1,152 @@
+#include "nautilus-task.h"
+
+typedef struct
+{
+ GCancellable *cancellable;
+
+ gpointer task_data;
+ GDestroyNotify task_data_destroy;
+} NautilusTaskPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (NautilusTask, nautilus_task,
+ G_TYPE_OBJECT)
+
+enum
+{
+ PROP_CANCELLABLE = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
+static void
+set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_CANCELLABLE:
+ {
+ NautilusTask *self;
+ NautilusTaskPrivate *priv;
+
+ self = NAUTILUS_TASK (object);
+ priv = nautilus_task_get_instance_private (self);
+
+ if (G_UNLIKELY (priv->cancellable) != NULL)
+ {
+ g_clear_object (&priv->cancellable);
+ }
+
+ priv->cancellable = g_value_dup_object (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ }
+}
+
+static void
+finalize (GObject *object)
+{
+ NautilusTask *self;
+ NautilusTaskPrivate *priv;
+
+ self = NAUTILUS_TASK (object);
+ priv = nautilus_task_get_instance_private (self);
+
+ g_clear_object (&priv->cancellable);
+
+ if (priv->task_data != NULL && priv->task_data_destroy != NULL)
+ {
+ priv->task_data_destroy (priv->task_data);
+ }
+
+ G_OBJECT_CLASS (nautilus_task_parent_class)->finalize (object);
+}
+
+static void
+nautilus_task_class_init (NautilusTaskClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = set_property;
+ object_class->finalize = finalize;
+
+ properties[PROP_CANCELLABLE] =
+ g_param_spec_object ("cancellable", "Cancellable", "Cancellable",
+ G_TYPE_CANCELLABLE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+nautilus_task_init (NautilusTask *self)
+{
+}
+
+GCancellable *
+nautilus_task_get_cancellable (NautilusTask *task)
+{
+ NautilusTaskPrivate *priv;
+
+ g_return_val_if_fail (NAUTILUS_TASK (task), NULL);
+
+ priv = nautilus_task_get_instance_private (task);
+
+ return g_object_ref (priv->cancellable);
+}
+
+void
+nautilus_task_execute (NautilusTask *task)
+{
+ NautilusTaskClass *klass;
+
+ g_return_if_fail (NAUTILUS_IS_TASK (task));
+
+ klass = NAUTILUS_TASK_GET_CLASS (task);
+
+ g_return_if_fail (klass->execute != NULL);
+
+ klass->execute (task);
+}
+
+gpointer
+nautilus_task_get_task_data (NautilusTask *task)
+{
+ NautilusTaskPrivate *priv;
+
+ g_return_val_if_fail (NAUTILUS_IS_TASK (task), NULL);
+
+ priv = nautilus_task_get_instance_private (task);
+
+ return priv->task_data;
+}
+
+void
+nautilus_task_set_task_data (NautilusTask *task,
+ gpointer task_data,
+ GDestroyNotify task_data_destroy)
+{
+ NautilusTaskPrivate *priv;
+
+ g_return_if_fail (NAUTILUS_IS_TASK (task));
+
+ priv = nautilus_task_get_instance_private (task);
+
+ if (priv->task_data != NULL && priv->task_data_destroy != NULL)
+ {
+ priv->task_data_destroy (priv->task_data);
+ }
+
+ priv->task_data = task_data;
+ priv->task_data_destroy = task_data_destroy;
+}
diff --git a/src/nautilus-task.h b/src/nautilus-task.h
new file mode 100644
index 0000000..8c86841
--- /dev/null
+++ b/src/nautilus-task.h
@@ -0,0 +1,50 @@
+/* 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_TASK_H
+#define NAUTILUS_TASK_H
+
+#include <gio/gio.h>
+#include <glib-object.h>
+
+#define NAUTILUS_TYPE_TASK (nautilus_task_get_type ())
+
+G_DECLARE_DERIVABLE_TYPE (NautilusTask, nautilus_task,
+ NAUTILUS, TASK,
+ GObject)
+
+typedef void (*NautilusTaskCallback) (NautilusTask *task,
+ gpointer user_data);
+
+struct _NautilusTaskClass
+{
+ GObjectClass parent_class;
+
+ void (*execute) (NautilusTask *task);
+};
+
+GCancellable *nautilus_task_get_cancellable (NautilusTask *task);
+
+void nautilus_task_execute (NautilusTask *task);
+
+gpointer nautilus_task_get_task_data (NautilusTask *task);
+void nautilus_task_set_task_data (NautilusTask *task,
+ gpointer task_data,
+ GDestroyNotify task_data_destroy);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]