[gvfs] Use UDisksObjectInfo API from udisks 2.0.90, if available, for symbolic icons



commit d2273d404cb3e895ba67052dde4a3e85b1c084ba
Author: David Zeuthen <zeuthen gmail com>
Date:   Tue Nov 20 15:58:18 2012 -0500

    Use UDisksObjectInfo API from udisks 2.0.90, if available, for symbolic icons
    
    Without this fix volumes would fall back to folder-remote-symbolic
    which is obviosly wrong. With this fix, it looks correct, see
    
     http://people.freedesktop.org/~david/gvfs-udisks2-symbolic-icons.png
    
    Right now we only use the API if it's available - things still work
    with udisks >= 1.97.
    
    Signed-off-by: David Zeuthen <zeuthen gmail com>

 monitor/udisks2/gvfsudisks2drive.c  |   66 ++++++++++++++++++++---
 monitor/udisks2/gvfsudisks2mount.c  |   30 ++++++++---
 monitor/udisks2/gvfsudisks2volume.c |  103 +++++++++++++++++++++++++++++------
 3 files changed, 167 insertions(+), 32 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2drive.c b/monitor/udisks2/gvfsudisks2drive.c
index a5da220..e91a9c1 100644
--- a/monitor/udisks2/gvfsudisks2drive.c
+++ b/monitor/udisks2/gvfsudisks2drive.c
@@ -52,6 +52,7 @@ struct _GVfsUDisks2Drive
   UDisksDrive *udisks_drive;
 
   GIcon *icon;
+  GIcon *symbolic_icon;
   gchar *name;
   gchar *sort_key;
   gchar *device_file;
@@ -88,8 +89,8 @@ gvfs_udisks2_drive_finalize (GObject *object)
       g_object_unref (drive->udisks_drive);
     }
 
-  if (drive->icon != NULL)
-    g_object_unref (drive->icon);
+  g_clear_object (&drive->icon);
+  g_clear_object (&drive->symbolic_icon);
   g_free (drive->name);
   g_free (drive->sort_key);
   g_free (drive->device_file);
@@ -118,11 +119,23 @@ emit_changed (GVfsUDisks2Drive *drive)
   g_signal_emit_by_name (drive->monitor, "drive-changed", drive);
 }
 
+
+static gpointer
+_g_object_ref0 (gpointer object)
+{
+  if (object != NULL)
+    return g_object_ref (G_OBJECT (object));
+  else
+    return NULL;
+}
+
 static gboolean
 update_drive (GVfsUDisks2Drive *drive)
 {
+  UDisksClient *udisks_client;
   gboolean changed;
   GIcon *old_icon;
+  GIcon *old_symbolic_icon;
   gchar *old_name;
   gchar *old_sort_key;
   gchar *old_device_file;
@@ -131,6 +144,11 @@ update_drive (GVfsUDisks2Drive *drive)
   gboolean old_has_media;
   gboolean old_can_eject;
   UDisksBlock *block;
+#if UDISKS_CHECK_VERSION(2,0,90)
+  UDisksObjectInfo *info = NULL;
+#endif
+
+  udisks_client = gvfs_udisks2_volume_monitor_get_udisks_client (drive->monitor);
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* save old values */
@@ -144,6 +162,7 @@ update_drive (GVfsUDisks2Drive *drive)
   old_device_file = g_strdup (drive->device_file);
   old_dev = drive->dev;
   old_icon = drive->icon != NULL ? g_object_ref (drive->icon) : NULL;
+  old_symbolic_icon = drive->symbolic_icon != NULL ? g_object_ref (drive->symbolic_icon) : NULL;
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* reset */
@@ -154,11 +173,12 @@ update_drive (GVfsUDisks2Drive *drive)
   g_free (drive->device_file); drive->device_file = NULL;
   drive->dev = 0;
   g_clear_object (&drive->icon);
+  g_clear_object (&drive->symbolic_icon);
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* in with the new */
 
-  block = udisks_client_get_block_for_drive (gvfs_udisks2_volume_monitor_get_udisks_client (drive->monitor),
+  block = udisks_client_get_block_for_drive (udisks_client,
                                              drive->udisks_drive,
                                              FALSE);
   if (block != NULL)
@@ -182,14 +202,29 @@ update_drive (GVfsUDisks2Drive *drive)
     }
   drive->can_eject = udisks_drive_get_ejectable (drive->udisks_drive);
 
-  udisks_client_get_drive_info (gvfs_udisks2_volume_monitor_get_udisks_client (drive->monitor),
+#if UDISKS_CHECK_VERSION(2,0,90)
+  {
+    UDisksObject *object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (drive->udisks_drive));
+    if (object != NULL)
+      {
+        info = udisks_client_get_object_info (udisks_client, object);
+        if (info != NULL)
+          {
+            drive->name = g_strdup (udisks_object_info_get_name (info));
+            drive->icon = _g_object_ref0 (udisks_object_info_get_icon (info));
+            drive->symbolic_icon = _g_object_ref0 (udisks_object_info_get_icon_symbolic (info));
+          }
+      }
+  }
+#else
+  udisks_client_get_drive_info (udisks_client,
                                 drive->udisks_drive,
                                 NULL,         /* drive_name */
                                 &drive->name,
                                 &drive->icon,
                                 NULL,         /* media_desc */
                                 NULL);        /* media_icon */
-
+#endif
   /* ---------------------------------------------------------------------------------------------------- */
   /* fallbacks */
 
@@ -203,6 +238,8 @@ update_drive (GVfsUDisks2Drive *drive)
     }
   if (drive->icon == NULL)
     drive->icon = g_themed_icon_new ("drive-removable-media");
