1 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 /* Copyright (C) 2007 The glibmm Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <glibmm/object.h>
21 #include <glibmm/arrayhandle.h>
22 #include <glibmm/listhandle.h>
23 #include <giomm/asyncresult.h>
24 #include <giomm/cancellable.h>
25 #include <giomm/fileinfo.h>
26 //#include <giomm/file.h>
29 _PINCLUDE(glibmm/private/object_p.h)
36 //TODO: Consider wrapping this like a std::iterator (or at least renaming it), though the asyncness probably makes that unsuitable.
38 /** Enumerated Files Routines.
39 * FileEnumerator allows you to operate on a set of Gio::Files, returning a Gio::FileInfo instance for each file enumerated
40 * (e.g. Gio::File::enumerate_children() will return a FileEnumerator for each of the children within a directory).
42 * To get the next file's information from a Gio::FileEnumerator, use next_file() or its asynchronous version, next_file_async().
43 * Note that the asynchronous version will return a list of Gio::FileInfos, whereas the synchronous version will only return the next
44 * file in the enumerator.
46 * To close a Gio::FileEnumerator, use FileEnumerator::close(), or its asynchronous version, close_async(). Once a FileEnumerator is closed,
47 * no further actions may be performed on it.
51 class FileEnumerator : public Glib::Object
53 _CLASS_GOBJECT(FileEnumerator, GFileEnumerator, G_FILE_ENUMERATOR, Glib::Object, GObject)
56 _WRAP_METHOD(Glib::RefPtr<FileInfo> next_file(const Glib::RefPtr<Cancellable>& cancellable),
57 g_file_enumerator_next_file,
61 * @return A FileInfo or an empty RefPtr on error or end of enumerator.
63 #ifdef GLIBMM_EXCEPTIONS_ENABLED
64 Glib::RefPtr<FileInfo> next_file();
66 Glib::RefPtr<FileInfo> next_file(std::auto_ptr<Glib::Error>& error);
67 #endif //GLIBMM_EXCEPTIONS_ENABLED
69 _WRAP_METHOD(bool close(const Glib::RefPtr<Cancellable>& cancellable),
70 g_file_enumerator_close,
73 /** Releases all resources used by this enumerator, making the
74 * enumerator throw a Gio::Error with CLOSED on all calls.
76 * This will be automatically called when the last reference
77 * is dropped, but you might want to call this method to make sure resources
78 * are released as early as possible.
79 * @return #<tt>true</tt> on success or an empty RefPtr on error.
81 #ifdef GLIBMM_EXCEPTIONS_ENABLED
84 bool close(std::auto_ptr<Glib::Error>& error);
85 #endif //GLIBMM_EXCEPTIONS_ENABLED
88 /** Request information for a number of files from the enumerator asynchronously.
89 * When all I/O for the operation is finished the callback slot will be called with the requested information.
91 * The callback could be called with less than num_files files in case of error or at the end of the enumerator.
92 * 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.
93 * If a request is cancelled the callback will be called with ERROR_CANCELLED.
95 * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors.
97 * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority.
98 * The default priority is PRIORITY_DEFAULT.
99 * @param slot A callback to call when the request is satisfied.
100 * @param cancellable An cancellable object which can be used to cancel the request.
101 * @param num_files The number of file info objects to request.
102 * @param io_priority The I/O priority of the request.
104 void next_files_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT);
106 /** Request information for a number of files from the enumerator asynchronously.
107 * When all I/O for the operation is finished the callback slot will be called with the requested information.
109 * The callback could be called with less than num_files files in case of error or at the end of the enumerator.
110 * 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.
111 * If a request is cancelled the callback will be called with ERROR_CANCELLED.
113 * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors.
115 * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority.
116 * The default priority is PRIORITY_DEFAULT.
117 * @param slot A callback to call when the request is satisfied.
118 * @param num_files The number of file info objects to request.
119 * @param io_priority The I/O priority of the request.
121 void next_files_async(const SlotAsyncReady& slot, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT);
122 _IGNORE(g_file_enumerator_next_files_async)
124 #m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<FileInfo> >', `$2(($3), Glib::OWNERSHIP_DEEP)')
125 _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<FileInfo> > next_files_finish(const Glib::RefPtr<AsyncResult>& result),
126 g_file_enumerator_next_files_finish,
131 /** Asynchronously closes the file enumerator.
133 * See close(), which is the synchronous version of this function.
135 * The operation can be cancelled by triggering the cancellable object from another thread.
136 * If the operation was cancelled, a Gio::Error with CANCELLED will be thrown by close_finish().
138 * @param io_priority The I/O priority of the request.
139 * @param cancellable A Cancellable object which can be used to cancel the operation.
140 * @param slot A callback to call when the request is satisfied.
142 void close_async(int io_priority, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
144 /** Asynchronously closes the file enumerator.
146 * See close(), which is the synchronous version of this function.
148 * @param io_priority The I/O priority of the request.
149 * @param slot A callback to call when the request is satisfied.
151 void close_async(int io_priority, const SlotAsyncReady& slot);
152 _IGNORE(g_file_enumerator_close_async)
154 _WRAP_METHOD(bool close_finish(const Glib::RefPtr<AsyncResult>& result),
155 g_file_enumerator_close_finish,
158 _WRAP_METHOD(bool is_closed() const, g_file_enumerator_is_closed)
159 _WRAP_METHOD(bool has_pending() const, g_file_enumerator_has_pending)
160 _WRAP_METHOD(void set_pending(bool pending = true), g_file_enumerator_set_pending)
162 _WRAP_METHOD(Glib::RefPtr<File> get_container(), g_file_enumerator_get_container, refreturn)
163 _WRAP_METHOD(Glib::RefPtr<const File> get_container() const, g_file_enumerator_get_container, refreturn)