Skip to content

Gio.VolumeMonitor

class — extends GObject.Object

GVolumeMonitor is for listing the user interesting devices and volumes on the computer. In other words, what a file selector or file manager would show in a sidebar.

GVolumeMonitor is not thread-default-context aware (see GLib.MainContext.push_thread_default), and so should not be used other than from the main thread, with no thread-default-context active.

In order to receive updates about volumes and mounts monitored through GVFS, a main loop must be running.

Methods

get_connected_drives

def get_connected_drives(self) -> list[Drive]

Gets a list of drives connected to the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

get_mount_for_uuid

def get_mount_for_uuid(self, uuid: str) -> Mount | None

Finds a Mount object by its UUID (see Mount.get_uuid)

Parameters:

  • uuid — the UUID to look for

get_mounts

def get_mounts(self) -> list[Mount]

Gets a list of the mounts on the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

get_volume_for_uuid

def get_volume_for_uuid(self, uuid: str) -> Volume | None

Finds a Volume object by its UUID (see Volume.get_uuid)

Parameters:

  • uuid — the UUID to look for

get_volumes

def get_volumes(self) -> list[Volume]

Gets a list of the volumes on the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

Static functions

adopt_orphan_mount

@staticmethod
def adopt_orphan_mount(mount: Mount) -> Volume

:::warning Deprecated since 2.20 This API is deprecated. :::

This function should be called by any VolumeMonitor implementation when a new Mount object is created that is not associated with a Volume object. It must be called just before emitting the mount_added signal.

If the return value is not None, the caller must associate the returned Volume object with the Mount. This involves returning it in its Mount.get_volume implementation. The caller must also listen for the "removed" signal on the returned object and give up its reference when handling that signal

Similarly, if implementing VolumeMonitor.adopt_orphan_mount, the implementor must take a reference to mount and return it in its Volume.get_mount implemented. Also, the implementor must listen for the "unmounted" signal on mount and give up its reference upon handling that signal.

There are two main use cases for this function.

One is when implementing a user space file system driver that reads blocks of a block device that is already represented by the native volume monitor (for example a CD Audio file system driver). Such a driver will generate its own Mount object that needs to be associated with the Volume object that represents the volume.

The other is for implementing a VolumeMonitor whose sole purpose is to return Volume objects representing entries in the users "favorite servers" list or similar.

Parameters:

  • mount — a Mount object to find a parent for

get

@staticmethod
def get() -> VolumeMonitor

Gets the volume monitor used by gio.

Virtual methods

do_drive_changed

def do_drive_changed(self, drive: Drive) -> None

do_drive_connected

def do_drive_connected(self, drive: Drive) -> None

do_drive_disconnected

def do_drive_disconnected(self, drive: Drive) -> None

do_drive_eject_button

def do_drive_eject_button(self, drive: Drive) -> None

do_drive_stop_button

def do_drive_stop_button(self, drive: Drive) -> None

do_get_connected_drives

def do_get_connected_drives(self) -> list[Drive]

Gets a list of drives connected to the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

do_get_mount_for_uuid

def do_get_mount_for_uuid(self, uuid: str) -> Mount | None

Finds a Mount object by its UUID (see Mount.get_uuid)

Parameters:

  • uuid — the UUID to look for

do_get_mounts

def do_get_mounts(self) -> list[Mount]

Gets a list of the mounts on the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

do_get_volume_for_uuid

def do_get_volume_for_uuid(self, uuid: str) -> Volume | None

Finds a Volume object by its UUID (see Volume.get_uuid)

Parameters:

  • uuid — the UUID to look for

do_get_volumes

def do_get_volumes(self) -> list[Volume]

Gets a list of the volumes on the system.

The returned list should be freed with g_list_free(), after its elements have been unreffed with GObject.Object.unref.

do_mount_added

def do_mount_added(self, mount: Mount) -> None

do_mount_changed

def do_mount_changed(self, mount: Mount) -> None

do_mount_pre_unmount

def do_mount_pre_unmount(self, mount: Mount) -> None

do_mount_removed

def do_mount_removed(self, mount: Mount) -> None

do_volume_added

def do_volume_added(self, volume: Volume) -> None

do_volume_changed

def do_volume_changed(self, volume: Volume) -> None

do_volume_removed

def do_volume_removed(self, volume: Volume) -> None

Signals

drive-changed

def on_drive_changed(self, drive: Drive) -> None: ...

Emitted when a drive changes.

drive-connected

def on_drive_connected(self, drive: Drive) -> None: ...

Emitted when a drive is connected to the system.

drive-disconnected

def on_drive_disconnected(self, drive: Drive) -> None: ...

Emitted when a drive is disconnected from the system.

drive-eject-button

def on_drive_eject_button(self, drive: Drive) -> None: ...

Emitted when the eject button is pressed on drive.

drive-stop-button

def on_drive_stop_button(self, drive: Drive) -> None: ...

Emitted when the stop button is pressed on drive.

mount-added

def on_mount_added(self, mount: Mount) -> None: ...

Emitted when a mount is added.

mount-changed

def on_mount_changed(self, mount: Mount) -> None: ...

Emitted when a mount changes.

mount-pre-unmount

def on_mount_pre_unmount(self, mount: Mount) -> None: ...

May be emitted when a mount is about to be removed.

This signal depends on the backend and is only emitted if GIO was used to unmount.

mount-removed

def on_mount_removed(self, mount: Mount) -> None: ...

Emitted when a mount is removed.

volume-added

def on_volume_added(self, volume: Volume) -> None: ...

Emitted when a mountable volume is added to the system.

volume-changed

def on_volume_changed(self, volume: Volume) -> None: ...

Emitted when mountable volume is changed.

volume-removed

def on_volume_removed(self, volume: Volume) -> None: ...

Emitted when a mountable volume is removed from the system.