gi-gio-2.0.35: Gio bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.Gio.Objects.FileEnumerator

Contents

- Exported types
- Methods
  - close
  - closeAsync
  - closeFinish
  - getChild
  - getContainer
  - hasPending
  - isClosed
  - iterate
  - nextFile
  - nextFilesAsync
  - nextFilesFinish
  - setPending
- Properties
  - container

Description

`GFileEnumerator` allows you to operate on a set of `File` objects, returning a `FileInfo` structure for each file enumerated (e.g. `fileEnumerateChildren` will return a `GFileEnumerator` for each of the children within a directory).

To get the next file's information from a `GFileEnumerator`, use `fileEnumeratorNextFile` or its asynchronous version, `fileEnumeratorNextFilesAsync`. Note that the asynchronous version will return a list of `FileInfo` objects, whereas the synchronous will only return the next file in the enumerator.

The ordering of returned files is unspecified for non-Unix platforms; for more information, see `dirReadName`. On Unix, when operating on local files, returned files will be sorted by inode number. Effectively you can assume that the ordering of returned files will be stable between successive calls (and applications) assuming the directory is unchanged.

If your application needs a specific ordering, such as by name or modification time, you will have to implement that in your application code.

To close a `GFileEnumerator`, use `fileEnumeratorClose`, or its asynchronous version, `fileEnumeratorCloseAsync`. Once a `GFileEnumerator` is closed, no further actions may be performed on it, and it should be freed with `objectUnref`.

Synopsis

- newtype FileEnumerator = FileEnumerator (ManagedPtr FileEnumerator)
- class (GObject o, IsDescendantOf FileEnumerator o) => IsFileEnumerator o
- toFileEnumerator :: (MonadIO m, IsFileEnumerator o) => o -> m FileEnumerator
- fileEnumeratorClose :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) => a -> Maybe b -> m ()
- fileEnumeratorCloseAsync :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) => a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- fileEnumeratorCloseFinish :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsAsyncResult b) => a -> b -> m ()
- fileEnumeratorGetChild :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsFileInfo b) => a -> b -> m File
- fileEnumeratorGetContainer :: (HasCallStack, MonadIO m, IsFileEnumerator a) => a -> m File
- fileEnumeratorHasPending :: (HasCallStack, MonadIO m, IsFileEnumerator a) => a -> m Bool
- fileEnumeratorIsClosed :: (HasCallStack, MonadIO m, IsFileEnumerator a) => a -> m Bool
- fileEnumeratorIterate :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) => a -> Maybe b -> m (FileInfo, File)
- fileEnumeratorNextFile :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) => a -> Maybe b -> m (Maybe FileInfo)
- fileEnumeratorNextFilesAsync :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) => a -> Int32 -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- fileEnumeratorNextFilesFinish :: (HasCallStack, MonadIO m, IsFileEnumerator a, IsAsyncResult b) => a -> b -> m [FileInfo]
- fileEnumeratorSetPending :: (HasCallStack, MonadIO m, IsFileEnumerator a) => a -> Bool -> m ()
- constructFileEnumeratorContainer :: (IsFileEnumerator o, MonadIO m, IsFile a) => a -> m (GValueConstruct o)

# Exported types

newtype FileEnumerator Source #

Memory-managed wrapper type.

Constructors

FileEnumerator (ManagedPtr FileEnumerator) |

#### Instances

Instances details

Eq FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator Methods (==) :: FileEnumerator -> FileEnumerator -> Bool Source # (/=) :: FileEnumerator -> FileEnumerator -> Bool Source #
GObject FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator
ManagedPtrNewtype FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator Methods toManagedPtr :: FileEnumerator -> ManagedPtr FileEnumerator Source #
TypedObject FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator Methods glibType :: IO GType Source #
HasParentTypes FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator
IsGValue (Maybe FileEnumerator) Source # | Convert `FileEnumerator` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gio.Objects.FileEnumerator Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe FileEnumerator -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe FileEnumerator) Source #
type ParentTypes FileEnumerator Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator type ParentTypes FileEnumerator = '[Object]

class (GObject o, IsDescendantOf FileEnumerator o) => IsFileEnumerator o Source #

Type class for types which can be safely cast to `FileEnumerator`, for instance with `toFileEnumerator`.

#### Instances

Instances details

(GObject o, IsDescendantOf FileEnumerator o) => IsFileEnumerator o Source # |
Instance details Defined in GI.Gio.Objects.FileEnumerator

