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.VolumeT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.DriveIF;
30 public  import gio.FileIF;
31 public  import gio.IconIF;
32 public  import gio.MountIF;
33 public  import gio.MountOperation;
34 public  import gio.c.functions;
35 public  import gio.c.types;
36 public  import glib.ErrorG;
37 public  import glib.GException;
38 public  import glib.Str;
39 public  import gobject.ObjectG;
40 public  import gobject.Signals;
41 public  import gtkc.giotypes;
42 public  import std.algorithm;
43 
44 
45 /**
46  * The #GVolume interface represents user-visible objects that can be
47  * mounted. Note, when porting from GnomeVFS, #GVolume is the moral
48  * equivalent of #GnomeVFSDrive.
49  * 
50  * Mounting a #GVolume instance is an asynchronous operation. For more
51  * information about asynchronous operations, see #GAsyncResult and
52  * #GTask. To mount a #GVolume, first call g_volume_mount() with (at
53  * least) the #GVolume instance, optionally a #GMountOperation object
54  * and a #GAsyncReadyCallback.
55  * 
56  * Typically, one will only want to pass %NULL for the
57  * #GMountOperation if automounting all volumes when a desktop session
58  * starts since it's not desirable to put up a lot of dialogs asking
59  * for credentials.
60  * 
61  * The callback will be fired when the operation has resolved (either
62  * with success or failure), and a #GAsyncReady structure will be
63  * passed to the callback.  That callback should then call
64  * g_volume_mount_finish() with the #GVolume instance and the
65  * #GAsyncReady data to see if the operation was completed
66  * successfully.  If an @error is present when g_volume_mount_finish()
67  * is called, then it will be filled with any error information.
68  * 
69  * ## Volume Identifiers # {#volume-identifier}
70  * 
71  * It is sometimes necessary to directly access the underlying
72  * operating system object behind a volume (e.g. for passing a volume
73  * to an application via the commandline). For this purpose, GIO
74  * allows to obtain an 'identifier' for the volume. There can be
75  * different kinds of identifiers, such as Hal UDIs, filesystem labels,
76  * traditional Unix devices (e.g. `/dev/sda2`), UUIDs. GIO uses predefined
77  * strings as names for the different kinds of identifiers:
78  * #G_VOLUME_IDENTIFIER_KIND_HAL_UDI, #G_VOLUME_IDENTIFIER_KIND_LABEL, etc.
79  * Use g_volume_get_identifier() to obtain an identifier for a volume.
80  * 
81  * 
82  * Note that #G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available
83  * when the gvfs hal volume monitor is in use. Other volume monitors
84  * will generally be able to provide the #G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE
85  * identifier, which can be used to obtain a hal device by means of
86  * libhal_manager_find_device_string_match().
87  */
88 public template VolumeT(TStruct)
89 {
90 	/** Get the main Gtk struct */
91 	public GVolume* getVolumeStruct(bool transferOwnership = false)
92 	{
93 		if (transferOwnership)
94 			ownedRef = false;
95 		return cast(GVolume*)getStruct();
96 	}
97 
98 
99 	/**
100 	 * Checks if a volume can be ejected.
101 	 *
102 	 * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise
103 	 */
104 	public bool canEject()
105 	{
106 		return g_volume_can_eject(getVolumeStruct()) != 0;
107 	}
108 
109 	/**
110 	 * Checks if a volume can be mounted.
111 	 *
112 	 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise
113 	 */
114 	public bool canMount()
115 	{
116 		return g_volume_can_mount(getVolumeStruct()) != 0;
117 	}
118 
119 	/**
120 	 * Ejects a volume. This is an asynchronous operation, and is
121 	 * finished by calling g_volume_eject_finish() with the @volume
122 	 * and #GAsyncResult returned in the @callback.
123 	 *
124 	 * Deprecated: Use g_volume_eject_with_operation() instead.
125 	 *
126 	 * Params:
127 	 *     flags = flags affecting the unmount if required for eject
128 	 *     cancellable = optional #GCancellable object, %NULL to ignore
129 	 *     callback = a #GAsyncReadyCallback, or %NULL
130 	 *     userData = user data that gets passed to @callback
131 	 */
132 	public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
133 	{
134 		g_volume_eject(getVolumeStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
135 	}
136 
137 	/**
138 	 * Finishes ejecting a volume. If any errors occurred during the operation,
139 	 * @error will be set to contain the errors and %FALSE will be returned.
140 	 *
141 	 * Deprecated: Use g_volume_eject_with_operation_finish() instead.
142 	 *
143 	 * Params:
144 	 *     result = a #GAsyncResult
145 	 *
146 	 * Returns: %TRUE, %FALSE if operation failed
147 	 *
148 	 * Throws: GException on failure.
149 	 */
150 	public bool ejectFinish(AsyncResultIF result)
151 	{
152 		GError* err = null;
153 
154 		auto p = g_volume_eject_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
155 
156 		if (err !is null)
157 		{
158 			throw new GException( new ErrorG(err) );
159 		}
160 
161 		return p;
162 	}
163 
164 	/**
165 	 * Ejects a volume. This is an asynchronous operation, and is
166 	 * finished by calling g_volume_eject_with_operation_finish() with the @volume
167 	 * and #GAsyncResult data returned in the @callback.
168 	 *
169 	 * Params:
170 	 *     flags = flags affecting the unmount if required for eject
171 	 *     mountOperation = a #GMountOperation or %NULL to
172 	 *         avoid user interaction
173 	 *     cancellable = optional #GCancellable object, %NULL to ignore
174 	 *     callback = a #GAsyncReadyCallback, or %NULL
175 	 *     userData = user data passed to @callback
176 	 *
177 	 * Since: 2.22
178 	 */
179 	public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
180 	{
181 		g_volume_eject_with_operation(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
182 	}
183 
184 	/**
185 	 * Finishes ejecting a volume. If any errors occurred during the operation,
186 	 * @error will be set to contain the errors and %FALSE will be returned.
187 	 *
188 	 * Params:
189 	 *     result = a #GAsyncResult
190 	 *
191 	 * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise
192 	 *
193 	 * Since: 2.22
194 	 *
195 	 * Throws: GException on failure.
196 	 */
197 	public bool ejectWithOperationFinish(AsyncResultIF result)
198 	{
199 		GError* err = null;
200 
201 		auto p = g_volume_eject_with_operation_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
202 
203 		if (err !is null)
204 		{
205 			throw new GException( new ErrorG(err) );
206 		}
207 
208 		return p;
209 	}
210 
211 	/**
212 	 * Gets the kinds of [identifiers][volume-identifier] that @volume has.
213 	 * Use g_volume_get_identifier() to obtain the identifiers themselves.
214 	 *
215 	 * Returns: a %NULL-terminated array
216 	 *     of strings containing kinds of identifiers. Use g_strfreev() to free.
217 	 */
218 	public string[] enumerateIdentifiers()
219 	{
220 		auto retStr = g_volume_enumerate_identifiers(getVolumeStruct());
221 
222 		scope(exit) Str.freeStringArray(retStr);
223 		return Str.toStringArray(retStr);
224 	}
225 
226 	/**
227 	 * Gets the activation root for a #GVolume if it is known ahead of
228 	 * mount time. Returns %NULL otherwise. If not %NULL and if @volume
229 	 * is mounted, then the result of g_mount_get_root() on the
230 	 * #GMount object obtained from g_volume_get_mount() will always
231 	 * either be equal or a prefix of what this function returns. In
232 	 * other words, in code
233 	 *
234 	 * |[<!-- language="C" -->
235 	 * GMount *mount;
236 	 * GFile *mount_root
237 	 * GFile *volume_activation_root;
238 	 *
239 	 * mount = g_volume_get_mount (volume); // mounted, so never NULL
240 	 * mount_root = g_mount_get_root (mount);
241 	 * volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL
242 	 * ]|
243 	 * then the expression
244 	 * |[<!-- language="C" -->
245 	 * (g_file_has_prefix (volume_activation_root, mount_root) ||
246 	 * g_file_equal (volume_activation_root, mount_root))
247 	 * ]|
248 	 * will always be %TRUE.
249 	 *
250 	 * Activation roots are typically used in #GVolumeMonitor
251 	 * implementations to find the underlying mount to shadow, see
252 	 * g_mount_is_shadowed() for more details.
253 	 *
254 	 * Returns: the activation root of @volume
255 	 *     or %NULL. Use g_object_unref() to free.
256 	 *
257 	 * Since: 2.18
258 	 */
259 	public FileIF getActivationRoot()
260 	{
261 		auto p = g_volume_get_activation_root(getVolumeStruct());
262 
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true);
269 	}
270 
271 	/**
272 	 * Gets the drive for the @volume.
273 	 *
274 	 * Returns: a #GDrive or %NULL if @volume is not
275 	 *     associated with a drive. The returned object should be unreffed
276 	 *     with g_object_unref() when no longer needed.
277 	 */
278 	public DriveIF getDrive()
279 	{
280 		auto p = g_volume_get_drive(getVolumeStruct());
281 
282 		if(p is null)
283 		{
284 			return null;
285 		}
286 
287 		return ObjectG.getDObject!(DriveIF)(cast(GDrive*) p, true);
288 	}
289 
290 	/**
291 	 * Gets the icon for @volume.
292 	 *
293 	 * Returns: a #GIcon.
294 	 *     The returned object should be unreffed with g_object_unref()
295 	 *     when no longer needed.
296 	 */
297 	public IconIF getIcon()
298 	{
299 		auto p = g_volume_get_icon(getVolumeStruct());
300 
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 
306 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) p, true);
307 	}
308 
309 	/**
310 	 * Gets the identifier of the given kind for @volume.
311 	 * See the [introduction][volume-identifier] for more
312 	 * information about volume identifiers.
313 	 *
314 	 * Params:
315 	 *     kind = the kind of identifier to return
316 	 *
317 	 * Returns: a newly allocated string containing the
318 	 *     requested identfier, or %NULL if the #GVolume
319 	 *     doesn't have this kind of identifier
320 	 */
321 	public string getIdentifier(string kind)
322 	{
323 		auto retStr = g_volume_get_identifier(getVolumeStruct(), Str.toStringz(kind));
324 
325 		scope(exit) Str.freeString(retStr);
326 		return Str.toString(retStr);
327 	}
328 
329 	/**
330 	 * Gets the mount for the @volume.
331 	 *
332 	 * Returns: a #GMount or %NULL if @volume isn't mounted.
333 	 *     The returned object should be unreffed with g_object_unref()
334 	 *     when no longer needed.
335 	 */
336 	public MountIF getMount()
337 	{
338 		auto p = g_volume_get_mount(getVolumeStruct());
339 
340 		if(p is null)
341 		{
342 			return null;
343 		}
344 
345 		return ObjectG.getDObject!(MountIF)(cast(GMount*) p, true);
346 	}
347 
348 	/**
349 	 * Gets the name of @volume.
350 	 *
351 	 * Returns: the name for the given @volume. The returned string should
352 	 *     be freed with g_free() when no longer needed.
353 	 */
354 	public string getName()
355 	{
356 		auto retStr = g_volume_get_name(getVolumeStruct());
357 
358 		scope(exit) Str.freeString(retStr);
359 		return Str.toString(retStr);
360 	}
361 
362 	/**
363 	 * Gets the sort key for @volume, if any.
364 	 *
365 	 * Returns: Sorting key for @volume or %NULL if no such key is available
366 	 *
367 	 * Since: 2.32
368 	 */
369 	public string getSortKey()
370 	{
371 		return Str.toString(g_volume_get_sort_key(getVolumeStruct()));
372 	}
373 
374 	/**
375 	 * Gets the symbolic icon for @volume.
376 	 *
377 	 * Returns: a #GIcon.
378 	 *     The returned object should be unreffed with g_object_unref()
379 	 *     when no longer needed.
380 	 *
381 	 * Since: 2.34
382 	 */
383 	public IconIF getSymbolicIcon()
384 	{
385 		auto p = g_volume_get_symbolic_icon(getVolumeStruct());
386 
387 		if(p is null)
388 		{
389 			return null;
390 		}
391 
392 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) p, true);
393 	}
394 
395 	/**
396 	 * Gets the UUID for the @volume. The reference is typically based on
397 	 * the file system UUID for the volume in question and should be
398 	 * considered an opaque string. Returns %NULL if there is no UUID
399 	 * available.
400 	 *
401 	 * Returns: the UUID for @volume or %NULL if no UUID can be computed.
402 	 *     The returned string should be freed with g_free()
403 	 *     when no longer needed.
404 	 */
405 	public string getUuid()
406 	{
407 		auto retStr = g_volume_get_uuid(getVolumeStruct());
408 
409 		scope(exit) Str.freeString(retStr);
410 		return Str.toString(retStr);
411 	}
412 
413 	/**
414 	 * Mounts a volume. This is an asynchronous operation, and is
415 	 * finished by calling g_volume_mount_finish() with the @volume
416 	 * and #GAsyncResult returned in the @callback.
417 	 *
418 	 * Params:
419 	 *     flags = flags affecting the operation
420 	 *     mountOperation = a #GMountOperation or %NULL to avoid user interaction
421 	 *     cancellable = optional #GCancellable object, %NULL to ignore
422 	 *     callback = a #GAsyncReadyCallback, or %NULL
423 	 *     userData = user data that gets passed to @callback
424 	 */
425 	public void mount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
426 	{
427 		g_volume_mount(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
428 	}
429 
430 	/**
431 	 * Finishes mounting a volume. If any errors occurred during the operation,
432 	 * @error will be set to contain the errors and %FALSE will be returned.
433 	 *
434 	 * If the mount operation succeeded, g_volume_get_mount() on @volume
435 	 * is guaranteed to return the mount right after calling this
436 	 * function; there's no need to listen for the 'mount-added' signal on
437 	 * #GVolumeMonitor.
438 	 *
439 	 * Params:
440 	 *     result = a #GAsyncResult
441 	 *
442 	 * Returns: %TRUE, %FALSE if operation failed
443 	 *
444 	 * Throws: GException on failure.
445 	 */
446 	public bool mountFinish(AsyncResultIF result)
447 	{
448 		GError* err = null;
449 
450 		auto p = g_volume_mount_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
451 
452 		if (err !is null)
453 		{
454 			throw new GException( new ErrorG(err) );
455 		}
456 
457 		return p;
458 	}
459 
460 	/**
461 	 * Returns whether the volume should be automatically mounted.
462 	 *
463 	 * Returns: %TRUE if the volume should be automatically mounted
464 	 */
465 	public bool shouldAutomount()
466 	{
467 		return g_volume_should_automount(getVolumeStruct()) != 0;
468 	}
469 
470 	/**
471 	 * Emitted when the volume has been changed.
472 	 */
473 	gulong addOnChanged(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
474 	{
475 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
476 	}
477 
478 	/**
479 	 * This signal is emitted when the #GVolume have been removed. If
480 	 * the recipient is holding references to the object they should
481 	 * release them so the object can be finalized.
482 	 */
483 	gulong addOnRemoved(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
484 	{
485 		return Signals.connect(this, "removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
486 	}
487 }