Module: Gio::Volume
- Defined in:
- lib/gio2/volume.rb
Overview
The GVolume interface represents user-visible objects that can be
mounted. Note, when porting from GnomeVFS,
GVolume is the moral equivalent of GnomeVFSDrive.
Mounting a GVolume instance is an asynchronous operation. For more
information about asynchronous operations, see [ifaceGio.AsyncResult] and
[classGio.Task]. To mount a GVolume, first call [methodGio.Volume.mount]
with (at least) the GVolume instance, optionally a
[classGio.MountOperation] object and a [typeGio.AsyncReadyCallback].
Typically, one will only want to pass NULL for the
[classGio.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 [ifaceGio.AsyncResult] instance will be
passed to the callback. That callback should then call
[methodGio.Volume.mount_finish] with the GVolume instance and the
[ifaceGio.AsyncResult] data to see if the operation was completed
successfully. If a [typeGLib.Error] is present when
[methodGio.Volume.mount_finish] is called, then it will be filled with any
error information.
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 [methodGio.Volume.get_identifier] 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().
Instance Method Summary collapse
-
#activation_root ⇒ Gio::File
Gets the activation root for a #GVolume if it is known ahead of mount time.
-
#can_eject(volume) ⇒ Boolean
True if the volume can be ejected.
-
#can_mount(volume) ⇒ Boolean
True if the volume can be mounted.
- #changed(volume) ⇒ nil
-
#drive ⇒ Gio::Drive
Gets the drive for the volume.
- #eject(volume, flags, cancellable, callback, user_data) ⇒ nil
-
#eject_finish(volume, result) ⇒ Boolean
True, false if operation failed.
- #eject_with_operation(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil
-
#eject_with_operation_finish(volume, result) ⇒ Boolean
True if the volume was successfully ejected.
-
#enumerate_identifiers(volume) ⇒ Array<String>
An array of strings containing kinds of identifiers.
-
#get_activation_root(volume) ⇒ Gio::File
The activation root of volume or nil.
-
#get_drive(volume) ⇒ Gio::Drive
A #GDrive or nil if volume is not associated with a drive.
-
#get_icon(volume) ⇒ Gio::Icon
A #GIcon.
-
#get_identifier(volume, kind) ⇒ String
A newly allocated string containing the requested identifier, or nil if the #GVolume doesn't have this kind of identifier.
-
#get_mount(volume) ⇒ Gio::Mount
A #GMount or nil if volume isn't mounted.
-
#get_name(volume) ⇒ String
The name for the given volume.
-
#get_sort_key(volume) ⇒ String
Sorting key for volume or nil if no such key is available.
-
#get_symbolic_icon(volume) ⇒ Gio::Icon
A #GIcon.
-
#get_uuid(volume) ⇒ String
The UUID for volume or nil if no UUID can be computed.
-
#icon ⇒ Gio::Icon
Gets the icon for volume.
-
#mount(*args, &block) ⇒ nil
Mounts a volume.
-
#mount_finish(volume, result) ⇒ Boolean
True, false if operation failed.
- #mount_fn(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil
-
#mount_raw ⇒ nil
Mounts a volume.
-
#name ⇒ String
Gets the name of volume.
- #removed(volume) ⇒ nil
-
#should_automount(volume) ⇒ Boolean
True if the volume should be automatically mounted.
-
#sort_key ⇒ String
Gets the sort key for volume, if any.
-
#symbolic_icon ⇒ Gio::Icon
Gets the symbolic icon for volume.
-
#uuid ⇒ String
Gets the UUID for the volume.
Instance Method Details
#activation_root ⇒ Gio::File
Gets the activation root for a #GVolume if it is known ahead of mount time. Returns nil otherwise. If not nil and if volume is mounted, then the result of g_mount_get_root() on the #GMount 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
(g_file_has_prefix (volume_activation_root, mount_root) ||
g_file_equal (volume_activation_root, mount_root))
will always be true.
Activation roots are typically used in GVolume::Monitor implementations to find the underlying mount to shadow, see g_mount_is_shadowed() for more details.
#can_eject(volume) ⇒ Boolean
Returns true if the volume can be ejected. false otherwise.
#can_mount(volume) ⇒ Boolean
Returns true if the volume can be mounted. false otherwise.
#changed(volume) ⇒ nil
#drive ⇒ Gio::Drive
Gets the drive for the volume.
#eject(volume, flags, cancellable, callback, user_data) ⇒ nil
#eject_finish(volume, result) ⇒ Boolean
Returns true, false if operation failed.
#eject_with_operation(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil
#eject_with_operation_finish(volume, result) ⇒ Boolean
Returns true if the volume was successfully ejected. false otherwise.
#enumerate_identifiers(volume) ⇒ Array<String>
Returns an array of strings containing kinds of identifiers. Use g_strfreev() to free.
#get_activation_root(volume) ⇒ Gio::File
Returns the activation root of volume or nil. Use g_object_unref() to free.
#get_drive(volume) ⇒ Gio::Drive
Returns a #GDrive or nil if volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.
#get_icon(volume) ⇒ Gio::Icon
Returns a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.
#get_identifier(volume, kind) ⇒ String
Returns a newly allocated string containing the requested identifier, or nil if the #GVolume doesn't have this kind of identifier.
#get_mount(volume) ⇒ Gio::Mount
Returns a #GMount or nil if volume isn't mounted. The returned object should be unreffed with g_object_unref() when no longer needed.
#get_name(volume) ⇒ String
Returns the name for the given volume. The returned string should be freed with g_free() when no longer needed.
#get_sort_key(volume) ⇒ String
Returns Sorting key for volume or nil if no such key is available.
#get_symbolic_icon(volume) ⇒ Gio::Icon
Returns a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.
#get_uuid(volume) ⇒ String
Returns the UUID for volume or nil if no UUID can be computed. The returned string should be freed with g_free() when no longer needed.
#icon ⇒ Gio::Icon
Gets the icon for volume.
#mount(*args, &block) ⇒ nil
Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the volume and GAsync::Result returned in the callback.
20 21 22 23 24 25 26 |
# File 'lib/gio2/volume.rb', line 20 def mount(*args, &block) if args.size.zero? get_mount else mount_raw(*args, &block) end end |
#mount_finish(volume, result) ⇒ Boolean
Returns true, false if operation failed.
#mount_fn(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil
#mount_raw ⇒ nil
Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the volume and GAsync::Result returned in the callback.
|
|
# File 'lib/gio2/volume.rb', line 19
|
#name ⇒ String
Gets the name of volume.
#removed(volume) ⇒ nil
#should_automount(volume) ⇒ Boolean
Returns true if the volume should be automatically mounted.
#sort_key ⇒ String
Gets the sort key for volume, if any.
#symbolic_icon ⇒ Gio::Icon
Gets the symbolic icon for volume.
#uuid ⇒ String
Gets the UUID for the volume. The reference is typically based on the file system UUID for the volume in question and should be considered an opaque string. Returns nil if there is no UUID available.