Icon Metadata for Filesystems



Holas,

I have written the attached patch to GIO, which implements getting an
icon name for a mounted volume from an .iconrc file within its file
system. David Z suggested that it might be useful to also allow other
information to be provided here, such as the volume name to use in the
display. I'd like to get some definite agreement on the file name to use
here (davdiz suggested possibly using .xdg-volume-info), and get the
patch upstream. I implemented this in GIO, as it appears the HAL is not
aware of all possible mounts (particularly user owned fuse mounts), and
this should work for all volumes. Particularly, some fuse mounts may
want to provide this metadata file virtually, to specify their icon.

What do you think about the file name, and the patch in general?

Thanks,
Rodney

PS: I'm not subscribed to the list, so please use reply-all.

Index: gio/gunixmounts.c
===================================================================
--- gio/gunixmounts.c	(revision 7398)
+++ gio/gunixmounts.c	(working copy)
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <signal.h>
 #include <gstdio.h>
+#include <glib.h>
 
 #include "gunixmounts.h"
 #include "gfile.h"
@@ -1760,6 +1785,34 @@ type_to_icon (GUnixMountType type, gbool
   return icon_name;
 }
 
+static char *
+mount_to_icon (GUnixMountEntry *mount)
+{
+  GKeyFile *key_file;
+  char *path;
+  char *icon;
+
+  icon = NULL;
+
+  path = g_build_filename (mount->mount_path, ".iconrc", NULL);
+  if (g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+    {
+      key_file = g_key_file_new ();
+      g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL);
+      if (g_key_file_has_key (key_file, "Volume Info", "Icon", NULL))
+        {
+          icon = g_key_file_get_string (key_file, "Volume Info", "Icon", NULL);
+        }
+      g_key_file_free (key_file);
+    }
+  g_free (path);
+
+  if (icon != NULL)
+    return icon;
+  else
+    return g_strdup (type_to_icon (g_unix_mount_guess_type (mount), FALSE));
+}
+
 /**
  * g_unix_mount_guess_name:
  * @mount_entry: a #GUnixMountEntry
@@ -1794,7 +1847,14 @@ g_unix_mount_guess_name (GUnixMountEntry
 GIcon *
 g_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
 {
-  return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE));
+  GIcon *icon;
+  char *icon_name;
+
+  icon_name = mount_to_icon (mount_entry);
+  icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+  g_free (icon_name);
+
+  return icon;
 }
 
 /**


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