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 
102 	/**
103 	 * Checks if a volume can be ejected.
104 	 *
105 	 * Return: %TRUE if the @volume can be ejected. %FALSE otherwise
106 	 */
107 	public bool canEject()
108 	{
109 		return g_volume_can_eject(getVolumeStruct()) != 0;
110 	}
111 
112 	/**
113 	 * Checks if a volume can be mounted.
114 	 *
115 	 * Return: %TRUE if the @volume can be mounted. %FALSE otherwise
116 	 */
117 	public bool canMount()
118 	{
119 		return g_volume_can_mount(getVolumeStruct()) != 0;
120 	}
121 
122 	/**
123 	 * Ejects a volume. This is an asynchronous operation, and is
124 	 * finished by calling g_volume_eject_finish() with the @volume
125 	 * and #GAsyncResult returned in the @callback.
126 	 *
127 	 * Deprecated: Use g_volume_eject_with_operation() instead.
128 	 *
129 	 * Params:
130 	 *     flags = flags affecting the unmount if required for eject
131 	 *     cancellable = optional #GCancellable object, %NULL to ignore
132 	 *     callback = a #GAsyncReadyCallback, or %NULL
133 	 *     userData = user data that gets passed to @callback
134 	 */
135 	public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
136 	{
137 		g_volume_eject(getVolumeStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
138 	}
139 
140 	/**
141 	 * Finishes ejecting a volume. If any errors occurred during the operation,
142 	 * @error will be set to contain the errors and %FALSE will be returned.
143 	 *
144 	 * Deprecated: Use g_volume_eject_with_operation_finish() instead.
145 	 *
146 	 * Params:
147 	 *     result = a #GAsyncResult
148 	 *
149 	 * Return: %TRUE, %FALSE if operation failed
150 	 *
151 	 * Throws: GException on failure.
152 	 */
153 	public bool ejectFinish(AsyncResultIF result)
154 	{
155 		GError* err = null;
156 		
157 		auto p = g_volume_eject_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
158 		
159 		if (err !is null)
160 		{
161 			throw new GException( new ErrorG(err) );
162 		}
163 		
164 		return p;
165 	}
166 
167 	/**
168 	 * Ejects a volume. This is an asynchronous operation, and is
169 	 * finished by calling g_volume_eject_with_operation_finish() with the @volume
170 	 * and #GAsyncResult data returned in the @callback.
171 	 *
172 	 * Params:
173 	 *     flags = flags affecting the unmount if required for eject
174 	 *     mountOperation = a #GMountOperation or %NULL to
175 	 *         avoid user interaction
176 	 *     cancellable = optional #GCancellable object, %NULL to ignore
177 	 *     callback = a #GAsyncReadyCallback, or %NULL
178 	 *     userData = user data passed to @callback
179 	 *
180 	 * Since: 2.22
181 	 */
182 	public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
183 	{
184 		g_volume_eject_with_operation(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
185 	}
186 
187 	/**
188 	 * Finishes ejecting a volume. If any errors occurred during the operation,
189 	 * @error will be set to contain the errors and %FALSE will be returned.
190 	 *
191 	 * Params:
192 	 *     result = a #GAsyncResult
193 	 *
194 	 * Return: %TRUE if the volume was successfully ejected. %FALSE otherwise
195 	 *
196 	 * Since: 2.22
197 	 *
198 	 * Throws: GException on failure.
199 	 */
200 	public bool ejectWithOperationFinish(AsyncResultIF result)
201 	{
202 		GError* err = null;
203 		
204 		auto p = g_volume_eject_with_operation_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
205 		
206 		if (err !is null)
207 		{
208 			throw new GException( new ErrorG(err) );
209 		}
210 		
211 		return p;
212 	}
213 
214 	/**
215 	 * Gets the kinds of [identifiers][volume-identifier] that @volume has.
216 	 * Use g_volume_get_identifier() to obtain the identifiers themselves.
217 	 *
218 	 * Return: a %NULL-terminated array
219 	 *     of strings containing kinds of identifiers. Use g_strfreev() to free.
220 	 */
221 	public string[] enumerateIdentifiers()
222 	{
223 		return Str.toStringArray(g_volume_enumerate_identifiers(getVolumeStruct()));
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 	 * Return: 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!(File, FileIF)(cast(GFile*) p);
269 	}
270 
271 	/**
272 	 * Gets the drive for the @volume.
273 	 *
274 	 * Return: 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!(Drive, DriveIF)(cast(GDrive*) p);
288 	}
289 
290 	/**
291 	 * Gets the icon for @volume.
292 	 *
293 	 * Return: 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!(Icon, IconIF)(cast(GIcon*) p);
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 	 * Return: 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 		return Str.toString(g_volume_get_identifier(getVolumeStruct(), Str.toStringz(kind)));
324 	}
325 
326 	/**
327 	 * Gets the mount for the @volume.
328 	 *
329 	 * Return: a #GMount or %NULL if @volume isn't mounted.
330 	 *     The returned object should be unreffed with g_object_unref()
331 	 *     when no longer needed.
332 	 */
333 	public MountIF getMount()
334 	{
335 		auto p = g_volume_get_mount(getVolumeStruct());
336 		
337 		if(p is null)
338 		{
339 			return null;
340 		}
341 		
342 		return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p);
343 	}
344 
345 	/**
346 	 * Gets the name of @volume.
347 	 *
348 	 * Return: the name for the given @volume. The returned string should
349 	 *     be freed with g_free() when no longer needed.
350 	 */
351 	public string getName()
352 	{
353 		return Str.toString(g_volume_get_name(getVolumeStruct()));
354 	}
355 
356 	/**
357 	 * Gets the sort key for @volume, if any.
358 	 *
359 	 * Return: Sorting key for @volume or %NULL if no such key is available
360 	 *
361 	 * Since: 2.32
362 	 */
363 	public string getSortKey()
364 	{
365 		return Str.toString(g_volume_get_sort_key(getVolumeStruct()));
366 	}
367 
368 	/**
369 	 * Gets the symbolic icon for @volume.
370 	 *
371 	 * Return: a #GIcon.
372 	 *     The returned object should be unreffed with g_object_unref()
373 	 *     when no longer needed.
374 	 *
375 	 * Since: 2.34
376 	 */
377 	public IconIF getSymbolicIcon()
378 	{
379 		auto p = g_volume_get_symbolic_icon(getVolumeStruct());
380 		
381 		if(p is null)
382 		{
383 			return null;
384 		}
385 		
386 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
387 	}
388 
389 	/**
390 	 * Gets the UUID for the @volume. The reference is typically based on
391 	 * the file system UUID for the volume in question and should be
392 	 * considered an opaque string. Returns %NULL if there is no UUID
393 	 * available.
394 	 *
395 	 * Return: the UUID for @volume or %NULL if no UUID can be computed.
396 	 *     The returned string should be freed with g_free()
397 	 *     when no longer needed.
398 	 */
399 	public string getUuid()
400 	{
401 		return Str.toString(g_volume_get_uuid(getVolumeStruct()));
402 	}
403 
404 	/**
405 	 * Mounts a volume. This is an asynchronous operation, and is
406 	 * finished by calling g_volume_mount_finish() with the @volume
407 	 * and #GAsyncResult returned in the @callback.
408 	 *
409 	 * Params:
410 	 *     flags = flags affecting the operation
411 	 *     mountOperation = a #GMountOperation or %NULL to avoid user interaction
412 	 *     cancellable = optional #GCancellable object, %NULL to ignore
413 	 *     callback = a #GAsyncReadyCallback, or %NULL
414 	 *     userData = user data that gets passed to @callback
415 	 */
416 	public void mount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
417 	{
418 		g_volume_mount(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
419 	}
420 
421 	/**
422 	 * Finishes mounting a volume. If any errors occurred during the operation,
423 	 * @error will be set to contain the errors and %FALSE will be returned.
424 	 *
425 	 * If the mount operation succeeded, g_volume_get_mount() on @volume
426 	 * is guaranteed to return the mount right after calling this
427 	 * function; there's no need to listen for the 'mount-added' signal on
428 	 * #GVolumeMonitor.
429 	 *
430 	 * Params:
431 	 *     result = a #GAsyncResult
432 	 *
433 	 * Return: %TRUE, %FALSE if operation failed
434 	 *
435 	 * Throws: GException on failure.
436 	 */
437 	public bool mountFinish(AsyncResultIF result)
438 	{
439 		GError* err = null;
440 		
441 		auto p = g_volume_mount_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
442 		
443 		if (err !is null)
444 		{
445 			throw new GException( new ErrorG(err) );
446 		}
447 		
448 		return p;
449 	}
450 
451 	/**
452 	 * Returns whether the volume should be automatically mounted.
453 	 *
454 	 * Return: %TRUE if the volume should be automatically mounted
455 	 */
456 	public bool shouldAutomount()
457 	{
458 		return g_volume_should_automount(getVolumeStruct()) != 0;
459 	}
460 
461 	int[string] connectedSignals;
462 
463 	void delegate(VolumeIF)[] _onChangedListeners;
464 	@property void delegate(VolumeIF)[] onChangedListeners()
465 	{
466 		return _onChangedListeners;
467 	}
468 	/**
469 	 * Emitted when the volume has been changed.
470 	 */
471 	void addOnChanged(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
472 	{
473 		if ( "changed" !in connectedSignals )
474 		{
475 			Signals.connectData(
476 				this,
477 				"changed",
478 				cast(GCallback)&callBackChanged,
479 				cast(void*)cast(VolumeIF)this,
480 				null,
481 				connectFlags);
482 			connectedSignals["changed"] = 1;
483 		}
484 		_onChangedListeners ~= dlg;
485 	}
486 	extern(C) static void callBackChanged(GVolume* volumeStruct, VolumeIF _volume)
487 	{
488 		foreach ( void delegate(VolumeIF) dlg; _volume.onChangedListeners )
489 		{
490 			dlg(_volume);
491 		}
492 	}
493 
494 	void delegate(VolumeIF)[] _onRemovedListeners;
495 	@property void delegate(VolumeIF)[] onRemovedListeners()
496 	{
497 		return _onRemovedListeners;
498 	}
499 	/**
500 	 * This signal is emitted when the #GVolume have been removed. If
501 	 * the recipient is holding references to the object they should
502 	 * release them so the object can be finalized.
503 	 */
504 	void addOnRemoved(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
505 	{
506 		if ( "removed" !in connectedSignals )
507 		{
508 			Signals.connectData(
509 				this,
510 				"removed",
511 				cast(GCallback)&callBackRemoved,
512 				cast(void*)cast(VolumeIF)this,
513 				null,
514 				connectFlags);
515 			connectedSignals["removed"] = 1;
516 		}
517 		_onRemovedListeners ~= dlg;
518 	}
519 	extern(C) static void callBackRemoved(GVolume* volumeStruct, VolumeIF _volume)
520 	{
521 		foreach ( void delegate(VolumeIF) dlg; _volume.onRemovedListeners )
522 		{
523 			dlg(_volume);
524 		}
525 	}
526 }