[gnome-desktop/wip/hadess/xlarge-thumbnails: 1/2] thumbnail: Factor out size to dirname and pixel size computation




commit 1397de7633631ef61b5245bbfe1dbcc7fa2d0f08
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 17 12:14:30 2020 +0100

    thumbnail: Factor out size to dirname and pixel size computation
    
    This will make it easier to add new thumbnail sizes.

 libgnome-desktop/gnome-desktop-thumbnail.c | 31 +++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index ad031c25..31ba1847 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -303,6 +303,30 @@ get_thumbnailers_dirs (void)
   return g_once (&once_init, init_thumbnailers_dirs, NULL);
 }
 
+static const char *
+gnome_desktop_thumbnail_size_to_dirname (GnomeDesktopThumbnailSize size)
+{
+  switch (size) {
+  case GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL:
+    return "normal";
+  case GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE:
+    return "large";
+  default:
+    g_assert_not_reached ();
+}
+
+static guint
+gnome_desktop_thumbnail_size_to_size (GnomeDesktopThumbnailSize size)
+{
+  switch (size) {
+  case GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL:
+    return 128;
+  case GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE:
+    return 256;
+  default:
+    g_assert_not_reached ();
+}
+
 /* These should be called with the lock held */
 static void
 gnome_desktop_thumbnail_factory_register_mime_types (GnomeDesktopThumbnailFactory *factory,
@@ -761,7 +785,7 @@ thumbnail_path (const char                *uri,
   file = thumbnail_filename (uri);
   path = g_build_filename (g_get_user_cache_dir (),
                            "thumbnails",
-                           size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE ? "large" : "normal",
+                           gnome_desktop_thumbnail_size_to_dirname (size),
                            file,
                            NULL);
   g_free (file);
@@ -1047,10 +1071,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
 
   /* Doesn't access any volatile fields in factory, so it's threadsafe */
 
-  size = 128;
-  if (factory->priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE)
-    size = 256;
-
+  size = gnome_desktop_thumbnail_size_to_size (factory->priv->size);
   pixbuf = get_preview_thumbnail (uri, size);
   if (pixbuf != NULL)
     return pixbuf;


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