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