gio: Add g_drive_is_removable() support

Nautilus wants to show entries in the sidebar only for removable devices.
It uses currently sort of conditions to determine which devices should be
shown. Those condition fails in some cases unfortunatelly. Lets provide
g_drive_is_removable() which uses udisks Removable property to determine
which devices should be shown. It should return true for all drives with
removable media, or flash media, or drives on usb and firewire buses.

https://bugzilla.gnome.org/show_bug.cgi?id=765900
This commit is contained in:
Ondrej Holy 2016-04-29 17:14:57 +02:00
parent 098f19bced
commit 7b3f6da307
3 changed files with 30 additions and 0 deletions

View File

@ -1225,6 +1225,7 @@ g_drive_poll_for_media
g_drive_poll_for_media_finish
g_drive_has_media
g_drive_is_media_check_automatic
g_drive_is_removable
g_drive_is_media_removable
g_drive_eject
g_drive_eject_finish

View File

@ -266,6 +266,31 @@ g_drive_is_media_check_automatic (GDrive *drive)
return (* iface->is_media_check_automatic) (drive);
}
/**
* g_drive_is_removable:
* @drive: a #GDrive.
*
* Checks if the #GDrive and/or its media is considered removable by the user.
* See g_drive_is_media_removable().
*
* Returns: %TRUE if @drive and/or its media is considered removable, %FALSE otherwise.
*
* Since: 2.50
**/
gboolean
g_drive_is_removable (GDrive *drive)
{
GDriveIface *iface;
g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
iface = G_DRIVE_GET_IFACE (drive);
if (iface->is_removable != NULL)
return iface->is_removable (drive);
return FALSE;
}
/**
* g_drive_is_media_removable:
* @drive: a #GDrive.

View File

@ -45,6 +45,7 @@ G_BEGIN_DECLS
* @get_icon: Returns a #GIcon for the given #GDrive.
* @has_volumes: Returns %TRUE if the #GDrive has mountable volumes.
* @get_volumes: Returns a list #GList of #GVolume for the #GDrive.
* @is_removable: Returns %TRUE if the #GDrive and/or its media is considered removable by the user. Since 2.50.
* @is_media_removable: Returns %TRUE if the #GDrive supports removal and insertion of media.
* @has_media: Returns %TRUE if the #GDrive has media inserted.
* @is_media_check_automatic: Returns %TRUE if the #GDrive is capabable of automatically detecting media changes.
@ -90,6 +91,7 @@ struct _GDriveIface
GIcon * (* get_icon) (GDrive *drive);
gboolean (* has_volumes) (GDrive *drive);
GList * (* get_volumes) (GDrive *drive);
gboolean (* is_removable) (GDrive *drive);
gboolean (* is_media_removable) (GDrive *drive);
gboolean (* has_media) (GDrive *drive);
gboolean (* is_media_check_automatic) (GDrive *drive);
@ -170,6 +172,8 @@ GLIB_AVAILABLE_IN_ALL
gboolean g_drive_has_volumes (GDrive *drive);
GLIB_AVAILABLE_IN_ALL
GList * g_drive_get_volumes (GDrive *drive);
GLIB_AVAILABLE_IN_2_50
gboolean g_drive_is_removable (GDrive *drive);
GLIB_AVAILABLE_IN_ALL
gboolean g_drive_is_media_removable (GDrive *drive);
GLIB_AVAILABLE_IN_ALL