[gvfs] monitor: Add g_drive_is_removable() support
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] monitor: Add g_drive_is_removable() support
- Date: Fri, 20 May 2016 08:53:02 +0000 (UTC)
commit b7986553f898976bade0f4dc2f042c30ec550255
Author: Ondrej Holy <oholy redhat com>
Date: Fri Apr 29 16:59:41 2016 +0200
monitor: 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.
Add support for this property also in gvfs-mount tool.
Bump GLib version accordingly.
https://bugzilla.gnome.org/show_bug.cgi?id=765457
configure.ac | 2 +-
monitor/proxy/gproxydrive.c | 25 ++++++++++++++++++++++++-
monitor/proxy/gvfsproxyvolumemonitordaemon.c | 4 ++++
monitor/udisks2/gvfsudisks2drive.c | 17 +++++++++++++++--
programs/gvfs-mount.c | 1 +
5 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4768691..7207026 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,7 @@ GTK_DOC_CHECK
DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
-PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.45.7 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0])
+PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.49.1 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0])
PKG_CHECK_MODULES([DBUS], [dbus-1])
diff --git a/monitor/proxy/gproxydrive.c b/monitor/proxy/gproxydrive.c
index a8ac61d..8cb5e6a 100644
--- a/monitor/proxy/gproxydrive.c
+++ b/monitor/proxy/gproxydrive.c
@@ -53,6 +53,7 @@ struct _GProxyDrive {
gboolean can_poll_for_media;
gboolean is_media_check_automatic;
gboolean has_media;
+ gboolean is_removable;
gboolean is_media_removable;
gboolean can_start;
gboolean can_start_degraded;
@@ -141,6 +142,7 @@ g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor)
* dict:string->string identifiers
* string sort_key
* a{sv} expansion
+ * boolean is-removable
*/
#define DRIVE_STRUCT_TYPE "(&s&s&s&sbbbbbbbbuasa{ss}&sa{sv})"
@@ -168,6 +170,8 @@ g_proxy_drive_update (GProxyDrive *drive,
GVariantIter *iter_volume_ids;
GVariantIter *iter_identifiers;
GVariantIter *iter_expansion;
+ GVariant *value;
+ const gchar *key;
sort_key = NULL;
@@ -238,7 +242,12 @@ g_proxy_drive_update (GProxyDrive *drive,
drive->volume_ids = g_strdupv ((char **) volume_ids->pdata);
drive->sort_key = g_strdup (sort_key);
- /* TODO: decode expansion, once used */
+ drive->is_removable = FALSE;
+ while (g_variant_iter_loop (iter_expansion, "{sv}", &key, &value))
+ {
+ if (g_str_equal (key, "is-removable"))
+ drive->is_removable = g_variant_get_boolean (value);
+ }
out:
g_variant_iter_free (iter_volume_ids);
@@ -335,6 +344,19 @@ g_proxy_drive_has_volumes (GDrive *drive)
}
static gboolean
+g_proxy_drive_is_removable (GDrive *drive)
+{
+ GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
+ gboolean res;
+
+ G_LOCK (proxy_drive);
+ res = proxy_drive->is_removable;
+ G_UNLOCK (proxy_drive);
+
+ return res;
+}
+
+static gboolean
g_proxy_drive_is_media_removable (GDrive *drive)
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
@@ -1152,6 +1174,7 @@ g_proxy_drive_drive_iface_init (GDriveIface *iface)
iface->get_symbolic_icon = g_proxy_drive_get_symbolic_icon;
iface->has_volumes = g_proxy_drive_has_volumes;
iface->get_volumes = g_proxy_drive_get_volumes;
+ iface->is_removable = g_proxy_drive_is_removable;
iface->is_media_removable = g_proxy_drive_is_media_removable;
iface->has_media = g_proxy_drive_has_media;
iface->is_media_check_automatic = g_proxy_drive_is_media_check_automatic;
diff --git a/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
index 768d307..9a2e8da 100644
--- a/monitor/proxy/gvfsproxyvolumemonitordaemon.c
+++ b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
@@ -531,6 +531,7 @@ static void monitor_try_create (void);
* dict:string->string identifiers
* string sort_key
* a{sv} expansion
+ * boolean is-removable
*/
#define DRIVE_STRUCT_TYPE "(ssssbbbbbbbbuasa{ss}sa{sv})"
@@ -546,6 +547,7 @@ drive_to_dbus (GDrive *drive)
gboolean can_eject;
gboolean can_poll_for_media;
gboolean has_media;
+ gboolean is_removable;
gboolean is_media_removable;
gboolean is_media_check_automatic;
gboolean can_start;
@@ -577,6 +579,7 @@ drive_to_dbus (GDrive *drive)
can_eject = g_drive_can_eject (drive);
can_poll_for_media = g_drive_can_poll_for_media (drive);
has_media = g_drive_has_media (drive);
+ is_removable = g_drive_is_removable (drive);
is_media_removable = g_drive_is_media_removable (drive);
is_media_check_automatic = g_drive_is_media_check_automatic (drive);
can_start = g_drive_can_start (drive);
@@ -616,6 +619,7 @@ drive_to_dbus (GDrive *drive)
}
expansion_builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
+ g_variant_builder_add (expansion_builder, "{sv}", "is-removable", g_variant_new_boolean (is_removable));
/* left for future expansion without ABI breaks */
for (n = 0; identifiers != NULL && identifiers[n] != NULL; n++)
diff --git a/monitor/udisks2/gvfsudisks2drive.c b/monitor/udisks2/gvfsudisks2drive.c
index 8da76a1..021b0a2 100644
--- a/monitor/udisks2/gvfsudisks2drive.c
+++ b/monitor/udisks2/gvfsudisks2drive.c
@@ -60,6 +60,7 @@ struct _GVfsUDisks2Drive
gchar *sort_key;
gchar *device_file;
dev_t dev;
+ gboolean is_removable;
gboolean is_media_removable;
gboolean has_media;
gboolean can_eject;
@@ -146,6 +147,7 @@ update_drive (GVfsUDisks2Drive *drive)
gchar *old_sort_key;
gchar *old_device_file;
dev_t old_dev;
+ gboolean old_is_removable;
gboolean old_is_media_removable;
gboolean old_has_media;
gboolean old_can_eject;
@@ -160,6 +162,7 @@ update_drive (GVfsUDisks2Drive *drive)
/* ---------------------------------------------------------------------------------------------------- */
/* save old values */
+ old_is_removable = drive->is_removable;
old_is_media_removable = drive->is_media_removable;
old_has_media = drive->has_media;
old_can_eject = drive->can_eject;
@@ -175,7 +178,7 @@ update_drive (GVfsUDisks2Drive *drive)
/* ---------------------------------------------------------------------------------------------------- */
/* reset */
- drive->is_media_removable = drive->has_media = drive->can_eject = drive->can_stop = FALSE;
+ drive->is_removable = drive->is_media_removable = drive->has_media = drive->can_eject = drive->can_stop =
FALSE;
g_free (drive->name); drive->name = NULL;
g_free (drive->sort_key); drive->sort_key = NULL;
g_free (drive->device_file); drive->device_file = NULL;
@@ -199,6 +202,7 @@ update_drive (GVfsUDisks2Drive *drive)
drive->sort_key = g_strdup (udisks_drive_get_sort_key (drive->udisks_drive));
+ drive->is_removable = udisks_drive_get_removable (drive->udisks_drive);
drive->is_media_removable = udisks_drive_get_media_removable (drive->udisks_drive);
if (drive->is_media_removable)
{
@@ -294,7 +298,8 @@ update_drive (GVfsUDisks2Drive *drive)
/* ---------------------------------------------------------------------------------------------------- */
/* compute whether something changed */
- changed = !((old_is_media_removable == drive->is_media_removable) &&
+ changed = !((old_is_removable == drive->is_removable) &&
+ (old_is_media_removable == drive->is_media_removable) &&
(old_has_media == drive->has_media) &&
(old_can_eject == drive->can_eject) &&
(old_can_stop == drive->can_stop) &&
@@ -434,6 +439,13 @@ gvfs_udisks2_drive_has_volumes (GDrive *_drive)
}
static gboolean
+gvfs_udisks2_drive_is_removable (GDrive *_drive)
+{
+ GVfsUDisks2Drive *drive = GVFS_UDISKS2_DRIVE (_drive);
+ return drive->is_removable;
+}
+
+static gboolean
gvfs_udisks2_drive_is_media_removable (GDrive *_drive)
{
GVfsUDisks2Drive *drive = GVFS_UDISKS2_DRIVE (_drive);
@@ -1055,6 +1067,7 @@ gvfs_udisks2_drive_drive_iface_init (GDriveIface *iface)
iface->get_symbolic_icon = gvfs_udisks2_drive_get_symbolic_icon;
iface->has_volumes = gvfs_udisks2_drive_has_volumes;
iface->get_volumes = gvfs_udisks2_drive_get_volumes;
+ iface->is_removable = gvfs_udisks2_drive_is_removable;
iface->is_media_removable = gvfs_udisks2_drive_is_media_removable;
iface->has_media = gvfs_udisks2_drive_has_media;
iface->is_media_check_automatic = gvfs_udisks2_drive_is_media_check_automatic;
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c
index 961e257..208e668 100644
--- a/programs/gvfs-mount.c
+++ b/programs/gvfs-mount.c
@@ -779,6 +779,7 @@ list_drives (GList *drives,
g_object_unref (icon);
}
+ g_print ("%*sis_removable=%d\n", indent + 2, "", g_drive_is_removable (drive));
g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive));
g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive));
g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic
(drive));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]