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