# Gio::Volume Class Reference

The Volume interface represents user-visible objects that can be mounted. More...

`#include <giomm/volume.h>`

Inheritance diagram for Gio::Volume:
[legend]

List of all members.

## Public Member Functions
virtual | ~Volume ()
GVolume* | gobj ()
| Provides access to the underlying C GObject.
const GVolume* | gobj () const
| Provides access to the underlying C GObject.
std::string | get_name () const
| Gets the name of volume.
std::string | get_uuid () const
| Gets the UUID for the volume.
Glib::RefPtr< Icon > | get_icon ()
| Gets the icon for volume.
Glib::RefPtr< const Icon > | get_icon () const
| Gets the icon for volume.
Glib::RefPtr< Drive > | get_drive ()
| Gets the drive for the volume.
Glib::RefPtr< const Drive > | get_drive () const
| Gets the drive for the volume.
Glib::RefPtr< Mount > | get_mount ()
| Gets the mount for the volume.
Glib::RefPtr< const Mount > | get_mount () const
| Gets the mount for the volume.
bool | can_mount () const
| Checks if a volume can be mounted.
bool | can_eject () const
| Checks if a volume can be ejected.
bool | should_automount () const
| Returns whether the volume should be automatically mounted.
void | mount (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, MountMountFlags flags=MOUNT_MOUNT_NONE)
| Mounts a volume.
void | mount (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, MountMountFlags flags=MOUNT_MOUNT_NONE)
| Mounts a volume.
void | mount (const Glib::RefPtr< MountOperation >& mount_operation, MountMountFlags flags=MOUNT_MOUNT_NONE)
| Mounts a volume.
void | mount (MountMountFlags flags=MOUNT_MOUNT_NONE)
| Mounts a volume.
bool | mount_finish (const Glib::RefPtr< AsyncResult >& result)
| Finishes mounting a volume.
void | eject (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
void | eject (const SlotAsyncReady& slot, MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
void | eject (MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
void | eject (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
void | eject (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
void | eject (const Glib::RefPtr< MountOperation >& mount_operation, MountUnmountFlags flags=MOUNT_UNMOUNT_NONE)
bool | eject_finish (const Glib::RefPtr< AsyncResult >& result)
| Finishes ejecting a volume.
std::string | get_identifier (const std::string& kind) const
| Gets the identifier of the given kind for volume.
Glib::StringArrayHandle | enumerate_identifiers () const
| Gets the kinds of <link linkend="volume-identifier">identifiers</link> that volume has.
Glib::RefPtr< File > | get_activation_root ()
| Gets the activation root for a Volume if it is known ahead of mount time.
Glib::RefPtr< const File > | get_activation_root () const
| Gets the activation root for a Volume if it is known ahead of mount time.
Glib::SignalProxy0< void > | signal_changed ()
Glib::SignalProxy0< void > | signal_removed ()
## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
## Protected Member Functions
virtual void | on_changed ()
virtual void | on_removed ()
## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::Volume > | wrap (GVolume* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

The Volume interface represents user-visible objects that can be mounted.

Mounting a Volume instance is an asynchronous operation. For more information about asynchronous operations, see AsyncReady and SimpleAsyncReady. To mount a GVolume, first call mount(), optionally providing a MountOperation object and a SlotAsyncReady callback.

Typically, you will not want to provide a 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 AsyncReady structure will be passed to the callback. That callback should then call g_volume_mount_finish() with the GVolume instance and the GAsyncReady data to see if the operation was completed successfully. If an error is present when finish() is called, then it will be filled with any error information.

Since glibmm 2.16:

## Constructor & Destructor Documentation

virtual Gio::Volume::~Volume | ( |  | ) | `[virtual]`

## Member Function Documentation

static void Gio::Volume::add_interface | ( | GType | gtype_implementer | ) | `[static]`

bool Gio::Volume::can_eject | ( |  | ) | const

Checks if a volume can be ejected.

Returns:
  `true` if the volume can be ejected. `false` otherwise.

bool Gio::Volume::can_mount | ( |  | ) | const

Checks if a volume can be mounted.

Returns:
  `true` if the volume can be mounted. `false` otherwise.

void Gio::Volume::eject | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` |
| ) |  |  |

void Gio::Volume::eject | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` |
| ) |  |  |

void Gio::Volume::eject | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` |
| ) |  |  |

void Gio::Volume::eject | ( | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` | ) |

void Gio::Volume::eject | ( | const SlotAsyncReady & | slot,
|  | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` |
| ) |  |  |

void Gio::Volume::eject | ( | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | MountUnmountFlags | flags = `MOUNT_UNMOUNT_NONE` |
| ) |  |  |

bool Gio::Volume::eject_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Finishes ejecting a volume.

If any errors occurred during the operation, error will be set to contain the errors and `false` will be returned.

Since glibmm 2.22:

Parameters:

  | result | A AsyncResult.

Returns:
  `true` if the volume was successfully ejected. `false` otherwise.

Glib::StringArrayHandle Gio::Volume::enumerate_identifiers | ( |  | ) | const

Gets the kinds of <link linkend="volume-identifier">identifiers</link> that volume has.

Use Glib::volume_get_identifer() to obtain the identifiers themselves.

Returns:
  A `0`-terminated array of strings containing kinds of identifiers. Use Glib::strfreev() to free.

Glib::RefPtr<const File> Gio::Volume::get_activation_root | ( |  | ) | const

Gets the activation root for a Volume if it is known ahead of mount time.

Returns `0` otherwise. If not `0` and if volume is mounted, then the result of g_mount_get_root() on the Mount 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

<programlisting> GMount *mount; GFile *mount_root GFile *volume_activation_root;

mount = g_volume_get_mount (volume); // mounted, so never `0` mount_root = g_mount_get_root (mount); volume_activation_root = g_volume_get_activation_root(volume); // assume not `0` </programlisting>

then the expression

<programlisting> (g_file_has_prefix (volume_activation_root, mount_root) || g_file_equal (volume_activation_root, mount_root)) </programlisting>

will always be `true`.

Activation roots are typically used in VolumeMonitor implementations to find the underlying mount to shadow, see g_mount_is_shadowed() for more details.

Returns:
  The activation root of volume or `0`. Use Glib::object_unref() to free.

Since glibmm 2.18:

Glib::RefPtr<File> Gio::Volume::get_activation_root | ( |  | ) |

Gets the activation root for a Volume if it is known ahead of mount time.

Returns `0` otherwise. If not `0` and if volume is mounted, then the result of g_mount_get_root() on the Mount 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

<programlisting> GMount *mount; GFile *mount_root GFile *volume_activation_root;

mount = g_volume_get_mount (volume); // mounted, so never `0` mount_root = g_mount_get_root (mount); volume_activation_root = g_volume_get_activation_root(volume); // assume not `0` </programlisting>

then the expression

<programlisting> (g_file_has_prefix (volume_activation_root, mount_root) || g_file_equal (volume_activation_root, mount_root)) </programlisting>

will always be `true`.

Activation roots are typically used in VolumeMonitor implementations to find the underlying mount to shadow, see g_mount_is_shadowed() for more details.

Returns:
  The activation root of volume or `0`. Use Glib::object_unref() to free.

Since glibmm 2.18:

Glib::RefPtr<const Drive> Gio::Volume::get_drive | ( |  | ) | const

Gets the drive for the volume.

Returns:
  A Drive or `0` if volume is not associated with a drive. The returned object should be unreffed with Glib::object_unref() when no longer needed.

Glib::RefPtr<Drive> Gio::Volume::get_drive | ( |  | ) |

Gets the drive for the volume.

Returns:
  A Drive or `0` if volume is not associated with a drive. The returned object should be unreffed with Glib::object_unref() when no longer needed.

Glib::RefPtr<const Icon> Gio::Volume::get_icon | ( |  | ) | const

Gets the icon for volume.

Returns:
  A Icon. The returned object should be unreffed with Glib::object_unref() when no longer needed.

Glib::RefPtr<Icon> Gio::Volume::get_icon | ( |  | ) |

Gets the icon for volume.

Returns:
  A Icon. The returned object should be unreffed with Glib::object_unref() when no longer needed.

std::string Gio::Volume::get_identifier | ( | const std::string & | kind | ) | const

Gets the identifier of the given kind for volume.

See the <link linkend="volume-identifier">introduction</link> for more information about volume identifiers.

Parameters:

  | kind | The kind of identifier to return.

Returns:
  A newly allocated string containing the requested identfier, or `0` if the Volume doesn't have this kind of identifier.

Glib::RefPtr<const Mount> Gio::Volume::get_mount | ( |  | ) | const

Gets the mount for the volume.

Returns:
  A Mount or `0` if volume isn't mounted. The returned object should be unreffed with Glib::object_unref() when no longer needed.

Glib::RefPtr<Mount> Gio::Volume::get_mount | ( |  | ) |

Gets the mount for the volume.

Returns:
  A Mount or `0` if volume isn't mounted. The returned object should be unreffed with Glib::object_unref() when no longer needed.

std::string Gio::Volume::get_name | ( |  | ) | const

Gets the name of volume.

Returns:
  The name for the given volume. The returned string should be freed with Glib::free() when no longer needed.

std::string Gio::Volume::get_uuid | ( |  | ) | const

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 `0` if there is no UUID available.

Returns:
  The UUID for volume or `0` if no UUID can be computed. The returned string should be freed with Glib::free() when no longer needed.

const GVolume* Gio::Volume::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::Interface.

GVolume* Gio::Volume::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::Interface.

void Gio::Volume::mount | ( | MountMountFlags | flags = `MOUNT_MOUNT_NONE` | ) |

Mounts a volume.

void Gio::Volume::mount | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | MountMountFlags | flags = `MOUNT_MOUNT_NONE` |
| ) |  |  |

Mounts a volume.

Parameters:

  | mount_operation | A mount operation.

void Gio::Volume::mount | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | MountMountFlags | flags = `MOUNT_MOUNT_NONE` |
| ) |  |  |

Mounts a volume.

This is an asynchronous operation, and is finished by calling mount_finish() with the AsyncResult data returned in the callback slot.

Parameters:

  | slot | A callback which will be called when the operation is completed or canceled.
  | mount_operation | A mount operation.

void Gio::Volume::mount | ( | const Glib::RefPtr< MountOperation >& | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | MountMountFlags | flags = `MOUNT_MOUNT_NONE` |
| ) |  |  |

Mounts a volume.

This is an asynchronous operation, and is finished by calling mount_finish() with the AsyncResult data returned in the callback slot.

Parameters:

  | slot | A callback which will be called when the operation is completed or canceled.
  | cancellable | A cancellable object which can be used to cancel the operation.
  | mount_operation | A mount operation.

bool Gio::Volume::mount_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Finishes mounting a volume.

If any errors occured during the operation, error will be set to contain the errors and `false` will be returned.

If the mount operation succeeded, g_volume_get_mount() on volume is guaranteed to return the mount right after calling this function; there's no need to listen for the 'mount-added' signal on VolumeMonitor.

Parameters:

  | result | A AsyncResult.

Returns:
  `true`, `false` if operation failed.

virtual void Gio::Volume::on_changed | ( |  | ) | `[protected, virtual]`

virtual void Gio::Volume::on_removed | ( |  | ) | `[protected, virtual]`

bool Gio::Volume::should_automount | ( |  | ) | const

Returns whether the volume should be automatically mounted.

Returns:
  `true` if the volume should be automatically mounted.

Glib::SignalProxy0< void > Gio::Volume::signal_changed | ( |  | ) |

Prototype:
  `void on_my_changed()`

Glib::SignalProxy0< void > Gio::Volume::signal_removed | ( |  | ) |

Prototype:
  `void on_my_removed()`

## Friends And Related Function Documentation

Glib::RefPtr< Gio::Volume > wrap | ( | GVolume * | object,
|  | bool | take_copy = `false` |
| ) |  |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  | object | The C instance.
  | take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.