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 		auto retStr = g_volume_enumerate_identifiers(getVolumeStruct());
222 		
223 		scope(exit) Str.freeStringArray(retStr);
224 		return Str.toStringArray(retStr);
225 	}
226 
227 	/**
228 	 * Gets the activation root for a #GVolume if it is known ahead of
229 	 * mount time. Returns %NULL otherwise. If not %NULL and if @volume
230 	 * is mounted, then the result of g_mount_get_root() on the
231 	 * #GMount object obtained from g_volume_get_mount() will always
232 	 * either be equal or a prefix of what this function returns. In
233 	 * other words, in code
234 	 *
235 	 * |[<!-- language="C" -->
236 	 * GMount *mount;
237 	 * GFile *mount_root
238 	 * GFile *volume_activation_root;
239 	 *
240 	 * mount = g_volume_get_mount (volume); // mounted, so never NULL
241 	 * mount_root = g_mount_get_root (mount);
242 	 * volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL
243 	 * ]|
244 	 * then the expression
245 	 * |[<!-- language="C" -->
246 	 * (g_file_has_prefix (volume_activation_root, mount_root) ||
247 	 * g_file_equal (volume_activation_root, mount_root))
248 	 * ]|
249 	 * will always be %TRUE.
250 	 *
251 	 * Activation roots are typically used in #GVolumeMonitor
252 	 * implementations to find the underlying mount to shadow, see
253 	 * g_mount_is_shadowed() for more details.
254 	 *
255 	 * Return: the activation root of @volume
256 	 *     or %NULL. Use g_object_unref() to free.
257 	 *
258 	 * Since: 2.18
259 	 */
260 	public FileIF getActivationRoot()
261 	{
262 		auto p = g_volume_get_activation_root(getVolumeStruct());
263 		
264 		if(p is null)
265 		{
266 			return null;
267 		}
268 		
269 		return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true);
270 	}
271 
272 	/**
273 	 * Gets the drive for the @volume.
274 	 *
275 	 * Return: a #GDrive or %NULL if @volume is not
276 	 *     associated with a drive. The returned object should be unreffed
277 	 *     with g_object_unref() when no longer needed.
278 	 */
279 	public DriveIF getDrive()
280 	{
281 		auto p = g_volume_get_drive(getVolumeStruct());
282 		
283 		if(p is null)
284 		{
285 			return null;
286 		}
287 		
288 		return ObjectG.getDObject!(Drive, DriveIF)(cast(GDrive*) p, true);
289 	}
290 
291 	/**
292 	 * Gets the icon for @volume.
293 	 *
294 	 * Return: a #GIcon.
295 	 *     The returned object should be unreffed with g_object_unref()
296 	 *     when no longer needed.
297 	 */
298 	public IconIF getIcon()
299 	{
300 		auto p = g_volume_get_icon(getVolumeStruct());
301 		
302 		if(p is null)
303 		{
304 			return null;
305 		}
306 		
307 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true);
308 	}
309 
310 	/**
311 	 * Gets the identifier of the given kind for @volume.
312 	 * See the [introduction][volume-identifier] for more
313 	 * information about volume identifiers.
314 	 *
315 	 * Params:
316 	 *     kind = the kind of identifier to return
317 	 *
318 	 * Return: a newly allocated string containing the
319 	 *     requested identfier, or %NULL if the #GVolume
320 	 *     doesn't have this kind of identifier
321 	 */
322 	public string getIdentifier(string kind)
323 	{
324 		auto retStr = g_volume_get_identifier(getVolumeStruct(), Str.toStringz(kind));
325 		
326 		scope(exit) Str.freeString(retStr);
327 		return Str.toString(retStr);
328 	}
329 
330 	/**
331 	 * Gets the mount for the @volume.
332 	 *
333 	 * Return: a #GMount or %NULL if @volume isn't mounted.
334 	 *     The returned object should be unreffed with g_object_unref()
335 	 *     when no longer needed.
336 	 */
337 	public MountIF getMount()
338 	{
339 		auto p = g_volume_get_mount(getVolumeStruct());
340 		
341 		if(p is null)
342 		{
343 			return null;
344 		}
345 		
346 		return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p, true);
347 	}
348 
349 	/**
350 	 * Gets the name of @volume.
351 	 *
352 	 * Return: the name for the given @volume. The returned string should
353 	 *     be freed with g_free() when no longer needed.
354 	 */
355 	public string getName()
356 	{
357 		auto retStr = g_volume_get_name(getVolumeStruct());
358 		
359 		scope(exit) Str.freeString(retStr);
360 		return Str.toString(retStr);
361 	}
362 
363 	/**
364 	 * Gets the sort key for @volume, if any.
365 	 *
366 	 * Return: Sorting key for @volume or %NULL if no such key is available
367 	 *
368 	 * Since: 2.32
369 	 */
370 	public string getSortKey()
371 	{
372 		return Str.toString(g_volume_get_sort_key(getVolumeStruct()));
373 	}
374 
375 	/**
376 	 * Gets the symbolic icon for @volume.
377 	 *
378 	 * Return: a #GIcon.
379 	 *     The returned object should be unreffed with g_object_unref()
380 	 *     when no longer needed.
381 	 *
382 	 * Since: 2.34
383 	 */
384 	public IconIF getSymbolicIcon()
385 	{
386 		auto p = g_volume_get_symbolic_icon(getVolumeStruct());
387 		
388 		if(p is null)
389 		{
390 			return null;
391 		}
392 		
393 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true);
394 	}
395 
396 	/**
397 	 * Gets the UUID for the @volume. The reference is typically based on
398 	 * the file system UUID for the volume in question and should be
399 	 * considered an opaque string. Returns %NULL if there is no UUID
400 	 * available.
401 	 *
402 	 * Return: the UUID for @volume or %NULL if no UUID can be computed.
403 	 *     The returned string should be freed with g_free()
404 	 *     when no longer needed.
405 	 */
406 	public string getUuid()
407 	{
408 		auto retStr = g_volume_get_uuid(getVolumeStruct());
409 		
410 		scope(exit) Str.freeString(retStr);
411 		return Str.toString(retStr);
412 	}
413 
414 	/**
415 	 * Mounts a volume. This is an asynchronous operation, and is
416 	 * finished by calling g_volume_mount_finish() with the @volume
417 	 * and #GAsyncResult returned in the @callback.
418 	 *
419 	 * Params:
420 	 *     flags = flags affecting the operation
421 	 *     mountOperation = a #GMountOperation or %NULL to avoid user interaction
422 	 *     cancellable = optional #GCancellable object, %NULL to ignore
423 	 *     callback = a #GAsyncReadyCallback, or %NULL
424 	 *     userData = user data that gets passed to @callback
425 	 */
426 	public void mount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
427 	{
428 		g_volume_mount(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
429 	}
430 
431 	/**
432 	 * Finishes mounting a volume. If any errors occurred during the operation,
433 	 * @error will be set to contain the errors and %FALSE will be returned.
434 	 *
435 	 * If the mount operation succeeded, g_volume_get_mount() on @volume
436 	 * is guaranteed to return the mount right after calling this
437 	 * function; there's no need to listen for the 'mount-added' signal on
438 	 * #GVolumeMonitor.
439 	 *
440 	 * Params:
441 	 *     result = a #GAsyncResult
442 	 *
443 	 * Return: %TRUE, %FALSE if operation failed
444 	 *
445 	 * Throws: GException on failure.
446 	 */
447 	public bool mountFinish(AsyncResultIF result)
448 	{
449 		GError* err = null;
450 		
451 		auto p = g_volume_mount_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
452 		
453 		if (err !is null)
454 		{
455 			throw new GException( new ErrorG(err) );
456 		}
457 		
458 		return p;
459 	}
460 
461 	/**
462 	 * Returns whether the volume should be automatically mounted.
463 	 *
464 	 * Return: %TRUE if the volume should be automatically mounted
465 	 */
466 	public bool shouldAutomount()
467 	{
468 		return g_volume_should_automount(getVolumeStruct()) != 0;
469 	}
470 
471 	int[string] connectedSignals;
472 
473 	void delegate(VolumeIF)[] _onChangedListeners;
474 	@property void delegate(VolumeIF)[] onChangedListeners()
475 	{
476 		return _onChangedListeners;
477 	}
478 	/**
479 	 * Emitted when the volume has been changed.
480 	 */
481 	void addOnChanged(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
482 	{
483 		if ( "changed" !in connectedSignals )
484 		{
485 			Signals.connectData(
486 				this,
487 				"changed",
488 				cast(GCallback)&callBackChanged,
489 				cast(void*)cast(VolumeIF)this,
490 				null,
491 				connectFlags);
492 			connectedSignals["changed"] = 1;
493 		}
494 		_onChangedListeners ~= dlg;
495 	}
496 	extern(C) static void callBackChanged(GVolume* volumeStruct, VolumeIF _volume)
497 	{
498 		foreach ( void delegate(VolumeIF) dlg; _volume.onChangedListeners )
499 		{
500 			dlg(_volume);
501 		}
502 	}
503 
504 	void delegate(VolumeIF)[] _onRemovedListeners;
505 	@property void delegate(VolumeIF)[] onRemovedListeners()
506 	{
507 		return _onRemovedListeners;
508 	}
509 	/**
510 	 * This signal is emitted when the #GVolume have been removed. If
511 	 * the recipient is holding references to the object they should
512 	 * release them so the object can be finalized.
513 	 */
514 	void addOnRemoved(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
515 	{
516 		if ( "removed" !in connectedSignals )
517 		{
518 			Signals.connectData(
519 				this,
520 				"removed",
521 				cast(GCallback)&callBackRemoved,
522 				cast(void*)cast(VolumeIF)this,
523 				null,
524 				connectFlags);
525 			connectedSignals["removed"] = 1;
526 		}
527 		_onRemovedListeners ~= dlg;
528 	}
529 	extern(C) static void callBackRemoved(GVolume* volumeStruct, VolumeIF _volume)
530 	{
531 		foreach ( void delegate(VolumeIF) dlg; _volume.onRemovedListeners )
532 		{
533 			dlg(_volume);
534 		}
535 	}
536 }