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  = 
27  * outPack = glib
28  * outFile = Directory
29  * strct   = GDir
30  * realStrct=
31  * ctorStrct=
32  * clss    = Directory
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_dir_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * structWrap:
50  * 	- GDir* -> Directory
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module glib.Directory;
57 
58 public  import gtkc.glibtypes;
59 
60 private import gtkc.glib;
61 private import glib.ConstructionException;
62 
63 private import glib.Str;
64 private import glib.ErrorG;
65 private import glib.GException;
66 
67 
68 
69 /**
70  * There is a group of functions which wrap the common POSIX functions
71  * dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(),
72  * g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these
73  * wrappers is to make it possible to handle file names with any Unicode
74  * characters in them on Windows without having to use ifdefs and the
75  * wide character API in the application code.
76  *
77  * The pathname argument should be in the GLib file name encoding.
78  * On POSIX this is the actual on-disk encoding which might correspond
79  * to the locale settings of the process (or the
80  * G_FILENAME_ENCODING environment variable), or not.
81  *
82  * On Windows the GLib file name encoding is UTF-8. Note that the
83  * Microsoft C library does not use UTF-8, but has separate APIs for
84  * current system code page and wide characters (UTF-16). The GLib
85  * wrappers call the wide character API if present (on modern Windows
86  * systems), otherwise convert to/from the system code page.
87  *
88  * Another group of functions allows to open and read directories
89  * in the GLib file name encoding. These are g_dir_open(),
90  * g_dir_read_name(), g_dir_rewind(), g_dir_close().
91  */
92 public class Directory
93 {
94 	
95 	/** the main Gtk struct */
96 	protected GDir* gDir;
97 	
98 	
99 	/** Get the main Gtk struct */
100 	public GDir* getDirectoryStruct()
101 	{
102 		return gDir;
103 	}
104 	
105 	
106 	/** the main Gtk struct as a void* */
107 	protected void* getStruct()
108 	{
109 		return cast(void*)gDir;
110 	}
111 	
112 	/**
113 	 * Sets our main struct and passes it to the parent class
114 	 */
115 	public this (GDir* gDir)
116 	{
117 		this.gDir = gDir;
118 	}
119 	
120 	/**
121 	 */
122 	
123 	/**
124 	 * Creates a subdirectory in the preferred directory for temporary
125 	 * files (as returned by g_get_tmp_dir()).
126 	 * tmpl should be a string in the GLib file name encoding containing
127 	 * a sequence of six 'X' characters, as the parameter to g_mkstemp().
128 	 * However, unlike these functions, the template should only be a
129 	 * basename, no directory components are allowed. If template is
130 	 * NULL, a default template is used.
131 	 * Note that in contrast to g_mkdtemp() (and mkdtemp()) tmpl is not
132 	 * modified, and might thus be a read-only literal string.
133 	 * Since 2.30
134 	 * Params:
135 	 * tmpl = Template for directory name,
136 	 * as in g_mkdtemp(), basename only, or NULL for a default template. [type filename][allow-none]
137 	 * Returns: The actual name used. This string should be freed with g_free() when not needed any longer and is is in the GLib file name encoding. In case of errors, NULL is returned and error will be set. [type filename]
138 	 * Throws: GException on failure.
139 	 */
140 	public static string makeTmp(string tmpl)
141 	{
142 		// gchar * g_dir_make_tmp (const gchar *tmpl,  GError **error);
143 		GError* err = null;
144 		
145 		auto p = g_dir_make_tmp(Str.toStringz(tmpl), &err);
146 		
147 		if (err !is null)
148 		{
149 			throw new GException( new ErrorG(err) );
150 		}
151 		
152 		return Str.toString(p);
153 	}
154 	
155 	/**
156 	 * Opens a directory for reading. The names of the files in the
157 	 * directory can then be retrieved using g_dir_read_name(). Note
158 	 * that the ordering is not defined.
159 	 * Params:
160 	 * path = the path to the directory you are interested in. On Unix
161 	 * in the on-disk encoding. On Windows in UTF-8
162 	 * flags = Currently must be set to 0. Reserved for future use.
163 	 * Returns: a newly allocated GDir on success, NULL on failure. If non-NULL, you must free the result with g_dir_close() when you are finished with it.
164 	 * Throws: GException on failure.
165 	 */
166 	public static Directory open(string path, uint flags)
167 	{
168 		// GDir * g_dir_open (const gchar *path,  guint flags,  GError **error);
169 		GError* err = null;
170 		
171 		auto p = g_dir_open(Str.toStringz(path), flags, &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 new Directory(cast(GDir*) p);
185 	}
186 	
187 	/**
188 	 * Retrieves the name of another entry in the directory, or NULL.
189 	 * The order of entries returned from this function is not defined,
190 	 * and may vary by file system or other operating-system dependent
191 	 * factors.
192 	 * NULL may also be returned in case of errors. On Unix, you can
193 	 * check errno to find out if NULL was returned
194 	 * because of an error.
195 	 * On Unix, the '.' and '..' entries are omitted, and the returned
196 	 * name is in the on-disk encoding.
197 	 * On Windows, as is true of all GLib functions which operate on
198 	 * filenames, the returned name is in UTF-8.
199 	 * Returns: The entry's name or NULL if there are no more entries. The return value is owned by GLib and must not be modified or freed.
200 	 */
201 	public string readName()
202 	{
203 		// const gchar * g_dir_read_name (GDir *dir);
204 		return Str.toString(g_dir_read_name(gDir));
205 	}
206 	
207 	/**
208 	 * Resets the given directory. The next call to g_dir_read_name()
209 	 * will return the first entry again.
210 	 */
211 	public void rewind()
212 	{
213 		// void g_dir_rewind (GDir *dir);
214 		g_dir_rewind(gDir);
215 	}
216 	
217 	/**
218 	 * Closes the directory and deallocates all related resources.
219 	 */
220 	public void close()
221 	{
222 		// void g_dir_close (GDir *dir);
223 		g_dir_close(gDir);
224 	}
225 }