Interface Drive
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Drive.Drive$Impl
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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface declaration of theChangedCallbackcallback.static interfaceFunctional interface declaration of theDisconnectedCallbackcallback.static classThe Drive$Impl type represents a native instance of the Drive interface.static classInterface for creatingGDriveimplementations.static interfaceFunctional interface declaration of theEjectButtonCallbackcallback.static interfaceFunctional interface declaration of theStopButtonCallbackcallback. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanEject()Checks if a drive can be ejected.default booleanChecks if a drive can be polled for media changes.default booleancanStart()Checks if a drive can be started.default booleanChecks if a drive can be started degraded.default booleancanStop()Checks if a drive can be stopped.default voideject(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.default voideject(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.default booleanejectFinish(AsyncResult result) Deprecated.Use g_drive_eject_with_operation_finish() instead.default voidejectWithOperation(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a drive.default voidejectWithOperation(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Ejects a drive.default booleanejectWithOperationFinish(AsyncResult result) Finishes ejecting a drive.default voidEmits the "changed" signal.default voidEmits the "disconnected" signal.default voidEmits the "eject-button" signal.default voidEmits the "stop-button" signal.default String[]Gets the kinds of identifiers that this Drive has.default IcongetIcon()Gets the icon fordrive.default @Nullable StringgetIdentifier(String kind) Gets the identifier of the given kind fordrive.The only identifier currently available isG_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE.default StringgetName()Gets the name ofdrive.default @Nullable StringGets the sort key fordrive,if any.default DriveStartStopTypeGets a hint about how a drive can be started/stopped.default IconGets the icon fordrive.static @Nullable TypegetType()Get the GType of the Drive classGet a list of mountable volumes fordrive.default booleanhasMedia()Checks if the this Drive has media.default booleanCheck if this Drive has any mountable volumes.default booleanChecks if this Drive is capable of automatically detecting media changes.default booleanChecks if the this Drive supports removable media.default booleanChecks if theGDriveand/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 theGDrivehave 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 voidpollForMedia(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously polls this Drive to see if media has been inserted or removed.default booleanpollForMediaFinish(AsyncResult result) Finishes an operation started with g_drive_poll_for_media() on a drive.default voidstart(Set<DriveStartFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.default voidstart(DriveStartFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.default booleanstartFinish(AsyncResult result) Finishes starting a drive.default voidstop(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.default voidstop(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.default booleanstopFinish(AsyncResult result) Finishes stopping a drive.
-
Method Details
-
getType
-
canEject
default boolean canEject()Checks if a drive can be ejected.- Returns:
trueif the this Drive can be ejected,falseotherwise.
-
canPollForMedia
default boolean canPollForMedia()Checks if a drive can be polled for media changes.- Returns:
trueif the this Drive can be polled for media changes,falseotherwise.
-
canStart
default boolean canStart()Checks if a drive can be started.- Returns:
trueif the this Drive can be started,falseotherwise.- Since:
- 2.22
-
canStartDegraded
default boolean canStartDegraded()Checks if a drive can be started degraded.- Returns:
trueif the this Drive can be started degraded,falseotherwise.- Since:
- 2.22
-
canStop
default boolean canStop()Checks if a drive can be stopped.- Returns:
trueif the this Drive can be stopped,falseotherwise.- Since:
- 2.22
-
eject
@Deprecated default void eject(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.Asynchronously ejects a drive.When the operation is finished,
callbackwill 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.
-
eject
@Deprecated default void eject(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_drive_eject_with_operation() instead.Asynchronously ejects a drive.When the operation is finished,
callbackwill 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.
-
ejectFinish
Deprecated.Use g_drive_eject_with_operation_finish() instead.Finishes ejecting a drive.- Parameters:
result- aGAsyncResult.- Returns:
trueif the drive has been ejected successfully,falseotherwise.- Throws:
GErrorException- seeGError
-
ejectWithOperation
default void ejectWithOperation(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @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 andGAsyncResultdata returned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectmountOperation- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
ejectWithOperation
default void ejectWithOperation(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @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 andGAsyncResultdata returned in thecallback.- Parameters:
flags- flags affecting the unmount if required for ejectmountOperation- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
ejectWithOperationFinish
Finishes ejecting a drive. If any errors occurred during the operation,errorwill be set to contain the errors andfalsewill be returned.- Parameters:
result- aGAsyncResult.- Returns:
trueif the drive was successfully ejected.falseotherwise.- Throws:
GErrorException- seeGError- Since:
- 2.22
-
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 fordrive.- Returns:
GIconfor thedrive.Free the returned object with g_object_unref().
-
getIdentifier
Gets the identifier of the given kind fordrive.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
nullif theGDrivedoesn't have this kind of identifier.
-
getName
Gets the name ofdrive.- Returns:
- a string containing
drive'sname. The returned string should be freed when no longer needed.
-
getSortKey
Gets the sort key fordrive,if any.- Returns:
- Sorting key for this Drive or
nullif no such key is available. - Since:
- 2.32
-
getStartStopType
Gets a hint about how a drive can be started/stopped.- Returns:
- A value from the
GDriveStartStopTypeenumeration. - Since:
- 2.22
-
getSymbolicIcon
Gets the icon fordrive.- Returns:
- symbolic
GIconfor thedrive.Free the returned object with g_object_unref(). - Since:
- 2.34
-
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:
trueif this Drive has media,falseotherwise.
-
hasVolumes
default boolean hasVolumes()Check if this Drive has any mountable volumes.- Returns:
trueif the this Drive contains volumes,falseotherwise.
-
isMediaCheckAutomatic
default boolean isMediaCheckAutomatic()Checks if this Drive is capable of automatically detecting media changes.- Returns:
trueif the this Drive is capable of automatically detecting media changes,falseotherwise.
-
isMediaRemovable
default boolean isMediaRemovable()Checks if the this Drive supports removable media.- Returns:
trueif this Drive supports removable media,falseotherwise.
-
isRemovable
default boolean isRemovable()Checks if theGDriveand/or its media is considered removable by the user. See g_drive_is_media_removable().- Returns:
trueif this Drive and/or its media is considered removable,falseotherwise.- Since:
- 2.50
-
pollForMedia
Asynchronously polls this Drive to see if media has been inserted or removed.When the operation is finished,
callbackwill be called. You can then call g_drive_poll_for_media_finish() to obtain the result of the operation.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.
-
pollForMediaFinish
Finishes an operation started with g_drive_poll_for_media() on a drive.- Parameters:
result- aGAsyncResult.- Returns:
trueif the drive has been poll_for_mediaed successfully,falseotherwise.- Throws:
GErrorException- seeGError
-
start
default void start(Set<DriveStartFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.When the operation is finished,
callbackwill 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- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
start
default void start(DriveStartFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously starts a drive.When the operation is finished,
callbackwill 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- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
startFinish
Finishes starting a drive.- Parameters:
result- aGAsyncResult.- Returns:
trueif the drive has been started successfully,falseotherwise.- Throws:
GErrorException- seeGError- Since:
- 2.22
-
stop
default void stop(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.When the operation is finished,
callbackwill 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- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
stop
default void stop(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously stops a drive.When the operation is finished,
callbackwill 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- aGMountOperationornullto avoid user interaction.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallback, ornull.- Since:
- 2.22
-
stopFinish
Finishes stopping a drive.- Parameters:
result- aGAsyncResult.- Returns:
trueif the drive has been stopped successfully,falseotherwise.- Throws:
GErrorException- seeGError- Since:
- 2.22
-
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 theGDrivehave 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
- Since:
- 2.22
- See Also:
-
emitStopButton
default void emitStopButton()Emits the "stop-button" signal. SeeonStopButton(org.gnome.gio.Drive.StopButtonCallback).
-