Class Drive

All Implemented Interfaces:
PointerInterface

public class Drive extends Interface
#GDrive - this represent a piece of hardware connected to the machine.
It's generally only created for removable hardware or hardware with
removable media.

#GDrive is a container class for #GVolume 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 g_drive_get_start_stop_type().

For porting from GnomeVFS note that there is no equivalent of
#GDrive in that API.

https://docs.gtk.org/gio/iface.Drive.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • canEject

      public boolean canEject()
      Checks if a drive can be ejected.
      Returns:
      %TRUE if the @drive can be ejected, %FALSE otherwise.
    • canPollForMedia

      public boolean canPollForMedia()
      Checks if a drive can be polled for media changes.
      Returns:
      %TRUE if the @drive can be polled for media changes, %FALSE otherwise.
    • canStart

      public boolean canStart()
      Checks if a drive can be started.
      Returns:
      %TRUE if the @drive can be started, %FALSE otherwise.
    • canStartDegraded

      public boolean canStartDegraded()
      Checks if a drive can be started degraded.
      Returns:
      %TRUE if the @drive can be started degraded, %FALSE otherwise.
    • canStop

      public boolean canStop()
      Checks if a drive can be stopped.
      Returns:
      %TRUE if the @drive can be stopped, %FALSE otherwise.
    • ejectWithOperation

      public void ejectWithOperation(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, Drive.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Ejects a drive. This is an asynchronous operation, and is
      finished by calling g_drive_eject_with_operation_finish() with the @drive
      and #GAsyncResult data returned in the @callback.
      Parameters:
      flags - flags affecting the unmount if required for eject
      mount_operation - a #GMountOperation or %NULL to avoid user interaction.
      cancellable - optional #GCancellable object, %NULL to ignore.
      callback - a #GAsyncReadyCallback, or %NULL.
      user_data - user data passed to @callback.
    • ejectWithOperationFinish

      public boolean ejectWithOperationFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes ejecting a drive. If any errors occurred during the operation,
      @error will be set to contain the errors and %FALSE will be returned.
      Parameters:
      result - a #GAsyncResult.
      Returns:
      %TRUE if the drive was successfully ejected. %FALSE otherwise.
      Throws:
      AllocationError
    • enumerateIdentifiers

      public Strs enumerateIdentifiers()
      Gets the kinds of identifiers that @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

      public Icon getIcon()
      Gets the icon for @drive.
      Returns:
      #GIcon for the @drive. Free the returned object with g_object_unref().
    • getIdentifier

      public Str getIdentifier(@Nonnull Str kind)
      Gets the identifier of the given kind for @drive. The only
      identifier currently available is
      %G_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 the #GDrive doesn't have this kind of identifier.
    • getIdentifier

      public Str getIdentifier(String kind)
      Gets the identifier of the given kind for @drive. The only
      identifier currently available is
      %G_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 the #GDrive doesn't have this kind of identifier.
    • getName

      public Str getName()
      Gets the name of @drive.
      Returns:
      a string containing @drive's name. The returned string should be freed when no longer needed.
    • getSortKey

      public Str getSortKey()
      Gets the sort key for @drive, if any.
      Returns:
      Sorting key for @drive or %NULL if no such key is available.
    • getStartStopType

      public int getStartStopType()
      Gets a hint about how a drive can be started/stopped.
      Returns:
      A value from the #GDriveStartStopType enumeration.
    • getSymbolicIcon

      public Icon getSymbolicIcon()
      Gets the icon for @drive.
      Returns:
      symbolic #GIcon for the @drive. Free the returned object with g_object_unref().
    • getVolumes

      public List getVolumes()
      Get a list of mountable volumes for @drive.

      The returned list should be freed with g_list_free(), after
      its elements have been unreffed with g_object_unref().
      Returns:
      #GList containing any #GVolume objects on the given @drive.
    • hasMedia

      public boolean hasMedia()
      Checks if the @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 @drive has media, %FALSE otherwise.
    • hasVolumes

      public boolean hasVolumes()
      Check if @drive has any mountable volumes.
      Returns:
      %TRUE if the @drive contains volumes, %FALSE otherwise.
    • isMediaCheckAutomatic

      public boolean isMediaCheckAutomatic()
      Checks if @drive is capable of automatically detecting media changes.
      Returns:
      %TRUE if the @drive is capable of automatically detecting media changes, %FALSE otherwise.
    • isMediaRemovable

      public boolean isMediaRemovable()
      Checks if the @drive supports removable media.
      Returns:
      %TRUE if @drive supports removable media, %FALSE otherwise.
    • isRemovable

      public boolean isRemovable()
      Checks if the #GDrive and/or its media is considered removable by the user.
      See g_drive_is_media_removable().
      Returns:
      %TRUE if @drive and/or its media is considered removable, %FALSE otherwise.
    • pollForMedia

      public void pollForMedia(@Nullable Cancellable cancellable, Drive.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously polls @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 - optional #GCancellable object, %NULL to ignore.
      callback - a #GAsyncReadyCallback, or %NULL.
      user_data - user data to pass to @callback
    • pollForMediaFinish

      public boolean pollForMediaFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an operation started with g_drive_poll_for_media() on a drive.
      Parameters:
      result - a #GAsyncResult.
      Returns:
      %TRUE if the drive has been poll_for_mediaed successfully, %FALSE otherwise.
      Throws:
      AllocationError
    • start

      public void start(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, Drive.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      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.
      mount_operation - a #GMountOperation or %NULL to avoid user interaction.
      cancellable - optional #GCancellable object, %NULL to ignore.
      callback - a #GAsyncReadyCallback, or %NULL.
      user_data - user data to pass to @callback
    • startFinish

      public boolean startFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes starting a drive.
      Parameters:
      result - a #GAsyncResult.
      Returns:
      %TRUE if the drive has been started successfully, %FALSE otherwise.
      Throws:
      AllocationError
    • stop

      public void stop(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, Drive.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      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.
      mount_operation - a #GMountOperation or %NULL to avoid user interaction.
      cancellable - optional #GCancellable object, %NULL to ignore.
      callback - a #GAsyncReadyCallback, or %NULL.
      user_data - user data to pass to @callback
    • stopFinish

      public boolean stopFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes stopping a drive.
      Parameters:
      result - a #GAsyncResult.
      Returns:
      %TRUE if the drive has been stopped successfully, %FALSE otherwise.
      Throws:
      AllocationError
    • onChanged

      public SignalHandler onChanged(Drive.OnChanged signal)
      Connect to signal "changed".
      See Drive.OnChanged.onChanged() for signal description.
      Field SIGNAL_ON_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onDisconnected

      public SignalHandler onDisconnected(Drive.OnDisconnected signal)
      Connect to signal "disconnected".
      See Drive.OnDisconnected.onDisconnected() for signal description.
      Field SIGNAL_ON_DISCONNECTED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onEjectButton

      public SignalHandler onEjectButton(Drive.OnEjectButton signal)
      Connect to signal "eject-button".
      See Drive.OnEjectButton.onEjectButton() for signal description.
      Field SIGNAL_ON_EJECT_BUTTON contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onStopButton

      public SignalHandler onStopButton(Drive.OnStopButton signal)
      Connect to signal "stop-button".
      See Drive.OnStopButton.onStopButton() for signal description.
      Field SIGNAL_ON_STOP_BUTTON contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()