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.SourceFileSaver;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FileIF;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.GException;
33 private import gobject.ObjectG;
34 private import gsv.SourceBuffer;
35 private import gsv.SourceEncoding;
36 private import gsv.SourceFile;
37 private import gsv.c.functions;
38 public  import gsv.c.types;
39 public  import gsvc.gsvtypes;
40 
41 
42 /** */
43 public class SourceFileSaver : ObjectG
44 {
45 	/** the main Gtk struct */
46 	protected GtkSourceFileSaver* gtkSourceFileSaver;
47 
48 	/** Get the main Gtk struct */
49 	public GtkSourceFileSaver* getSourceFileSaverStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return gtkSourceFileSaver;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected override void* getStruct()
58 	{
59 		return cast(void*)gtkSourceFileSaver;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GtkSourceFileSaver* gtkSourceFileSaver, bool ownedRef = false)
66 	{
67 		this.gtkSourceFileSaver = gtkSourceFileSaver;
68 		super(cast(GObject*)gtkSourceFileSaver, ownedRef);
69 	}
70 
71 
72 	/** */
73 	public static GType getType()
74 	{
75 		return gtk_source_file_saver_get_type();
76 	}
77 
78 	/**
79 	 * Creates a new #GtkSourceFileSaver object. The @buffer will be saved to the
80 	 * #GtkSourceFile's location.
81 	 *
82 	 * This constructor is suitable for a simple "save" operation, when the @file
83 	 * already contains a non-%NULL #GtkSourceFile:location.
84 	 *
85 	 * Params:
86 	 *     buffer = the #GtkSourceBuffer to save.
87 	 *     file = the #GtkSourceFile.
88 	 *
89 	 * Returns: a new #GtkSourceFileSaver object.
90 	 *
91 	 * Since: 3.14
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(SourceBuffer buffer, SourceFile file)
96 	{
97 		auto p = gtk_source_file_saver_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct());
98 
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GtkSourceFileSaver*) p, true);
105 	}
106 
107 	/**
108 	 * Creates a new #GtkSourceFileSaver object with a target location. When the
109 	 * file saving is finished successfully, @target_location is set to the @file's
110 	 * #GtkSourceFile:location property. If an error occurs, the previous valid
111 	 * location is still available in #GtkSourceFile.
112 	 *
113 	 * This constructor is suitable for a "save as" operation, or for saving a new
114 	 * buffer for the first time.
115 	 *
116 	 * Params:
117 	 *     buffer = the #GtkSourceBuffer to save.
118 	 *     file = the #GtkSourceFile.
119 	 *     targetLocation = the #GFile where to save the buffer to.
120 	 *
121 	 * Returns: a new #GtkSourceFileSaver object.
122 	 *
123 	 * Since: 3.14
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this(SourceBuffer buffer, SourceFile file, FileIF targetLocation)
128 	{
129 		auto p = gtk_source_file_saver_new_with_target((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct(), (targetLocation is null) ? null : targetLocation.getFileStruct());
130 
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by new_with_target");
134 		}
135 
136 		this(cast(GtkSourceFileSaver*) p, true);
137 	}
138 
139 	/**
140 	 * Returns: the #GtkSourceBuffer to save.
141 	 *
142 	 * Since: 3.14
143 	 */
144 	public SourceBuffer getBuffer()
145 	{
146 		auto p = gtk_source_file_saver_get_buffer(gtkSourceFileSaver);
147 
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 
153 		return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p);
154 	}
155 
156 	/**
157 	 * Returns: the compression type.
158 	 *
159 	 * Since: 3.14
160 	 */
161 	public GtkSourceCompressionType getCompressionType()
162 	{
163 		return gtk_source_file_saver_get_compression_type(gtkSourceFileSaver);
164 	}
165 
166 	/**
167 	 * Returns: the encoding.
168 	 *
169 	 * Since: 3.14
170 	 */
171 	public SourceEncoding getEncoding()
172 	{
173 		auto p = gtk_source_file_saver_get_encoding(gtkSourceFileSaver);
174 
175 		if(p is null)
176 		{
177 			return null;
178 		}
179 
180 		return ObjectG.getDObject!(SourceEncoding)(cast(GtkSourceEncoding*) p);
181 	}
182 
183 	/**
184 	 * Returns: the #GtkSourceFile.
185 	 *
186 	 * Since: 3.14
187 	 */
188 	public SourceFile getFile()
189 	{
190 		auto p = gtk_source_file_saver_get_file(gtkSourceFileSaver);
191 
192 		if(p is null)
193 		{
194 			return null;
195 		}
196 
197 		return ObjectG.getDObject!(SourceFile)(cast(GtkSourceFile*) p);
198 	}
199 
200 	/**
201 	 * Returns: the flags.
202 	 *
203 	 * Since: 3.14
204 	 */
205 	public GtkSourceFileSaverFlags getFlags()
206 	{
207 		return gtk_source_file_saver_get_flags(gtkSourceFileSaver);
208 	}
209 
210 	/**
211 	 * Returns: the #GFile where to save the buffer to.
212 	 *
213 	 * Since: 3.14
214 	 */
215 	public FileIF getLocation()
216 	{
217 		auto p = gtk_source_file_saver_get_location(gtkSourceFileSaver);
218 
219 		if(p is null)
220 		{
221 			return null;
222 		}
223 
224 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p);
225 	}
226 
227 	/**
228 	 * Returns: the newline type.
229 	 *
230 	 * Since: 3.14
231 	 */
232 	public GtkSourceNewlineType getNewlineType()
233 	{
234 		return gtk_source_file_saver_get_newline_type(gtkSourceFileSaver);
235 	}
236 
237 	/**
238 	 * Saves asynchronously the buffer into the file. See the #GAsyncResult
239 	 * documentation to know how to use this function.
240 	 *
241 	 * Params:
242 	 *     ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW,
243 	 *         %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
244 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
245 	 *     progressCallback = function to call back with
246 	 *         progress information, or %NULL if progress information is not needed.
247 	 *     progressCallbackData = user data to pass to @progress_callback.
248 	 *     progressCallbackNotify = function to call on
249 	 *         @progress_callback_data when the @progress_callback is no longer needed, or
250 	 *         %NULL.
251 	 *     callback = a #GAsyncReadyCallback to call when the request is
252 	 *         satisfied.
253 	 *     userData = user data to pass to @callback.
254 	 *
255 	 * Since: 3.14
256 	 */
257 	public void saveAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData)
258 	{
259 		gtk_source_file_saver_save_async(gtkSourceFileSaver, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData);
260 	}
261 
262 	/**
263 	 * Finishes a file saving started with gtk_source_file_saver_save_async().
264 	 *
265 	 * If the file has been saved successfully, the following #GtkSourceFile
266 	 * properties will be updated: the location, the encoding, the newline type and
267 	 * the compression type.
268 	 *
269 	 * Since the 3.20 version, gtk_text_buffer_set_modified() is called with %FALSE
270 	 * if the file has been saved successfully.
271 	 *
272 	 * Params:
273 	 *     result = a #GAsyncResult.
274 	 *
275 	 * Returns: whether the file was saved successfully.
276 	 *
277 	 * Since: 3.14
278 	 *
279 	 * Throws: GException on failure.
280 	 */
281 	public bool saveFinish(AsyncResultIF result)
282 	{
283 		GError* err = null;
284 
285 		auto p = gtk_source_file_saver_save_finish(gtkSourceFileSaver, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
286 
287 		if (err !is null)
288 		{
289 			throw new GException( new ErrorG(err) );
290 		}
291 
292 		return p;
293 	}
294 
295 	/**
296 	 * Sets the compression type. By default the compression type is taken from the
297 	 * #GtkSourceFile.
298 	 *
299 	 * Params:
300 	 *     compressionType = the new compression type.
301 	 *
302 	 * Since: 3.14
303 	 */
304 	public void setCompressionType(GtkSourceCompressionType compressionType)
305 	{
306 		gtk_source_file_saver_set_compression_type(gtkSourceFileSaver, compressionType);
307 	}
308 
309 	/**
310 	 * Sets the encoding. If @encoding is %NULL, the UTF-8 encoding will be set.
311 	 * By default the encoding is taken from the #GtkSourceFile.
312 	 *
313 	 * Params:
314 	 *     encoding = the new encoding, or %NULL for UTF-8.
315 	 *
316 	 * Since: 3.14
317 	 */
318 	public void setEncoding(SourceEncoding encoding)
319 	{
320 		gtk_source_file_saver_set_encoding(gtkSourceFileSaver, (encoding is null) ? null : encoding.getSourceEncodingStruct());
321 	}
322 
323 	/** */
324 	public void setFlags(GtkSourceFileSaverFlags flags)
325 	{
326 		gtk_source_file_saver_set_flags(gtkSourceFileSaver, flags);
327 	}
328 
329 	/**
330 	 * Sets the newline type. By default the newline type is taken from the
331 	 * #GtkSourceFile.
332 	 *
333 	 * Params:
334 	 *     newlineType = the new newline type.
335 	 *
336 	 * Since: 3.14
337 	 */
338 	public void setNewlineType(GtkSourceNewlineType newlineType)
339 	{
340 		gtk_source_file_saver_set_newline_type(gtkSourceFileSaver, newlineType);
341 	}
342 }