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