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.FileInputStream;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FileInfo;
30 private import gio.InputStream;
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  * GFileInputStream provides input streams that take their
44  * content from a file.
45  * 
46  * GFileInputStream implements #GSeekable, which allows the input
47  * stream to jump to arbitrary positions in the file, provided the
48  * filesystem of the file allows it. To find the position of a file
49  * input stream, use g_seekable_tell(). To find out if a file input
50  * stream supports seeking, use g_seekable_can_seek().
51  * To position a file input stream, use g_seekable_seek().
52  */
53 public class FileInputStream : InputStream, SeekableIF
54 {
55 	/** the main Gtk struct */
56 	protected GFileInputStream* gFileInputStream;
57 
58 	/** Get the main Gtk struct */
59 	public GFileInputStream* getFileInputStreamStruct(bool transferOwnership = false)
60 	{
61 		if (transferOwnership)
62 			ownedRef = false;
63 		return gFileInputStream;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)gFileInputStream;
70 	}
71 
72 	protected override void setStruct(GObject* obj)
73 	{
74 		gFileInputStream = cast(GFileInputStream*)obj;
75 		super.setStruct(obj);
76 	}
77 
78 	/**
79 	 * Sets our main struct and passes it to the parent class.
80 	 */
81 	public this (GFileInputStream* gFileInputStream, bool ownedRef = false)
82 	{
83 		this.gFileInputStream = gFileInputStream;
84 		super(cast(GInputStream*)gFileInputStream, ownedRef);
85 	}
86 
87 	// add the Seekable capabilities
88 	mixin SeekableT!(GFileInputStream);
89 
90 
91 	/** */
92 	public static GType getType()
93 	{
94 		return g_file_input_stream_get_type();
95 	}
96 
97 	/**
98 	 * Queries a file input stream the given @attributes. This function blocks
99 	 * while querying the stream. For the asynchronous (non-blocking) version
100 	 * of this function, see g_file_input_stream_query_info_async(). While the
101 	 * stream is blocked, the stream will set the pending flag internally, and
102 	 * any other operations on the stream will fail with %G_IO_ERROR_PENDING.
103 	 *
104 	 * Params:
105 	 *     attributes = a file attribute query string.
106 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
107 	 *
108 	 * Returns: a #GFileInfo, or %NULL on error.
109 	 *
110 	 * Throws: GException on failure.
111 	 */
112 	public FileInfo queryInfo(string attributes, Cancellable cancellable)
113 	{
114 		GError* err = null;
115 
116 		auto p = g_file_input_stream_query_info(gFileInputStream, Str.toStringz(attributes), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
117 
118 		if (err !is null)
119 		{
120 			throw new GException( new ErrorG(err) );
121 		}
122 
123 		if(p is null)
124 		{
125 			return null;
126 		}
127 
128 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true);
129 	}
130 
131 	/**
132 	 * Queries the stream information asynchronously.
133 	 * When the operation is finished @callback will be called.
134 	 * You can then call g_file_input_stream_query_info_finish()
135 	 * to get the result of the operation.
136 	 *
137 	 * For the synchronous version of this function,
138 	 * see g_file_input_stream_query_info().
139 	 *
140 	 * If @cancellable is not %NULL, then the operation can be cancelled by
141 	 * triggering the cancellable object from another thread. If the operation
142 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set
143 	 *
144 	 * Params:
145 	 *     attributes = a file attribute query string.
146 	 *     ioPriority = the [I/O priority][io-priority] of the request
147 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
148 	 *     callback = callback to call when the request is satisfied
149 	 *     userData = the data to pass to callback function
150 	 */
151 	public void queryInfoAsync(string attributes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
152 	{
153 		g_file_input_stream_query_info_async(gFileInputStream, Str.toStringz(attributes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
154 	}
155 
156 	/**
157 	 * Finishes an asynchronous info query operation.
158 	 *
159 	 * Params:
160 	 *     result = a #GAsyncResult.
161 	 *
162 	 * Returns: #GFileInfo.
163 	 *
164 	 * Throws: GException on failure.
165 	 */
166 	public FileInfo queryInfoFinish(AsyncResultIF result)
167 	{
168 		GError* err = null;
169 
170 		auto p = g_file_input_stream_query_info_finish(gFileInputStream, (result is null) ? null : result.getAsyncResultStruct(), &err);
171 
172 		if (err !is null)
173 		{
174 			throw new GException( new ErrorG(err) );
175 		}
176 
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 
182 		return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true);
183 	}
184 }