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