Interface Volume
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Volume.VolumeImpl
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
Modifier and TypeInterfaceDescriptionstatic interface
Functional interface declaration of theChangedCallback
callback.static interface
Functional interface declaration of theRemovedCallback
callback.static class
Interface for implementing operations for mountable volumes.static class
The VolumeImpl type represents a native instance of the Volume interface. -
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
canEject()
Checks if a volume can be ejected.default boolean
canMount()
Checks if a volume can be mounted.default void
eject
(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.default void
eject
(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_volume_eject_with_operation() instead.default boolean
ejectFinish
(AsyncResult result) Deprecated.Use g_volume_eject_with_operation_finish() instead.default void
ejectWithOperation
(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume.default void
ejectWithOperation
(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a volume.default boolean
ejectWithOperationFinish
(AsyncResult result) Finishes ejecting a volume.default void
Emits the "changed" signal.default void
Emits the "removed" signal.default String[]
Gets the kinds of identifiers that this Volume has.default File
Gets the activation root for aGVolume
if it is known ahead of mount time.default Drive
getDrive()
Gets the drive for the this Volume.default Icon
getIcon()
Gets the icon for this Volume.default String
getIdentifier
(String kind) Gets the identifier of the given kind for this Volume.default Mount
getMount()
Gets the mount for the this Volume.default String
getName()
Gets the name of this Volume.default String
Gets the sort key for this Volume, if any.default Icon
Gets the symbolic icon for this Volume.static Type
getType()
Get the GType of the Volume classdefault String
getUuid()
Gets the UUID for the this Volume.default void
mount
(Set<MountMountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume.default void
mount
(MountMountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Mounts a volume.default boolean
mountFinish
(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 theGVolume
have been removed.default boolean
Returns whether the volume should be automatically mounted.
-
Method Details
-
getType
-
canEject
default boolean canEject()Checks if a volume can be ejected.- Returns:
true
if the this Volume can be ejected.false
otherwise
-
canMount
default boolean canMount()Checks if a volume can be mounted.- Returns:
true
if the this Volume can be mounted.false
otherwise
-
eject
@Deprecated default void eject(Set<MountUnmountFlags> flags, @Nullable @Nullable Cancellable cancellable, @Nullable @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 andGAsyncResult
returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectcancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
eject
@Deprecated default void eject(MountUnmountFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @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 andGAsyncResult
returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectcancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
ejectFinish
Deprecated.Use g_volume_eject_with_operation_finish() instead.Finishes ejecting a volume. If any errors occurred during the operation,error
will be set to contain the errors andfalse
will be returned.- Parameters:
result
- aGAsyncResult
- Returns:
true
,false
if operation failed- Throws:
GErrorException
- seeGError
-
ejectWithOperation
default void ejectWithOperation(Set<MountUnmountFlags> flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @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 andGAsyncResult
data returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectmountOperation
- aGMountOperation
ornull
to avoid user interactioncancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
ejectWithOperation
default void ejectWithOperation(MountUnmountFlags flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @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 andGAsyncResult
data returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectmountOperation
- aGMountOperation
ornull
to avoid user interactioncancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
ejectWithOperationFinish
Finishes ejecting a volume. If any errors occurred during the operation,error
will be set to contain the errors andfalse
will be returned.- Parameters:
result
- aGAsyncResult
- Returns:
true
if the volume was successfully ejected.false
otherwise- Throws:
GErrorException
- seeGError
-
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 aGVolume
if it is known ahead of mount time. Returnsnull
otherwise. If notnull
and if this Volume is mounted, then the result of g_mount_get_root() on theGMount
object 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
GVolumeMonitor
implementations 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.
-
getDrive
Gets the drive for the this Volume.- Returns:
- a
GDrive
ornull
if 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 for this Volume.- 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 for this Volume. 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
null
if theGVolume
doesn't have this kind of identifier
-
getMount
Gets the mount for the this Volume.- Returns:
- a
GMount
ornull
if this Volume isn't mounted. The returned object should be unreffed with g_object_unref() when no longer needed.
-
getName
Gets the name of this Volume.- Returns:
- the name for the given this Volume. The returned string should be freed with g_free() when no longer needed.
-
getSortKey
Gets the sort key for this Volume, if any.- Returns:
- Sorting key for this Volume or
null
if no such key is available
-
getSymbolicIcon
Gets the symbolic icon for this Volume.- Returns:
- a
GIcon
. The returned object should be unreffed with g_object_unref() when no longer needed.
-
getUuid
Gets the UUID for the this Volume. The reference is typically based on the file system UUID for the volume in question and should be considered an opaque string. Returnsnull
if there is no UUID available.- Returns:
- the UUID for this Volume or
null
if 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 @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume andGAsyncResult
returned in thecallback
.- Parameters:
flags
- flags affecting the operationmountOperation
- aGMountOperation
ornull
to avoid user interactioncancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
mount
default void mount(MountMountFlags flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume andGAsyncResult
returned in thecallback
.- Parameters:
flags
- flags affecting the operationmountOperation
- aGMountOperation
ornull
to avoid user interactioncancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
, ornull
-
mountFinish
Finishes mounting a volume. If any errors occurred during the operation,error
will be set to contain the errors andfalse
will 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
,false
if operation failed- Throws:
GErrorException
- seeGError
-
shouldAutomount
default boolean shouldAutomount()Returns whether the volume should be automatically mounted.- Returns:
true
if 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 theGVolume
have 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)
.
-