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 	 * Returns information for the next file in the enumerated object.
262 	 * Will block until the information is available. The #GFileInfo
263 	 * returned from this function will contain attributes that match the
264 	 * attribute string that was passed when the #GFileEnumerator was created.
265 	 *
266 	 * See the documentation of #GFileEnumerator for information about the
267 	 * order of returned files.
268 	 *
269 	 * On error, returns %NULL and sets @error to the error. If the
270 	 * enumerator is at the end, %NULL will be returned and @error will
271 	 * be unset.
272 	 *
273 	 * Params:
274 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
275 	 *
276 	 * Return: A #GFileInfo or %NULL on error
277 	 *     or end of enumerator.  Free the returned object with
278 	 *     g_object_unref() when no longer needed.
279 	 *
280 	 * Throws: GException on failure.
281 	 */
282 	public FileInfo nextFile(Cancellable cancellable)
283 	{
284 		GError* err = null;
285 		
286 		auto p = g_file_enumerator_next_file(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
287 		
288 		if (err !is null)
289 		{
290 			throw new GException( new ErrorG(err) );
291 		}
292 		
293 		if(p is null)
294 		{
295 			return null;
296 		}
297 		
298 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true);
299 	}
300 
301 	/**
302 	 * Request information for a number of files from the enumerator asynchronously.
303 	 * When all i/o for the operation is finished the @callback will be called with
304 	 * the requested information.
305 	 *
306 	 * See the documentation of #GFileEnumerator for information about the
307 	 * order of returned files.
308 	 *
309 	 * The callback can be called with less than @num_files files in case of error
310 	 * or at the end of the enumerator. In case of a partial error the callback will
311 	 * be called with any succeeding items and no error, and on the next request the
312 	 * error will be reported. If a request is cancelled the callback will be called
313 	 * with %G_IO_ERROR_CANCELLED.
314 	 *
315 	 * During an async request no other sync and async calls are allowed, and will
316 	 * result in %G_IO_ERROR_PENDING errors.
317 	 *
318 	 * Any outstanding i/o request with higher priority (lower numerical value) will
319 	 * be executed before an outstanding request with lower priority. Default
320 	 * priority is %G_PRIORITY_DEFAULT.
321 	 *
322 	 * Params:
323 	 *     numFiles = the number of file info objects to request
324 	 *     ioPriority = the [I/O priority][io-priority] of the request
325 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
326 	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
327 	 *     userData = the data to pass to callback function
328 	 */
329 	public void nextFilesAsync(int numFiles, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
330 	{
331 		g_file_enumerator_next_files_async(gFileEnumerator, numFiles, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
332 	}
333 
334 	/**
335 	 * Finishes the asynchronous operation started with g_file_enumerator_next_files_async().
336 	 *
337 	 * Params:
338 	 *     result = a #GAsyncResult.
339 	 *
340 	 * Return: a #GList of #GFileInfos. You must free the list with
341 	 *     g_list_free() and unref the infos with g_object_unref() when you're
342 	 *     done with them.
343 	 *
344 	 * Throws: GException on failure.
345 	 */
346 	public ListG nextFilesFinish(AsyncResultIF result)
347 	{
348 		GError* err = null;
349 		
350 		auto p = g_file_enumerator_next_files_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err);
351 		
352 		if (err !is null)
353 		{
354 			throw new GException( new ErrorG(err) );
355 		}
356 		
357 		if(p is null)
358 		{
359 			return null;
360 		}
361 		
362 		return new ListG(cast(GList*) p);
363 	}
364 
365 	/**
366 	 * Sets the file enumerator as having pending operations.
367 	 *
368 	 * Params:
369 	 *     pending = a boolean value.
370 	 */
371 	public void setPending(bool pending)
372 	{
373 		g_file_enumerator_set_pending(gFileEnumerator, pending);
374 	}
375 }