+  if (drive->symbolic_icon == NULL)
+    drive->symbolic_icon = g_themed_icon_new ("drive-removable-media-symbolic");
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* compute whether something changed */
@@ -213,18 +250,23 @@ update_drive (GVfsUDisks2Drive *drive)
               (g_strcmp0 (old_sort_key, drive->sort_key) == 0) &&
               (g_strcmp0 (old_device_file, drive->device_file) == 0) &&
               (old_dev == drive->dev) &&
-              g_icon_equal (old_icon, drive->icon)
+              g_icon_equal (old_icon, drive->icon) &&
+              g_icon_equal (old_symbolic_icon, drive->symbolic_icon)
               );
 
   /* free old values */
   g_free (old_name);
   g_free (old_sort_key);
   g_free (old_device_file);
-  if (old_icon != NULL)
-    g_object_unref (old_icon);
+  g_clear_object (&old_icon);
+  g_clear_object (&old_symbolic_icon);
 
   /*g_debug ("in update_drive(); has_media=%d changed=%d", drive->has_media, changed);*/
 
+#if UDISKS_CHECK_VERSION(2,0,90)
+  g_clear_object (&info);
+#endif
+
   return changed;
 }
 
@@ -304,6 +346,13 @@ gvfs_udisks2_drive_get_icon (GDrive *_drive)
   return drive->icon != NULL ? g_object_ref (drive->icon) : NULL;
 }
 
+static GIcon *
+gvfs_udisks2_drive_get_symbolic_icon (GDrive *_drive)
+{
+  GVfsUDisks2Drive *drive = GVFS_UDISKS2_DRIVE (_drive);
+  return drive->symbolic_icon != NULL ? g_object_ref (drive->symbolic_icon) : NULL;
+}
+
 static char *
 gvfs_udisks2_drive_get_name (GDrive *_drive)
 {
@@ -718,6 +767,7 @@ gvfs_udisks2_drive_drive_iface_init (GDriveIface *iface)
 {
   iface->get_name = gvfs_udisks2_drive_get_name;
   iface->get_icon = gvfs_udisks2_drive_get_icon;
+  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_media_removable = gvfs_udisks2_drive_is_media_removable;
diff --git a/monitor/udisks2/gvfsudisks2mount.c b/monitor/udisks2/gvfsudisks2mount.c
index 32b8cf3..cb888c2 100644
--- a/monitor/udisks2/gvfsudisks2mount.c
+++ b/monitor/udisks2/gvfsudisks2mount.c
@@ -64,6 +64,7 @@ struct _GVfsUDisks2Mount
   /* the following members are set in update_mount() */
   GFile *root;
   GIcon *icon;
+  GIcon *symbolic_icon;
   gchar *name;
   gchar *sort_key;
   gchar *uuid;
@@ -108,10 +109,9 @@ gvfs_udisks2_mount_finalize (GObject *object)
       gvfs_udisks2_volume_unset_mount (mount->volume, mount);
     }
 
-  if (mount->root != NULL)
-    g_object_unref (mount->root);
-  if (mount->icon != NULL)
-    g_object_unref (mount->icon);
+  g_clear_object (&mount->root);
+  g_clear_object (&mount->icon);
+  g_clear_object (&mount->symbolic_icon);
   g_free (mount->name);
   g_free (mount->sort_key);
   g_free (mount->uuid);
@@ -200,15 +200,18 @@ update_mount (GVfsUDisks2Mount *mount)
   gboolean old_can_unmount;
   gchar *old_name;
   GIcon *old_icon;
+  GIcon *old_symbolic_icon;
 
   /* save old values */
   old_can_unmount = mount->can_unmount;
   old_name = g_strdup (mount->name);
   old_icon = mount->icon != NULL ? g_object_ref (mount->icon) : NULL;
+  old_symbolic_icon = mount->symbolic_icon != NULL ? g_object_ref (mount->symbolic_icon) : NULL;
 
   /* reset */
   mount->can_unmount = FALSE;
   g_clear_object (&mount->icon);
+  g_clear_object (&mount->symbolic_icon);
   g_free (mount->name); mount->name = NULL;
 
   /* in with the new */
@@ -233,6 +236,8 @@ update_mount (GVfsUDisks2Mount *mount)
         mount->name = g_strdup (mount->xdg_volume_info_name);
       else
         mount->name = g_volume_get_name (G_VOLUME (mount->volume));
+
+      mount->symbolic_icon = g_volume_get_symbolic_icon (G_VOLUME (mount->volume));
     }
   else
     {
@@ -262,17 +267,20 @@ update_mount (GVfsUDisks2Mount *mount)
         mount->name = g_strdup (mount->xdg_volume_info_name);
       else
         mount->name = g_strdup (mount->mount_entry_name);
+
+      mount->symbolic_icon = g_themed_icon_new ("folder-remote-symbolic");
     }
 
   /* compute whether something changed */
   changed = !((old_can_unmount == mount->can_unmount) &&
               (g_strcmp0 (old_name, mount->name) == 0) &&
-              g_icon_equal (old_icon, mount->icon));
+              g_icon_equal (old_icon, mount->icon) &&
+              g_icon_equal (old_symbolic_icon, mount->symbolic_icon));
 
   /* free old values */
   g_free (old_name);