toFileEnumerator :: (MonadIO m, IsFileEnumerator o) => o -> m FileEnumerator Source #

Cast to `FileEnumerator`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

bindProperty, bindPropertyFull, close, closeAsync, closeFinish, forceFloating, freezeNotify, getv, hasPending, isClosed, isFloating, iterate, nextFile, nextFilesAsync, nextFilesFinish, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, unref, watchClosure.

#### Getters

getChild, getContainer, getData, getProperty, getQdata.

#### Setters

setData, setDataFull, setPending, setProperty.

## close

fileEnumeratorClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) |
=> a | `enumerator`: a `FileEnumerator`.
-> Maybe b | `cancellable`: optional `Cancellable` object, `Nothing` to ignore.
-> m () | (Can throw `GError`)

Releases all resources used by this enumerator, making the enumerator return `IOErrorEnumClosed` on all calls.

This will be automatically called when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.

## closeAsync

fileEnumeratorCloseAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) |
=> a | `enumerator`: a `FileEnumerator`.
-> Int32 | `ioPriority`: the I/O priority of the request
-> Maybe b | `cancellable`: optional `Cancellable` object, `Nothing` to ignore.
-> Maybe AsyncReadyCallback | `callback`: a `AsyncReadyCallback` to call when the request is satisfied
-> m () |

Asynchronously closes the file enumerator.

If `cancellable` is not `Nothing`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error `IOErrorEnumCancelled` will be returned in `fileEnumeratorCloseFinish`.

## closeFinish

fileEnumeratorCloseFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsAsyncResult b) |
=> a | `enumerator`: a `FileEnumerator`.
-> b | `result`: a `AsyncResult`.
-> m () | (Can throw `GError`)

Finishes closing a file enumerator, started from `fileEnumeratorCloseAsync`.

If the file enumerator was already closed when `fileEnumeratorCloseAsync` was called, then this function will report `IOErrorEnumClosed` in `error`, and return `False`. If the file enumerator had pending operation when the close operation was started, then this function will report `IOErrorEnumPending`, and return `False`. If `cancellable` was not `Nothing`, then the operation may have been cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error `IOErrorEnumCancelled` will be set, and `False` will be returned.

## getChild

fileEnumeratorGetChild Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsFileInfo b) |
=> a | `enumerator`: a `FileEnumerator`
-> b | `info`: a `FileInfo` gotten from `fileEnumeratorNextFile` or the async equivalents.
-> m File | Returns: a `File` for the `FileInfo` passed it.

Return a new `File` which refers to the file named by `info` in the source directory of `enumerator`. This function is primarily intended to be used inside loops with `fileEnumeratorNextFile`.

To use this, `FILE_ATTRIBUTE_STANDARD_NAME` must have been listed in the attributes list used when creating the `FileEnumerator`.

This is a convenience method that's equivalent to:

### C code

     gchar *name = g_file_info_get_name (info);
     GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
                                      name);

Since: 2.36

## getContainer

fileEnumeratorGetContainer Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a) |
=> a | `enumerator`: a `FileEnumerator`
-> m File | Returns: the `File` which is being enumerated.

Get the `File` container which is being enumerated.

Since: 2.18

## hasPending

fileEnumeratorHasPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a) |
=> a | `enumerator`: a `FileEnumerator`.
-> m Bool | Returns: `True` if the `enumerator` has pending operations.

Checks if the file enumerator has pending operations.

## isClosed

fileEnumeratorIsClosed Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a) |
=> a | `enumerator`: a `FileEnumerator`.
-> m Bool | Returns: `True` if the `enumerator` is closed.

Checks if the file enumerator has been closed.

## iterate

fileEnumeratorIterate Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) |
=> a | `direnum`: an open `FileEnumerator`
-> Maybe b | `cancellable`: a `Cancellable`
-> m (FileInfo, File) | (Can throw `GError`)

This is a version of `fileEnumeratorNextFile` that's easier to use correctly from C programs. With `fileEnumeratorNextFile`, the gboolean return value signifies "end of iteration or error", which requires allocation of a temporary `GError`.

In contrast, with this function, a `False` return from `fileEnumeratorIterate` *always* means "error". End of iteration is signaled by `outInfo` or `outChild` being `Nothing`.

Another crucial difference is that the references for `outInfo` and `outChild` are owned by `direnum` (they are cached as hidden properties). You must not unref them in your own code. This makes memory management significantly easier for C code in combination with loops.

Finally, this function optionally allows retrieving a `File` as well.

You must specify at least one of `outInfo` or `outChild`.

