1/* Copyright (C) 2007 The glibmm Development Team 2 * 3 * This library is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU Lesser General Public 5 * License as published by the Free Software Foundation; either 6 * version 2.1 of the License, or (at your option) any later version. 7 * 8 * This library is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public 14 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17#include <glibmm/object.h> 18#include <glibmm/arrayhandle.h> 19#include <glibmm/listhandle.h> 20#include <glibmm/priorities.h> 21#include <giomm/asyncresult.h> 22#include <giomm/cancellable.h> 23#include <giomm/fileinfo.h> 24//#include <giomm/file.h> 25 26_DEFS(giomm,gio) 27_PINCLUDE(glibmm/private/object_p.h) 28 29namespace Gio 30{ 31 32class GIOMM_API File; 33 34//TODO: Consider wrapping this like a std::iterator (or at least renaming it), though the asyncness probably makes that unsuitable. 35 36/** Enumerated Files Routines. 37 * FileEnumerator allows you to operate on a set of Gio::Files, returning a Gio::FileInfo instance for each file enumerated 38 * (e.g. Gio::File::enumerate_children() will return a FileEnumerator for each of the children within a directory). 39 * 40 * To get the next file's information from a Gio::FileEnumerator, use next_file() or its asynchronous version, next_file_async(). 41 * Note that the asynchronous version will return a list of Gio::FileInfos, whereas the synchronous version will only return the next 42 * file in the enumerator. 43 * 44 * To close a Gio::FileEnumerator, use FileEnumerator::close(), or its asynchronous version, close_async(). Once a FileEnumerator is closed, 45 * no further actions may be performed on it. 46 * 47 * @newin{2,16} 48 */ 49class GIOMM_API FileEnumerator : public Glib::Object 50{ 51 _CLASS_GOBJECT(FileEnumerator, GFileEnumerator, G_FILE_ENUMERATOR, Glib::Object, GObject, , , GIOMM_API) 52 53public: 54 _WRAP_METHOD(Glib::RefPtr<FileInfo> next_file(const Glib::RefPtr<Cancellable>& cancellable{?}), 55 g_file_enumerator_next_file, 56 errthrow) 57 58 _WRAP_METHOD(bool close(const Glib::RefPtr<Cancellable>& cancellable{?}), 59 g_file_enumerator_close, 60 errthrow) 61 62 63 /** Request information for a number of files from the enumerator asynchronously. 64 * When all I/O for the operation is finished the callback slot will be called with the requested information. 65 * 66 * The callback could be called with less than num_files files in case of error or at the end of the enumerator. 67 * 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. 68 * If a request is cancelled the callback will be called with ERROR_CANCELLED. 69 * 70 * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors. 71 * 72 * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. 73 * The default priority is PRIORITY_DEFAULT. 74 * @param slot A callback to call when the request is satisfied. 75 * @param cancellable An cancellable object which can be used to cancel the request. 76 * @param num_files The number of file info objects to request. 77 * @param io_priority The I/O priority of the request. 78 */ 79 void next_files_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT); 80 81 /** Request information for a number of files from the enumerator asynchronously. 82 * When all I/O for the operation is finished the callback slot will be called with the requested information. 83 * 84 * The callback could be called with less than num_files files in case of error or at the end of the enumerator. 85 * 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. 86 * If a request is cancelled the callback will be called with ERROR_CANCELLED. 87 * 88 * During an async request no other sync and async calls are allowed, and will result in ERROR_PENDING errors. 89 * 90 * Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. 91 * The default priority is PRIORITY_DEFAULT. 92 * @param slot A callback to call when the request is satisfied. 93 * @param num_files The number of file info objects to request. 94 * @param io_priority The I/O priority of the request. 95 */ 96 void next_files_async(const SlotAsyncReady& slot, int num_files = 1, int io_priority = Glib::PRIORITY_DEFAULT); 97 _IGNORE(g_file_enumerator_next_files_async) 98 99#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<FileInfo> >', `$2(($3), Glib::OWNERSHIP_DEEP)') 100 _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<FileInfo> > next_files_finish(const Glib::RefPtr<AsyncResult>& result), 101 g_file_enumerator_next_files_finish, 102 errthrow) 103 104 105 106 /** Asynchronously closes the file enumerator. 107 * 108 * See close(), which is the synchronous version of this function. 109 * 110 * The operation can be cancelled by triggering the cancellable object from another thread. 111 * If the operation was cancelled, a Gio::Error with CANCELLED will be thrown by close_finish(). 112 * 113 * @param io_priority The I/O priority of the request. 114 * @param cancellable A Cancellable object which can be used to cancel the operation. 115 * @param slot A callback to call when the request is satisfied. 116 */ 117 void close_async(int io_priority, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot); 118 119 /** Asynchronously closes the file enumerator. 120 * 121 * See close(), which is the synchronous version of this function. 122 * 123 * @param io_priority The I/O priority of the request. 124 * @param slot A callback to call when the request is satisfied. 125 */ 126 void close_async(int io_priority, const SlotAsyncReady& slot); 127 _IGNORE(g_file_enumerator_close_async) 128 129 _WRAP_METHOD(bool close_finish(const Glib::RefPtr<AsyncResult>& result), 130 g_file_enumerator_close_finish, 131 errthrow) 132 133 _WRAP_METHOD(bool is_closed() const, g_file_enumerator_is_closed) 134 _WRAP_METHOD(bool has_pending() const, g_file_enumerator_has_pending) 135 _WRAP_METHOD(void set_pending(bool pending = true), g_file_enumerator_set_pending) 136 137 _WRAP_METHOD(Glib::RefPtr<File> get_container(), g_file_enumerator_get_container, refreturn) 138 _WRAP_METHOD(Glib::RefPtr<const File> get_container() const, g_file_enumerator_get_container, refreturn) 139 140 _WRAP_METHOD(Glib::RefPtr<File> get_child(const Glib::RefPtr<FileInfo>& info), g_file_enumerator_get_child, refreturn) 141 _WRAP_METHOD(Glib::RefPtr<const File> get_child(const Glib::RefPtr<FileInfo>& info) const, g_file_enumerator_get_child, refreturn) 142 143}; 144 145} // namespace Gio 146 147