File: FileEnumerator.d

package info (click to toggle)
gtk-d 3.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,204 kB
  • sloc: javascript: 565; sh: 71; makefile: 23
file content (438 lines) | stat: -rw-r--r-- 13,941 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/*
 * This file is part of gtkD.
 *
 * gtkD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version, with
 * some exceptions, please read the COPYING file.
 *
 * gtkD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with gtkD; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage


module gio.FileEnumerator;

private import gio.AsyncResultIF;
private import gio.Cancellable;
private import gio.FileIF;
private import gio.FileInfo;
private import gio.c.functions;
public  import gio.c.types;
private import glib.ErrorG;
private import glib.GException;
private import glib.ListG;
private import gobject.ObjectG;
public  import gtkc.giotypes;


/**
 * #GFileEnumerator allows you to operate on a set of #GFiles,
 * returning a #GFileInfo structure for each file enumerated (e.g.
 * g_file_enumerate_children() will return a #GFileEnumerator for each
 * of the children within a directory).
 * 
 * To get the next file's information from a #GFileEnumerator, use
 * g_file_enumerator_next_file() or its asynchronous version,
 * g_file_enumerator_next_files_async(). Note that the asynchronous
 * version will return a list of #GFileInfos, whereas the
 * synchronous will only return the next file in the enumerator.
 * 
 * The ordering of returned files is unspecified for non-Unix
 * platforms; for more information, see g_dir_read_name().  On Unix,
 * when operating on local files, returned files will be sorted by
 * inode number.  Effectively you can assume that the ordering of
 * returned files will be stable between successive calls (and
 * applications) assuming the directory is unchanged.
 * 
 * If your application needs a specific ordering, such as by name or
 * modification time, you will have to implement that in your
 * application code.
 * 
 * To close a #GFileEnumerator, use g_file_enumerator_close(), or
 * its asynchronous version, g_file_enumerator_close_async(). Once
 * a #GFileEnumerator is closed, no further actions may be performed
 * on it, and it should be freed with g_object_unref().
 */
public class FileEnumerator : ObjectG
{
	/** the main Gtk struct */
	protected GFileEnumerator* gFileEnumerator;

	/** Get the main Gtk struct */
	public GFileEnumerator* getFileEnumeratorStruct(bool transferOwnership = false)
	{
		if (transferOwnership)
			ownedRef = false;
		return gFileEnumerator;
	}

	/** the main Gtk struct as a void* */
	protected override void* getStruct()
	{
		return cast(void*)gFileEnumerator;
	}

	/**
	 * Sets our main struct and passes it to the parent class.
	 */
	public this (GFileEnumerator* gFileEnumerator, bool ownedRef = false)
	{
		this.gFileEnumerator = gFileEnumerator;
		super(cast(GObject*)gFileEnumerator, ownedRef);
	}


	/** */
	public static GType getType()
	{
		return g_file_enumerator_get_type();
	}

