glibmm 2.66.5
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Gio::FileEnumerator Class Reference

Enumerated Files Routines. More...

#include <giomm/fileenumerator.h>

Inheritance diagram for Gio::FileEnumerator:
Inheritance graph
[legend]

Public Member Functions

 FileEnumerator (FileEnumerator && src) noexcept
 
FileEnumeratoroperator= (FileEnumerator && src) noexcept
 
 ~FileEnumerator () noexcept override
 
GFileEnumerator * gobj ()
 Provides access to the underlying C GObject. More...
 
const GFileEnumerator * gobj () const
 Provides access to the underlying C GObject. More...
 
GFileEnumerator * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::RefPtr< FileInfonext_file (const Glib::RefPtr< Cancellable > & cancellable)
 Returns information for the next file in the enumerated object. More...
 
Glib::RefPtr< FileInfonext_file ()
 A next_file() convenience overload. More...
 
bool close (const Glib::RefPtr< Cancellable > & cancellable)
 Releases all resources used by this enumerator, making the enumerator return IO_ERROR_CLOSED on all calls. More...
 
bool close ()
 A close() convenience overload. More...
 
void next_files_async (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, int num_files=1, int io_priority=Glib::PRIORITY_DEFAULT)
 Request information for a number of files from the enumerator asynchronously. More...
 
void next_files_async (const SlotAsyncReady & slot, int num_files=1, int io_priority=Glib::PRIORITY_DEFAULT)
 Request information for a number of files from the enumerator asynchronously. More...
 
Glib::ListHandle< Glib::RefPtr< FileInfo > > next_files_finish (const Glib::RefPtr< AsyncResult > & result)
 Finishes the asynchronous operation started with g_file_enumerator_next_files_async(). More...
 
void close_async (int io_priority, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
 Asynchronously closes the file enumerator. More...
 
void close_async (int io_priority, const SlotAsyncReady & slot)
 Asynchronously closes the file enumerator. More...
 
bool close_finish (const Glib::RefPtr< AsyncResult > & result)
 Finishes closing a file enumerator, started from g_file_enumerator_close_async(). More...
 
bool is_closed () const
 Checks if the file enumerator has been closed. More...
 
bool has_pending () const
 Checks if the file enumerator has pending operations. More...
 
void set_pending (bool pending=true)
 Sets the file enumerator as having pending operations. More...
 
Glib::RefPtr< Fileget_container ()
 Get the File container which is being enumerated. More...
 
Glib::RefPtr< const Fileget_container () const
 Get the File container which is being enumerated. More...
 
Glib::RefPtr< Fileget_child (const Glib::RefPtr< FileInfo > & info)
 Return a new File which refers to the file named by info in the source directory of enumerator. More...
 
Glib::RefPtr< const Fileget_child (const Glib::RefPtr< FileInfo > & info) const
 Return a new File which refers to the file named by info in the source directory of enumerator. More...
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object && src) noexcept
 
Objectoperator= (Object && src) noexcept
 
void * get_data (const QueryQuark & key)
 
void set_data (const Quark & key, void *data)
 
void set_data (const Quark & key, void *data, DestroyNotify notify)
 
void remove_data (const QueryQuark & quark)
 
void * steal_data (const QueryQuark & quark)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (const ObjectBase &)=delete
 
