gio.drive_mixin

Module for Drive interface mixin

Templates 2

tmplDriveT()

gio.drive.Drive represents a piece of hardware connected to the machine. It’s generally only created for removable hardware or hardware with removable media.

gio.drive.Drive is a container class for gio.volume.Volume objects that stem from the same piece of media. As such, gio.drive.Drive 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 gio.drive.Drive 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.

gio.drive.Drive 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 gio.drive.Drive may vary according to implementation. To choose the correct verbs in e.g. a file manager, use gio.drive.Drive.getStartStopType.

For porting from GnomeVFS note that there is no equivalent of gio.drive.Drive in that API.

Functions
bool canEject()

Checks if a drive can be ejected.

Returns

true if the drive can be ejected, false otherwise.
bool canPollForMedia()

Checks if a drive can be polled for media changes.

Returns

true if the drive can be polled for media changes,

false otherwise.

bool canStart()

Checks if a drive can be started.

Returns

true if the drive can be started, false otherwise.
bool canStartDegraded()

Checks if a drive can be started degraded.

Returns

true if the drive can be started degraded, false otherwise.
bool canStop()

Checks if a drive can be stopped.

Returns

true if the drive can be stopped, false otherwise.
void eject(gio.types.MountUnmountFlags flags, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)

Asynchronously ejects a drive.

When the operation is finished, callback will be called. You can then call gio.drive.Drive.ejectFinish to obtain the result of the operation.

Parameters

flagsflags affecting the unmount if required for eject
cancellableoptional #GCancellable object, null to ignore.
callbacka #GAsyncReadyCallback, or null.

Deprecated

bool ejectFinish(gio.async_result.AsyncResult result)

Finishes ejecting a drive.

Parameters

resulta #GAsyncResult.

Returns

true if the drive has been ejected successfully,

false otherwise.

Throws

Deprecated

void ejectWithOperation(gio.types.MountUnmountFlags flags, gio.mount_operation.MountOperation mountOperation = null, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)

Ejects a drive. This is an asynchronous operation, and is finished by calling gio.drive.Drive.ejectWithOperationFinish with the drive and #GAsyncResult data returned in the callback.

Parameters

flagsflags affecting the unmount if required for eject
mountOperationa #GMountOperation or null to avoid user interaction.
cancellableoptional #GCancellable object, null to ignore.
callbacka #GAsyncReadyCallback, or null.
bool ejectWithOperationFinish(gio.async_result.AsyncResult result)

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

resulta #GAsyncResult.

Returns

true if the drive was successfully ejected. false otherwise.

Throws

string[] enumerateIdentifiers()

Gets the kinds of identifiers that drive has. Use gio.drive.Drive.getIdentifier to obtain the identifiers themselves.

Returns

a null-terminated

array of strings containing kinds of identifiers. Use glib.global.strfreev to free.

gio.icon.Icon getIcon()

Gets the icon for drive.

Returns

#GIcon for the drive.

Free the returned object with gobject.object.ObjectWrap.unref.

string getIdentifier(string kind)

Gets the identifier of the given kind for drive. The only identifier currently available is gio.types.DRIVE_IDENTIFIER_KIND_UNIX_DEVICE.

Parameters

kindthe 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.

string getName()

Gets the name of drive.

Returns

a string containing drive's name. The returned

string should be freed when no longer needed.

string getSortKey()

Gets the sort key for drive, if any.

Returns

Sorting key for drive or null if no such key is available.
gio.types.DriveStartStopType getStartStopType()

Gets a hint about how a drive can be started/stopped.

Returns

A value from the #GDriveStartStopType enumeration.
gio.icon.Icon getSymbolicIcon()

Gets the icon for drive.

Returns

symbolic #GIcon for the drive.

Free the returned object with gobject.object.ObjectWrap.unref.

gio.volume.Volume[] getVolumes()

Get a list of mountable volumes for drive.

The returned list should be freed with glib.list.List.free, after its elements have been unreffed with gobject.object.ObjectWrap.unref.

Returns

#GList containing any #GVolume objects on the given drive.
bool hasMedia()

Checks if the drive has media. Note that the OS may not be polling the drive for media changes; see gio.drive.Drive.isMediaCheckAutomatic for more details.

