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 gtk.DirectoryList;
26 
27 private import gio.FileIF;
28 private import gio.ListModelIF;
29 private import gio.ListModelT;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.Str;
33 private import glib.c.functions;
34 private import gobject.ObjectG;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * `GtkDirectoryList` is a list model that wraps g_file_enumerate_children_async().
41  * 
42  * It presents a `GListModel` and fills it asynchronously with the `GFileInfo`s
43  * returned from that function.
44  * 
45  * Enumeration will start automatically when a the
46  * [property@Gtk.DirectoryList:file] property is set.
47  * 
48  * While the `GtkDirectoryList` is being filled, the
49  * [property@Gtk.DirectoryList:loading] property will be set to %TRUE. You can
50  * listen to that property if you want to show information like a `GtkSpinner`
51  * or a "Loading..." text.
52  * 
53  * If loading fails at any point, the [property@Gtk.DirectoryList:error]
54  * property will be set to give more indication about the failure.
55  * 
56  * The `GFileInfo`s returned from a `GtkDirectoryList` have the "standard::file"
57  * attribute set to the `GFile` they refer to. This way you can get at the file
58  * that is referred to in the same way you would via g_file_enumerator_get_child().
59  * This means you do not need access to the `GtkDirectoryList`, but can access
60  * the `GFile` directly from the `GFileInfo` when operating with a `GtkListView`
61  * or similar.
62  */
63 public class DirectoryList : ObjectG, ListModelIF
64 {
65 	/** the main Gtk struct */
66 	protected GtkDirectoryList* gtkDirectoryList;
67 
68 	/** Get the main Gtk struct */
69 	public GtkDirectoryList* getDirectoryListStruct(bool transferOwnership = false)
70 	{
71 		if (transferOwnership)
72 			ownedRef = false;
73 		return gtkDirectoryList;
74 	}
75 
76 	/** the main Gtk struct as a void* */
77 	protected override void* getStruct()
78 	{
79 		return cast(void*)gtkDirectoryList;
80 	}
81 
82 	/**
83 	 * Sets our main struct and passes it to the parent class.
84 	 */
85 	public this (GtkDirectoryList* gtkDirectoryList, bool ownedRef = false)
86 	{
87 		this.gtkDirectoryList = gtkDirectoryList;
88 		super(cast(GObject*)gtkDirectoryList, ownedRef);
89 	}
90 
91 	// add the ListModel capabilities
92 	mixin ListModelT!(GtkDirectoryList);
93 
94 
95 	/** */
96 	public static GType getType()
97 	{
98 		return gtk_directory_list_get_type();
99 	}
100 
101 	/**
102 	 * Creates a new `GtkDirectoryList`.
103 	 *
104 	 * The `GtkDirectoryList` is querying the given @file
105 	 * with the given @attributes.
106 	 *
107 	 * Params:
108 	 *     attributes = The attributes to query with
109 	 *     file = The file to query
110 	 *
111 	 * Returns: a new `GtkDirectoryList`
112 	 *
113 	 * Throws: ConstructionException GTK+ fails to create the object.
114 	 */
115 	public this(string attributes, FileIF file)
116 	{
117 		auto __p = gtk_directory_list_new(Str.toStringz(attributes), (file is null) ? null : file.getFileStruct());
118 
119 		if(__p is null)
120 		{
121 			throw new ConstructionException("null returned by new");
122 		}
123 
124 		this(cast(GtkDirectoryList*) __p, true);
125 	}
126 
127 	/**
128 	 * Gets the attributes queried on the children.
129 	 *
130 	 * Returns: The queried attributes
131 	 */
132 	public string getAttributes()
133 	{
134 		return Str.toString(gtk_directory_list_get_attributes(gtkDirectoryList));
135 	}
136 
137 	/**
138 	 * Gets the loading error, if any.
139 	 *
140 	 * If an error occurs during the loading process, the loading process
141 	 * will finish and this property allows querying the error that happened.
142 	 * This error will persist until a file is loaded again.
143 	 *
144 	 * An error being set does not mean that no files were loaded, and all
145 	 * successfully queried files will remain in the list.
146 	 *
147 	 * Returns: The loading error or %NULL if
148 	 *     loading finished successfully.
149 	 */
150 	public ErrorG getError()
151 	{
152 		auto __p = gtk_directory_list_get_error(gtkDirectoryList);
153 
154 		if(__p is null)
155 		{
156 			return null;
157 		}
158 
159 		return new ErrorG(cast(GError*) __p);
160 	}
161 
162 	/**
163 	 * Gets the file whose children are currently enumerated.
164 	 *
165 	 * Returns: The file whose children are enumerated
166 	 */
167 	public FileIF getFile()
168 	{
169 		auto __p = gtk_directory_list_get_file(gtkDirectoryList);
170 
171 		if(__p is null)
172 		{
173 			return null;
174 		}
175 
176 		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p);
177 	}
178 
179 	/**
180 	 * Gets the IO priority set via gtk_directory_list_set_io_priority().
181 	 *
182 	 * Returns: The IO priority.
183 	 */
184 	public int getIoPriority()
185 	{
186 		return gtk_directory_list_get_io_priority(gtkDirectoryList);
187 	}
188 
189 	/**
190 	 * Returns whether the directory list is monitoring
191 	 * the directory for changes.
192 	 *
193 	 * Returns: %TRUE if the directory is monitored
194 	 */
195 	public bool getMonitored()
196 	{
197 		return gtk_directory_list_get_monitored(gtkDirectoryList) != 0;
198 	}
199 
200 	/**
201 	 * Returns %TRUE if the children enumeration is currently in
202 	 * progress.
203 	 *
204 	 * Files will be added to @self from time to time while loading is
205 	 * going on. The order in which are added is undefined and may change
206 	 * in between runs.
207 	 *
208 	 * Returns: %TRUE if @self is loading
209 	 */
210 	public bool isLoading()
211 	{
212 		return gtk_directory_list_is_loading(gtkDirectoryList) != 0;
213 	}
214 
215 	/**
216 	 * Sets the @attributes to be enumerated and starts the enumeration.
217 	 *
218 	 * If @attributes is %NULL, no attributes will be queried, but a list
219 	 * of `GFileInfo`s will still be created.
220 	 *
221 	 * Params:
222 	 *     attributes = the attributes to enumerate
223 	 */
224 	public void setAttributes(string attributes)
225 	{
226 		gtk_directory_list_set_attributes(gtkDirectoryList, Str.toStringz(attributes));
227 	}
228 
229 	/**
230 	 * Sets the @file to be enumerated and starts the enumeration.
231 	 *
232 	 * If @file is %NULL, the result will be an empty list.
233 	 *
234 	 * Params:
235 	 *     file = the #GFile to be enumerated
236 	 */
237 	public void setFile(FileIF file)
238 	{
239 		gtk_directory_list_set_file(gtkDirectoryList, (file is null) ? null : file.getFileStruct());
240 	}
241 
242 	/**
243 	 * Sets the IO priority to use while loading directories.
244 	 *
245 	 * Setting the priority while @self is loading will reprioritize the
246 	 * ongoing load as soon as possible.
247 	 *
248 	 * The default IO priority is %G_PRIORITY_DEFAULT, which is higher than
249 	 * the GTK redraw priority. If you are loading a lot of directories in
250 	 * parallel, lowering it to something like %G_PRIORITY_DEFAULT_IDLE
251 	 * may increase responsiveness.
252 	 *
253 	 * Params:
254 	 *     ioPriority = IO priority to use
255 	 */
256 	public void setIoPriority(int ioPriority)
257 	{
258 		gtk_directory_list_set_io_priority(gtkDirectoryList, ioPriority);
259 	}
260 
261 	/**
262 	 * Sets whether the directory list will monitor the directory
263 	 * for changes. If monitoring is enabled, the ::items-changed
264 	 * signal will be emitted when the directory contents change.
265 	 *
266 	 * When monitoring is turned on after the initial creation
267 	 * of the directory list, the directory is reloaded to avoid
268 	 * missing files that appeared between the initial loading
269 	 * and when monitoring was turned on.
270 	 *
271 	 * Params:
272 	 *     monitored = %TRUE to monitor the directory for changes
273 	 */
274 	public void setMonitored(bool monitored)
275 	{
276 		gtk_directory_list_set_monitored(gtkDirectoryList, monitored);
277 	}
278 }