Interface Drive
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Drive.DriveImpl
GDrive
represents a piece of hardware connected to the machine.
It’s generally only created for removable hardware or hardware with
removable media. For example, an optical disc drive, or a USB flash drive.
GDrive
is a container class for Volume
objects that stem from
the same piece of media. As such, GDrive
abstracts a drive with
(or without) removable media and provides operations for querying
whether media is available, determining whether media change is
automatically detected and ejecting the media.
If the GDrive
reports that media isn’t automatically detected, one
can poll for media; typically one should not do this periodically
as a poll for media operation is potentially expensive and may
spin up the drive creating noise.
GDrive
supports starting and stopping drives with authentication
support for the former. This can be used to support a diverse set
of use cases including connecting/disconnecting iSCSI devices,
powering down external disk enclosures and starting/stopping
multi-disk devices such as RAID devices. Note that the actual
semantics and side-effects of starting/stopping a GDrive
may vary
according to implementation. To choose the correct verbs in e.g. a
file manager, use getStartStopType()
.
For porting from GnomeVFS note that there is no
equivalent of GDrive
in that API.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Functional interface declaration of theChangedCallback
callback.static interface
Functional interface declaration of theDisconnectedCallback
callback.static class
Interface for creatingGDrive
implementations.static class
The DriveImpl type represents a native instance of the Drive interface.static interface
Functional interface declaration of theEjectButtonCallback
callback.static interface
Functional interface declaration of theStopButtonCallback
callback. -
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
canEject()
Checks if a drive can be ejected.default boolean
Checks if a drive can be polled for media changes.default boolean
canStart()
Checks if a drive can be started.default boolean
Checks if a drive can be started degraded.default boolean
canStop()
Checks if a drive can be stopped.default void
eject
(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.default void
eject
(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.default boolean
ejectFinish
(AsyncResult result) Deprecated.Use g_drive_eject_with_operation_finish() instead.default void
ejectWithOperation
(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a drive.default void
ejectWithOperation
(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a drive.default boolean
ejectWithOperationFinish
(AsyncResult result) Finishes ejecting a drive.default void
Emits the "changed" signal.default void
Emits the "disconnected" signal.default void
Emits the "eject-button" signal.default void
Emits the "stop-button" signal.default String[]
Gets the kinds of identifiers that this Drive has.default Icon
getIcon()
Gets the icon for this Drive.default String
getIdentifier
(String kind) Gets the identifier of the given kind for this Drive.default String
getName()
Gets the name of this Drive.default String
Gets the sort key for this Drive, if any.default DriveStartStopType
Gets a hint about how a drive can be started/stopped.default Icon
Gets the icon for this Drive.static Type
getType()
Get the GType of the Drive classGet a list of mountable volumes for this Drive.default boolean
hasMedia()
Checks if the this Drive has media.default boolean
Check if this Drive has any mountable volumes.default boolean
Checks if this Drive is capable of automatically detecting media changes.default boolean
Checks if the this Drive supports removable media.default boolean
Checks if theGDrive
and/or its media is considered removable by the user.default SignalConnection
<Drive.ChangedCallback> onChanged
(Drive.ChangedCallback handler) Emitted when the drive's state has changed.onDisconnected
(Drive.DisconnectedCallback handler) This signal is emitted when theGDrive
have been disconnected.onEjectButton
(Drive.EjectButtonCallback handler) Emitted when the physical eject button (if any) of a drive has been pressed.default SignalConnection
<Drive.StopButtonCallback> onStopButton
(Drive.StopButtonCallback handler) Emitted when the physical stop button (if any) of a drive has been pressed.default void
pollForMedia
(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously polls this Drive to see if media has been inserted or removed.default boolean
pollForMediaFinish
(AsyncResult result) Finishes an operation started with g_drive_poll_for_media() on a drive.default void
start
(Set<DriveStartFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.default void
start
(DriveStartFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.default boolean
startFinish
(AsyncResult result) Finishes starting a drive.default void
stop
(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.default void
stop
(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.default boolean
stopFinish
(AsyncResult result) Finishes stopping a drive.
-
Method Details
-
getType
-
canEject
default boolean canEject()Checks if a drive can be ejected.- Returns:
true
if the this Drive can be ejected,false
otherwise.
-
canPollForMedia
default boolean canPollForMedia()Checks if a drive can be polled for media changes.- Returns:
true
if the this Drive can be polled for media changes,false
otherwise.
-
canStart
default boolean canStart()Checks if a drive can be started.- Returns:
true
if the this Drive can be started,false
otherwise.
-
canStartDegraded
default boolean canStartDegraded()Checks if a drive can be started degraded.- Returns:
true
if the this Drive can be started degraded,false
otherwise.
-
canStop
default boolean canStop()Checks if a drive can be stopped.- Returns:
true
if the this Drive can be stopped,false
otherwise.
-
eject
@Deprecated default void eject(Set<MountUnmountFlags> flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.Asynchronously ejects a drive.When the operation is finished,
callback
will be called. You can then call g_drive_eject_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the unmount if required for ejectcancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
eject
@Deprecated default void eject(MountUnmountFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.Asynchronously ejects a drive.When the operation is finished,
callback
will be called. You can then call g_drive_eject_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the unmount if required for ejectcancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
ejectFinish
Deprecated.Use g_drive_eject_with_operation_finish() instead.Finishes ejecting a drive.- Parameters:
result
- aGAsyncResult
.- Returns:
true
if the drive has been ejected successfully,false
otherwise.- Throws:
GErrorException
- seeGError
-
ejectWithOperation
default void ejectWithOperation(Set<MountUnmountFlags> flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Ejects a drive. This is an asynchronous operation, and is finished by calling g_drive_eject_with_operation_finish() with the this Drive andGAsyncResult
data returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectmountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
ejectWithOperation
default void ejectWithOperation(MountUnmountFlags flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Ejects a drive. This is an asynchronous operation, and is finished by calling g_drive_eject_with_operation_finish() with the this Drive andGAsyncResult
data returned in thecallback
.- Parameters:
flags
- flags affecting the unmount if required for ejectmountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
ejectWithOperationFinish
Finishes ejecting a drive. 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 drive was successfully ejected.false
otherwise.- Throws:
GErrorException
- seeGError
-
enumerateIdentifiers
Gets the kinds of identifiers that this Drive has. Use g_drive_get_identifier() to obtain the identifiers themselves.- Returns:
- a
null
-terminated array of strings containing kinds of identifiers. Use g_strfreev() to free.
-
getIcon
Gets the icon for this Drive.- Returns:
GIcon
for the this Drive. Free the returned object with g_object_unref().
-
getIdentifier
Gets the identifier of the given kind for this Drive. The only identifier currently available isG_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE
.- Parameters:
kind
- the kind of identifier to return- Returns:
- a newly allocated string containing the
requested identifier, or
null
if theGDrive
doesn't have this kind of identifier.
-
getName
Gets the name of this Drive.- Returns:
- a string containing this Drive's name. The returned string should be freed when no longer needed.
-
getSortKey
Gets the sort key for this Drive, if any.- Returns:
- Sorting key for this Drive or
null
if no such key is available.
-
getStartStopType
Gets a hint about how a drive can be started/stopped.- Returns:
- A value from the
GDriveStartStopType
enumeration.
-
getSymbolicIcon
Gets the icon for this Drive.- Returns:
- symbolic
GIcon
for the this Drive. Free the returned object with g_object_unref().
-
getVolumes
-
hasMedia
default boolean hasMedia()Checks if the this Drive has media. Note that the OS may not be polling the drive for media changes; see g_drive_is_media_check_automatic() for more details.- Returns:
true
if this Drive has media,false
otherwise.
-
hasVolumes
default boolean hasVolumes()Check if this Drive has any mountable volumes.- Returns:
true
if the this Drive contains volumes,false
otherwise.
-
isMediaCheckAutomatic
default boolean isMediaCheckAutomatic()Checks if this Drive is capable of automatically detecting media changes.- Returns:
true
if the this Drive is capable of automatically detecting media changes,false
otherwise.
-
isMediaRemovable
default boolean isMediaRemovable()Checks if the this Drive supports removable media.- Returns:
true
if this Drive supports removable media,false
otherwise.
-
isRemovable
default boolean isRemovable()Checks if theGDrive
and/or its media is considered removable by the user. See g_drive_is_media_removable().- Returns:
true
if this Drive and/or its media is considered removable,false
otherwise.
-
pollForMedia
default void pollForMedia(@Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously polls this Drive to see if media has been inserted or removed.When the operation is finished,
callback
will be called. You can then call g_drive_poll_for_media_finish() to obtain the result of the operation.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
pollForMediaFinish
Finishes an operation started with g_drive_poll_for_media() on a drive.- Parameters:
result
- aGAsyncResult
.- Returns:
true
if the drive has been poll_for_mediaed successfully,false
otherwise.- Throws:
GErrorException
- seeGError
-
start
default void start(Set<DriveStartFlags> flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.When the operation is finished,
callback
will be called. You can then call g_drive_start_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the start operation.mountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
start
default void start(DriveStartFlags flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.When the operation is finished,
callback
will be called. You can then call g_drive_start_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the start operation.mountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
startFinish
Finishes starting a drive.- Parameters:
result
- aGAsyncResult
.- Returns:
true
if the drive has been started successfully,false
otherwise.- Throws:
GErrorException
- seeGError
-
stop
default void stop(Set<MountUnmountFlags> flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.When the operation is finished,
callback
will be called. You can then call g_drive_stop_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the unmount if required for stopping.mountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
stop
default void stop(MountUnmountFlags flags, @Nullable @Nullable MountOperation mountOperation, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.When the operation is finished,
callback
will be called. You can then call g_drive_stop_finish() to obtain the result of the operation.- Parameters:
flags
- flags affecting the unmount if required for stopping.mountOperation
- aGMountOperation
ornull
to avoid user interaction.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
, ornull
.
-
stopFinish
Finishes stopping a drive.- Parameters:
result
- aGAsyncResult
.- Returns:
true
if the drive has been stopped successfully,false
otherwise.- Throws:
GErrorException
- seeGError
-
onChanged
Emitted when the drive's state has 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.Drive.ChangedCallback)
. -
onDisconnected
default SignalConnection<Drive.DisconnectedCallback> onDisconnected(Drive.DisconnectedCallback handler) This signal is emitted when theGDrive
have been disconnected. 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:
-
emitDisconnected
default void emitDisconnected()Emits the "disconnected" signal. SeeonDisconnected(org.gnome.gio.Drive.DisconnectedCallback)
. -
onEjectButton
default SignalConnection<Drive.EjectButtonCallback> onEjectButton(Drive.EjectButtonCallback handler) Emitted when the physical eject button (if any) of a drive has been pressed.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEjectButton
default void emitEjectButton()Emits the "eject-button" signal. SeeonEjectButton(org.gnome.gio.Drive.EjectButtonCallback)
. -
onStopButton
Emitted when the physical stop button (if any) of a drive has been pressed.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitStopButton
default void emitStopButton()Emits the "stop-button" signal. SeeonStopButton(org.gnome.gio.Drive.StopButtonCallback)
.
-