Returns

true if drive has media, false otherwise.
bool hasVolumes()

Check if drive has any mountable volumes.

Returns

true if the drive contains volumes, false otherwise.
bool 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.

bool isMediaRemovable()

Checks if the drive supports removable media.

Returns

true if drive supports removable media, false otherwise.
bool isRemovable()

Checks if the #GDrive and/or its media is considered removable by the user. See gio.drive.Drive.isMediaRemovable.

Returns

true if drive and/or its media is considered removable, false otherwise.
void pollForMedia(gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)

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 gio.drive.Drive.pollForMediaFinish to obtain the result of the operation.

Parameters

cancellableoptional #GCancellable object, null to ignore.
callbacka #GAsyncReadyCallback, or null.
bool pollForMediaFinish(gio.async_result.AsyncResult result)

Finishes an operation started with gio.drive.Drive.pollForMedia on a drive.

Parameters

resulta #GAsyncResult.

Returns

true if the drive has been poll_for_mediaed successfully,

false otherwise.

Throws

void start(gio.types.DriveStartFlags flags, gio.mount_operation.MountOperation mountOperation = null, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)

Asynchronously starts a drive.

When the operation is finished, callback will be called. You can then call gio.drive.Drive.startFinish to obtain the result of the operation.

Parameters

flagsflags affecting the start operation.
mountOperationa #GMountOperation or null to avoid user interaction.
cancellableoptional #GCancellable object, null to ignore.
callbacka #GAsyncReadyCallback, or null.
bool startFinish(gio.async_result.AsyncResult result)

Finishes starting a drive.

Parameters

resulta #GAsyncResult.

Returns

true if the drive has been started successfully,

false otherwise.

Throws

void stop(gio.types.MountUnmountFlags flags, gio.mount_operation.MountOperation mountOperation = null, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)

Asynchronously stops a drive.

When the operation is finished, callback will be called. You can then call gio.drive.Drive.stopFinish to obtain the result of the operation.

Parameters

flagsflags affecting the unmount if required for stopping.
mountOperationa #GMountOperation or null to avoid user interaction.
cancellableoptional #GCancellable object, null to ignore.
callbacka #GAsyncReadyCallback, or null.
bool stopFinish(gio.async_result.AsyncResult result)

Finishes stopping a drive.

Parameters

resulta #GAsyncResult.

Returns

true if the drive has been stopped successfully,

false otherwise.

Throws

gulong connectChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gio.drive.Drive))) && Parameters!T.length < 2)

Connect to Changed signal.

Emitted when the drive's state has changed.

Parameters

callbacksignal callback delegate or function to connect void callback(gio.drive.Drive drive) drive the instance the signal is connected to (optional)
afterYes.After to execute callback after default handler, No.After to execute before (default)

Returns

Signal ID
gulong connectDisconnected(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gio.drive.Drive))) && Parameters!T.length < 2)

Connect to Disconnected signal.

This signal is emitted when the #GDrive have been disconnected. If the recipient is holding references to the object they should release them so the object can be finalized.

Parameters

callbacksignal callback delegate or function to connect void callback(gio.drive.Drive drive) drive the instance the signal is connected to (optional)
afterYes.After to execute callback after default handler, No.After to execute before (default)

Returns

Signal ID
gulong connectEjectButton(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gio.drive.Drive))) && Parameters!T.length < 2)

Connect to EjectButton signal.

Emitted when the physical eject button (if any) of a drive has been pressed.

Parameters

callbacksignal callback delegate or function to connect void callback(gio.drive.Drive drive) drive the instance the signal is connected to (optional)
afterYes.After to execute callback after default handler, No.After to execute before (default)

Returns

Signal ID
gulong connectStopButton(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gio.drive.Drive))) && Parameters!T.length < 2)

Connect to StopButton signal.

Emitted when the physical stop button (if any) of a drive has been pressed.

Parameters

callbacksignal callback delegate or function to connect void callback(gio.drive.Drive drive) drive the instance the signal is connected to (optional)
afterYes.After to execute callback after default handler, No.After to execute before (default)

Returns

Signal ID
tmplDriveGidBuilderT()

Fluent builder implementation template for gio.drive.Drive