	/**
	 * Releases all resources used by this enumerator, making the
	 * enumerator return %G_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.
	 *
	 * Params:
	 *     cancellable = optional #GCancellable object, %NULL to ignore.
	 *
	 * Returns: #TRUE on success or #FALSE on error.
	 *
	 * Throws: GException on failure.
	 */
	public bool close(Cancellable cancellable)
	{
		GError* err = null;

		auto __p = g_file_enumerator_close(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;

		if (err !is null)
		{
			throw new GException( new ErrorG(err) );
		}

		return __p;
	}

	/**
	 * Asynchronously closes the file enumerator.
	 *
	 * If @cancellable is not %NULL, then the operation can be cancelled by
	 * triggering the cancellable object from another thread. If the operation
	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned in
	 * g_file_enumerator_close_finish().
	 *
	 * Params:
	 *     ioPriority = the [I/O priority][io-priority] of the request
	 *     cancellable = optional #GCancellable object, %NULL to ignore.
	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
	 *     userData = the data to pass to callback function
	 */
	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
	{
		g_file_enumerator_close_async(gFileEnumerator, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
	}

	/**
	 * 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 report %G_IO_ERROR_CLOSED in @error, and
	 * return %FALSE. If the file enumerator had pending operation when the close
	 * operation was started, then this function will report %G_IO_ERROR_PENDING, and
	 * return %FALSE.  If @cancellable was not %NULL, then the operation may have been
	 * cancelled by triggering the cancellable object from another thread. If the operation
	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and %FALSE will be
	 * returned.
	 *
	 * Params:
	 *     result = a #GAsyncResult.
	 *
	 * Returns: %TRUE if the close operation has finished successfully.
	 *
	 * Throws: GException on failure.
	 */
	public bool closeFinish(AsyncResultIF result)
	{
		GError* err = null;

		auto __p = g_file_enumerator_close_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;

		if (err !is null)
		{
			throw new GException( new ErrorG(err) );
		}

		return __p;
	}

	/**
	 * Return a new #GFile 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:
	 * |[<!-- language="C" -->
	 * gchar *name = g_file_info_get_name (info);
	 * GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
	 * name);
	 * ]|
	 *
	 * Params:
	 *     info = a #GFileInfo gotten from g_file_enumerator_next_file()
	 *         or the async equivalents.
	 *
	 * Returns: a #GFile for the #GFileInfo passed it.
	 *
	 * Since: 2.36
	 */
	public FileIF getChild(FileInfo info)
	{
		auto __p = g_file_enumerator_get_child(gFileEnumerator, (info is null) ? null : info.getFileInfoStruct());

		if(__p is null)
		{
			return null;
		}

		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p, true);
	}

	/**
	 * Get the #GFile container which is being enumerated.
	 *
	 * Returns: the #GFile which is being enumerated.
	 *
	 * Since: 2.18
	 */
	public FileIF getContainer()
	{
		auto __p = g_file_enumerator_get_container(gFileEnumerator);

		if(__p is null)
		{
			return null;
		}

		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p);
	}

	/**
	 * Checks if the file enumerator has pending operations.
	 *
	 * Returns: %TRUE if the @enumerator has pending operations.
	 */
	public bool hasPending()
	{
		return g_file_enumerator_has_pending(gFileEnumerator) != 0;
	}

	/**
	 * Checks if the file enumerator has been closed.
	 *
	 * Returns: %TRUE if the @enumerator is closed.
	 */
	public bool isClosed()
	{
		return g_file_enumerator_is_closed(gFileEnumerator) != 0;
	}

