summaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2016-04-29 16:59:41 +0200
committerOndrej Holy <oholy@redhat.com>2016-05-20 10:39:34 +0200
commitb7986553f898976bade0f4dc2f042c30ec550255 (patch)
treedee3da7d27d23d740dd36faa3d00c2b737cc265d /monitor
parent265c237408ec7a9ca0c02396b1e9d1bab265fb42 (diff)
downloadgvfs-b7986553f898976bade0f4dc2f042c30ec550255.tar.gz
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
Diffstat (limited to 'monitor')
-rw-r--r--monitor/proxy/gproxydrive.c25
-rw-r--r--monitor/proxy/gvfsproxyvolumemonitordaemon.c4
-rw-r--r--monitor/udisks2/gvfsudisks2drive.c17
3 files changed, 43 insertions, 3 deletions
diff --git a/monitor/proxy/gproxydrive.c b/monitor/proxy/gproxydrive.c
index a8ac61d3..8cb5e6a4 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 768d307a..9a2e8da6 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 8da76a1b..021b0a2c 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;