[Xfce4-commits] <thunar:nick/1.8> Move task thread function in separate file.
Nick Schermer
noreply at xfce.org
Sun Aug 4 21:52:11 CEST 2013
Updating branch refs/heads/nick/1.8
to da5da99a22c83f519a9369b8d90d2c948423b510 (commit)
from 9f2040763c3661ac865a798281d720b0df1e0fd0 (commit)
commit da5da99a22c83f519a9369b8d90d2c948423b510
Author: Nick Schermer <nick at xfce.org>
Date: Sun Aug 4 02:26:15 2013 +0200
Move task thread function in separate file.
Makes it for me easier to read.
thunar/Makefile.am | 2 +
thunar/thunar-folder.c | 12 +--
thunar/thunar-io-jobs.c | 31 -------
thunar/thunar-io-jobs.h | 4 -
thunar/thunar-tasks.c | 94 ++++++++++++++++++++++
thunar/{thunar-io-jobs-util.h => thunar-tasks.h} | 20 ++---
thunar/thunar-templates-action.c | 15 ++--
7 files changed, 116 insertions(+), 62 deletions(-)
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index 24c4009..ace59c9 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -188,6 +188,8 @@ thunar_SOURCES = \
thunar-templates-action.h \
thunar-text-renderer.c \
thunar-text-renderer.h \
+ thunar-tasks.c \
+ thunar-tasks.h \
thunar-thumbnail-cache.c \
thunar-thumbnail-cache.h \
thunar-thumbnailer.c \
diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c
index d305404..46fac6b 100644
--- a/thunar/thunar-folder.c
+++ b/thunar/thunar-folder.c
@@ -25,8 +25,7 @@
#include <thunar/thunar-file-monitor.h>
#include <thunar/thunar-folder.h>
#include <thunar/thunar-gobject-extensions.h>
-#include <thunar/thunar-io-jobs.h>
-#include <thunar/thunar-job.h>
+#include <thunar/thunar-tasks.h>
#include <thunar/thunar-private.h>
#define DEBUG_FILE_CHANGES FALSE
@@ -867,8 +866,6 @@ thunar_folder_get_loading (const ThunarFolder *folder)
void
thunar_folder_reload (ThunarFolder *folder)
{
- GCancellable *cancellable;
-
_thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
/* stop metadata collector */
@@ -894,11 +891,8 @@ thunar_folder_reload (ThunarFolder *folder)
}
/* start a new task */
- cancellable = g_cancellable_new ();
- folder->task = g_task_new (folder, cancellable, thunar_folder_finished, NULL);
- g_task_set_task_data (folder->task, thunar_file_get_file (folder->corresponding_file), NULL);
- g_task_run_in_thread (folder->task, thunar_io_jobs_list_directory);
- g_object_unref (cancellable);
+ folder->task = thunar_tasks_new (folder,thunar_folder_finished, NULL);
+ thunar_tasks_list_directory (folder->task, thunar_file_get_file (folder->corresponding_file));
/* tell all consumers that we're loading */
g_object_notify (G_OBJECT (folder), "loading");
diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c
index c9dd3e6..f72a246 100644
--- a/thunar/thunar-io-jobs.c
+++ b/thunar/thunar-io-jobs.c
@@ -1165,37 +1165,6 @@ thunar_io_jobs_change_mode (GList *files,
-void
-thunar_io_jobs_list_directory (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GFile *directory = G_FILE (task_data);
- GList *file_list;
- GError *err = NULL;
-
- _thunar_return_if_fail (G_IS_FILE (task_data));
-
- /* collect directory contents (non-recursively) */
- file_list = thunar_io_scan_directory2 (directory, cancellable,
- G_FILE_QUERY_INFO_NONE,
- FALSE, FALSE, TRUE, &err);
-
- /* abort on errors or cancellation */
- if (err != NULL)
- {
- _thunar_assert (file_list == NULL);
- g_task_return_error (task, err);
- return;
- }
-
- /* we've got the files */
- g_task_return_pointer (task, file_list, NULL);
-}
-
-
-
static gboolean
_thunar_io_jobs_rename_notify (ThunarFile *file)
{
diff --git a/thunar/thunar-io-jobs.h b/thunar/thunar-io-jobs.h
index 82b1aa2..851e35d 100644
--- a/thunar/thunar-io-jobs.h
+++ b/thunar/thunar-io-jobs.h
@@ -48,10 +48,6 @@ ThunarJob *thunar_io_jobs_change_mode (GList *files,
ThunarFileMode file_mask,
ThunarFileMode file_mode,
gboolean recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-void thunar_io_jobs_list_directory (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable);
ThunarJob *thunar_io_jobs_rename_file (ThunarFile *file,
const gchar *display_name) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
diff --git a/thunar/thunar-tasks.c b/thunar/thunar-tasks.c
new file mode 100644
index 0000000..3eff724
--- /dev/null
+++ b/thunar/thunar-tasks.c
@@ -0,0 +1,94 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gio/gio.h>
+
+#include <thunar/thunar-enum-types.h>
+#include <thunar/thunar-gio-extensions.h>
+#include <thunar/thunar-tasks.h>
+#include <thunar/thunar-private.h>
+#include <thunar/thunar-io-scan-directory.h>
+
+
+
+GTask *
+thunar_tasks_new (gpointer source_object,
+ GAsyncReadyCallback callback,
+ gpointer callback_data)
+{
+ GCancellable *cancellable;
+ GTask *task;
+
+ _thunar_return_val_if_fail (source_object == NULL || G_IS_OBJECT (source_object), NULL);
+
+ cancellable = g_cancellable_new ();
+ task = g_task_new (source_object, cancellable, callback, callback_data);
+ g_object_unref (cancellable);
+
+ return task;
+}
+
+
+
+static void
+thunar_tasks_list_directory_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GFile *directory = G_FILE (task_data);
+ GList *file_list;
+ GError *err = NULL;
+
+ _thunar_return_if_fail (G_IS_FILE (task_data));
+
+ /* collect directory contents (non-recursively) */
+ file_list = thunar_io_scan_directory2 (directory, cancellable,
+ G_FILE_QUERY_INFO_NONE,
+ FALSE, FALSE, TRUE, &err);
+
+ /* abort on errors or cancellation */
+ if (err != NULL)
+ {
+ _thunar_assert (file_list == NULL);
+ g_task_return_error (task, err);
+ return;
+ }
+
+ /* we've got the files */
+ g_task_return_pointer (task, file_list, NULL);
+}
+
+
+
+void
+thunar_tasks_list_directory (GTask *task,
+ GFile *directory)
+{
+ _thunar_return_if_fail (G_IS_FILE (directory));
+ _thunar_return_if_fail (G_IS_TASK (task));
+
+ g_task_set_task_data (task, g_object_ref (directory), g_object_unref);
+ g_task_run_in_thread (task, thunar_tasks_list_directory_thread);
+}
diff --git a/thunar/thunar-io-jobs-util.h b/thunar/thunar-tasks.h
similarity index 60%
copy from thunar/thunar-io-jobs-util.h
copy to thunar/thunar-tasks.h
index 2ff2896..911121c 100644
--- a/thunar/thunar-io-jobs-util.h
+++ b/thunar/thunar-tasks.h
@@ -1,6 +1,7 @@
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
* Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2013 Nick Schermer <nick at xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,19 +19,20 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __THUNAR_IO_JOBS_UTIL_H__
-#define __THUNAR_IO_JOBS_UTIL_H__
+#ifndef __THUNAR_TASKS_H__
+#define __THUNAR_TASKS_H__
-#include <thunar/thunar-job.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
-GFile *thunar_io_jobs_util_next_duplicate_file (ThunarJob *job,
- GFile *file,
- gboolean copy,
- guint n,
- GError **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GTask *thunar_tasks_new (gpointer source_object,
+ GAsyncReadyCallback callback,
+ gpointer callback_data);
+
+void thunar_tasks_list_directory (GTask *task,
+ GFile *directory);
G_END_DECLS
-#endif /* !__THUNAR_IO_JOBS_UITL_H__ */
+#endif /* !__THUNAR_TASKS_H__ */
diff --git a/thunar/thunar-templates-action.c b/thunar/thunar-templates-action.c
index f43ef5a..7af55b4 100644
--- a/thunar/thunar-templates-action.c
+++ b/thunar/thunar-templates-action.c
@@ -25,7 +25,7 @@
#include <gio/gio.h>
#include <thunar/thunar-icon-factory.h>
-#include <thunar/thunar-io-jobs.h>
+#include <thunar/thunar-tasks.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-templates-action.h>
@@ -504,9 +504,8 @@ static void
thunar_templates_action_menu_shown (GtkWidget *menu,
ThunarTemplatesAction *templates_action)
{
- GList *children;
- GFile *templates_dir;
- GCancellable *cancellable;
+ GList *children;
+ GFile *templates_dir;
_thunar_return_if_fail (THUNAR_IS_TEMPLATES_ACTION (templates_action));
_thunar_return_if_fail (GTK_IS_MENU_SHELL (menu));
@@ -521,11 +520,9 @@ thunar_templates_action_menu_shown (GtkWidget *menu,
if (templates_dir != NULL)
{
/* start the collection task */
- cancellable = g_cancellable_new ();
- templates_action->task = g_task_new (templates_action, cancellable, thunar_templates_action_load_finished, menu);
- g_task_set_task_data (templates_action->task, templates_dir, g_object_unref);
- g_task_run_in_thread (templates_action->task, thunar_io_jobs_list_directory);
- g_object_unref (cancellable);
+ templates_action->task = thunar_tasks_new (templates_action, thunar_templates_action_load_finished, menu);
+ thunar_tasks_list_directory (templates_action->task, templates_dir);
+ g_object_unref (templates_dir);
}
else
{
More information about the Xfce4-commits
mailing list