+2008-06-16 Ross Burton <ross@burtonini.com>
+
+ 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 <mclasen@redhat.com>
* glib/gtestutils.c: Move docs around
g_file_enumerator_is_closed
g_file_enumerator_has_pending
g_file_enumerator_set_pending
+g_file_enumerator_get_container
<SUBSECTION Standard>
GFileEnumeratorClass
G_FILE_ENUMERATOR
G_FILE_MONITOR_WATCH_MOUNTS = (1<<0)
} GFileMonitorFlags;
+#if 0
/**
* GFile:
*
* necessarily represent files or directories that currently exist.
**/
typedef struct _GFile GFile; /* Dummy typedef */
+#endif
typedef struct _GFileIface GFileIface;
typedef struct _GFileMonitor GFileMonitor;
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,
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)
{
GFileEnumerator *enumerator;
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
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;
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
{
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
g_file_enumerator_is_closed
g_file_enumerator_has_pending
g_file_enumerator_set_pending
+g_file_enumerator_get_container
#endif
#endif
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);
}
#include <glib.h>
#include <glocalfileenumerator.h>
#include <glocalfileinfo.h>
+#include <glocalfile.h>
#include <string.h>
#include <stdlib.h>
#include "glibintl.h"
#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;
convert_file_to_io_error (error, dir_error);
g_error_free (dir_error);
}
+ g_free (filename);
return NULL;
}
#else
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;
#include <gfileenumerator.h>
#include <gfileinfo.h>
#include <gfile.h>
+#include <glocalfile.h>
G_BEGIN_DECLS
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,