	/**
	 * This is a version of g_file_enumerator_next_file() that's easier to
	 * use correctly from C programs.  With g_file_enumerator_next_file(),
	 * the gboolean return value signifies "end of iteration or error", which
	 * requires allocation of a temporary #GError.
	 *
	 * In contrast, with this function, a %FALSE return from
	 * g_file_enumerator_iterate() *always* means
	 * "error".  End of iteration is signaled by @out_info or @out_child being %NULL.
	 *
	 * Another crucial difference is that the references for @out_info and
	 * @out_child are owned by @direnum (they are cached as hidden
	 * properties).  You must not unref them in your own code.  This makes
	 * memory management significantly easier for C code in combination
	 * with loops.
	 *
	 * Finally, this function optionally allows retrieving a #GFile as
	 * well.
	 *
	 * You must specify at least one of @out_info or @out_child.
	 *
	 * The code pattern for correctly using g_file_enumerator_iterate() from C
	 * is:
	 *
	 * |[
	 * direnum = g_file_enumerate_children (file, ...);
	 * while (TRUE)
	 * {
	 * GFileInfo *info;
	 * if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error))
	 * goto out;
	 * if (!info)
	 * break;
	 * ... do stuff with "info"; do not unref it! ...
	 * }
	 *
	 * out:
	 * g_object_unref (direnum); // Note: frees the last @info
	 * ]|
	 *
	 * Params:
	 *     outInfo = Output location for the next #GFileInfo, or %NULL
	 *     outChild = Output location for the next #GFile, or %NULL
	 *     cancellable = a #GCancellable
	 *
	 * Since: 2.44
	 *
	 * Throws: GException on failure.
	 */
	public bool iterate(out FileInfo outInfo, out FileIF outChild, Cancellable cancellable)
	{
		GFileInfo* outoutInfo = null;
		GFile* outoutChild = null;
		GError* err = null;

		auto __p = g_file_enumerator_iterate(gFileEnumerator, &outoutInfo, &outoutChild, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;

		if (err !is null)
		{
			throw new GException( new ErrorG(err) );
		}

		outInfo = ObjectG.getDObject!(FileInfo)(outoutInfo);
		outChild = ObjectG.getDObject!(FileIF)(outoutChild);

		return __p;
	}

	/**
	 * Returns information for the next file in the enumerated object.
	 * Will block until the information is available. The #GFileInfo
	 * returned from this function will contain attributes that match the
	 * attribute string that was passed when the #GFileEnumerator was created.
	 *
	 * See the documentation of #GFileEnumerator for information about the
	 * order of returned files.
	 *
	 * On error, returns %NULL and sets @error to the error. If the
	 * enumerator is at the end, %NULL will be returned and @error will
	 * be unset.
	 *
	 * Params:
	 *     cancellable = optional #GCancellable object, %NULL to ignore.
	 *
	 * Returns: A #GFileInfo or %NULL on error
	 *     or end of enumerator.  Free the returned object with
	 *     g_object_unref() when no longer needed.
	 *
	 * Throws: GException on failure.
	 */
	public FileInfo nextFile(Cancellable cancellable)
	{
		GError* err = null;

		auto __p = g_file_enumerator_next_file(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);

		if (err !is null)
		{
			throw new GException( new ErrorG(err) );
		}

		if(__p is null)
		{
			return null;
		}

		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) __p, true);
	}

	/**
	 * Request information for a number of files from the enumerator asynchronously.
	 * When all i/o for the operation is finished the @callback will be called with
	 * the requested information.
	 *
	 * See the documentation of #GFileEnumerator for information about the
	 * order of returned files.
	 *
	 * The callback can 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 %G_IO_ERROR_CANCELLED.
	 *
	 * During an async request no other sync and async calls are allowed, and will
	 * result in %G_IO_ERROR_PENDING errors.
	 *
	 * Any outstanding i/o request with higher priority (lower numerical value) will
	 * be executed before an outstanding request with lower priority. Default
	 * priority is %G_PRIORITY_DEFAULT.
	 *
	 * Params:
	 *     numFiles = the number of file info objects to request
	 *     ioPriority = the [I/O priority][io-priority] of the request
	 *     cancellable = optional #GCancellable object, %NULL to ignore.
	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
	 *     userData = the data to pass to callback function
	 */
	public void nextFilesAsync(int numFiles, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
	{
		g_file_enumerator_next_files_async(gFileEnumerator, numFiles, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
	}

	/**
	 * Finishes the asynchronous operation started with g_file_enumerator_next_files_async().
	 *
	 * Params:
	 *     result = a #GAsyncResult.
	 *
	 * Returns: a #GList of #GFileInfos. You must free the list with
	 *     g_list_free() and unref the infos with g_object_unref() when you're
	 *     done with them.
	 *
	 * Throws: GException on failure.
	 */
	public ListG nextFilesFinish(AsyncResultIF result)
	{
		GError* err = null;

		auto __p = g_file_enumerator_next_files_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err);

		if (err !is null)
		{
			throw new GException( new ErrorG(err) );
		}

		if(__p is null)
		{
			return null;
		}

		return new ListG(cast(GList*) __p, true);
	}

	/**
	 * Sets the file enumerator as having pending operations.
	 *
	 * Params:
	 *     pending = a boolean value.
	 */
	public void setPending(bool pending)
	{
		g_file_enumerator_set_pending(gFileEnumerator, pending);
	}
}