-  if (old_icon != NULL)
-    g_object_unref (old_icon);
+  g_clear_object (&old_icon);
+  g_clear_object (&old_symbolic_icon);
 
   /*g_debug ("in update_mount(), changed=%d", changed);*/
 
@@ -424,6 +432,13 @@ gvfs_udisks2_mount_get_icon (GMount *_mount)
   return mount->icon != NULL ? g_object_ref (mount->icon) : NULL;
 }
 
+static GIcon *
+gvfs_udisks2_mount_get_symbolic_icon (GMount *_mount)
+{
+  GVfsUDisks2Mount *mount = GVFS_UDISKS2_MOUNT (_mount);
+  return mount->symbolic_icon != NULL ? g_object_ref (mount->symbolic_icon) : NULL;
+}
+
 static gchar *
 gvfs_udisks2_mount_get_uuid (GMount *_mount)
 {
@@ -1279,6 +1294,7 @@ gvfs_udisks2_mount_mount_iface_init (GMountIface *iface)
   iface->get_root = gvfs_udisks2_mount_get_root;
   iface->get_name = gvfs_udisks2_mount_get_name;
   iface->get_icon = gvfs_udisks2_mount_get_icon;
+  iface->get_symbolic_icon = gvfs_udisks2_mount_get_symbolic_icon;
   iface->get_uuid = gvfs_udisks2_mount_get_uuid;
   iface->get_drive = gvfs_udisks2_mount_get_drive;
   iface->get_volume = gvfs_udisks2_mount_get_volume_;
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index 7652a4b..8502266 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -69,6 +69,7 @@ struct _GVfsUDisks2Volume
 
   /* set in update_volume() */
   GIcon *icon;
+  GIcon *symbolic_icon;
   GFile *activation_root;
   gchar *name;
   gchar *sort_key;
@@ -125,10 +126,9 @@ gvfs_udisks2_volume_finalize (GObject *object)
   if (volume->mount_point != NULL)
     g_unix_mount_point_free (volume->mount_point);
 
-  if (volume->icon != NULL)
-    g_object_unref (volume->icon);
-  if (volume->activation_root != NULL)
-    g_object_unref (volume->activation_root);
+  g_clear_object (&volume->icon);
+  g_clear_object (&volume->symbolic_icon);
+  g_clear_object (&volume->activation_root);
 
   g_free (volume->name);
   g_free (volume->sort_key);
@@ -181,9 +181,20 @@ apply_options_from_fstab (GVfsUDisks2Volume *volume,
     }
 }
 
