Interface Volume
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Volume.Volume$Impl
GVolume interface represents user-visible objects that can be
mounted. For example, a file system partition on a USB flash drive, or an
optical disc inserted into a disc drive.
If a GVolume is currently mounted, the corresponding Mount can
be retrieved using getMount().
Mounting a GVolume instance is an asynchronous operation. For more
information about asynchronous operations, see AsyncResult and
Task. To mount a GVolume, first call mount(java.util.Set<org.gnome.gio.MountMountFlags>, org.gnome.gio.MountOperation, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
with (at least) the GVolume instance, optionally a
MountOperation object and a Gio.AsyncReadyCallback.
Typically, one will only want to pass NULL for the
MountOperation if automounting all volumes when a desktop session
starts since it’s not desirable to put up a lot of dialogs asking
for credentials.
The callback will be fired when the operation has resolved (either
with success or failure), and a AsyncResult instance will be
passed to the callback. That callback should then call
mountFinish(org.gnome.gio.AsyncResult) with the GVolume instance and the
AsyncResult data to see if the operation was completed
successfully. If a GLib.Error is present when
mountFinish(org.gnome.gio.AsyncResult) is called, then it will be filled with any
error information.
Note, when porting from GnomeVFS,
GVolume is the moral equivalent of GnomeVFSDrive.
Volume Identifiers
It is sometimes necessary to directly access the underlying
operating system object behind a volume (e.g. for passing a volume
to an application via the command line). For this purpose, GIO
allows to obtain an ‘identifier’ for the volume. There can be
different kinds of identifiers, such as Hal UDIs, filesystem labels,
traditional Unix devices (e.g. /dev/sda2), UUIDs. GIO uses predefined
strings as names for the different kinds of identifiers:
G_VOLUME_IDENTIFIER_KIND_UUID, G_VOLUME_IDENTIFIER_KIND_LABEL, etc.
Use getIdentifier(java.lang.String) to obtain an identifier for a volume.
Note that G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available
when the GVFS hal volume monitor is in use. Other volume monitors
will generally be able to provide the G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE
identifier, which can be used to obtain a hal device by means of
libhal_manager_find_device_string_match().
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface declaration of theChangedCallbackcallback.static interfaceFunctional interface declaration of theRemovedCallbackcallback.static classThe Volume$Impl type represents a native instance of the Volume interface.static classInterface for implementing operations for mountable volumes. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanEject()Checks if a volume can be ejected.default booleancanMount()Checks if a volume can be mounted.default voideject(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.default voideject(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.default booleanejectFinish(AsyncResult result) Deprecated.Use g_volume_eject_with_operation_finish() instead.default voidejectWithOperation(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume.default voidejectWithOperation(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume.default booleanejectWithOperationFinish(AsyncResult result) Finishes ejecting a volume.default voidEmits the "changed" signal.default voidEmits the "removed" signal.default String[]Gets the kinds of identifiers that this Volume has.default @Nullable FileGets the activation root for aGVolumeif it is known ahead of mount time.default @Nullable DrivegetDrive()Gets the drive for thevolume.default IcongetIcon()Gets the icon forvolume.default @Nullable StringgetIdentifier(String kind) Gets the identifier of the given kind forvolume.See the introduction for more information about volume identifiers.default @Nullable MountgetMount()Gets the mount for thevolume.default StringgetName()Gets the name ofvolume.default @Nullable StringGets the sort key forvolume,if any.default IconGets the symbolic icon forvolume.static @Nullable TypegetType()Get the GType of the Volume classdefault @Nullable StringgetUuid()Gets the UUID for thevolume.The reference is typically based on the file system UUID for the volume in question and should be considered an opaque string.default voidmount(Set<MountMountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume.default voidmount(MountMountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume.default booleanmountFinish(AsyncResult result) Finishes mounting a volume.default SignalConnection<Volume.ChangedCallback> onChanged(Volume.ChangedCallback handler) Emitted when the volume has been changed.default SignalConnection<Volume.RemovedCallback> onRemoved(Volume.RemovedCallback handler) This signal is emitted when theGVolumehave been removed.default booleanReturns whether the volume should be automatically mounted.
-
Method Details
-
getType
-
canEject
default boolean canEject()Checks if a volume can be ejected.- Returns:
trueif the this Volume can be ejected.falseotherwise
-
canMount
default boolean canMount()Checks if a volume can be mounted.- Returns:
trueif the this Volume can be mounted.falseotherwise
-
eject
@Deprecated default void eject(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_finish() with the this Volume andGAsyncResultreturned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectcancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull
-
eject
@Deprecated default void eject(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_finish() with the this Volume andGAsyncResultreturned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectcancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull
-
ejectFinish
Deprecated.Use g_volume_eject_with_operation_finish() instead.Finishes ejecting a volume. If any errors occurred during the operation,errorwill be set to contain the errors andfalsewill be returned.- Parameters:
result- aGAsyncResult- Returns:
true,falseif operation failed- Throws:
GErrorException- seeGError
-
ejectWithOperation
default void ejectWithOperation(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_with_operation_finish() with the this Volume andGAsyncResultdata returned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectmountOperation- aGMountOperationornullto avoid user interactioncancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull- Since:
- 2.22
-
ejectWithOperation
default void ejectWithOperation(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_with_operation_finish() with the this Volume andGAsyncResultdata returned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectmountOperation- aGMountOperationornullto avoid user interactioncancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull- Since:
- 2.22
-
ejectWithOperationFinish
Finishes ejecting a volume. If any errors occurred during the operation,errorwill be set to contain the errors andfalsewill be returned.- Parameters:
result- aGAsyncResult- Returns:
trueif the volume was successfully ejected.falseotherwise- Throws:
GErrorException- seeGError- Since:
- 2.22
-
enumerateIdentifiers
Gets the kinds of identifiers that this Volume has. Use g_volume_get_identifier() to obtain the identifiers themselves.- Returns:
- a
null-terminated array of strings containing kinds of identifiers. Use g_strfreev() to free.
-
getActivationRoot
Gets the activation root for aGVolumeif it is known ahead of mount time. Returnsnullotherwise. If notnulland if this Volume is mounted, then the result of g_mount_get_root() on theGMountobject obtained from g_volume_get_mount() will always either be equal or a prefix of what this function returns. In other words, in code
then the expressionGMount *mount; GFile *mount_root GFile *volume_activation_root; mount = g_volume_get_mount (volume); // mounted, so never NULL mount_root = g_mount_get_root (mount); volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL
will always be(g_file_has_prefix (volume_activation_root, mount_root) || g_file_equal (volume_activation_root, mount_root))true.Activation roots are typically used in
GVolumeMonitorimplementations to find the underlying mount to shadow, see g_mount_is_shadowed() for more details.- Returns:
- the activation root of this Volume
or
null. Use g_object_unref() to free. - Since:
- 2.18
-
getDrive
Gets the drive for thevolume.- Returns:
- a
GDriveornullif this Volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.
-
getIcon
Gets the icon forvolume.- Returns:
- a
GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.
-
getIdentifier
Gets the identifier of the given kind forvolume.See the introduction for more information about volume identifiers.- Parameters:
kind- the kind of identifier to return- Returns:
- a newly allocated string containing the
requested identifier, or
nullif theGVolumedoesn't have this kind of identifier
-
getMount
Gets the mount for thevolume.- Returns:
- a
GMountornullif this Volume isn't mounted. The returned object should be unreffed with g_object_unref() when no longer needed.
-
getName
Gets the name ofvolume.- Returns:
- the name for the given
volume.The returned string should be freed with g_free() when no longer needed.
-
getSortKey
Gets the sort key forvolume,if any.- Returns:
- Sorting key for this Volume or
nullif no such key is available - Since:
- 2.32
-
getSymbolicIcon
Gets the symbolic icon forvolume.- Returns:
- a
GIcon. The returned object should be unreffed with g_object_unref() when no longer needed. - Since:
- 2.34
-
getUuid
Gets the UUID for thevolume.The reference is typically based on the file system UUID for the volume in question and should be considered an opaque string. Returnsnullif there is no UUID available.- Returns:
- the UUID for this Volume or
nullif no UUID can be computed. The returned string should be freed with g_free() when no longer needed.
-
mount
default void mount(Set<MountMountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume andGAsyncResultreturned in thecallback.- Parameters:
flags- flags affecting the operationmountOperation- aGMountOperationornullto avoid user interactioncancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull
-
mount
default void mount(MountMountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume andGAsyncResultreturned in thecallback.- Parameters:
flags- flags affecting the operationmountOperation- aGMountOperationornullto avoid user interactioncancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallback, ornull
-
mountFinish
Finishes mounting a volume. If any errors occurred during the operation,errorwill be set to contain the errors andfalsewill be returned.If the mount operation succeeded, g_volume_get_mount() on this Volume is guaranteed to return the mount right after calling this function; there's no need to listen for the 'mount-added' signal on
GVolumeMonitor.- Parameters:
result- aGAsyncResult- Returns:
true,falseif operation failed- Throws:
GErrorException- seeGError
-
shouldAutomount
default boolean shouldAutomount()Returns whether the volume should be automatically mounted.- Returns:
trueif the volume should be automatically mounted
-
onChanged
Emitted when the volume has been changed.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
default void emitChanged()Emits the "changed" signal. SeeonChanged(org.gnome.gio.Volume.ChangedCallback). -
onRemoved
This signal is emitted when theGVolumehave been removed. If the recipient is holding references to the object they should release them so the object can be finalized.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRemoved
default void emitRemoved()Emits the "removed" signal. SeeonRemoved(org.gnome.gio.Volume.RemovedCallback).
-