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.Vfs;
26 
27 private import gio.FileIF;
28 private import gio.c.functions;
29 public  import gio.c.types;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 public  import gtkc.giotypes;
33 
34 
35 /**
36  * Entry point for using GIO functionality.
37  */
38 public class Vfs : ObjectG
39 {
40 	/** the main Gtk struct */
41 	protected GVfs* gVfs;
42 
43 	/** Get the main Gtk struct */
44 	public GVfs* getVfsStruct(bool transferOwnership = false)
45 	{
46 		if (transferOwnership)
47 			ownedRef = false;
48 		return gVfs;
49 	}
50 
51 	/** the main Gtk struct as a void* */
52 	protected override void* getStruct()
53 	{
54 		return cast(void*)gVfs;
55 	}
56 
57 	protected override void setStruct(GObject* obj)
58 	{
59 		gVfs = cast(GVfs*)obj;
60 		super.setStruct(obj);
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (GVfs* gVfs, bool ownedRef = false)
67 	{
68 		this.gVfs = gVfs;
69 		super(cast(GObject*)gVfs, ownedRef);
70 	}
71 
72 
73 	/** */
74 	public static GType getType()
75 	{
76 		return g_vfs_get_type();
77 	}
78 
79 	/**
80 	 * Gets the default #GVfs for the system.
81 	 *
82 	 * Returns: a #GVfs.
83 	 */
84 	public static Vfs getDefault()
85 	{
86 		auto p = g_vfs_get_default();
87 
88 		if(p is null)
89 		{
90 			return null;
91 		}
92 
93 		return ObjectG.getDObject!(Vfs)(cast(GVfs*) p);
94 	}
95 
96 	/**
97 	 * Gets the local #GVfs for the system.
98 	 *
99 	 * Returns: a #GVfs.
100 	 */
101 	public static Vfs getLocal()
102 	{
103 		auto p = g_vfs_get_local();
104 
105 		if(p is null)
106 		{
107 			return null;
108 		}
109 
110 		return ObjectG.getDObject!(Vfs)(cast(GVfs*) p);
111 	}
112 
113 	/**
114 	 * Gets a #GFile for @path.
115 	 *
116 	 * Params:
117 	 *     path = a string containing a VFS path.
118 	 *
119 	 * Returns: a #GFile.
120 	 *     Free the returned object with g_object_unref().
121 	 */
122 	public FileIF getFileForPath(string path)
123 	{
124 		auto p = g_vfs_get_file_for_path(gVfs, Str.toStringz(path));
125 
126 		if(p is null)
127 		{
128 			return null;
129 		}
130 
131 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true);
132 	}
133 
134 	/**
135 	 * Gets a #GFile for @uri.
136 	 *
137 	 * This operation never fails, but the returned object
138 	 * might not support any I/O operation if the URI
139 	 * is malformed or if the URI scheme is not supported.
140 	 *
141 	 * Params:
142 	 *     uri = a string containing a URI
143 	 *
144 	 * Returns: a #GFile.
145 	 *     Free the returned object with g_object_unref().
146 	 */
147 	public FileIF getFileForUri(string uri)
148 	{
149 		auto p = g_vfs_get_file_for_uri(gVfs, Str.toStringz(uri));
150 
151 		if(p is null)
152 		{
153 			return null;
154 		}
155 
156 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true);
157 	}
158 
159 	/**
160 	 * Gets a list of URI schemes supported by @vfs.
161 	 *
162 	 * Returns: a %NULL-terminated array of strings.
163 	 *     The returned array belongs to GIO and must
164 	 *     not be freed or modified.
165 	 */
166 	public string[] getSupportedUriSchemes()
167 	{
168 		return Str.toStringArray(g_vfs_get_supported_uri_schemes(gVfs));
169 	}
170 
171 	/**
172 	 * Checks if the VFS is active.
173 	 *
174 	 * Returns: %TRUE if construction of the @vfs was successful
175 	 *     and it is now active.
176 	 */
177 	public bool isActive()
178 	{
179 		return g_vfs_is_active(gVfs) != 0;
180 	}
181 
182 	/**
183 	 * This operation never fails, but the returned object might
184 	 * not support any I/O operations if the @parse_name cannot
185 	 * be parsed by the #GVfs module.
186 	 *
187 	 * Params:
188 	 *     parseName = a string to be parsed by the VFS module.
189 	 *
190 	 * Returns: a #GFile for the given @parse_name.
191 	 *     Free the returned object with g_object_unref().
192 	 */
193 	public FileIF parseName(string parseName)
194 	{
195 		auto p = g_vfs_parse_name(gVfs, Str.toStringz(parseName));
196 
197 		if(p is null)
198 		{
199 			return null;
200 		}
201 
202 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true);
203 	}
204 
205 	/**
206 	 * Registers @uri_func and @parse_name_func as the #GFile URI and parse name
207 	 * lookup functions for URIs with a scheme matching @scheme.
208 	 * Note that @scheme is registered only within the running application, as
209 	 * opposed to desktop-wide as it happens with GVfs backends.
210 	 *
211 	 * When a #GFile is requested with an URI containing @scheme (e.g. through
212 	 * g_file_new_for_uri()), @uri_func will be called to allow a custom
213 	 * constructor. The implementation of @uri_func should not be blocking, and
214 	 * must not call g_vfs_register_uri_scheme() or g_vfs_unregister_uri_scheme().
215 	 *
216 	 * When g_file_parse_name() is called with a parse name obtained from such file,
217 	 * @parse_name_func will be called to allow the #GFile to be created again. In
218 	 * that case, it's responsibility of @parse_name_func to make sure the parse
219 	 * name matches what the custom #GFile implementation returned when
220 	 * g_file_get_parse_name() was previously called. The implementation of
221 	 * @parse_name_func should not be blocking, and must not call
222 	 * g_vfs_register_uri_scheme() or g_vfs_unregister_uri_scheme().
223 	 *
224 	 * It's an error to call this function twice with the same scheme. To unregister
225 	 * a custom URI scheme, use g_vfs_unregister_uri_scheme().
226 	 *
227 	 * Params:
228 	 *     scheme = an URI scheme, e.g. "http"
229 	 *     uriFunc = a #GVfsFileLookupFunc
230 	 *     uriData = custom data passed to be passed to @uri_func, or %NULL
231 	 *     uriDestroy = function to be called when unregistering the
232 	 *         URI scheme, or when @vfs is disposed, to free the resources used
233 	 *         by the URI lookup function
234 	 *     parseNameFunc = a #GVfsFileLookupFunc
235 	 *     parseNameData = custom data passed to be passed to
236 	 *         @parse_name_func, or %NULL
237 	 *     parseNameDestroy = function to be called when unregistering the
238 	 *         URI scheme, or when @vfs is disposed, to free the resources used
239 	 *         by the parse name lookup function
240 	 *
241 	 * Returns: %TRUE if @scheme was successfully registered, or %FALSE if a handler
242 	 *     for @scheme already exists.
243 	 *
244 	 * Since: 2.50
245 	 */
246 	public bool registerUriScheme(string scheme, GVfsFileLookupFunc uriFunc, void* uriData, GDestroyNotify uriDestroy, GVfsFileLookupFunc parseNameFunc, void* parseNameData, GDestroyNotify parseNameDestroy)
247 	{
248 		return g_vfs_register_uri_scheme(gVfs, Str.toStringz(scheme), uriFunc, uriData, uriDestroy, parseNameFunc, parseNameData, parseNameDestroy) != 0;
249 	}
250 
251 	/**
252 	 * Unregisters the URI handler for @scheme previously registered with
253 	 * g_vfs_register_uri_scheme().
254 	 *
255 	 * Params:
256 	 *     scheme = an URI scheme, e.g. "http"
257 	 *
258 	 * Returns: %TRUE if @scheme was successfully unregistered, or %FALSE if a
259 	 *     handler for @scheme does not exist.
260 	 *
261 	 * Since: 2.50
262 	 */
263 	public bool unregisterUriScheme(string scheme)
264 	{
265 		return g_vfs_unregister_uri_scheme(gVfs, Str.toStringz(scheme)) != 0;
266 	}
267 }