VolumeMonitor
- class VolumeMonitor(*args, **kwargs)
Superclasses: Object
Subclasses: NativeVolumeMonitor
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
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
- class VolumeMonitor
- adopt_orphan_mount(mount: Mount) Volume
This function should be called by any
VolumeMonitor
implementation when a newMount
object is created that is not associated with aVolume
object. It must be called just before emitting themount_added
signal.If the return value is not
None
, the caller must associate the returnedVolume
object with theMount
. This involves returning it in itsget_volume()
implementation. The caller must also listen for the “removed” signal on the returned object and give up its reference when handling that signalSimilarly, if implementing
adopt_orphan_mount()
, the implementor must take a reference tomount
and return it in itsget_mount()
implemented. Also, the implementor must listen for the “unmounted” signal onmount
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 theVolume
object that represents the volume.The other is for implementing a
VolumeMonitor
whose sole purpose is to returnVolume
objects representing entries in the users “favorite servers” list or similar.Deprecated since version 2.20: Instead of using this function,
VolumeMonitor
implementations should instead create shadow mounts with the URI of the mount they intend to adopt. See the proxy volume monitor in gvfs for an example of this. Also seeis_shadowed()
,shadow()
andunshadow()
functions.- Parameters:
mount – a
Mount
object to find a parent for
- get() VolumeMonitor
Gets the volume monitor used by gio.
- get_connected_drives() list[Drive]
Gets a list of drives connected to the system.
The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
- get_mount_for_uuid(uuid: str) Mount | None
Finds a
Mount
object by its UUID (seeget_uuid()
)- Parameters:
uuid – the UUID to look for
- get_mounts() list[Mount]
Gets a list of the mounts on the system.
The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
Signals
- class VolumeMonitor.signals
- drive_changed(drive: Drive) None
Emitted when a drive changes.
- Parameters:
drive – the drive that changed
- drive_connected(drive: Drive) None
Emitted when a drive is connected to the system.
- Parameters:
drive – a
Drive
that was connected.
- drive_disconnected(drive: Drive) None
Emitted when a drive is disconnected from the system.
- Parameters:
drive – a
Drive
that was disconnected.
- drive_eject_button(drive: Drive) None
Emitted when the eject button is pressed on
drive
.Added in version 2.18.
- Parameters:
drive – the drive where the eject button was pressed
- drive_stop_button(drive: Drive) None
Emitted when the stop button is pressed on
drive
.Added in version 2.22.
- Parameters:
drive – the drive where the stop button was pressed
- mount_added(mount: Mount) None
Emitted when a mount is added.
- Parameters:
mount – a
Mount
that was added.
- mount_changed(mount: Mount) None
Emitted when a mount changes.
- Parameters:
mount – a
Mount
that changed.
- mount_pre_unmount(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.
- Parameters:
mount – a
Mount
that is being unmounted.
- mount_removed(mount: Mount) None
Emitted when a mount is removed.
- Parameters:
mount – a
Mount
that was removed.
- volume_added(volume: Volume) None
Emitted when a mountable volume is added to the system.
- Parameters:
volume – a
Volume
that was added.
Virtual Methods
- class VolumeMonitor
-
- do_get_connected_drives() list[Drive]
Gets a list of drives connected to the system.
The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
- do_get_mount_for_uuid(uuid: str) Mount | None
Finds a
Mount
object by its UUID (seeget_uuid()
)- Parameters:
uuid – the UUID to look for
- do_get_mounts() list[Mount]
Gets a list of the mounts on the system.
The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
- do_get_volume_for_uuid(uuid: str) Volume | None
Finds a
Volume
object by its UUID (seeget_uuid()
)- Parameters:
uuid – the UUID to look for