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  * Conversion parameters:
26  * inFile  = GFileEnumerator.html
27  * outPack = gio
28  * outFile = FileEnumerator
29  * strct   = GFileEnumerator
30  * realStrct=
31  * ctorStrct=
32  * clss    = FileEnumerator
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_file_enumerator_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * 	- glib.ListG
50  * 	- gio.AsyncResultIF
51  * 	- gio.Cancellable
52  * 	- gio.File
53  * 	- gio.FileInfo
54  * structWrap:
55  * 	- GAsyncResult* -> AsyncResultIF
56  * 	- GCancellable* -> Cancellable
57  * 	- GFile* -> File
58  * 	- GFileInfo* -> FileInfo
59  * 	- GList* -> ListG
60  * module aliases:
61  * local aliases:
62  * overrides:
63  */
64 
65 module gio.FileEnumerator;
66 
67 public  import gtkc.giotypes;
68 
69 private import gtkc.gio;
70 private import glib.ConstructionException;
71 private import gobject.ObjectG;
72 
73 private import glib.Str;
74 private import glib.ErrorG;
75 private import glib.GException;
76 private import glib.ListG;
77 private import gio.AsyncResultIF;
78 private import gio.Cancellable;
79 private import gio.File;
80 private import gio.FileInfo;
81 
82 
83 private import gobject.ObjectG;
84 
85 /**
86  * GFileEnumerator allows you to operate on a set of GFiles,
87  * returning a GFileInfo structure for each file enumerated (e.g.
88  * g_file_enumerate_children() will return a GFileEnumerator for each
89  * of the children within a directory).
90  *
91  * To get the next file's information from a GFileEnumerator, use
92  * g_file_enumerator_next_file() or its asynchronous version,
93  * g_file_enumerator_next_files_async(). Note that the asynchronous
94  * version will return a list of GFileInfos, whereas the
95  * synchronous will only return the next file in the enumerator.
96  *
97  * The ordering of returned files is unspecified for non-Unix
98  * platforms; for more information, see g_dir_read_name(). On Unix,
99  * when operating on local files, returned files will be sorted by
100  * inode number. Effectively you can assume that the ordering of
101  * returned files will be stable between successive calls (and
102  * applications) assuming the directory is unchanged.
103  *
104  * If your application needs a specific ordering, such as by name or
105  * modification time, you will have to implement that in your
106  * application code.
107  *
108  * To close a GFileEnumerator, use g_file_enumerator_close(), or
109  * its asynchronous version, g_file_enumerator_close_async(). Once
110  * a GFileEnumerator is closed, no further actions may be performed
111  * on it, and it should be freed with g_object_unref().
112  */
113 public class FileEnumerator : ObjectG
114 {
115 	
116 	/** the main Gtk struct */
117 	protected GFileEnumerator* gFileEnumerator;
118 	
119 	
120 	/** Get the main Gtk struct */
121 	public GFileEnumerator* getFileEnumeratorStruct()
122 	{
123 		return gFileEnumerator;
124 	}
125 	
126 	
127 	/** the main Gtk struct as a void* */
128 	protected override void* getStruct()
129 	{
130 		return cast(void*)gFileEnumerator;
131 	}
132 	
133 	/**
134 	 * Sets our main struct and passes it to the parent class
135 	 */
136 	public this (GFileEnumerator* gFileEnumerator)
137 	{
138 		super(cast(GObject*)gFileEnumerator);
139 		this.gFileEnumerator = gFileEnumerator;
140 	}
141 	
142 	protected override void setStruct(GObject* obj)
143 	{
144 		super.setStruct(obj);
145 		gFileEnumerator = cast(GFileEnumerator*)obj;
146 	}
147 	
148 	/**
149 	 */
150 	
151 	/**
152 	 * Returns information for the next file in the enumerated object.
153 	 * Will block until the information is available. The GFileInfo
154 	 * returned from this function will contain attributes that match the
155 	 * attribute string that was passed when the GFileEnumerator was created.
156 	 * See the documentation of GFileEnumerator for information about the
157 	 * order of returned files.
158 	 * On error, returns NULL and sets error to the error. If the
159 	 * enumerator is at the end, NULL will be returned and error will
160 	 * be unset.
161 	 * Params:
162 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
163 	 * Returns: A GFileInfo or NULL on error or end of enumerator. Free the returned object with g_object_unref() when no longer needed. [transfer full]
164 	 * Throws: GException on failure.
165 	 */
166 	public FileInfo nextFile(Cancellable cancellable)
167 	{
168 		// GFileInfo * g_file_enumerator_next_file (GFileEnumerator *enumerator,  GCancellable *cancellable,  GError **error);
169 		GError* err = null;
170 		
171 		auto p = g_file_enumerator_next_file(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
172 		
173 		if (err !is null)
174 		{
175 			throw new GException( new ErrorG(err) );
176 		}
177 		
178 		
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 		
184 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p);
185 	}
186 	
187 	/**
188 	 * Releases all resources used by this enumerator, making the
189 	 * enumerator return G_IO_ERROR_CLOSED on all calls.
190 	 * This will be automatically called when the last reference
191 	 * is dropped, but you might want to call this function to make
192 	 * sure resources are released as early as possible.
193 	 * Params:
194 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
195 	 * Returns: TRUE on success or FALSE on error.
196 	 * Throws: GException on failure.
197 	 */
198 	public int close(Cancellable cancellable)
199 	{
200 		// gboolean g_file_enumerator_close (GFileEnumerator *enumerator,  GCancellable *cancellable,  GError **error);
201 		GError* err = null;
202 		
203 		auto p = g_file_enumerator_close(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
204 		
205 		if (err !is null)
206 		{
207 			throw new GException( new ErrorG(err) );
208 		}
209 		
210 		return p;
211 	}
212 	
213 	/**
214 	 * Request information for a number of files from the enumerator asynchronously.
215 	 * When all i/o for the operation is finished the callback will be called with
216 	 * the requested information.
217 	 * See the documentation of GFileEnumerator for information about the
218 	 * order of returned files.
219 	 * The callback can be called with less than num_files files in case of error
220 	 * or at the end of the enumerator. In case of a partial error the callback will
221 	 * be called with any succeeding items and no error, and on the next request the
222 	 * error will be reported. If a request is cancelled the callback will be called
223 	 * with G_IO_ERROR_CANCELLED.
224 	 * During an async request no other sync and async calls are allowed, and will
225 	 * result in G_IO_ERROR_PENDING errors.
226 	 * Any outstanding i/o request with higher priority (lower numerical value) will
227 	 * be executed before an outstanding request with lower priority. Default
228 	 * priority is G_PRIORITY_DEFAULT.
229 	 * Params:
230 	 * numFiles = the number of file info objects to request
231 	 * ioPriority = the io priority
232 	 * of the request.
233 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
234 	 * callback = a GAsyncReadyCallback to call when the request is satisfied. [scope async]
235 	 * userData = the data to pass to callback function. [closure]
236 	 */
237 	public void nextFilesAsync(int numFiles, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
238 	{
239 		// void g_file_enumerator_next_files_async (GFileEnumerator *enumerator,  int num_files,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
240 		g_file_enumerator_next_files_async(gFileEnumerator, numFiles, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
241 	}
242 	
243 	/**
244 	 * Finishes the asynchronous operation started with g_file_enumerator_next_files_async().
245 	 * Params:
246 	 * result = a GAsyncResult.
247 	 * 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. [transfer full][element-type Gio.FileInfo]
248 	 * Throws: GException on failure.
249 	 */
250 	public ListG nextFilesFinish(AsyncResultIF result)
251 	{
252 		// GList * g_file_enumerator_next_files_finish (GFileEnumerator *enumerator,  GAsyncResult *result,  GError **error);
253 		GError* err = null;
254 		
255 		auto p = g_file_enumerator_next_files_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultTStruct(), &err);
256 		
257 		if (err !is null)
258 		{
259 			throw new GException( new ErrorG(err) );
260 		}
261 		
262 		
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 		
268 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
269 	}
270 	
271 	/**
272 	 * Asynchronously closes the file enumerator.
273 	 * If cancellable is not NULL, then the operation can be cancelled by
274 	 * triggering the cancellable object from another thread. If the operation
275 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned in
276 	 * g_file_enumerator_close_finish().
277 	 * Params:
278 	 * ioPriority = the I/O priority
279 	 * of the request.
280 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
281 	 * callback = a GAsyncReadyCallback to call when the request is satisfied. [scope async]
282 	 * userData = the data to pass to callback function. [closure]
283 	 */
284 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
285 	{
286 		// void g_file_enumerator_close_async (GFileEnumerator *enumerator,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
287 		g_file_enumerator_close_async(gFileEnumerator, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
288 	}
289 	
290 	/**
291 	 * Finishes closing a file enumerator, started from g_file_enumerator_close_async().
292 	 * If the file enumerator was already closed when g_file_enumerator_close_async()
293 	 * was called, then this function will report G_IO_ERROR_CLOSED in error, and
294 	 * return FALSE. If the file enumerator had pending operation when the close
295 	 * operation was started, then this function will report G_IO_ERROR_PENDING, and
296 	 * return FALSE. If cancellable was not NULL, then the operation may have been
297 	 * cancelled by triggering the cancellable object from another thread. If the operation
298 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be set, and FALSE will be
299 	 * returned.
300 	 * Params:
301 	 * result = a GAsyncResult.
302 	 * Returns: TRUE if the close operation has finished successfully.
303 	 * Throws: GException on failure.
304 	 */
305 	public int closeFinish(AsyncResultIF result)
306 	{
307 		// gboolean g_file_enumerator_close_finish (GFileEnumerator *enumerator,  GAsyncResult *result,  GError **error);
308 		GError* err = null;
309 		
310 		auto p = g_file_enumerator_close_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultTStruct(), &err);
311 		
312 		if (err !is null)
313 		{
314 			throw new GException( new ErrorG(err) );
315 		}
316 		
317 		return p;
318 	}
319 	
320 	/**
321 	 * Checks if the file enumerator has been closed.
322 	 * Returns: TRUE if the enumerator is closed.
323 	 */
324 	public int isClosed()
325 	{
326 		// gboolean g_file_enumerator_is_closed (GFileEnumerator *enumerator);
327 		return g_file_enumerator_is_closed(gFileEnumerator);
328 	}
329 	
330 	/**
331 	 * Checks if the file enumerator has pending operations.
332 	 * Returns: TRUE if the enumerator has pending operations.
333 	 */
334 	public int hasPending()
335 	{
336 		// gboolean g_file_enumerator_has_pending (GFileEnumerator *enumerator);
337 		return g_file_enumerator_has_pending(gFileEnumerator);
338 	}
339 	
340 	/**
341 	 * Sets the file enumerator as having pending operations.
342 	 * Params:
343 	 * pending = a boolean value.
344 	 */
345 	public void setPending(int pending)
346 	{
347 		// void g_file_enumerator_set_pending (GFileEnumerator *enumerator,  gboolean pending);
348 		g_file_enumerator_set_pending(gFileEnumerator, pending);
349 	}
350 	
351 	/**
352 	 * Get the GFile container which is being enumerated.
353 	 * Since 2.18
354 	 * Returns: the GFile which is being enumerated. [transfer none]
355 	 */
356 	public File getContainer()
357 	{
358 		// GFile * g_file_enumerator_get_container (GFileEnumerator *enumerator);
359 		auto p = g_file_enumerator_get_container(gFileEnumerator);
360 		
361 		if(p is null)
362 		{
363 			return null;
364 		}
365 		
366 		return ObjectG.getDObject!(File)(cast(GFile*) p);
367 	}
368 	
369 	/**
370 	 * Return a new GFile which refers to the file named by info in the source
371 	 * directory of enumerator. This function is primarily intended to be used
372 	 * inside loops with g_file_enumerator_next_file().
373 	 * Since 2.36
374 	 * Params:
375 	 * info = a GFileInfo gotten from g_file_enumerator_next_file()
376 	 * or the async equivalents.
377 	 * Returns: a GFile for the GFileInfo passed it. [transfer full]
378 	 */
379 	public File getChild(FileInfo info)
380 	{
381 		// GFile * g_file_enumerator_get_child (GFileEnumerator *enumerator,  GFileInfo *info);
382 		auto p = g_file_enumerator_get_child(gFileEnumerator, (info is null) ? null : info.getFileInfoStruct());
383 		
384 		if(p is null)
385 		{
386 			return null;
387 		}
388 		
389 		return ObjectG.getDObject!(File)(cast(GFile*) p);
390 	}
391 }