mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
Bug 536252 – GFileEnumerator should allow access to the containing GFile
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. svn path=/trunk/; revision=7044
This commit is contained in:
22
ChangeLog
22
ChangeLog
@@ -1,3 +1,25 @@
|
|||||||
|
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>
|
2008-06-14 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gtestutils.c: Move docs around
|
* glib/gtestutils.c: Move docs around
|
||||||
|
@@ -146,6 +146,7 @@ g_file_enumerator_close_finish
|
|||||||
g_file_enumerator_is_closed
|
g_file_enumerator_is_closed
|
||||||
g_file_enumerator_has_pending
|
g_file_enumerator_has_pending
|
||||||
g_file_enumerator_set_pending
|
g_file_enumerator_set_pending
|
||||||
|
g_file_enumerator_get_container
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
GFileEnumeratorClass
|
GFileEnumeratorClass
|
||||||
G_FILE_ENUMERATOR
|
G_FILE_ENUMERATOR
|
||||||
|
@@ -124,6 +124,7 @@ typedef enum {
|
|||||||
G_FILE_MONITOR_WATCH_MOUNTS = (1<<0)
|
G_FILE_MONITOR_WATCH_MOUNTS = (1<<0)
|
||||||
} GFileMonitorFlags;
|
} GFileMonitorFlags;
|
||||||
|
|
||||||
|
#if 0
|
||||||
/**
|
/**
|
||||||
* GFile:
|
* GFile:
|
||||||
*
|
*
|
||||||
@@ -132,6 +133,7 @@ typedef enum {
|
|||||||
* necessarily represent files or directories that currently exist.
|
* necessarily represent files or directories that currently exist.
|
||||||
**/
|
**/
|
||||||
typedef struct _GFile GFile; /* Dummy typedef */
|
typedef struct _GFile GFile; /* Dummy typedef */
|
||||||
|
#endif
|
||||||
typedef struct _GFileIface GFileIface;
|
typedef struct _GFileIface GFileIface;
|
||||||
typedef struct _GFileMonitor GFileMonitor;
|
typedef struct _GFileMonitor GFileMonitor;
|
||||||
|
|
||||||
|
@@ -56,12 +56,18 @@ G_DEFINE_TYPE (GFileEnumerator, g_file_enumerator, G_TYPE_OBJECT);
|
|||||||
|
|
||||||
struct _GFileEnumeratorPrivate {
|
struct _GFileEnumeratorPrivate {
|
||||||
/* TODO: Should be public for subclasses? */
|
/* TODO: Should be public for subclasses? */
|
||||||
|
GFile *container;
|
||||||
guint closed : 1;
|
guint closed : 1;
|
||||||
guint pending : 1;
|
guint pending : 1;
|
||||||
GAsyncReadyCallback outstanding_callback;
|
GAsyncReadyCallback outstanding_callback;
|
||||||
GError *outstanding_error;
|
GError *outstanding_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_0,
|
||||||
|
PROP_CONTAINER
|
||||||
|
};
|
||||||
|
|
||||||
static void g_file_enumerator_real_next_files_async (GFileEnumerator *enumerator,
|
static void g_file_enumerator_real_next_files_async (GFileEnumerator *enumerator,
|
||||||
int num_files,
|
int num_files,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
@@ -80,6 +86,42 @@ static gboolean g_file_enumerator_real_close_finish (GFileEnumerator *
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error);
|
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
|
static void
|
||||||
g_file_enumerator_finalize (GObject *object)
|
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));
|
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;
|
gobject_class->finalize = g_file_enumerator_finalize;
|
||||||
|
|
||||||
klass->next_files_async = g_file_enumerator_real_next_files_async;
|
klass->next_files_async = g_file_enumerator_real_next_files_async;
|
||||||
klass->next_files_finish = g_file_enumerator_real_next_files_finish;
|
klass->next_files_finish = g_file_enumerator_real_next_files_finish;
|
||||||
klass->close_async = g_file_enumerator_real_close_async;
|
klass->close_async = g_file_enumerator_real_close_async;
|
||||||
klass->close_finish = g_file_enumerator_real_close_finish;
|
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
|
static void
|
||||||
@@ -526,6 +579,24 @@ g_file_enumerator_set_pending (GFileEnumerator *enumerator,
|
|||||||
enumerator->priv->pending = pending;
|
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 {
|
typedef struct {
|
||||||
int num_files;
|
int num_files;
|
||||||
GList *files;
|
GList *files;
|
||||||
|
@@ -53,6 +53,17 @@ typedef struct _GFileEnumerator GFileEnumerator;
|
|||||||
typedef struct _GFileEnumeratorClass GFileEnumeratorClass;
|
typedef struct _GFileEnumeratorClass GFileEnumeratorClass;
|
||||||
typedef struct _GFileEnumeratorPrivate GFileEnumeratorPrivate;
|
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
|
struct _GFileEnumerator
|
||||||
{
|
{
|
||||||
@@ -133,6 +144,7 @@ gboolean g_file_enumerator_is_closed (GFileEnumerator *enumerator
|
|||||||
gboolean g_file_enumerator_has_pending (GFileEnumerator *enumerator);
|
gboolean g_file_enumerator_has_pending (GFileEnumerator *enumerator);
|
||||||
void g_file_enumerator_set_pending (GFileEnumerator *enumerator,
|
void g_file_enumerator_set_pending (GFileEnumerator *enumerator,
|
||||||
gboolean pending);
|
gboolean pending);
|
||||||
|
GFile * g_file_enumerator_get_container (GFileEnumerator *enumerator);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@@ -323,6 +323,7 @@ g_file_enumerator_close_finish
|
|||||||
g_file_enumerator_is_closed
|
g_file_enumerator_is_closed
|
||||||
g_file_enumerator_has_pending
|
g_file_enumerator_has_pending
|
||||||
g_file_enumerator_set_pending
|
g_file_enumerator_set_pending
|
||||||
|
g_file_enumerator_get_container
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -578,7 +578,7 @@ g_local_file_enumerate_children (GFile *file,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GLocalFile *local = G_LOCAL_FILE (file);
|
GLocalFile *local = G_LOCAL_FILE (file);
|
||||||
return _g_local_file_enumerator_new (local->filename,
|
return _g_local_file_enumerator_new (local,
|
||||||
attributes, flags,
|
attributes, flags,
|
||||||
cancellable, error);
|
cancellable, error);
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glocalfileenumerator.h>
|
#include <glocalfileenumerator.h>
|
||||||
#include <glocalfileinfo.h>
|
#include <glocalfileinfo.h>
|
||||||
|
#include <glocalfile.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
@@ -187,13 +188,16 @@ convert_file_to_io_error (GError **error,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
GFileEnumerator *
|
GFileEnumerator *
|
||||||
_g_local_file_enumerator_new (const char *filename,
|
_g_local_file_enumerator_new (GLocalFile *file,
|
||||||
const char *attributes,
|
const char *attributes,
|
||||||
GFileQueryInfoFlags flags,
|
GFileQueryInfoFlags flags,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GLocalFileEnumerator *local;
|
GLocalFileEnumerator *local;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
filename = g_file_get_path (G_FILE (file));
|
||||||
|
|
||||||
#ifdef USE_GDIR
|
#ifdef USE_GDIR
|
||||||
GError *dir_error;
|
GError *dir_error;
|
||||||
@@ -208,6 +212,7 @@ _g_local_file_enumerator_new (const char *filename,
|
|||||||
convert_file_to_io_error (error, dir_error);
|
convert_file_to_io_error (error, dir_error);
|
||||||
g_error_free (dir_error);
|
g_error_free (dir_error);
|
||||||
}
|
}
|
||||||
|
g_free (filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -222,15 +227,18 @@ _g_local_file_enumerator_new (const char *filename,
|
|||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
g_io_error_from_errno (errsv),
|
g_io_error_from_errno (errsv),
|
||||||
"%s", g_strerror (errsv));
|
"%s", g_strerror (errsv));
|
||||||
|
g_free (filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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->dir = dir;
|
||||||
local->filename = g_strdup (filename);
|
local->filename = filename;
|
||||||
local->matcher = g_file_attribute_matcher_new (attributes);
|
local->matcher = g_file_attribute_matcher_new (attributes);
|
||||||
local->flags = flags;
|
local->flags = flags;
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <gfileenumerator.h>
|
#include <gfileenumerator.h>
|
||||||
#include <gfileinfo.h>
|
#include <gfileinfo.h>
|
||||||
#include <gfile.h>
|
#include <gfile.h>
|
||||||
|
#include <glocalfile.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ struct _GLocalFileEnumeratorClass
|
|||||||
|
|
||||||
GType _g_local_file_enumerator_get_type (void) G_GNUC_CONST;
|
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,
|
const char *attributes,
|
||||||
GFileQueryInfoFlags flags,
|
GFileQueryInfoFlags flags,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
Reference in New Issue
Block a user