From 3480685d4e5a022530a07464fc20d10b45b3b358 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Mon, 16 Jun 2008 08:49:08 +0000 Subject: [PATCH] =?utf8?q?Bug=20536252=20=E2=80=93=20GFileEnumerator=20sho?= =?utf8?q?uld=20allow=20access=20to=20the=20containing=20GFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2008-06-16 Ross Burton Bug 536252 – GFileEnumerator should allow access to the containing GFile * gio/gfileenumerator.c: * gio/gfileenumerator.h: * gio/gfile.h: Add g_file_enumerator_get_container() and a container writeable construct-only property. Also shuffle around typedefs to make it compile. * gio/glocalfileenumerator.c: * gio/glocalfileenumerator.h: * gio/glocalfile.c: Instead of a string filename take a GFile in the constructor and use it to set the container property. * gio/gio.symbols: * docs/reference/gio/gio-sections.txt: Update with new API. svn path=/trunk/; revision=7044 --- ChangeLog | 22 +++++++++ docs/reference/gio/gio-sections.txt | 1 + gio/gfile.h | 2 + gio/gfileenumerator.c | 71 +++++++++++++++++++++++++++++ gio/gfileenumerator.h | 12 +++++ gio/gio.symbols | 1 + gio/glocalfile.c | 2 +- gio/glocalfileenumerator.c | 14 ++++-- gio/glocalfileenumerator.h | 3 +- 9 files changed, 123 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b4d50c7..52944192 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2008-06-16 Ross Burton + + Bug 536252 – GFileEnumerator should allow access to the containing + GFile + + * gio/gfileenumerator.c: + * gio/gfileenumerator.h: + * gio/gfile.h: + Add g_file_enumerator_get_container() and a container writeable + construct-only property. Also shuffle around typedefs to make it + compile. + + * gio/glocalfileenumerator.c: + * gio/glocalfileenumerator.h: + * gio/glocalfile.c: + Instead of a string filename take a GFile in the constructor and + use it to set the container property. + + * gio/gio.symbols: + * docs/reference/gio/gio-sections.txt: + Update with new API. + 2008-06-14 Matthias Clasen * glib/gtestutils.c: Move docs around diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index 7f95b321..8f68bd0d 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -146,6 +146,7 @@ g_file_enumerator_close_finish g_file_enumerator_is_closed g_file_enumerator_has_pending g_file_enumerator_set_pending +g_file_enumerator_get_container GFileEnumeratorClass G_FILE_ENUMERATOR diff --git a/gio/gfile.h b/gio/gfile.h index 2b9f35ed..711b01a5 100644 --- a/gio/gfile.h +++ b/gio/gfile.h @@ -124,6 +124,7 @@ typedef enum { G_FILE_MONITOR_WATCH_MOUNTS = (1<<0) } GFileMonitorFlags; +#if 0 /** * GFile: * @@ -132,6 +133,7 @@ typedef enum { * necessarily represent files or directories that currently exist. **/ typedef struct _GFile GFile; /* Dummy typedef */ +#endif typedef struct _GFileIface GFileIface; typedef struct _GFileMonitor GFileMonitor; diff --git a/gio/gfileenumerator.c b/gio/gfileenumerator.c index 32464622..e03edd52 100644 --- a/gio/gfileenumerator.c +++ b/gio/gfileenumerator.c @@ -56,12 +56,18 @@ G_DEFINE_TYPE (GFileEnumerator, g_file_enumerator, G_TYPE_OBJECT); struct _GFileEnumeratorPrivate { /* TODO: Should be public for subclasses? */ + GFile *container; guint closed : 1; guint pending : 1; GAsyncReadyCallback outstanding_callback; GError *outstanding_error; }; +enum { + PROP_0, + PROP_CONTAINER +}; + static void g_file_enumerator_real_next_files_async (GFileEnumerator *enumerator, int num_files, int io_priority, @@ -80,6 +86,42 @@ static gboolean g_file_enumerator_real_close_finish (GFileEnumerator * GAsyncResult *res, GError **error); +static void +g_file_enumerator_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GFileEnumerator *enumerator; + + enumerator = G_FILE_ENUMERATOR (object); + + switch (property_id) { + case PROP_CONTAINER: + enumerator->priv->container = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +g_file_enumerator_dispose (GObject *object) +{ + GFileEnumerator *enumerator; + + enumerator = G_FILE_ENUMERATOR (object); + + if (enumerator->priv->container) { + g_object_unref (enumerator->priv->container); + enumerator->priv->container = NULL; + } + + if (G_OBJECT_CLASS (g_file_enumerator_parent_class)->dispose) + (*G_OBJECT_CLASS (g_file_enumerator_parent_class)->dispose) (object); +} + static void g_file_enumerator_finalize (GObject *object) { @@ -101,12 +143,23 @@ g_file_enumerator_class_init (GFileEnumeratorClass *klass) g_type_class_add_private (klass, sizeof (GFileEnumeratorPrivate)); + gobject_class->set_property = g_file_enumerator_set_property; + gobject_class->dispose = g_file_enumerator_dispose; gobject_class->finalize = g_file_enumerator_finalize; klass->next_files_async = g_file_enumerator_real_next_files_async; klass->next_files_finish = g_file_enumerator_real_next_files_finish; klass->close_async = g_file_enumerator_real_close_async; klass->close_finish = g_file_enumerator_real_close_finish; + + g_object_class_install_property + (gobject_class, PROP_CONTAINER, + g_param_spec_object ("container", P_("Container"), + P_("The container that is being enumerated"), + G_TYPE_FILE, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } static void @@ -526,6 +579,24 @@ g_file_enumerator_set_pending (GFileEnumerator *enumerator, enumerator->priv->pending = pending; } +/** + * g_file_enumerator_get_container: + * @enumerator: a #GFileEnumerator + * + * Get the #GFile container which is being enumerated. + * + * Returns: the #GFile which is being enumerated. + * + * Since: 2.18. + */ +GFile * +g_file_enumerator_get_container (GFileEnumerator *enumerator) +{ + g_return_val_if_fail (G_IS_FILE_ENUMERATOR (enumerator), NULL); + + return enumerator->priv->container; +} + typedef struct { int num_files; GList *files; diff --git a/gio/gfileenumerator.h b/gio/gfileenumerator.h index 11d04fc4..af030c1e 100644 --- a/gio/gfileenumerator.h +++ b/gio/gfileenumerator.h @@ -53,6 +53,17 @@ typedef struct _GFileEnumerator GFileEnumerator; typedef struct _GFileEnumeratorClass GFileEnumeratorClass; typedef struct _GFileEnumeratorPrivate GFileEnumeratorPrivate; +/* Nasty */ +GType g_file_get_type (void) G_GNUC_CONST; +#define G_TYPE_FILE (g_file_get_type ()) +/** + * GFile: + * + * A handle to an object implementing the #GFileIface interface. + * Generally stores a location within the file system. Handles do not + * necessarily represent files or directories that currently exist. + **/ +typedef struct _GFile GFile; /* Dummy typedef */ struct _GFileEnumerator { @@ -133,6 +144,7 @@ gboolean g_file_enumerator_is_closed (GFileEnumerator *enumerator gboolean g_file_enumerator_has_pending (GFileEnumerator *enumerator); void g_file_enumerator_set_pending (GFileEnumerator *enumerator, gboolean pending); +GFile * g_file_enumerator_get_container (GFileEnumerator *enumerator); G_END_DECLS diff --git a/gio/gio.symbols b/gio/gio.symbols index 9f44c07b..28776c14 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -323,6 +323,7 @@ g_file_enumerator_close_finish g_file_enumerator_is_closed g_file_enumerator_has_pending g_file_enumerator_set_pending +g_file_enumerator_get_container #endif #endif diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 89d7033c..166a964e 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -578,7 +578,7 @@ g_local_file_enumerate_children (GFile *file, GError **error) { GLocalFile *local = G_LOCAL_FILE (file); - return _g_local_file_enumerator_new (local->filename, + return _g_local_file_enumerator_new (local, attributes, flags, cancellable, error); } diff --git a/gio/glocalfileenumerator.c b/gio/glocalfileenumerator.c index 7bef4080..2f78ed20 100644 --- a/gio/glocalfileenumerator.c +++ b/gio/glocalfileenumerator.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "glibintl.h" @@ -187,13 +188,16 @@ convert_file_to_io_error (GError **error, #endif GFileEnumerator * -_g_local_file_enumerator_new (const char *filename, +_g_local_file_enumerator_new (GLocalFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GLocalFileEnumerator *local; + char *filename; + + filename = g_file_get_path (G_FILE (file)); #ifdef USE_GDIR GError *dir_error; @@ -208,6 +212,7 @@ _g_local_file_enumerator_new (const char *filename, convert_file_to_io_error (error, dir_error); g_error_free (dir_error); } + g_free (filename); return NULL; } #else @@ -222,15 +227,18 @@ _g_local_file_enumerator_new (const char *filename, g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), "%s", g_strerror (errsv)); + g_free (filename); return NULL; } #endif - local = g_object_new (G_TYPE_LOCAL_FILE_ENUMERATOR, NULL); + local = g_object_new (G_TYPE_LOCAL_FILE_ENUMERATOR, + "container", file, + NULL); local->dir = dir; - local->filename = g_strdup (filename); + local->filename = filename; local->matcher = g_file_attribute_matcher_new (attributes); local->flags = flags; diff --git a/gio/glocalfileenumerator.h b/gio/glocalfileenumerator.h index a47565a0..7d93e9fc 100644 --- a/gio/glocalfileenumerator.h +++ b/gio/glocalfileenumerator.h @@ -26,6 +26,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -49,7 +50,7 @@ struct _GLocalFileEnumeratorClass GType _g_local_file_enumerator_get_type (void) G_GNUC_CONST; -GFileEnumerator *_g_local_file_enumerator_new (const char *filename, +GFileEnumerator *_g_local_file_enumerator_new (GLocalFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, -- 2.34.1