[Xfce4-commits] <tumbler:master> Make the font thumbnailer work with all URI schemes supported by GIO.

Jannis Pohlmann noreply at xfce.org
Wed Sep 30 03:42:01 CEST 2009


Updating branch refs/heads/master
         to 2ce5c9a917a46e2468bc4df48577042cdcd8fa97 (commit)
       from 8b48e3a585cc4f302665c1c63e0fe2af09e9c35d (commit)

commit 2ce5c9a917a46e2468bc4df48577042cdcd8fa97
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Wed Sep 30 03:40:27 2009 +0200

    Make the font thumbnailer work with all URI schemes supported by GIO.

 .../font-thumbnailer/font-thumbnailer-provider.c   |   11 ++++---
 plugins/font-thumbnailer/font-thumbnailer.c        |   32 ++++++++++++-------
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/plugins/font-thumbnailer/font-thumbnailer-provider.c b/plugins/font-thumbnailer/font-thumbnailer-provider.c
index 86fcf7c..487646f 100644
--- a/plugins/font-thumbnailer/font-thumbnailer-provider.c
+++ b/plugins/font-thumbnailer/font-thumbnailer-provider.c
@@ -103,11 +103,6 @@ font_thumbnailer_provider_init (FontThumbnailerProvider *provider)
 static GList *
 font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
 {
-  static const gchar *uri_schemes[] = 
-  { 
-    "file", 
-    NULL, 
-  };
   static const gchar *mime_types[] = 
   { 
     "application/x-font-otf",
@@ -116,8 +111,14 @@ font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider
     "application/x-font-type1",
     NULL,
   };
+  const gchar *const *uri_schemes;
   FontThumbnailer    *thumbnailer;
   GList              *thumbnailers = NULL;
+  GVfs               *vfs;
+
+  /* determine the URI schemes supported by GIO */
+  vfs = g_vfs_get_default ();
+  uri_schemes = g_vfs_get_supported_uri_schemes (vfs);
 
   /* create the pixbuf thumbnailer */
   thumbnailer = g_object_new (TYPE_FONT_THUMBNAILER, 
diff --git a/plugins/font-thumbnailer/font-thumbnailer.c b/plugins/font-thumbnailer/font-thumbnailer.c
index c4a5fad..d4e7ca2 100644
--- a/plugins/font-thumbnailer/font-thumbnailer.c
+++ b/plugins/font-thumbnailer/font-thumbnailer.c
@@ -451,7 +451,8 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
   GList                  *lp;
   GList                  *thumbnails;
   gchar                  *error_msg;
-  gchar                  *path;
+  gchar                  *font_data;
+  gsize                   length;
   gint                    n;
 
   g_return_if_fail (IS_FONT_THUMBNAILER (thumbnailer));
@@ -480,17 +481,28 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
       return;
     }
 
-  /* determine the local path of the file */
+  /* try to read the file into memory */
   file = g_file_new_for_uri (uri);
-  path = g_file_get_path (file);
-  g_object_unref (file);
+  if (!g_file_load_contents (file, NULL, &font_data, &length, NULL, &error))
+    {
+      /* there was an error, emit error signal */
+      error_msg = g_strdup_printf (_("Could not load file contents: %s"), 
+                                    error->message);
+      g_signal_emit_by_name (thumbnailer, "error", uri, 0, error_msg);
+      g_free (error_msg);
+
+      /* clean up */
+      g_error_free (error);
+      g_object_unref (file);
+      g_object_unref (info);
 
-  /* if the local path is not NULL, then something went wrong, as this thumbnailer
-   * only supports file URIs and all those should also have a local path */
-  g_assert (path != NULL);
+      return;
+    }
+  g_object_unref (file);
 
   /* try to open the font file */
-  ft_error = FT_New_Face (font_thumbnailer->library, path, 0, &face);
+  ft_error = FT_New_Memory_Face (font_thumbnailer->library, font_data, length, 
+                                 0, &face);
   if (G_UNLIKELY (ft_error != 0))
     {
       /* the font file could not be loaded, emit an error signal */
@@ -500,15 +512,11 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
       g_free (error_msg);
 
       /* clean up */
-      g_free (path);
       g_object_unref (info);
 
       return;
     }
 
-  /* free the local path */
-  g_free (path);
-
   /* try to set the character map */
   for (n = 0; n < face->num_charmaps; ++n)
     {



More information about the Xfce4-commits mailing list