[Xfce4-commits] r29867 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Mon Apr 20 18:28:52 CEST 2009
Author: jannis
Date: 2009-04-20 16:28:52 +0000 (Mon, 20 Apr 2009)
New Revision: 29867
Added:
thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.c
thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.h
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/Makefile.am
thunar/branches/migration-to-gio/thunar/thunar-enum-types.h
thunar/branches/migration-to-gio/thunar/thunar-job.c
thunar/branches/migration-to-gio/thunar/thunar-job.h
thunar/branches/migration-to-gio/thunar/thunar-size-label.c
Log:
* thunar/Makefile.am, thunar/thunar-deep-count-job.{c,h}: Add new class
for computing the total size of a file/directory recursively while
also counting the total number of files and directories. This
implementation is almost equivalent to ThunarVfsDeepCountJob except
that it is an implementation of ThunarJob and uses GIOScheduler for
the asynchronous operation.
* thunar/thunar-enum-types.h: Add missing public declaration of
thunar_job_response_get_type().
* thunar/thunar-job.{c,h}: Add new functions
thunar_job_get_cancellable() and thunar_job_set_error_if_cancelled().
Make thunar_job_emit() public so that it can be used in subclasses.
Don't try to emit signals in thunar_job_finished() and
thunar_job_error() using GIOScheduler because they are only emitted
in thunar_job_async_ready() which is called from the GUI thread.
* thunar/thunar-size-label.c: Drop all ThunarVFS references by
replacing ThunarVfsDeepCountJob with ThunarDeepCountJob. Yay, it
works!
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-20 16:28:52 UTC (rev 29867)
@@ -1,5 +1,25 @@
2009-04-20 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/Makefile.am, thunar/thunar-deep-count-job.{c,h}: Add new class
+ for computing the total size of a file/directory recursively while
+ also counting the total number of files and directories. This
+ implementation is almost equivalent to ThunarVfsDeepCountJob except
+ that it is an implementation of ThunarJob and uses GIOScheduler for
+ the asynchronous operation.
+ * thunar/thunar-enum-types.h: Add missing public declaration of
+ thunar_job_response_get_type().
+ * thunar/thunar-job.{c,h}: Add new functions
+ thunar_job_get_cancellable() and thunar_job_set_error_if_cancelled().
+ Make thunar_job_emit() public so that it can be used in subclasses.
+ Don't try to emit signals in thunar_job_finished() and
+ thunar_job_error() using GIOScheduler because they are only emitted
+ in thunar_job_async_ready() which is called from the GUI thread.
+ * thunar/thunar-size-label.c: Drop all ThunarVFS references by
+ replacing ThunarVfsDeepCountJob with ThunarDeepCountJob. Yay, it
+ works!
+
+2009-04-20 Jannis Pohlmann <jannis at xfce.org>
+
* thunar/Makefile.am, thunar/thunar-enum-types.{c,h},
thunar/thunar-job.{c,h}, thunar/thunar-marshal.list: Add abstract
class ThunarJob which is going to be an equivalent to ThunarVfsJob.
Modified: thunar/branches/migration-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/migration-to-gio/thunar/Makefile.am 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/thunar/Makefile.am 2009-04-20 16:28:52 UTC (rev 29867)
@@ -57,6 +57,8 @@
thunar-create-dialog.h \
thunar-debug.h \
thunar-debug.c \
+ thunar-deep-count-job.h \
+ thunar-deep-count-job.c \
thunar-details-view-ui.h \
thunar-details-view.c \
thunar-details-view.h \
Added: thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.c (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.c 2009-04-20 16:28:52 UTC (rev 29867)
@@ -0,0 +1,365 @@
+/* vi:set sw=2 sts=2 ts=2 et ai: */
+/*-
+ * Copyright (c) 2009 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include <thunar/thunar-deep-count-job.h>
+#include <thunar/thunar-job.h>
+#include <thunar/thunar-marshal.h>
+#include <thunar/thunar-private.h>
+
+
+
+/* Signal identifiers */
+enum
+{
+ STATUS_UPDATE,
+ LAST_SIGNAL,
+};
+
+
+
+static void thunar_deep_count_job_class_init (ThunarDeepCountJobClass *klass);
+static void thunar_deep_count_job_init (ThunarDeepCountJob *job);
+static void thunar_deep_count_job_finalize (GObject *object);
+static gboolean thunar_deep_count_job_execute (ThunarJob *job,
+ GError **error);
+
+
+
+struct _ThunarDeepCountJobClass
+{
+ ThunarJobClass __parent__;
+
+ /* signals */
+ void (*status_update) (ThunarJob *job,
+ guint64 total_size,
+ guint file_count,
+ guint directory_count,
+ guint unreadable_directory_count);
+};
+
+struct _ThunarDeepCountJob
+{
+ ThunarJob __parent__;
+
+ GFile *file;
+ GFileQueryInfoFlags query_flags;
+
+ /* the time of the last "status-update" emission */
+ GTimeVal last_time;
+
+ /* status information */
+ guint64 total_size;
+ guint file_count;
+ guint directory_count;
+ guint unreadable_directory_count;
+};
+
+
+
+static GObjectClass *thunar_deep_count_job_parent_class = NULL;
+static guint deep_count_signals[LAST_SIGNAL];
+
+
+
+GType
+thunar_deep_count_job_get_type (void)
+{
+ static GType type = G_TYPE_INVALID;
+
+ if (G_UNLIKELY (type == G_TYPE_INVALID))
+ {
+ type = g_type_register_static_simple (THUNAR_TYPE_JOB,
+ "ThunarDeepCountJob",
+ sizeof (ThunarDeepCountJobClass),
+ (GClassInitFunc) thunar_deep_count_job_class_init,
+ sizeof (ThunarDeepCountJob),
+ (GInstanceInitFunc) thunar_deep_count_job_init,
+ 0);
+ }
+
+ return type;
+}
+
+
+
+static void
+thunar_deep_count_job_class_init (ThunarDeepCountJobClass *klass)
+{
+ ThunarJobClass *job_class;
+ GObjectClass *gobject_class;
+
+ /* Determine the parent type class */
+ thunar_deep_count_job_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = thunar_deep_count_job_finalize;
+
+ job_class = THUNAR_JOB_CLASS (klass);
+ job_class->execute = thunar_deep_count_job_execute;
+
+ /**
+ * ThunarDeepCountJob::status-update:
+ * @job : a #ThunarJob.
+ * @total_size : the total size in bytes.
+ * @file_count : the number of files.
+ * @directory_count : the number of directories.
+ * @unreadable_directory_count : the number of unreadable directories.
+ *
+ * Emitted by the @job to inform listeners about the number of files,
+ * directories and bytes counted so far.
+ **/
+ deep_count_signals[STATUS_UPDATE] =
+ g_signal_new ("status-update",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (ThunarDeepCountJobClass, status_update),
+ NULL, NULL,
+ _thunar_marshal_VOID__UINT64_UINT_UINT_UINT,
+ G_TYPE_NONE, 4,
+ G_TYPE_UINT64,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_UINT);
+}
+
+
+
+static void
+thunar_deep_count_job_init (ThunarDeepCountJob *job)
+{
+ job->file = NULL;
+ job->query_flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
+ job->total_size = 0;
+ job->file_count = 0;
+ job->directory_count = 0;
+ job->unreadable_directory_count = 0;
+}
+
+
+
+static void
+thunar_deep_count_job_finalize (GObject *object)
+{
+ ThunarDeepCountJob *job = THUNAR_DEEP_COUNT_JOB (object);
+
+ if (G_LIKELY (job->file != NULL))
+ g_object_unref (job->file);
+
+ (*G_OBJECT_CLASS (thunar_deep_count_job_parent_class)->finalize) (object);
+}
+
+
+
+static void
+thunar_deep_count_job_status_update (ThunarDeepCountJob *job)
+{
+ _thunar_return_if_fail (THUNAR_IS_DEEP_COUNT_JOB (job));
+
+ thunar_job_emit (THUNAR_JOB (job),
+ deep_count_signals[STATUS_UPDATE],
+ 0,
+ job->total_size,
+ job->file_count,
+ job->directory_count,
+ job->unreadable_directory_count);
+}
+
+
+
+static gboolean
+thunar_deep_count_job_process (ThunarJob *job,
+ GFile *file,
+ GError **error)
+{
+ ThunarDeepCountJob *count_job = THUNAR_DEEP_COUNT_JOB (job);
+ GFileEnumerator *enumerator;
+ GFileInfo *child_info;
+ GFileInfo *info;
+ gboolean success = TRUE;
+ GFile *child;
+
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
+ _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
+ _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* abort if job was already cancelled */
+ if (thunar_job_is_cancelled (job))
+ return FALSE;
+
+ /* query size and type of the current file */
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ count_job->query_flags,
+ thunar_job_get_cancellable (job),
+ error);
+
+ /* abort on invalid info or cancellation */
+ if (info == NULL || thunar_job_is_cancelled (job))
+ return FALSE;
+
+ /* add size of the file to the total size */
+ count_job->total_size += g_file_info_get_size (info);
+
+ /* recurse if we have a directory */
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ /* try to read from the directory */
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_SIZE ","
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ count_job->query_flags,
+ thunar_job_get_cancellable (job),
+ error);
+
+ if (!thunar_job_is_cancelled (job))
+ {
+ if (enumerator == NULL)
+ {
+ /* directory was unreadable */
+ count_job->unreadable_directory_count += 1;
+
+ if (file == count_job->file)
+ {
+ /* we only bail out if the job file is unreadable */
+ success = FALSE;
+ }
+ else
+ {
+ /* ignore errors from files other than the job file */
+ g_error_free (*error);
+ *error = NULL;
+ }
+ }
+ else
+ {
+ /* directory was readable */
+ count_job->directory_count += 1;
+
+ while (!thunar_job_is_cancelled (job))
+ {
+ /* query next child info */
+ child_info = g_file_enumerator_next_file (enumerator,
+ thunar_job_get_cancellable (job),
+ error);
+
+ /* abort on invalid child info (iteration ends) or cancellation */
+ if (child_info == NULL || thunar_job_is_cancelled (job))
+ break;
+
+ /* generate a GFile for the child */
+ child = g_file_resolve_relative_path (file,
+ g_file_info_get_name (child_info));
+
+ /* recurse unless the job was cancelled before */
+ if (!thunar_job_is_cancelled (job))
+ thunar_deep_count_job_process (job, child, error);
+
+ /* free resources */
+ g_object_unref (child);
+ g_object_unref (child_info);
+ }
+
+ /* destroy the enumerator */
+ g_object_unref (enumerator);
+ }
+ }
+
+ /* emit status update whenever we've finished a directory */
+ thunar_deep_count_job_status_update (count_job);
+ }
+ else
+ {
+ /* we have a regular file or at least not a directory */
+ count_job->file_count += 1;
+ }
+
+ /* destroy the file info */
+ g_object_unref (info);
+
+ /* emit final status update at the very end of the computation */
+ if (file == count_job->file)
+ thunar_deep_count_job_status_update (count_job);
+
+ /* we've succeeded if there was no error when loading information
+ * about the job file itself and the job was not cancelled */
+ return !thunar_job_is_cancelled (job) && success;
+}
+
+
+
+static gboolean
+thunar_deep_count_job_execute (ThunarJob *job,
+ GError **error)
+{
+ gboolean success;
+
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
+ _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* don't start the job if it was already cancelled */
+ if (thunar_job_set_error_if_cancelled (job, error))
+ return FALSE;
+
+ /* count files, directories and compute size of the job file */
+ success = thunar_deep_count_job_process (job,
+ THUNAR_DEEP_COUNT_JOB (job)->file,
+ error);
+
+ /* avoid overwriting the error if the job was cancelled */
+ if (*error != NULL && thunar_job_is_cancelled (job))
+ {
+ g_error_free (*error);
+ *error = NULL;
+ }
+
+ /* set error if the job was cancelled. otherwise just propagate
+ * the results of the processing function */
+ if (thunar_job_set_error_if_cancelled (job, error))
+ return FALSE;
+ else
+ return success;
+}
+
+
+
+ThunarJob *
+thunar_deep_count_job_new (GFile *file,
+ GFileQueryInfoFlags flags)
+{
+ ThunarDeepCountJob *job;
+
+ _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ job = g_object_new (THUNAR_TYPE_DEEP_COUNT_JOB, NULL);
+ job->file = g_object_ref (file);
+ job->query_flags = flags;
+
+ return THUNAR_JOB (job);
+}
Added: thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.h (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-deep-count-job.h 2009-04-20 16:28:52 UTC (rev 29867)
@@ -0,0 +1,48 @@
+/* vi:set sw=2 sts=2 ts=2 et ai: */
+/*-
+ * Copyright (c) 2009 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __THUNAR_DEEP_COUNT_JOB_H__
+#define __THUNAR_DEEP_COUNT_JOB_H__
+
+#include <gio/gio.h>
+
+#include <thunar/thunar-job.h>
+
+G_BEGIN_DECLS;
+
+typedef struct _ThunarDeepCountJobPrivate ThunarDeepCountJobPrivate;
+typedef struct _ThunarDeepCountJobClass ThunarDeepCountJobClass;
+typedef struct _ThunarDeepCountJob ThunarDeepCountJob;
+
+#define THUNAR_TYPE_DEEP_COUNT_JOB (thunar_deep_count_job_get_type ())
+#define THUNAR_DEEP_COUNT_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_DEEP_COUNT_JOB, ThunarDeepCountJob))
+#define THUNAR_DEEP_COUNT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_DEEP_COUNT_JOB, ThunarDeepCountJobClass))
+#define THUNAR_IS_DEEP_COUNT_JOB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_DEEP_COUNT_JOB))
+#define THUNAR_IS_DEEP_COUNT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_DEEP_COUNT_JOB)
+#define THUNAR_DEEP_COUNT_JOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DEEP_COUNT_JOB, ThunarDeepCountJobClass))
+
+GType thunar_deep_count_job_get_type (void) G_GNUC_CONST;
+
+ThunarJob *thunar_deep_count_job_new (GFile *file,
+ GFileQueryInfoFlags flags);
+
+G_END_DECLS;
+
+#endif /* !__THUNAR_DEEP_COUNT_JOB_H__ */
Modified: thunar/branches/migration-to-gio/thunar/thunar-enum-types.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-enum-types.h 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/thunar/thunar-enum-types.h 2009-04-20 16:28:52 UTC (rev 29867)
@@ -259,6 +259,8 @@
THUNAR_JOB_RESPONSE_RETRY = 1 << 5,
} ThunarJobResponse;
+GType thunar_job_response_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
+
G_END_DECLS;
#endif /* !__THUNAR_ENUM_TYPES_H__ */
Modified: thunar/branches/migration-to-gio/thunar/thunar-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.c 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.c 2009-04-20 16:28:52 UTC (rev 29867)
@@ -322,7 +322,7 @@
/**
- * thunar_job_cancelled:
+ * thunar_job_is_cancelled:
* @job : a #ThunarJob.
*
* Checks whether @job was previously cancelled
@@ -331,7 +331,7 @@
* Return value: %TRUE if @job is cancelled.
**/
gboolean
-thunar_job_cancelled (const ThunarJob *job)
+thunar_job_is_cancelled (const ThunarJob *job)
{
_thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
return g_cancellable_is_cancelled (job->priv->cancellable);
@@ -339,6 +339,26 @@
+GCancellable *
+thunar_job_get_cancellable (const ThunarJob *job)
+{
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), NULL);
+ return job->priv->cancellable;
+}
+
+
+
+gboolean
+thunar_job_set_error_if_cancelled (ThunarJob *job,
+ GError **error)
+{
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
+ _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ return g_cancellable_set_error_if_cancelled (job->priv->cancellable, error);
+}
+
+
+
static gboolean
_thunar_job_emit_valist_in_mainloop (gpointer user_data)
{
@@ -402,7 +422,7 @@
_thunar_return_if_fail (error != NULL);
_thunar_return_if_fail (g_utf8_validate (error->message, -1, NULL));
- thunar_job_emit (job, job_signals[ERROR], 0, error);
+ g_signal_emit (job, job_signals[ERROR], 0, error);
}
@@ -412,5 +432,5 @@
{
_thunar_return_if_fail (THUNAR_IS_JOB (job));
- thunar_job_emit (job, job_signals[FINISHED], 0);
+ g_signal_emit (job, job_signals[FINISHED], 0);
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.h 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.h 2009-04-20 16:28:52 UTC (rev 29867)
@@ -59,15 +59,20 @@
ThunarJobPrivate *priv;
};
-GType thunar_job_get_type (void) G_GNUC_CONST;
-ThunarJob *thunar_job_launch (ThunarJob *job);
-void thunar_job_cancel (ThunarJob *job);
-gboolean thunar_job_is_cancelled (const ThunarJob *job);
+GType thunar_job_get_type (void) G_GNUC_CONST;
+ThunarJob *thunar_job_launch (ThunarJob *job);
+void thunar_job_cancel (ThunarJob *job);
+gboolean thunar_job_is_cancelled (const ThunarJob *job);
-void thunar_job_error (ThunarJob *job,
- GError *error);
-void thunar_job_finished (ThunarJob *job);
+GCancellable *thunar_job_get_cancellable (const ThunarJob *job);
+gboolean thunar_job_set_error_if_cancelled (ThunarJob *job,
+ GError **error);
+void thunar_job_emit (ThunarJob *job,
+ guint signal_id,
+ GQuark signal_detail,
+ ...);
+
G_END_DECLS
#endif /* !__THUNAR_JOB_H__ */
Modified: thunar/branches/migration-to-gio/thunar/thunar-size-label.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-size-label.c 2009-04-20 16:09:03 UTC (rev 29866)
+++ thunar/branches/migration-to-gio/thunar/thunar-size-label.c 2009-04-20 16:28:52 UTC (rev 29867)
@@ -32,6 +32,7 @@
#include <thunar/thunar-private.h>
#include <thunar/thunar-size-label.h>
#include <thunar/thunar-throbber.h>
+#include <thunar/thunar-deep-count-job.h>
@@ -60,12 +61,12 @@
ThunarSizeLabel *size_label);
static void thunar_size_label_file_changed (ThunarFile *file,
ThunarSizeLabel *size_label);
-static void thunar_size_label_error (ThunarVfsJob *job,
+static void thunar_size_label_error (ThunarJob *job,
const GError *error,
ThunarSizeLabel *size_label);
-static void thunar_size_label_finished (ThunarVfsJob *job,
+static void thunar_size_label_finished (ThunarJob *job,
ThunarSizeLabel *size_label);
-static void thunar_size_label_status_ready (ThunarVfsJob *job,
+static void thunar_size_label_status_update (ThunarJob *job,
guint64 total_size,
guint file_count,
guint directory_count,
@@ -84,8 +85,9 @@
struct _ThunarSizeLabel
{
GtkHBox __parent__;
- ThunarVfsJob *job;
+ ThunarJob *job;
+
ThunarFile *file;
GtkWidget *label;
@@ -206,7 +208,7 @@
if (G_UNLIKELY (size_label->job != NULL))
{
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
- thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
+ thunar_job_cancel (THUNAR_JOB (size_label->job));
g_object_unref (G_OBJECT (size_label->job));
}
@@ -285,8 +287,8 @@
if (G_UNLIKELY (size_label->job != NULL))
{
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
- thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
- g_object_unref (G_OBJECT (size_label->job));
+ thunar_job_cancel (size_label->job);
+ g_object_unref (size_label->job);
size_label->job = NULL;
}
@@ -307,7 +309,7 @@
static gchar*
-tsl_format_size_string (ThunarVfsFileSize size)
+tsl_format_size_string (guint64 size)
{
GString *result;
gchar *grouping;
@@ -356,11 +358,11 @@
thunar_size_label_file_changed (ThunarFile *file,
ThunarSizeLabel *size_label)
{
- ThunarVfsFileSize size;
- GError *error = NULL;
- gchar *size_humanized;
- gchar *size_string;
- gchar *text;
+ guint64 size;
+ GError *error = NULL;
+ gchar *size_humanized;
+ gchar *size_string;
+ gchar *text;
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
_thunar_return_if_fail (size_label->file == file);
@@ -374,7 +376,7 @@
if (G_UNLIKELY (size_label->job != NULL))
{
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
- thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
+ thunar_job_cancel (THUNAR_JOB (size_label->job));
g_object_unref (G_OBJECT (size_label->job));
size_label->job = NULL;
}
@@ -387,23 +389,16 @@
if (thunar_file_is_directory (file))
{
/* schedule a new job to determine the total size of the directory (not following symlinks) */
- size_label->job = thunar_vfs_deep_count (thunar_file_get_path (file), THUNAR_VFS_DEEP_COUNT_FLAGS_NONE, &error);
- if (G_UNLIKELY (size_label->job == NULL))
- {
- /* display the error to the user */
- gtk_label_set_text (GTK_LABEL (size_label->label), error->message);
- g_error_free (error);
- }
- else
- {
- /* connect to the job */
- g_signal_connect (G_OBJECT (size_label->job), "error", G_CALLBACK (thunar_size_label_error), size_label);
- g_signal_connect (G_OBJECT (size_label->job), "finished", G_CALLBACK (thunar_size_label_finished), size_label);
- g_signal_connect (G_OBJECT (size_label->job), "status-ready", G_CALLBACK (thunar_size_label_status_ready), size_label);
+ size_label->job = thunar_deep_count_job_new (thunar_file_get_file (file), G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS);
+ g_signal_connect (size_label->job, "error", G_CALLBACK (thunar_size_label_error), size_label);
+ g_signal_connect (size_label->job, "finished", G_CALLBACK (thunar_size_label_finished), size_label);
+ g_signal_connect (size_label->job, "status-update", G_CALLBACK (thunar_size_label_status_update), size_label);
- /* tell the user that we started calculation */
- gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
- }
+ /* tell the user that we started calculation */
+ gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
+
+ /* launch the job */
+ thunar_job_launch (size_label->job);
}
else
{
@@ -419,7 +414,7 @@
if (G_LIKELY (size > 1024ul))
{
/* prepend the humanized size */
- size_humanized = thunar_vfs_humanize_size (size, NULL, 0);
+ size_humanized = g_file_size_humanize (size);
text = g_strdup_printf ("%s (%s)", size_humanized, size_string);
g_free (size_humanized);
g_free (size_string);
@@ -437,12 +432,12 @@
static void
-thunar_size_label_error (ThunarVfsJob *job,
+thunar_size_label_error (ThunarJob *job,
const GError *error,
ThunarSizeLabel *size_label)
{
+ _thunar_return_if_fail (THUNAR_IS_JOB (job));
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
- _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
_thunar_return_if_fail (size_label->job == job);
/* setup the error text as label */
@@ -452,11 +447,11 @@
static void
-thunar_size_label_finished (ThunarVfsJob *job,
+thunar_size_label_finished (ThunarJob *job,
ThunarSizeLabel *size_label)
{
+ _thunar_return_if_fail (THUNAR_IS_JOB (job));
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
- _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
_thunar_return_if_fail (size_label->job == job);
/* be sure to cancel the animate timer */
@@ -476,19 +471,19 @@
static void
-thunar_size_label_status_ready (ThunarVfsJob *job,
- guint64 total_size,
- guint file_count,
- guint directory_count,
- guint unreadable_directory_count,
- ThunarSizeLabel *size_label)
+thunar_size_label_status_update (ThunarJob *job,
+ guint64 total_size,
+ guint file_count,
+ guint directory_count,
+ guint unreadable_directory_count,
+ ThunarSizeLabel *size_label)
{
gchar *size_string;
gchar *text;
guint n;
+ _thunar_return_if_fail (THUNAR_IS_JOB (job));
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
- _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
_thunar_return_if_fail (size_label->job == job);
/* check if the animate timer is already running */
@@ -503,7 +498,7 @@
n = file_count + directory_count + unreadable_directory_count;
/* update the label */
- size_string = thunar_vfs_humanize_size (total_size, NULL, 0);
+ size_string = g_file_size_humanize (total_size);
text = g_strdup_printf (ngettext ("%u item, totalling %s", "%u items, totalling %s", n), n, size_string);
gtk_label_set_text (GTK_LABEL (size_label->label), text);
g_free (size_string);
More information about the Xfce4-commits
mailing list