void set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
void get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void set_property (const Glib::ustring & property_name, const PropertyType & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void get_property (const Glib::ustring & property_name, PropertyType & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
void connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void > & slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
void connect_property_changed (const Glib::ustring & property_name, sigc::slot< void > && slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
sigc::connection connect_property_changed_with_return (const Glib::ustring & property_name, const sigc::slot< void > & slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
sigc::connection connect_property_changed_with_return (const Glib::ustring & property_name, sigc::slot< void > && slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
void freeze_notify ()
 Increases the freeze count on object. More...
 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify(). More...
 
virtual void reference () const
 Increment the reference count for this object. More...
 
virtual void unreference () const
 Decrement the reference count for this object. More...
 
GObject * gobj ()
 Provides access to the underlying C GObject. More...
 
const GObject * gobj () const
 Provides access to the underlying C GObject. More...
 
GObject * gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gio::FileEnumeratorwrap (GFileEnumerator * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Additional Inherited Members

- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams & construct_params)
 
 Object (GObject * castitem)
 
 ~Object () noexcept override
 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
 
 ObjectBase (const char * custom_type_name)
 A derived constructor always overrides this choice. More...
 
 ObjectBase (const std::type_info & custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
 
 ObjectBase (ObjectBase && src) noexcept
 
ObjectBaseoperator= (ObjectBase && src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject * castitem)
 
void initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)
 

Detailed Description

Enumerated Files Routines.

FileEnumerator allows you to operate on a set of Gio::Files, returning a Gio::FileInfo instance for each file enumerated (e.g. Gio::File::enumerate_children() will return a FileEnumerator for each of the children within a directory).

To get the next file's information from a Gio::FileEnumerator, use next_file() or its asynchronous version, next_file_async(). Note that the asynchronous version will return a list of Gio::FileInfos, whereas the synchronous version will only return the next file in the enumerator.

To close a Gio::FileEnumerator, use FileEnumerator::close(), or its asynchronous version, close_async(). Once a FileEnumerator is closed, no further actions may be performed on it.

Since glibmm 2.16:

Constructor & Destructor Documentation

◆ FileEnumerator()

Gio::FileEnumerator::FileEnumerator ( FileEnumerator &&  src)
noexcept

◆ ~FileEnumerator()

Gio::FileEnumerator::~FileEnumerator ( )
overridenoexcept

Member Function Documentation

◆ close() [1/2]

bool Gio::FileEnumerator::close ( )

A close() convenience overload.

◆ close() [2/2]

bool Gio::FileEnumerator::close ( const Glib::RefPtr< Cancellable > &  cancellable)

Releases all resources used by this enumerator, making the enumerator return IO_ERROR_CLOSED 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.

Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
#true on success or #false on error.
Exceptions
Glib::Error

◆ close_async() [1/2]

void Gio::FileEnumerator::close_async ( int  io_priority,
const Glib::RefPtr< Cancellable > &  cancellable,
const SlotAsyncReady &  slot 
)

Asynchronously closes the file enumerator.

See close(), which is the synchronous version of this function.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown by close_finish().

Parameters
io_priorityThe I/O priority of the request.
cancellableA Cancellable object which can be used to cancel the operation.
slotA callback to call when the request is satisfied.

◆ close_async() [2/2]

void Gio::FileEnumerator::close_async ( int  io_priority,
const SlotAsyncReady &  slot 
)

Asynchronously closes the file enumerator.

See close(), which is the synchronous version of this function.

Parameters
io_priorityThe I/O priority of the request.
slotA callback to call when the request is satisfied.

◆ close_finish()

bool Gio::FileEnumerator::close_finish ( const Glib::RefPtr< AsyncResult > &  result)

Finishes closing a file enumerator, started from g_file_enumerator_close_async().

If the file enumerator was already closed when g_file_enumerator_close_async() was called, then this function will throw a Gio::Error with CLOSED, and return false. If the file enumerator had pending operation when the close operation was started, then this function will throw a Gio::Error with PENDING, and return false. The operation may have been cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown, and false will be returned.

Parameters
resultA AsyncResult.
Returns
true if the close operation has finished successfully.
Exceptions
Glib::Error

◆ get_child() [1/2]

Glib::RefPtr< File > Gio::FileEnumerator::get_child ( const Glib::RefPtr< FileInfo > &  info)

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 g_file_enumerator_next_file().

This is a convenience method that's equivalent to:

[C example ellipted]

Since glibmm 2.36:
Parameters
infoA FileInfo gotten from g_file_enumerator_next_file() or the async equivalents.
Returns
A File for the FileInfo passed it.

◆ get_child() [2/2]

Glib::RefPtr< const File > Gio::FileEnumerator::get_child ( const Glib::RefPtr< FileInfo > &  info) const

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 g_file_enumerator_next_file().

This is a convenience method that's equivalent to:

[C example ellipted]

Since glibmm 2.36:
Parameters
infoA FileInfo gotten from g_file_enumerator_next_file() or the async equivalents.
Returns
A File for the FileInfo passed it.

◆ get_container() [1/2]

Glib::RefPtr< File > Gio::FileEnumerator::get_container ( )

Get the File container which is being enumerated.

Since glibmm 2.18:
Returns
The File which is being enumerated.

◆ get_container() [2/2]

Glib::RefPtr< const File > Gio::FileEnumerator::get_container ( ) const

Get the File container which is being enumerated.

Since glibmm 2.18:
Returns
The File which is being enumerated.

◆ get_type()

static GType Gio::FileEnumerator::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GFileEnumerator * Gio::FileEnumerator::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GFileEnumerator * Gio::FileEnumerator::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GFileEnumerator * Gio::FileEnumerator::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ has_pending()

bool Gio::FileEnumerator::has_pending ( ) const

Checks if the file enumerator has pending operations.

Returns
true if the enumerator has pending operations.

◆ is_closed()

bool Gio::FileEnumerator::is_closed ( ) const

Checks if the file enumerator has been closed.

Returns
true if the enumerator is closed.

◆ next_file() [1/2]

Glib::RefPtr< FileInfo > Gio::FileEnumerator::next_file ( )

A next_file() convenience overload.

◆ next_file() [2/2]

Glib::RefPtr< FileInfo > Gio::FileEnumerator::next_file ( const Glib::RefPtr< Cancellable > &  cancellable)

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 nullptr and sets error to the error. If the enumerator is at the end, nullptr will be returned and error will be unset.

Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A FileInfo or nullptr on error or end of enumerator. Free the returned object with Glib::object_unref() when no longer needed.
Exceptions
Glib::Error

◆ next_files_async() [1/2]

void Gio::FileEnumerator::next_files_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable > &  cancellable,
int  num_files = 1,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request information for a number of files from the enumerator asynchronously.

When all I/O for the operation is finished the callback slot will be called with the requested information.

The callback could be called with less than num_files files in case of error or at the end of the enumerator. In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. If a request is cancelled the callback will be called with ERROR_CANCELLED.

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

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

Parameters
slotA callback to call when the request is satisfied.
cancellableAn cancellable object which can be used to cancel the request.
num_filesThe number of file info objects to request.
io_priorityThe I/O priority of the request.

◆ next_files_async() [2/2]

void Gio::FileEnumerator::next_files_async ( const SlotAsyncReady &  slot,
int  num_files = 1,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request information for a number of files from the enumerator asynchronously.

When all I/O for the operation is finished the callback slot will be called with the requested information.

The callback could be called with less than num_files files in case of error or at the end of the enumerator. In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. If a request is cancelled the callback will be called with ERROR_CANCELLED.

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

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

Parameters
slotA callback to call when the request is satisfied.
num_filesThe number of file info objects to request.
io_priorityThe I/O priority of the request.

◆ next_files_finish()

Glib::ListHandle< Glib::RefPtr< FileInfo > > Gio::FileEnumerator::next_files_finish ( const Glib::RefPtr< AsyncResult > &  result)

Finishes the asynchronous operation started with g_file_enumerator_next_files_async().

Parameters
resultA AsyncResult.
Returns
A List of FileInfos.
Exceptions
Glib::Error

◆ operator=()

FileEnumerator & Gio::FileEnumerator::operator= ( FileEnumerator &&  src)
noexcept

◆ set_pending()

void Gio::FileEnumerator::set_pending ( bool  pending = true)

Sets the file enumerator as having pending operations.

Parameters
pendingA boolean value.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gio::FileEnumerator > wrap ( GFileEnumerator *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.