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