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