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 gsv.SourceFileLoader;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FileIF;
30 private import gio.InputStream;
31 private import glib.ConstructionException;
32 private import glib.ErrorG;
33 private import glib.GException;
34 private import glib.ListSG;
35 private import gobject.ObjectG;
36 private import gsv.SourceBuffer;
37 private import gsv.SourceEncoding;
38 private import gsv.SourceFile;
39 private import gsv.c.functions;
40 public  import gsv.c.types;
41 public  import gsvc.gsvtypes;
42 
43 
44 /** */
45 public class SourceFileLoader : ObjectG
46 {
47 	/** the main Gtk struct */
48 	protected GtkSourceFileLoader* gtkSourceFileLoader;
49 
50 	/** Get the main Gtk struct */
51 	public GtkSourceFileLoader* getSourceFileLoaderStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gtkSourceFileLoader;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkSourceFileLoader;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		gtkSourceFileLoader = cast(GtkSourceFileLoader*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkSourceFileLoader* gtkSourceFileLoader, bool ownedRef = false)
74 	{
75 		this.gtkSourceFileLoader = gtkSourceFileLoader;
76 		super(cast(GObject*)gtkSourceFileLoader, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_source_file_loader_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new #GtkSourceFileLoader object. The contents is read from the
88 	 * #GtkSourceFile's location. If not already done, call
89 	 * gtk_source_file_set_location() before calling this constructor. The previous
90 	 * location is anyway not needed, because as soon as the file loading begins,
91 	 * the @buffer is emptied.
92 	 *
93 	 * Params:
94 	 *     buffer = the #GtkSourceBuffer to load the contents into.
95 	 *     file = the #GtkSourceFile.
96 	 *
97 	 * Returns: a new #GtkSourceFileLoader object.
98 	 *
99 	 * Since: 3.14
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(SourceBuffer buffer, SourceFile file)
104 	{
105 		auto p = gtk_source_file_loader_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct());
106 
107 		if(p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 
112 		this(cast(GtkSourceFileLoader*) p, true);
113 	}
114 
115 	/**
116 	 * Creates a new #GtkSourceFileLoader object. The contents is read from @stream.
117 	 *
118 	 * Params:
119 	 *     buffer = the #GtkSourceBuffer to load the contents into.
120 	 *     file = the #GtkSourceFile.
121 	 *     stream = the #GInputStream to load, e.g. stdin.
122 	 *
123 	 * Returns: a new #GtkSourceFileLoader object.
124 	 *
125 	 * Since: 3.14
126 	 *
127 	 * Throws: ConstructionException GTK+ fails to create the object.
128 	 */
129 	public this(SourceBuffer buffer, SourceFile file, InputStream stream)
130 	{
131 		auto p = gtk_source_file_loader_new_from_stream((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct(), (stream is null) ? null : stream.getInputStreamStruct());
132 
133 		if(p is null)
134 		{
135 			throw new ConstructionException("null returned by new_from_stream");
136 		}
137 
138 		this(cast(GtkSourceFileLoader*) p, true);
139 	}
140 
141 	/**
142 	 * Returns: the #GtkSourceBuffer to load the contents into.
143 	 *
144 	 * Since: 3.14
145 	 */
146 	public SourceBuffer getBuffer()
147 	{
148 		auto p = gtk_source_file_loader_get_buffer(gtkSourceFileLoader);
149 
150 		if(p is null)
151 		{
152 			return null;
153 		}
154 
155 		return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p);
156 	}
157 
158 	/**
159 	 * Returns: the detected compression type.
160 	 *
161 	 * Since: 3.14
162 	 */
163 	public GtkSourceCompressionType getCompressionType()
164 	{
165 		return gtk_source_file_loader_get_compression_type(gtkSourceFileLoader);
166 	}
167 
168 	/**
169 	 * Returns: the detected file encoding.
170 	 *
171 	 * Since: 3.14
172 	 */
173 	public SourceEncoding getEncoding()
174 	{
175 		auto p = gtk_source_file_loader_get_encoding(gtkSourceFileLoader);
176 
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 
182 		return ObjectG.getDObject!(SourceEncoding)(cast(GtkSourceEncoding*) p);
183 	}
184 
185 	/**
186 	 * Returns: the #GtkSourceFile.
187 	 *
188 	 * Since: 3.14
189 	 */
190 	public SourceFile getFile()
191 	{
192 		auto p = gtk_source_file_loader_get_file(gtkSourceFileLoader);
193 
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 
199 		return ObjectG.getDObject!(SourceFile)(cast(GtkSourceFile*) p);
200 	}
201 
202 	/**
203 	 * Returns: the #GInputStream to load, or %NULL
204 	 *     if a #GFile is used.
205 	 *
206 	 * Since: 3.14
207 	 */
208 	public InputStream getInputStream()
209 	{
210 		auto p = gtk_source_file_loader_get_input_stream(gtkSourceFileLoader);
211 
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) p);
218 	}
219 
220 	/**
221 	 * Returns: the #GFile to load, or %NULL
222 	 *     if an input stream is used.
223 	 *
224 	 * Since: 3.14
225 	 */
226 	public FileIF getLocation()
227 	{
228 		auto p = gtk_source_file_loader_get_location(gtkSourceFileLoader);
229 
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 
235 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p);
236 	}
237 
238 	/**
239 	 * Returns: the detected newline type.
240 	 *
241 	 * Since: 3.14
242 	 */
243 	public GtkSourceNewlineType getNewlineType()
244 	{
245 		return gtk_source_file_loader_get_newline_type(gtkSourceFileLoader);
246 	}
247 
248 	/**
249 	 * Loads asynchronously the file or input stream contents into the
250 	 * #GtkSourceBuffer. See the #GAsyncResult documentation to know how to use this
251 	 * function.
252 	 *
253 	 * Params:
254 	 *     ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW,
255 	 *         %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
256 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
257 	 *     progressCallback = function to call back with
258 	 *         progress information, or %NULL if progress information is not needed.
259 	 *     progressCallbackData = user data to pass to @progress_callback.
260 	 *     progressCallbackNotify = function to call on
261 	 *         @progress_callback_data when the @progress_callback is no longer needed, or
262 	 *         %NULL.
263 	 *     callback = a #GAsyncReadyCallback to call when the request is
264 	 *         satisfied.
265 	 *     userData = user data to pass to @callback.
266 	 *
267 	 * Since: 3.14
268 	 */
269 	public void loadAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData)
270 	{
271 		gtk_source_file_loader_load_async(gtkSourceFileLoader, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData);
272 	}
273 
274 	/**
275 	 * Finishes a file loading started with gtk_source_file_loader_load_async().
276 	 *
277 	 * If the contents has been loaded, the following #GtkSourceFile properties will
278 	 * be updated: the location, the encoding, the newline type and the compression
279 	 * type.
280 	 *
281 	 * Params:
282 	 *     result = a #GAsyncResult.
283 	 *
284 	 * Returns: whether the contents has been loaded successfully.
285 	 *
286 	 * Since: 3.14
287 	 *
288 	 * Throws: GException on failure.
289 	 */
290 	public bool loadFinish(AsyncResultIF result)
291 	{
292 		GError* err = null;
293 
294 		auto p = gtk_source_file_loader_load_finish(gtkSourceFileLoader, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
295 
296 		if (err !is null)
297 		{
298 			throw new GException( new ErrorG(err) );
299 		}
300 
301 		return p;
302 	}
303 
304 	/**
305 	 * Sets the candidate encodings for the file loading. The encodings are tried in
306 	 * the same order as the list.
307 	 *
308 	 * For convenience, @candidate_encodings can contain duplicates. Only the first
309 	 * occurrence of a duplicated encoding is kept in the list.
310 	 *
311 	 * By default the candidate encodings are (in that order in the list):
312 	 * 1. If set, the #GtkSourceFile's encoding as returned by
313 	 * gtk_source_file_get_encoding().
314 	 * 2. The default candidates as returned by
315 	 * gtk_source_encoding_get_default_candidates().
316 	 *
317 	 * Params:
318 	 *     candidateEncodings = a list of
319 	 *         #GtkSourceEncoding<!-- -->s.
320 	 *
321 	 * Since: 3.14
322 	 */
323 	public void setCandidateEncodings(ListSG candidateEncodings)
324 	{
325 		gtk_source_file_loader_set_candidate_encodings(gtkSourceFileLoader, (candidateEncodings is null) ? null : candidateEncodings.getListSGStruct());
326 	}
327 }