1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD 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 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.FileEnumerator; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.FileIF; 30 private import gio.FileInfo; 31 private import gio.c.functions; 32 public import gio.c.types; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import glib.ListG; 36 private import gobject.ObjectG; 37 38 39 /** 40 * #GFileEnumerator allows you to operate on a set of #GFiles, 41 * returning a #GFileInfo structure for each file enumerated (e.g. 42 * g_file_enumerate_children() will return a #GFileEnumerator for each 43 * of the children within a directory). 44 * 45 * To get the next file's information from a #GFileEnumerator, use 46 * g_file_enumerator_next_file() or its asynchronous version, 47 * g_file_enumerator_next_files_async(). Note that the asynchronous 48 * version will return a list of #GFileInfos, whereas the 49 * synchronous will only return the next file in the enumerator. 50 * 51 * The ordering of returned files is unspecified for non-Unix 52 * platforms; for more information, see g_dir_read_name(). On Unix, 53 * when operating on local files, returned files will be sorted by 54 * inode number. Effectively you can assume that the ordering of 55 * returned files will be stable between successive calls (and 56 * applications) assuming the directory is unchanged. 57 * 58 * If your application needs a specific ordering, such as by name or 59 * modification time, you will have to implement that in your 60 * application code. 61 * 62 * To close a #GFileEnumerator, use g_file_enumerator_close(), or 63 * its asynchronous version, g_file_enumerator_close_async(). Once 64 * a #GFileEnumerator is closed, no further actions may be performed 65 * on it, and it should be freed with g_object_unref(). 66 */ 67 public class FileEnumerator : ObjectG 68 { 69 /** the main Gtk struct */ 70 protected GFileEnumerator* gFileEnumerator; 71 72 /** Get the main Gtk struct */ 73 public GFileEnumerator* getFileEnumeratorStruct(bool transferOwnership = false) 74 { 75 if (transferOwnership) 76 ownedRef = false; 77 return gFileEnumerator; 78 } 79 80 /** the main Gtk struct as a void* */ 81 protected override void* getStruct() 82 { 83 return cast(void*)gFileEnumerator; 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GFileEnumerator* gFileEnumerator, bool ownedRef = false) 90 { 91 this.gFileEnumerator = gFileEnumerator; 92 super(cast(GObject*)gFileEnumerator, ownedRef); 93 } 94 95 96 /** */ 97 public static GType getType() 98 { 99 return g_file_enumerator_get_type(); 100 } 101 102 /** 103 * Releases all resources used by this enumerator, making the 104 * enumerator return %G_IO_ERROR_CLOSED on all calls. 105 * 106 * This will be automatically called when the last reference 107 * is dropped, but you might want to call this function to make 108 * sure resources are released as early as possible. 109 * 110 * Params: 111 * cancellable = optional #GCancellable object, %NULL to ignore. 112 * 113 * Returns: #TRUE on success or #FALSE on error. 114 * 115 * Throws: GException on failure. 116 */ 117 public bool close(Cancellable cancellable) 118 { 119 GError* err = null; 120 121 auto __p = g_file_enumerator_close(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 122 123 if (err !is null) 124 { 125 throw new GException( new ErrorG(err) ); 126 } 127 128 return __p; 129 } 130 131 /** 132 * Asynchronously closes the file enumerator. 133 * 134 * If @cancellable is not %NULL, then the operation can be cancelled by 135 * triggering the cancellable object from another thread. If the operation 136 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned in 137 * g_file_enumerator_close_finish(). 138 * 139 * Params: 140 * ioPriority = the [I/O priority][io-priority] of the request 141 * cancellable = optional #GCancellable object, %NULL to ignore. 142 * callback = a #GAsyncReadyCallback to call when the request is satisfied 143 * userData = the data to pass to callback function 144 */ 145 public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 146 { 147 g_file_enumerator_close_async(gFileEnumerator, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 148 } 149 150 /** 151 * Finishes closing a file enumerator, started from g_file_enumerator_close_async(). 152 * 153 * If the file enumerator was already closed when g_file_enumerator_close_async() 154 * was called, then this function will report %G_IO_ERROR_CLOSED in @error, and 155 * return %FALSE. If the file enumerator had pending operation when the close 156 * operation was started, then this function will report %G_IO_ERROR_PENDING, and 157 * return %FALSE. If @cancellable was not %NULL, then the operation may have been 158 * cancelled by triggering the cancellable object from another thread. If the operation 159 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and %FALSE will be 160 * returned. 161 * 162 * Params: 163 * result = a #GAsyncResult. 164 * 165 * Returns: %TRUE if the close operation has finished successfully. 166 * 167 * Throws: GException on failure. 168 */ 169 public bool closeFinish(AsyncResultIF result) 170 { 171 GError* err = null; 172 173 auto __p = g_file_enumerator_close_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 174 175 if (err !is null) 176 { 177 throw new GException( new ErrorG(err) ); 178 } 179 180 return __p; 181 } 182 183 /** 184 * Return a new #GFile which refers to the file named by @info in the source 185 * directory of @enumerator. This function is primarily intended to be used 186 * inside loops with g_file_enumerator_next_file(). 187 * 188 * This is a convenience method that's equivalent to: 189 * |[<!-- language="C" --> 190 * gchar *name = g_file_info_get_name (info); 191 * GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr), 192 * name); 193 * ]| 194 * 195 * Params: 196 * info = a #GFileInfo gotten from g_file_enumerator_next_file() 197 * or the async equivalents. 198 * 199 * Returns: a #GFile for the #GFileInfo passed it. 200 * 201 * Since: 2.36 202 */ 203 public FileIF getChild(FileInfo info) 204 { 205 auto __p = g_file_enumerator_get_child(gFileEnumerator, (info is null) ? null : info.getFileInfoStruct()); 206 207 if(__p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p, true); 213 } 214 215 /** 216 * Get the #GFile container which is being enumerated. 217 * 218 * Returns: the #GFile which is being enumerated. 219 * 220 * Since: 2.18 221 */ 222 public FileIF getContainer() 223 { 224 auto __p = g_file_enumerator_get_container(gFileEnumerator); 225 226 if(__p is null) 227 { 228 return null; 229 } 230 231 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p); 232 } 233 234 /** 235 * Checks if the file enumerator has pending operations. 236 * 237 * Returns: %TRUE if the @enumerator has pending operations. 238 */ 239 public bool hasPending() 240 { 241 return g_file_enumerator_has_pending(gFileEnumerator) != 0; 242 } 243 244 /** 245 * Checks if the file enumerator has been closed. 246 * 247 * Returns: %TRUE if the @enumerator is closed. 248 */ 249 public bool isClosed() 250 { 251 return g_file_enumerator_is_closed(gFileEnumerator) != 0; 252 } 253 254 /** 255 * This is a version of g_file_enumerator_next_file() that's easier to 256 * use correctly from C programs. With g_file_enumerator_next_file(), 257 * the gboolean return value signifies "end of iteration or error", which 258 * requires allocation of a temporary #GError. 259 * 260 * In contrast, with this function, a %FALSE return from 261 * g_file_enumerator_iterate() *always* means 262 * "error". End of iteration is signaled by @out_info or @out_child being %NULL. 263 * 264 * Another crucial difference is that the references for @out_info and 265 * @out_child are owned by @direnum (they are cached as hidden 266 * properties). You must not unref them in your own code. This makes 267 * memory management significantly easier for C code in combination 268 * with loops. 269 * 270 * Finally, this function optionally allows retrieving a #GFile as 271 * well. 272 * 273 * You must specify at least one of @out_info or @out_child. 274 * 275 * The code pattern for correctly using g_file_enumerator_iterate() from C 276 * is: 277 * 278 * |[ 279 * direnum = g_file_enumerate_children (file, ...); 280 * while (TRUE) 281 * { 282 * GFileInfo *info; 283 * if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error)) 284 * goto out; 285 * if (!info) 286 * break; 287 * ... do stuff with "info"; do not unref it! ... 288 * } 289 * 290 * out: 291 * g_object_unref (direnum); // Note: frees the last @info 292 * ]| 293 * 294 * Params: 295 * outInfo = Output location for the next #GFileInfo, or %NULL 296 * outChild = Output location for the next #GFile, or %NULL 297 * cancellable = a #GCancellable 298 * 299 * Since: 2.44 300 * 301 * Throws: GException on failure. 302 */ 303 public bool iterate(out FileInfo outInfo, out FileIF outChild, Cancellable cancellable) 304 { 305 GFileInfo* outoutInfo = null; 306 GFile* outoutChild = null; 307 GError* err = null; 308 309 auto __p = g_file_enumerator_iterate(gFileEnumerator, &outoutInfo, &outoutChild, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 310 311 if (err !is null) 312 { 313 throw new GException( new ErrorG(err) ); 314 } 315 316 outInfo = ObjectG.getDObject!(FileInfo)(outoutInfo); 317 outChild = ObjectG.getDObject!(FileIF)(outoutChild); 318 319 return __p; 320 } 321 322 /** 323 * Returns information for the next file in the enumerated object. 324 * Will block until the information is available. The #GFileInfo 325 * returned from this function will contain attributes that match the 326 * attribute string that was passed when the #GFileEnumerator was created. 327 * 328 * See the documentation of #GFileEnumerator for information about the 329 * order of returned files. 330 * 331 * On error, returns %NULL and sets @error to the error. If the 332 * enumerator is at the end, %NULL will be returned and @error will 333 * be unset. 334 * 335 * Params: 336 * cancellable = optional #GCancellable object, %NULL to ignore. 337 * 338 * Returns: A #GFileInfo or %NULL on error 339 * or end of enumerator. Free the returned object with 340 * g_object_unref() when no longer needed. 341 * 342 * Throws: GException on failure. 343 */ 344 public FileInfo nextFile(Cancellable cancellable) 345 { 346 GError* err = null; 347 348 auto __p = g_file_enumerator_next_file(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 349 350 if (err !is null) 351 { 352 throw new GException( new ErrorG(err) ); 353 } 354 355 if(__p is null) 356 { 357 return null; 358 } 359 360 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) __p, true); 361 } 362 363 /** 364 * Request information for a number of files from the enumerator asynchronously. 365 * When all i/o for the operation is finished the @callback will be called with 366 * the requested information. 367 * 368 * See the documentation of #GFileEnumerator for information about the 369 * order of returned files. 370 * 371 * The callback can be called with less than @num_files files in case of error 372 * or at the end of the enumerator. In case of a partial error the callback will 373 * be called with any succeeding items and no error, and on the next request the 374 * error will be reported. If a request is cancelled the callback will be called 375 * with %G_IO_ERROR_CANCELLED. 376 * 377 * During an async request no other sync and async calls are allowed, and will 378 * result in %G_IO_ERROR_PENDING errors. 379 * 380 * Any outstanding i/o request with higher priority (lower numerical value) will 381 * be executed before an outstanding request with lower priority. Default 382 * priority is %G_PRIORITY_DEFAULT. 383 * 384 * Params: 385 * numFiles = the number of file info objects to request 386 * ioPriority = the [I/O priority][io-priority] of the request 387 * cancellable = optional #GCancellable object, %NULL to ignore. 388 * callback = a #GAsyncReadyCallback to call when the request is satisfied 389 * userData = the data to pass to callback function 390 */ 391 public void nextFilesAsync(int numFiles, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 392 { 393 g_file_enumerator_next_files_async(gFileEnumerator, numFiles, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 394 } 395 396 /** 397 * Finishes the asynchronous operation started with g_file_enumerator_next_files_async(). 398 * 399 * Params: 400 * result = a #GAsyncResult. 401 * 402 * Returns: a #GList of #GFileInfos. You must free the list with 403 * g_list_free() and unref the infos with g_object_unref() when you're 404 * done with them. 405 * 406 * Throws: GException on failure. 407 */ 408 public ListG nextFilesFinish(AsyncResultIF result) 409 { 410 GError* err = null; 411 412 auto __p = g_file_enumerator_next_files_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err); 413 414 if (err !is null) 415 { 416 throw new GException( new ErrorG(err) ); 417 } 418 419 if(__p is null) 420 { 421 return null; 422 } 423 424 return new ListG(cast(GList*) __p, true); 425 } 426 427 /** 428 * Sets the file enumerator as having pending operations. 429 * 430 * Params: 431 * pending = a boolean value. 432 */ 433 public void setPending(bool pending) 434 { 435 g_file_enumerator_set_pending(gFileEnumerator, pending); 436 } 437 }