+
+static gpointer
+_g_object_ref0 (gpointer object)
+{
+  if (object != NULL)
+    return g_object_ref (G_OBJECT (object));
+  else
+    return NULL;
+}
+
 static gboolean
 update_volume (GVfsUDisks2Volume *volume)
 {
+  UDisksClient *udisks_client;
   gboolean changed;
   gboolean old_can_mount;
   gboolean old_should_automount;
@@ -191,9 +202,12 @@ update_volume (GVfsUDisks2Volume *volume)
   gchar *old_device_file;
   dev_t old_dev;
   GIcon *old_icon;
+  GIcon *old_symbolic_icon;
   UDisksDrive *udisks_drive;
   gchar *s;
 
+  udisks_client = gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor);
+
   /* ---------------------------------------------------------------------------------------------------- */
   /* save old values */
 
@@ -203,6 +217,7 @@ update_volume (GVfsUDisks2Volume *volume)
   old_device_file = g_strdup (volume->device_file);
   old_dev = volume->dev;
   old_icon = volume->icon != NULL ? g_object_ref (volume->icon) : NULL;
+  old_symbolic_icon = volume->symbolic_icon != NULL ? g_object_ref (volume->symbolic_icon) : NULL;
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* reset */
@@ -212,6 +227,7 @@ update_volume (GVfsUDisks2Volume *volume)
   g_free (volume->device_file); volume->device_file = NULL;
   volume->dev = 0;
   g_clear_object (&volume->icon);
+  g_clear_object (&volume->symbolic_icon);
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* in with the new */
@@ -226,12 +242,11 @@ update_volume (GVfsUDisks2Volume *volume)
       GVariant *configuration_value;
       UDisksLoop *loop = NULL;
 
-      loop = udisks_client_get_loop_for_block (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
+      loop = udisks_client_get_loop_for_block (udisks_client,
                                                volume->block);
 
       /* 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),
-                                                           volume->block);
+      cleartext_block = udisks_client_get_cleartext_block (udisks_client, volume->block);
       if (cleartext_block != NULL)
         block = cleartext_block;
       else
@@ -246,8 +261,7 @@ update_volume (GVfsUDisks2Volume *volume)
         }
       else if (g_strcmp0 (udisks_block_get_id_type (block), "crypto_LUKS") == 0)
         {
-          s = udisks_client_get_size_for_display (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
-                                                  udisks_block_get_size (volume->block), FALSE, FALSE);
+          s = udisks_client_get_size_for_display (udisks_client, udisks_block_get_size (volume->block), FALSE, FALSE);
           /* Translators: This is used for encrypted volumes.
            *              The first %s is the formatted size (e.g. "42.0 MB").
            */
@@ -259,8 +273,7 @@ update_volume (GVfsUDisks2Volume *volume)
           guint64 size = udisks_block_get_size (block);
           if (size > 0)
             {
-              s = udisks_client_get_size_for_display (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
-                                                      size, FALSE, FALSE);
+              s = udisks_client_get_size_for_display (udisks_client, size, FALSE, FALSE);
               /* Translators: This is used for volume with no filesystem label.
                *              The first %s is the formatted size (e.g. "42.0 MB").
                */
@@ -269,22 +282,44 @@ update_volume (GVfsUDisks2Volume *volume)
             }
         }
 
-      udisks_drive = udisks_client_get_drive_for_block (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
-                                                        volume->block);
+      udisks_drive = udisks_client_get_drive_for_block (udisks_client, volume->block);
       if (udisks_drive != NULL)
         {
           gchar *drive_desc;
           GIcon *drive_icon;
+          GIcon *drive_symbolic_icon;
           gchar *media_desc;
           GIcon *media_icon;
-
-          udisks_client_get_drive_info (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
+          GIcon *media_symbolic_icon;
+
+#if UDISKS_CHECK_VERSION(2,0,90)
+          {
+            UDisksObject *object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (udisks_drive));
+            if (object != NULL)
+              {
+                UDisksObjectInfo *info = udisks_client_get_object_info (udisks_client, object);
+                if (info != NULL)
+                  {
+                    drive_desc = g_strdup (udisks_object_info_get_description (info));
+                    drive_icon = _g_object_ref0 (udisks_object_info_get_icon (info));
+                    drive_symbolic_icon = _g_object_ref0 (udisks_object_info_get_icon_symbolic (info));
+                    media_desc = g_strdup (udisks_object_info_get_media_description (info));
+                    media_icon = _g_object_ref0 (udisks_object_info_get_media_icon (info));
+                    media_symbolic_icon = _g_object_ref0 (udisks_object_info_get_media_icon_symbolic (info));
+                    g_object_unref (info);
+                  }
+              }
+          }
+#else
+          udisks_client_get_drive_info (udisks_client,
                                         udisks_drive,
                                         NULL, /* drive_name */
                                         &drive_desc,
                                         &drive_icon,
                                         &media_desc,
                                         &media_icon);
+#endif
+
           if (media_desc == NULL)
             {
               media_desc = drive_desc;
@@ -295,6 +330,11 @@ update_volume (GVfsUDisks2Volume *volume)
               media_icon = drive_icon;
               drive_icon = NULL;
             }
+          if (media_symbolic_icon == NULL)
+            {
+              media_symbolic_icon = drive_symbolic_icon;
+              drive_symbolic_icon = NULL;
+            }
 
           /* Override name for blank and audio discs */
           if (udisks_drive_get_optical_blank (udisks_drive))
@@ -309,6 +349,7 @@ update_volume (GVfsUDisks2Volume *volume)
             }
 
           volume->icon = media_icon != NULL ? g_object_ref (media_icon) : NULL;
