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 glib.Directory;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.Str;
30 private import gtkc.glib;
31 public  import gtkc.glibtypes;
32 
33 
34 /**
35  * An opaque structure representing an opened directory.
36  */
37 public class Directory
38 {
39 	/** the main Gtk struct */
40 	protected GDir* gDir;
41 	protected bool ownedRef;
42 
43 	/** Get the main Gtk struct */
44 	public GDir* getDirectoryStruct()
45 	{
46 		return gDir;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected void* getStruct()
51 	{
52 		return cast(void*)gDir;
53 	}
54 
55 	/**
56 	 * Sets our main struct and passes it to the parent class.
57 	 */
58 	public this (GDir* gDir, bool ownedRef = false)
59 	{
60 		this.gDir = gDir;
61 		this.ownedRef = ownedRef;
62 	}
63 
64 
65 	/**
66 	 * Closes the directory and deallocates all related resources.
67 	 */
68 	public void close()
69 	{
70 		g_dir_close(gDir);
71 	}
72 
73 	/**
74 	 * Retrieves the name of another entry in the directory, or %NULL.
75 	 * The order of entries returned from this function is not defined,
76 	 * and may vary by file system or other operating-system dependent
77 	 * factors.
78 	 *
79 	 * %NULL may also be returned in case of errors. On Unix, you can
80 	 * check `errno` to find out if %NULL was returned because of an error.
81 	 *
82 	 * On Unix, the '.' and '..' entries are omitted, and the returned
83 	 * name is in the on-disk encoding.
84 	 *
85 	 * On Windows, as is true of all GLib functions which operate on
86 	 * filenames, the returned name is in UTF-8.
87 	 *
88 	 * Return: The entry's name or %NULL if there are no
89 	 *     more entries. The return value is owned by GLib and
90 	 *     must not be modified or freed.
91 	 */
92 	public string readName()
93 	{
94 		return Str.toString(g_dir_read_name(gDir));
95 	}
96 
97 	/**
98 	 * Resets the given directory. The next call to g_dir_read_name()
99 	 * will return the first entry again.
100 	 */
101 	public void rewind()
102 	{
103 		g_dir_rewind(gDir);
104 	}
105 
106 	/**
107 	 * Creates a subdirectory in the preferred directory for temporary
108 	 * files (as returned by g_get_tmp_dir()).
109 	 *
110 	 * @tmpl should be a string in the GLib file name encoding containing
111 	 * a sequence of six 'X' characters, as the parameter to g_mkstemp().
112 	 * However, unlike these functions, the template should only be a
113 	 * basename, no directory components are allowed. If template is
114 	 * %NULL, a default template is used.
115 	 *
116 	 * Note that in contrast to g_mkdtemp() (and mkdtemp()) @tmpl is not
117 	 * modified, and might thus be a read-only literal string.
118 	 *
119 	 * Params:
120 	 *     tmpl = Template for directory name,
121 	 *         as in g_mkdtemp(), basename only, or %NULL for a default template
122 	 *
123 	 * Return: The actual name used. This string
124 	 *     should be freed with g_free() when not needed any longer and is
125 	 *     is in the GLib file name encoding. In case of errors, %NULL is
126 	 *     returned and @error will be set.
127 	 *
128 	 * Since: 2.30
129 	 *
130 	 * Throws: GException on failure.
131 	 */
132 	public static string makeTmp(string tmpl)
133 	{
134 		GError* err = null;
135 		
136 		auto retStr = g_dir_make_tmp(Str.toStringz(tmpl), &err);
137 		
138 		if (err !is null)
139 		{
140 			throw new GException( new ErrorG(err) );
141 		}
142 		
143 		scope(exit) Str.freeString(retStr);
144 		return Str.toString(retStr);
145 	}
146 
147 	/**
148 	 * Opens a directory for reading. The names of the files in the
149 	 * directory can then be retrieved using g_dir_read_name().  Note
150 	 * that the ordering is not defined.
151 	 *
152 	 * Params:
153 	 *     path = the path to the directory you are interested in. On Unix
154 	 *         in the on-disk encoding. On Windows in UTF-8
155 	 *     flags = Currently must be set to 0. Reserved for future use.
156 	 *
157 	 * Return: a newly allocated #GDir on success, %NULL on failure.
158 	 *     If non-%NULL, you must free the result with g_dir_close()
159 	 *     when you are finished with it.
160 	 *
161 	 * Throws: GException on failure.
162 	 */
163 	public static Directory open(string path, uint flags)
164 	{
165 		GError* err = null;
166 		
167 		auto p = g_dir_open(Str.toStringz(path), flags, &err);
168 		
169 		if (err !is null)
170 		{
171 			throw new GException( new ErrorG(err) );
172 		}
173 		
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 		
179 		return new Directory(cast(GDir*) p);
180 	}
181 }