[gvfs/wip/udisks2] udisks2: also use comment=gvfs.{name, icon_name} in the udisks case



commit 89784d4493a9d482ec3fd6559a5fa4c30958180d
Author: David Zeuthen <davidz redhat com>
Date:   Thu Oct 6 12:38:40 2011 -0400

    udisks2: also use comment=gvfs.{name,icon_name} in the udisks case
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 monitor/udisks2/gvfsudisks2utils.c  |   24 +++++++++++++
 monitor/udisks2/gvfsudisks2utils.h  |    3 ++
 monitor/udisks2/gvfsudisks2volume.c |   62 ++++++++++++++++++-----------------
 3 files changed, 59 insertions(+), 30 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2utils.c b/monitor/udisks2/gvfsudisks2utils.c
index ebbbc13..1906a00 100644
--- a/monitor/udisks2/gvfsudisks2utils.c
+++ b/monitor/udisks2/gvfsudisks2utils.c
@@ -81,3 +81,27 @@ gvfs_udisks2_utils_icon_from_fs_type (const gchar *fs_type)
     }
   return g_themed_icon_new_with_default_fallbacks (icon_name);
 }
+
+gchar *
+gvfs_udisks2_utils_lookup_fstab_options_value (const gchar *fstab_options,
+                                               const gchar *key)
+{
+  gchar *ret = NULL;
+
+  if (fstab_options != NULL)
+    {
+      const gchar *start;
+      guint n;
+
+      start = strstr (fstab_options, key);
+      if (start != NULL)
+        {
+          start += strlen (key);
+          for (n = 0; start[n] != ',' && start[n] != '\0'; n++)
+            ;
+          if (n > 1)
+            ret = g_uri_unescape_segment (start, start + n, NULL);
+        }
+    }
+  return ret;
+}
diff --git a/monitor/udisks2/gvfsudisks2utils.h b/monitor/udisks2/gvfsudisks2utils.h
index 8ba4ebb..ad3d6d7 100644
--- a/monitor/udisks2/gvfsudisks2utils.h
+++ b/monitor/udisks2/gvfsudisks2utils.h
@@ -34,6 +34,9 @@ G_BEGIN_DECLS
 void   gvfs_udisks2_utils_udisks_error_to_gio_error (GError *error);
 GIcon *gvfs_udisks2_utils_icon_from_fs_type (const gchar *fs_type);
 
+gchar *gvfs_udisks2_utils_lookup_fstab_options_value (const gchar *fstab_options,
+                                                      const gchar *key);
+
 G_END_DECLS
 
 #endif /* __GVFS_UDISKS2_UTILS_H__ */
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index fa9cb28..a2a0934 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -150,30 +150,26 @@ emit_changed (GVfsUDisks2Volume *volume)
   g_signal_emit_by_name (volume->monitor, "volume-changed", volume);
 }
 
-static gchar *
-lookup_mount_option_value (GUnixMountPoint *mount_point,
-                           const gchar     *key)
+static void
+apply_options_from_fstab (GVfsUDisks2Volume *volume,
+                          const gchar       *fstab_options)
 {
-  const gchar *options;
-  gchar *ret = NULL;
+  gchar *name;
+  gchar *icon_name;
 
-  options = g_unix_mount_point_get_options (mount_point);
-  if (options != NULL)
+  name = gvfs_udisks2_utils_lookup_fstab_options_value (fstab_options, "comment=gvfs.name=");
+  if (name != NULL)
     {
-      const gchar *start;
-      guint n;
+      g_free (volume->name);
+      volume->name = name;
+    }
 
-      start = strstr (options, key);
-      if (start != NULL)
-        {
-          start += strlen (key);
-          for (n = 0; start[n] != ',' && start[n] != '\0'; n++)
-            ;
-          if (n > 1)
-            ret = g_uri_unescape_segment (start, start + n, NULL);
-        }
+  icon_name = gvfs_udisks2_utils_lookup_fstab_options_value (fstab_options, "comment=gvfs.icon_name=");
+  if (icon_name != NULL)
+    {
+      volume->icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+      g_free (icon_name);
     }
-  return ret;
 }
 
 static gboolean
@@ -216,6 +212,9 @@ update_volume (GVfsUDisks2Volume *volume)
       const gchar *hint;
       UDisksBlock *block;
       UDisksBlock *cleartext_block;
+      GVariantIter iter;
+      const gchar *configuration_type;
+      GVariant *configuration_value;
 
       /* If unlocked, use the values from the unlocked block device for presentation */
       cleartext_block = udisks_client_get_cleartext_block (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
@@ -312,6 +311,19 @@ update_volume (GVfsUDisks2Volume *volume)
           volume->icon = g_themed_icon_new_with_default_fallbacks (hint);
         }
 
+      /* Use comment=gvfs.name=The%20Name and comment=gvfs.icon_name=foo-name, if available */
+      g_variant_iter_init (&iter, udisks_block_get_configuration (block));
+      while (g_variant_iter_next (&iter, "(&s a{sv})", &configuration_type, &configuration_value))
+        {
+          if (g_strcmp0 (configuration_type, "fstab") == 0)
+            {
+              const gchar *fstab_options;
+              if (g_variant_lookup (configuration_value, "opts", "^&ay", &fstab_options))
+                apply_options_from_fstab (volume, fstab_options);
+            }
+          g_variant_unref (configuration_value);
+        }
+
       /* Add an emblem, depending on whether the encrypted volume is locked or unlocked */
       if (g_strcmp0 (udisks_block_get_id_type (volume->block), "crypto_LUKS") == 0 && volume->icon != NULL)
         {
@@ -335,19 +347,9 @@ update_volume (GVfsUDisks2Volume *volume)
     }
   else
     {
-      gchar *icon_name;
-
-      volume->name = lookup_mount_option_value (volume->mount_point, "comment=gvfs.name=");
+      apply_options_from_fstab (volume, g_unix_mount_point_get_options (volume->mount_point));
       if (volume->name == NULL)
         volume->name = g_unix_mount_point_guess_name (volume->mount_point);
-
-      icon_name = lookup_mount_option_value (volume->mount_point, "comment=gvfs.icon_name=");
-      if (icon_name != NULL)
-        {
-          volume->icon = g_themed_icon_new_with_default_fallbacks (icon_name);
-          g_free (icon_name);
-        }
-
       if (volume->icon == NULL)
         volume->icon = gvfs_udisks2_utils_icon_from_fs_type (g_unix_mount_point_get_fs_type (volume->mount_point));
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]