[nautilus/wip/ernestask/tasks: 1/9] Add task class
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/ernestask/tasks: 1/9] Add task class
- Date: Mon, 5 Jun 2017 19:07:09 +0000 (UTC)
commit 0a14d1f04dd9e0b2eab9bc00dab3ba9573dd6ec1
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 | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/nautilus-task.h | 33 +++++++++++++++++++++++++
3 files changed, 102 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..ebeb33b
--- /dev/null
+++ b/src/nautilus-task.c
@@ -0,0 +1,66 @@
+#include "nautilus-task.h"
+
+G_DEFINE_INTERFACE (NautilusTask, nautilus_task, G_TYPE_OBJECT)
+
+static void
+nautilus_task_default_init (NautilusTaskInterface *klass)
+{
+}
+
+GCancellable *
+nautilus_task_get_cancellable (NautilusTask *task)
+{
+ NautilusTaskInterface *iface;
+
+ g_return_val_if_fail (NAUTILUS_IS_TASK (task), NULL);
+
+ iface = NAUTILUS_TASK_GET_IFACE (task);
+
+ g_return_val_if_fail (iface->get_cancellable != NULL, NULL);
+
+ return iface->get_cancellable (task);
+}
+
+gboolean
+nautilus_task_is_canceled (NautilusTask *task)
+{
+ GCancellable *cancellable;
+
+ g_return_val_if_fail (NAUTILUS_IS_TASK (task), FALSE);
+
+ cancellable = nautilus_task_get_cancellable (task);
+
+ return g_cancellable_is_cancelled (cancellable);
+}
+
+void
+nautilus_task_cancel (NautilusTask *task)
+{
+ GCancellable *cancellable;
+
+ g_return_if_fail (NAUTILUS_IS_TASK (task));
+
+ cancellable = nautilus_task_get_cancellable (task);
+
+ g_cancellable_cancel (cancellable);
+}
+
+void
+nautilus_task_execute (NautilusTask *task,
+ NautilusTaskCallback callback,
+ gpointer user_data)
+{
+ NautilusTaskInterface *iface;
+
+ g_return_if_fail (NAUTILUS_IS_TASK (task));
+
+ iface = NAUTILUS_TASK_GET_IFACE (task);
+
+ g_return_if_fail (iface->execute != NULL);
+
+ iface->execute (task);
+ if (callback != NULL)
+ {
+ callback (task, user_data);
+ }
+}
diff --git a/src/nautilus-task.h b/src/nautilus-task.h
new file mode 100644
index 0000000..7426004
--- /dev/null
+++ b/src/nautilus-task.h
@@ -0,0 +1,33 @@
+#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_INTERFACE (NautilusTask, nautilus_task, NAUTILUS, TASK, GObject)
+
+typedef void (*NautilusTaskCallback) (NautilusTask *task,
+ gpointer user_data);
+
+struct _NautilusTaskInterface
+{
+ GTypeInterface g_iface;
+
+ /* Public methods */
+ GCancellable * (*get_cancellable) (NautilusTask *task);
+
+ void (*execute) (NautilusTask *task);
+};
+
+GCancellable *nautilus_task_get_cancellable (NautilusTask *task);
+
+gboolean nautilus_task_is_canceled (NautilusTask *task);
+
+void nautilus_task_cancel (NautilusTask *task);
+void nautilus_task_execute (NautilusTask *task,
+ NautilusTaskCallback callback,
+ gpointer user_data);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]