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