glibmm: Gio::Drive Class Reference

glibmm 2.72.0

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::Drive Class Reference

Virtual File System drive management. More...

`#include <giomm/drive.h>`

Inheritance diagram for Gio::Drive:
[legend]

## Public Types
enum class | StartFlags { NONE = 0x0 }
| Flags used when starting a drive. More...
enum class | StartStopType { UNKNOWN , SHUTDOWN , NETWORK , MULTIDISK , PASSWORD }
| Enumeration describing how a drive can be started/stopped. More...
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify

## Public Member Functions
| Drive (Drive && src) noexcept
Drive & | operator= (Drive && src) noexcept
| ~Drive () noexcept override
GDrive * | gobj ()
| Provides access to the underlying C GObject. More...
const GDrive * | gobj () const
| Provides access to the underlying C GObject. More...
Glib::ustring | get_name () const
| Gets the name of drive. More...
Glib::RefPtr< Icon > | get_icon ()
| Gets the icon for drive. More...
Glib::RefPtr< const Icon > | get_icon () const
| Gets the icon for drive. More...
Glib::RefPtr< Icon > | get_symbolic_icon ()
| Gets the icon for drive. More...
Glib::RefPtr< const Icon > | get_symbolic_icon () const
| Gets the icon for drive. More...
bool | has_volumes () const
| Check if drive has any mountable volumes. More...
std::vector< Glib::RefPtr< Volume > > | get_volumes ()
| Get a list of mountable volumes for drive. More...
bool | is_media_removable () const
| Checks if the drive supports removable media. More...
bool | is_removable () const
| Checks if the Drive and/or its media is considered removable by the user. More...
bool | has_media () const
| Checks if the drive has media. More...
bool | is_media_check_automatic () const
| Checks if drive is capable of automatically detecting media changes. More...
bool | can_poll_for_media () const
| Checks if a drive can be polled for media changes. More...
bool | can_eject () const
| Checks if a drive can be ejected. More...
void | eject (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
| Ejects the drive. More...
void | eject (const SlotAsyncReady & slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
| Ejects the drive. More...
void | eject (const Glib::RefPtr< MountOperation > & mount_operation, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
void | eject (const Glib::RefPtr< MountOperation > & mount_operation, const SlotAsyncReady & slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
void | eject (Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
| Ejects the drive. More...
void | eject (const Glib::RefPtr< MountOperation > & mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
bool | eject_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes ejecting a drive. More...
void | poll_for_media (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable)
| Polls drive to see if media has been inserted or removed. More...
void | poll_for_media (const SlotAsyncReady & slot)
| Polls drive to see if media has been inserted or removed. More...
void | poll_for_media ()
| Polls drive to see if media has been inserted or removed. More...
bool | poll_for_media_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an operation started with g_drive_poll_for_media() on a drive. More...
std::string | get_identifier (const std::string & kind) const
| Gets the identifier of the given kind for drive. More...
std::vector< Glib::ustring > | enumerate_identifiers () const
| Gets the kinds of identifiers that drive has. More...
void | start (const Glib::RefPtr< MountOperation > & mount_operation, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot, StartFlags flags=StartFlags::NONE)
void | start (const Glib::RefPtr< MountOperation > & mount_operation, const SlotAsyncReady & slot, StartFlags flags=StartFlags::NONE)
bool | start_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes starting a drive. More...
bool | can_start () const
bool | can_start_degraded () const
void | stop (const Glib::RefPtr< MountOperation > & mount_operation, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
void | stop (const Glib::RefPtr< MountOperation > & mount_operation, const SlotAsyncReady & slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
bool | stop_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes stopping a drive. More...
bool | can_stop () const
StartStopType | get_start_stop_type () const
| Gets a hint about how a drive can be started/stopped. More...
Glib::ustring | get_sort_key () const
| Gets the sort key for drive, if any. More...
Glib::SignalProxy< void()> | signal_changed ()
Glib::SignalProxy< void()> | signal_disconnected ()
Glib::SignalProxy< void()> | signal_eject_button ()
Glib::SignalProxy< void()> | signal_stop_button ()
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor. More...
| Interface (Interface && src) noexcept
Interface & | operator= (Interface && src) noexcept
| Interface (const Glib::Interface_Class & interface_class)
| Called by constructors of derived classes. More...
| Interface (GObject * castitem)
| Called by constructors of derived classes. More...
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring & property_name, const PropertyType & value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring & property_name, PropertyType & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void()> & slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject * | gobj ()
| Provides access to the underlying C GObject. More...
const GObject * | gobj () const
| Provides access to the underlying C GObject. More...
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| Drive ()
| You should derive from this class to use it. More...
virtual void | on_changed ()
| This is a default handler for the signal signal_changed(). More...
virtual void | on_disconnected ()
| This is a default handler for the signal signal_disconnected(). More...
virtual void | on_eject_button ()
| This is a default handler for the signal signal_eject_button(). More...
virtual void | on_stop_button ()
| This is a default handler for the signal signal_stop_button(). More...
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char * custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info & custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::Drive > | wrap (GDrive * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Detailed Description

Virtual File System drive management.

This represent a piece of hardware connected to the machine. It's generally only created for removable hardware or hardware with removable media. Gio::Drive is a container class for Gio::Volume objects that stem from the same piece of media. As such, Gio::Drive abstracts a drive with (or without) removable media and provides operations for querying whether media is available, determing whether media change is automatically detected and ejecting the media.

If the Gio::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 potententially expensive and may spin up the drive, creating noise.

Since glibmm 2.16:

## Constructor & Destructor Documentation

## ◆ Drive() [1/2]

Gio::Drive::Drive | ( |  | ) |
| protected

You should derive from this class to use it.

## ◆ Drive() [2/2]

Gio::Drive::Drive | ( | Drive && | src | ) |
| noexcept

## ◆ ~Drive()

Gio::Drive::~Drive | ( |  | ) |
| overridenoexcept

## Member Function Documentation

## ◆ add_interface()

static void Gio::Drive::add_interface | ( | GType | gtype_implementer | ) |
| static

## ◆ can_eject()

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

Checks if a drive can be ejected.

Returns
  `true` if the drive can be ejected, `false` otherwise.

## ◆ can_poll_for_media()

bool Gio::Drive::can_poll_for_media | ( |  | ) | const

Checks if a drive can be polled for media changes.

Returns
  `true` if the drive can be polled for media changes, `false` otherwise.

## ◆ can_start()

bool Gio::Drive::can_start | ( |  | ) | const

Since glibmm 2.22:

## ◆ can_start_degraded()

bool Gio::Drive::can_start_degraded | ( |  | ) | const

Since glibmm 2.22:

## ◆ can_stop()

bool Gio::Drive::can_stop | ( |  | ) | const

Since glibmm 2.22:

## ◆ eject() [1/6]

void Gio::Drive::eject | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

## ◆ eject() [2/6]

void Gio::Drive::eject | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

## ◆ eject() [3/6]

void Gio::Drive::eject | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

## ◆ eject() [4/6]

void Gio::Drive::eject | ( | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

Ejects the drive.

Parameters

  slot | A callback which will be called when the eject is completed or canceled.
  flags | Flags affecting the unmount if required for eject.
  cancellable | A cancellable object which can be used to cancel the eject.

## ◆ eject() [5/6]

void Gio::Drive::eject | ( | const SlotAsyncReady & | slot,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

Ejects the drive.

Parameters

  slot | A callback which will be called when the eject is completed.
  flags | Flags affecting the unmount if required for eject.

## ◆ eject() [6/6]

void Gio::Drive::eject | ( | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE` | ) |

Ejects the drive.

Parameters

  flags | Flags affecting the unmount if required for eject.

## ◆ eject_finish()

bool Gio::Drive::eject_finish | ( | const Glib::RefPtr< 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.

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  `true` if the drive was successfully ejected. `false` otherwise.

Exceptions

  Glib::Error |

## ◆ enumerate_identifiers()

std::vector<Glib::ustring> Gio::Drive::enumerate_identifiers | ( |  | ) | const

Gets the kinds of identifiers that drive has.

Use g_drive_get_identifier() to obtain the identifiers themselves.

Returns
  A `nullptr`-terminated array of strings containing kinds of identifiers.

## ◆ get_icon() [1/2]

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

Gets the icon for drive.

Returns
  Icon for the drive. Free the returned object with Glib::object_unref().

## ◆ get_icon() [2/2]

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

Gets the icon for drive.

Returns
  Icon for the drive. Free the returned object with Glib::object_unref().

## ◆ get_identifier()

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

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 `nullptr` if the Drive doesn't have this kind of identifier.

## ◆ get_name()

Glib::ustring Gio::Drive::get_name | ( |  | ) | const

Gets the name of drive.

Returns
  A string containing drive's name. The returned string should be freed when no longer needed.

## ◆ get_sort_key()

Glib::ustring Gio::Drive::get_sort_key | ( |  | ) | const

Gets the sort key for drive, if any.

Since glibmm 2.32:

Returns
  Sorting key for drive or `nullptr` if no such key is available.

## ◆ get_start_stop_type()

StartStopType Gio::Drive::get_start_stop_type | ( |  | ) | const

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

Since glibmm 2.22:

Returns
  A value from the Gio::Drive::StartStopType enumeration.

## ◆ get_symbolic_icon() [1/2]

Glib::RefPtr<Icon> Gio::Drive::get_symbolic_icon | ( |  | ) |

Gets the icon for drive.

Since glibmm 2.34:

Returns
  Symbolic Icon for the drive. Free the returned object with Glib::object_unref().

## ◆ get_symbolic_icon() [2/2]

Glib::RefPtr<const Icon> Gio::Drive::get_symbolic_icon | ( |  | ) | const

Gets the icon for drive.

Since glibmm 2.34:

Returns
  Symbolic Icon for the drive. Free the returned object with Glib::object_unref().

## ◆ get_type()

static GType Gio::Drive::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ get_volumes()

std::vector<Glib::RefPtr<Volume> > Gio::Drive::get_volumes | ( |  | ) |

Get a list of mountable volumes for drive.

Returns
  List containing any Volume objects on the given drive.

## ◆ gobj() [1/2]

GDrive* Gio::Drive::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GDrive* Gio::Drive::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ has_media()

bool Gio::Drive::has_media | ( |  | ) | const

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.

## ◆ has_volumes()

bool Gio::Drive::has_volumes | ( |  | ) | const

Check if drive has any mountable volumes.

Returns
  `true` if the drive contains volumes, `false` otherwise.

## ◆ is_media_check_automatic()

bool Gio::Drive::is_media_check_automatic | ( |  | ) | const

Checks if drive is capable of automatically detecting media changes.

Returns
  `true` if the drive is capable of automatically detecting media changes, `false` otherwise.

## ◆ is_media_removable()

bool Gio::Drive::is_media_removable | ( |  | ) | const

Checks if the drive supports removable media.

Returns
  `true` if drive supports removable media, `false` otherwise.

## ◆ is_removable()

bool Gio::Drive::is_removable | ( |  | ) | const

Checks if the Drive and/or its media is considered removable by the user.

See g_drive_is_media_removable().

Since glibmm 2.50:

Returns
  `true` if drive and/or its media is considered removable, `false` otherwise.

## ◆ on_changed()

virtual void Gio::Drive::on_changed | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_changed().

## ◆ on_disconnected()

virtual void Gio::Drive::on_disconnected | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_disconnected().

## ◆ on_eject_button()

virtual void Gio::Drive::on_eject_button | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_eject_button().

## ◆ on_stop_button()

virtual void Gio::Drive::on_stop_button | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_stop_button().

## ◆ operator=()

Drive& Gio::Drive::operator= | ( | Drive && | src | ) |
| noexcept

## ◆ poll_for_media() [1/3]

void Gio::Drive::poll_for_media | ( |  | ) |

Polls drive to see if media has been inserted or removed.

## ◆ poll_for_media() [2/3]

void Gio::Drive::poll_for_media | ( | const SlotAsyncReady & | slot | ) |

Polls drive to see if media has been inserted or removed.

Parameters

  slot | A callback which will be called when the poll is completed.

## ◆ poll_for_media() [3/3]

void Gio::Drive::poll_for_media | ( | const SlotAsyncReady & | slot,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

Polls drive to see if media has been inserted or removed.

Parameters

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

## ◆ poll_for_media_finish()

bool Gio::Drive::poll_for_media_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an operation started with g_drive_poll_for_media() on a drive.

Parameters

  result | A AsyncResult.

Returns
  `true` if the drive has been poll_for_mediaed successfully, `false` otherwise.

Exceptions

  Glib::Error |

## ◆ signal_changed()

Glib::SignalProxy<void()> Gio::Drive::signal_changed | ( |  | ) |

Slot Prototype:
  `void on_my_changed()`

Flags: Run Last

Emitted when the drive's state has changed.

Since glibmm 2.20:

## ◆ signal_disconnected()

Glib::SignalProxy<void()> Gio::Drive::signal_disconnected | ( |  | ) |

Slot Prototype:
  `void on_my_disconnected()`

Flags: Run Last

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

Since glibmm 2.20:

## ◆ signal_eject_button()

Glib::SignalProxy<void()> Gio::Drive::signal_eject_button | ( |  | ) |

Slot Prototype:
  `void on_my_eject_button()`

Flags: Run Last

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

Since glibmm 2.20:

## ◆ signal_stop_button()

Glib::SignalProxy<void()> Gio::Drive::signal_stop_button | ( |  | ) |

Slot Prototype:
  `void on_my_stop_button()`

Flags: Run Last

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

Since glibmm 2.22:

## ◆ start() [1/2]

void Gio::Drive::start | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot,
|  | StartFlags | flags = `StartFlags::NONE`
| ) |  |

Since glibmm 2.22:

## ◆ start() [2/2]

void Gio::Drive::start | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | StartFlags | flags = `StartFlags::NONE`
| ) |  |

Since glibmm 2.22:

## ◆ start_finish()

bool Gio::Drive::start_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes starting a drive.

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  `true` if the drive has been started successfully, `false` otherwise.

Exceptions

  Glib::Error |

## ◆ stop() [1/2]

void Gio::Drive::stop | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

Since glibmm 2.22:

## ◆ stop() [2/2]

void Gio::Drive::stop | ( | const Glib::RefPtr< MountOperation > & | mount_operation,
|  | const SlotAsyncReady & | slot,
|  | Mount::UnmountFlags | flags = `Mount::UnmountFlags::NONE`
| ) |  |

Since glibmm 2.22:

## ◆ stop_finish()

bool Gio::Drive::stop_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes stopping a drive.

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  `true` if the drive has been stopped successfully, `false` otherwise.

Exceptions

  Glib::Error |

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gio::Drive > wrap | ( | GDrive * | 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.