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