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