[gnome-desktop/wip/hadess/thumbnail-test-stats: 1/6] thumbnail: Factor out thumbnailing functionality




commit c579cfae2fc71941d11b35f1431a2379a655b3f2
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Oct 14 11:35:35 2020 +0200

    thumbnail: Factor out thumbnailing functionality
    
    This will make it easier to add some profiling functionality to the
    tests.

 libgnome-desktop/test-desktop-thumbnail.c | 42 ++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/libgnome-desktop/test-desktop-thumbnail.c b/libgnome-desktop/test-desktop-thumbnail.c
index 510e88b6..e63bf263 100644
--- a/libgnome-desktop/test-desktop-thumbnail.c
+++ b/libgnome-desktop/test-desktop-thumbnail.c
@@ -24,42 +24,54 @@
 #define GNOME_DESKTOP_USE_UNSTABLE_API
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
-int main (int argc, char **argv)
+static gboolean
+thumbnail_file (GnomeDesktopThumbnailFactory *factory,
+               const char *in_path,
+               const char *out_path)
 {
        GdkPixbuf *pixbuf;
-       GnomeDesktopThumbnailFactory *factory;
        char *content_type;
        g_autoptr(GFile) file = NULL;
        g_autofree char *path = NULL;
        g_autofree char *uri = NULL;
 
-       if (argc != 3) {
-               g_print ("Usage: %s [INPUT FILE] [OUTPUT FILE]\n", argv[0]);
-               return 1;
-       }
-
-       file = g_file_new_for_commandline_arg (argv[1]);
+       file = g_file_new_for_commandline_arg (in_path);
        path = g_file_get_path (file);
        if (!path) {
-               g_warning ("Could not get path for %s", argv[1]);
-               return 1;
+               g_warning ("Could not get path for %s", in_path);
+               return FALSE;
        }
 
        content_type = g_content_type_guess (path, NULL, 0, NULL);
-       factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
        uri = g_file_get_uri (file);
        pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, uri, content_type);
        g_free (content_type);
 
        if (pixbuf == NULL) {
-               g_warning ("gnome_desktop_thumbnail_factory_generate_thumbnail() failed to generate a 
thumbnail for %s", argv[1]);
-               return 1;
+               g_warning ("gnome_desktop_thumbnail_factory_generate_thumbnail() failed to generate a 
thumbnail for %s", in_path);
+               return FALSE;
+       }
+
+       if (!gdk_pixbuf_save (pixbuf, out_path, "png", NULL, NULL)) {
+               g_warning ("gdk_pixbuf_save failed for %s", in_path);
+               return FALSE;
        }
 
-       if (!gdk_pixbuf_save (pixbuf, argv[2], "png", NULL, NULL)) {
-               g_warning ("gdk_pixbuf_save failed for %s", argv[1]);
+       return TRUE;
+}
+
+int main (int argc, char **argv)
+{
+       GnomeDesktopThumbnailFactory *factory;
+
+       if (argc != 3) {
+               g_print ("Usage: %s [INPUT FILE] [OUTPUT FILE]\n", argv[0]);
                return 1;
        }
 
+       factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
+       if (!thumbnail_file (factory, argv[1], argv[2]))
+               return 1;
+
        return 0;
 }


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