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 gio.FileOutputStream;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FileInfo;
30 private import gio.OutputStream;
31 private import gio.SeekableIF;
32 private import gio.SeekableT;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import glib.Str;
36 private import gobject.ObjectG;
37 private import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /**
42  * GFileOutputStream provides output streams that write their
43  * content to a file.
44  * 
45  * GFileOutputStream implements #GSeekable, which allows the output
46  * stream to jump to arbitrary positions in the file and to truncate
47  * the file, provided the filesystem of the file supports these
48  * operations.
49  * 
50  * To find the position of a file output stream, use g_seekable_tell().
51  * To find out if a file output stream supports seeking, use
52  * g_seekable_can_seek().To position a file output stream, use
53  * g_seekable_seek(). To find out if a file output stream supports
54  * truncating, use g_seekable_can_truncate(). To truncate a file output
55  * stream, use g_seekable_truncate().
56  */
57 public class FileOutputStream : OutputStream, SeekableIF
58 {
59 	/** the main Gtk struct */
60 	protected GFileOutputStream* gFileOutputStream;
61 
62 	/** Get the main Gtk struct */
63 	public GFileOutputStream* getFileOutputStreamStruct()
64 	{
65 		return gFileOutputStream;
66 	}
67 
68 	/** the main Gtk struct as a void* */
69 	protected override void* getStruct()
70 	{
71 		return cast(void*)gFileOutputStream;
72 	}
73 
74 	protected override void setStruct(GObject* obj)
75 	{
76 		gFileOutputStream = cast(GFileOutputStream*)obj;
77 		super.setStruct(obj);
78 	}
79 
80 	/**
81 	 * Sets our main struct and passes it to the parent class.
82 	 */
83 	public this (GFileOutputStream* gFileOutputStream, bool ownedRef = false)
84 	{
85 		this.gFileOutputStream = gFileOutputStream;
86 		super(cast(GOutputStream*)gFileOutputStream, ownedRef);
87 	}
88 
89 	// add the Seekable capabilities
90 	mixin SeekableT!(GFileOutputStream);
91 
92 	/**
93 	 */
94 
95 	public static GType getType()
96 	{
97 		return g_file_output_stream_get_type();
98 	}
99 
100 	/**
101 	 * Gets the entity tag for the file when it has been written.
102 	 * This must be called after the stream has been written
103 	 * and closed, as the etag can change while writing.
104 	 *
105 	 * Return: the entity tag for the stream.
106 	 */
107 	public string getEtag()
108 	{
109 		return Str.toString(g_file_output_stream_get_etag(gFileOutputStream));
110 	}
111 
112 	/**
113 	 * Queries a file output stream for the given @attributes.
114 	 * This function blocks while querying the stream. For the asynchronous
115 	 * version of this function, see g_file_output_stream_query_info_async().
116 	 * While the stream is blocked, the stream will set the pending flag
117 	 * internally, and any other operations on the stream will fail with
118 	 * %G_IO_ERROR_PENDING.
119 	 *
120 	 * Can fail if the stream was already closed (with @error being set to
121 	 * %G_IO_ERROR_CLOSED), the stream has pending operations (with @error being
122 	 * set to %G_IO_ERROR_PENDING), or if querying info is not supported for
123 	 * the stream's interface (with @error being set to %G_IO_ERROR_NOT_SUPPORTED). In
124 	 * all cases of failure, %NULL will be returned.
125 	 *
126 	 * If @cancellable is not %NULL, then the operation can be cancelled by
127 	 * triggering the cancellable object from another thread. If the operation
128 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and %NULL will
129 	 * be returned.
130 	 *
131 	 * Params:
132 	 *     attributes = a file attribute query string.
133 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
134 	 *
135 	 * Return: a #GFileInfo for the @stream, or %NULL on error.
136 	 *
137 	 * Throws: GException on failure.
138 	 */
139 	public FileInfo queryInfo(string attributes, Cancellable cancellable)
140 	{
141 		GError* err = null;
142 		
143 		auto p = g_file_output_stream_query_info(gFileOutputStream, Str.toStringz(attributes), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
144 		
145 		if (err !is null)
146 		{
147 			throw new GException( new ErrorG(err) );
148 		}
149 		
150 		if(p is null)
151 		{
152 			return null;
153 		}
154 		
155 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true);
156 	}
157 
158 	/**
159 	 * Asynchronously queries the @stream for a #GFileInfo. When completed,
160 	 * @callback will be called with a #GAsyncResult which can be used to
161 	 * finish the operation with g_file_output_stream_query_info_finish().
162 	 *
163 	 * For the synchronous version of this function, see
164 	 * g_file_output_stream_query_info().
165 	 *
166 	 * Params:
167 	 *     attributes = a file attribute query string.
168 	 *     ioPriority = the [I/O priority][gio-GIOScheduler] of the request
169 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
170 	 *     callback = callback to call when the request is satisfied
171 	 *     userData = the data to pass to callback function
172 	 */
173 	public void queryInfoAsync(string attributes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
174 	{
175 		g_file_output_stream_query_info_async(gFileOutputStream, Str.toStringz(attributes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
176 	}
177 
178 	/**
179 	 * Finalizes the asynchronous query started
180 	 * by g_file_output_stream_query_info_async().
181 	 *
182 	 * Params:
183 	 *     result = a #GAsyncResult.
184 	 *
185 	 * Return: A #GFileInfo for the finished query.
186 	 *
187 	 * Throws: GException on failure.
188 	 */
189 	public FileInfo queryInfoFinish(AsyncResultIF result)
190 	{
191 		GError* err = null;
192 		
193 		auto p = g_file_output_stream_query_info_finish(gFileOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err);
194 		
195 		if (err !is null)
196 		{
197 			throw new GException( new ErrorG(err) );
198 		}
199 		
200 		if(p is null)
201 		{
202 			return null;
203 		}
204 		
205 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true);
206 	}
207 }