+          volume->symbolic_icon = media_symbolic_icon != NULL ? g_object_ref (media_symbolic_icon) : NULL;
 
           /* use media_desc if we haven't figured out a name yet (applies to e.g.
            * /dev/fd0 since its size is 0)
@@ -320,8 +361,8 @@ update_volume (GVfsUDisks2Volume *volume)
             }
 
           g_free (media_desc);
-          if (media_icon != NULL)
-            g_object_unref (media_icon);
+          g_clear_object (&media_icon);
+          g_clear_object (&media_symbolic_icon);
 
           /* Only automount drives attached to the same seat as we're running on
            */
@@ -445,6 +486,8 @@ update_volume (GVfsUDisks2Volume *volume)
     }
   if (volume->icon == NULL)
     volume->icon = g_themed_icon_new ("drive-removable-media");
+  if (volume->symbolic_icon == NULL)
+    volume->symbolic_icon = g_themed_icon_new ("folder-remote-symbolic");
 
   /* ---------------------------------------------------------------------------------------------------- */
   /* compute whether something changed */
@@ -631,6 +674,13 @@ gvfs_udisks2_volume_get_icon (GVolume *_volume)
   return volume->icon != NULL ? g_object_ref (volume->icon) : NULL;
 }
 
+static GIcon *
+gvfs_udisks2_volume_get_symbolic_icon (GVolume *_volume)
+{
+  GVfsUDisks2Volume *volume = GVFS_UDISKS2_VOLUME (_volume);
+  return volume->symbolic_icon != NULL ? g_object_ref (volume->symbolic_icon) : NULL;
+}
+
 static char *
 gvfs_udisks2_volume_get_name (GVolume *_volume)
 {
@@ -1457,6 +1507,23 @@ gvfs_udisks2_volume_mount (GVolume             *_volume,
             {
               gchar *drive_name;
               gchar *drive_desc;
+
+#if UDISKS_CHECK_VERSION(2,0,90)
+              {
+                UDisksObject *object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (udisks_drive));
+                if (object != NULL)
+                  {
+                    UDisksObjectInfo *info = udisks_client_get_object_info (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
+                                                                            object);
+                    if (info != NULL)
+                      {
+                        drive_name = g_strdup (udisks_object_info_get_name (info));
+                        drive_desc = g_strdup (udisks_object_info_get_description (info));
+                        g_object_unref (info);
+                      }
+                  }
+              }
+#else
               udisks_client_get_drive_info (gvfs_udisks2_volume_monitor_get_udisks_client (volume->monitor),
                                             udisks_drive,
                                             &drive_name,
@@ -1464,6 +1531,7 @@ gvfs_udisks2_volume_mount (GVolume             *_volume,
                                             NULL,  /* drive_icon */
                                             NULL,  /* media_desc */
                                             NULL); /* media_icon */
+#endif
               /* Translators: this is used to describe the drive the encrypted media
                * is on - the first %s is the name (such as 'WD 2500JB External'), the
                * second %s is the description ('250 GB Hard Disk').
@@ -1623,6 +1691,7 @@ gvfs_udisks2_volume_volume_iface_init (GVolumeIface *iface)
 {
   iface->get_name = gvfs_udisks2_volume_get_name;
   iface->get_icon = gvfs_udisks2_volume_get_icon;
+  iface->get_symbolic_icon = gvfs_udisks2_volume_get_symbolic_icon;
   iface->get_uuid = gvfs_udisks2_volume_get_uuid;
   iface->get_drive = gvfs_udisks2_volume_get_drive;
   iface->get_mount = gvfs_udisks2_volume_get_mount;



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