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