The code pattern for correctly using `fileEnumeratorIterate` from C is:

    direnum = g_file_enumerate_children (file, ...);
    while (TRUE)
      {
        GFileInfo *info;
        if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error))
          goto out;
        if (!info)
          break;
        ... do stuff with "info"; do not unref it! ...
      }

    out:
      g_object_unref (direnum); // Note: frees the last @info

Since: 2.44

## nextFile

fileEnumeratorNextFile Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) |
=> a | `enumerator`: a `FileEnumerator`.
-> Maybe b | `cancellable`: optional `Cancellable` object, `Nothing` to ignore.
-> m (Maybe FileInfo) | Returns: A `FileInfo` or `Nothing` on error or end of enumerator. Free the returned object with `objectUnref` when no longer needed. (Can throw `GError`)

Returns information for the next file in the enumerated object. Will block until the information is available. The `FileInfo` returned from this function will contain attributes that match the attribute string that was passed when the `FileEnumerator` was created.

See the documentation of `FileEnumerator` for information about the order of returned files.

On error, returns `Nothing` and sets `error` to the error. If the enumerator is at the end, `Nothing` will be returned and `error` will be unset.

## nextFilesAsync

fileEnumeratorNextFilesAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsCancellable b) |
=> a | `enumerator`: a `FileEnumerator`.
-> Int32 | `numFiles`: the number of file info objects to request
-> Int32 | `ioPriority`: the I/O priority of the request
-> Maybe b | `cancellable`: optional `Cancellable` object, `Nothing` to ignore.
-> Maybe AsyncReadyCallback | `callback`: a `AsyncReadyCallback` to call when the request is satisfied
-> m () |

Request information for a number of files from the enumerator asynchronously. When all I/O for the operation is finished the `callback` will be called with the requested information.

See the documentation of `FileEnumerator` for information about the order of returned files.

Once the end of the enumerator is reached, or if an error occurs, the `callback` will be called with an empty list. In this case, the previous call to `fileEnumeratorNextFilesAsync` will typically have returned fewer than `numFiles` items.

If a request is cancelled the callback will be called with `IOErrorEnumCancelled`.

This leads to the following pseudo-code usage: > >g_autoptr(GFile) dir = get_directory (); >g_autoptr(GFileEnumerator) enumerator = NULL; >g_autolist(GFileInfo) files = NULL; >g_autoptr(GError) local_error = NULL; > >enumerator = yield g_file_enumerate_children_async (dir, > G_FILE_ATTRIBUTE_STANDARD_NAME "," > G_FILE_ATTRIBUTE_STANDARD_TYPE, > G_FILE_QUERY_INFO_NONE, > G_PRIORITY_DEFAULT, > cancellable, > …, > &local_error); >if (enumerator == NULL) > g_error ("Error enumerating: %s", local_error->message); > >// Loop until no files are returned, either because the end of the enumerator >// has been reached, or an error was returned. >do > { > files = yield g_file_enumerator_next_files_async (enumerator, > 5, // number of files to request > G_PRIORITY_DEFAULT, > cancellable, > …, > &local_error); > > // Process the returned files, but don’t assume that exactly 5 were returned. > for (GList *l = files; l != NULL; l = l->next) > { > GFileInfo *info = l->data; > handle_file_info (info); > } > } >while (files != NULL); > >if (local_error != NULL && > !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) > g_error ("Error while enumerating: %s", local_error->message);

During an async request no other sync and async calls are allowed, and will result in `IOErrorEnumPending` errors.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is `PRIORITY_DEFAULT`.

## nextFilesFinish

fileEnumeratorNextFilesFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a, IsAsyncResult b) |
=> a | `enumerator`: a `FileEnumerator`.
-> b | `result`: a `AsyncResult`.
-> m [FileInfo] | Returns: a `List` of `GFileInfos`. You must free the list with `g_list_free()` and unref the infos with `objectUnref` when you're done with them. (Can throw `GError`)

Finishes the asynchronous operation started with `fileEnumeratorNextFilesAsync`.

## setPending

fileEnumeratorSetPending Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileEnumerator a) |
=> a | `enumerator`: a `FileEnumerator`.
-> Bool | `pending`: a boolean value.
-> m () |

Sets the file enumerator as having pending operations.

# Properties

## container

The container that is being enumerated.

constructFileEnumeratorContainer :: (IsFileEnumerator o, MonadIO m, IsFile a) => a -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`container`” property. This is rarely needed directly, but it is used by `new`.