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 
42 	/** Get the main Gtk struct */
43 	public GDir* getDirectoryStruct()
44 	{
45 		return gDir;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected void* getStruct()
50 	{
51 		return cast(void*)gDir;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (GDir* gDir)
58 	{
59 		this.gDir = gDir;
60 	}
61 
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 p = 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 		return Str.toString(p);
144 	}
145 
146 	/**
147 	 * Opens a directory for reading. The names of the files in the
148 	 * directory can then be retrieved using g_dir_read_name().  Note
149 	 * that the ordering is not defined.
150 	 *
151 	 * Params:
152 	 *     path = the path to the directory you are interested in. On Unix
153 	 *         in the on-disk encoding. On Windows in UTF-8
154 	 *     flags = Currently must be set to 0. Reserved for future use.
155 	 *
156 	 * Return: a newly allocated #GDir on success, %NULL on failure.
157 	 *     If non-%NULL, you must free the result with g_dir_close()
158 	 *     when you are finished with it.
159 	 *
160 	 * Throws: GException on failure.
161 	 */
162 	public static Directory open(string path, uint flags)
163 	{
164 		GError* err = null;
165 		
166 		auto p = g_dir_open(Str.toStringz(path), flags, &err);
167 		
168 		if (err !is null)
169 		{
170 			throw new GException( new ErrorG(err) );
171 		}
172 		
173 		if(p is null)
174 		{
175 			return null;
176 		}
177 		
178 		return new Directory(cast(GDir*) p);
179 	}
180 }