diff options
author | Jannis Pohlmann <jannis@xfce.org> | 2009-05-22 01:55:59 +0200 |
---|---|---|
committer | Jannis Pohlmann <jannis@xfce.org> | 2009-05-22 01:55:59 +0200 |
commit | 9f137e1e3b0973786c9ef1363858ba77688ad06f (patch) | |
tree | ccb9fd03a5aceabddca879754ae4a2b3b97ff4dc /tumblerd | |
parent | efab2f56c73c1dec60a14c83a5aff6a5620f7bbc (diff) | |
download | tumbler-9f137e1e3b0973786c9ef1363858ba77688ad06f.tar.gz |
Implement the built-in pixbuf thumbnailer (doesn't crop yet), fix bugs.
The built-in pixbuf thumbnailer can now generate and save normal and
large thumbnails using GdkPixbuf and the new utility functions. It
doesn't support cropping yet though.
Fix a few typos and bugs across tumblerd which are not really worth
mentioning.
Diffstat (limited to 'tumblerd')
-rw-r--r-- | tumblerd/tumbler-builtin-thumbnailer.c | 2 | ||||
-rw-r--r-- | tumblerd/tumbler-builtin-thumbnailers.c | 106 | ||||
-rw-r--r-- | tumblerd/tumbler-service.c | 4 | ||||
-rw-r--r-- | tumblerd/tumbler-thumbnailer.c | 2 |
4 files changed, 110 insertions, 4 deletions
diff --git a/tumblerd/tumbler-builtin-thumbnailer.c b/tumblerd/tumbler-builtin-thumbnailer.c index d68be28..f6348e2 100644 --- a/tumblerd/tumbler-builtin-thumbnailer.c +++ b/tumblerd/tumbler-builtin-thumbnailer.c @@ -276,7 +276,7 @@ tumbler_builtin_thumbnailer_create (TumblerThumbnailer *thumbnailer, { TumblerBuiltinThumbnailer *builtin_thumbnailer = TUMBLER_BUILTIN_THUMBNAILER (thumbnailer); gboolean success; - GError *error; + GError *error = NULL; g_return_if_fail (TUMBLER_IS_BUILTIN_THUMBNAILER (thumbnailer)); g_return_if_fail (uri != NULL); diff --git a/tumblerd/tumbler-builtin-thumbnailers.c b/tumblerd/tumbler-builtin-thumbnailers.c index 9567a72..0cc3b0e 100644 --- a/tumblerd/tumbler-builtin-thumbnailers.c +++ b/tumblerd/tumbler-builtin-thumbnailers.c @@ -26,6 +26,10 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #endif +#include <gio/gio.h> + +#include <tumbler/tumbler.h> + #include <tumblerd/tumbler-builtin-thumbnailer.h> #include <tumblerd/tumbler-thumbnailer.h> @@ -39,7 +43,107 @@ _tumbler_pixbuf_thumbnailer (TumblerBuiltinThumbnailer *thumbnailer, const gchar *mime_hint, GError **error) { - g_debug ("Hello"); + TumblerThumbnailFlavor *flavors; + GFileOutputStream *output_stream; + GFileInputStream *input_stream; + GdkPixbuf *pixbuf = NULL; + GError *err = NULL; + GFile *input_file; + GFile *output_file; + gchar *basename; + gchar *filename; + gint size; + gint n; + + g_return_val_if_fail (TUMBLER_IS_BUILTIN_THUMBNAILER (thumbnailer), FALSE); + g_return_val_if_fail (uri != NULL, FALSE); + g_return_val_if_fail (mime_hint != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* try to open the file for reading */ + input_file = g_file_new_for_uri (uri); + input_stream = g_file_read (input_file, NULL, &err); + g_object_unref (input_file); + + /* propagate error if opening failed */ + if (err != NULL) + { + g_propagate_error (error, err); + return FALSE; + } + + flavors = tumbler_thumbnail_get_flavors (); + + for (n = 0; flavors[n] != TUMBLER_THUMBNAIL_FLAVOR_INVALID; ++n) + { + /* determine the thumbnail file */ + output_file = tumbler_thumbnail_get_file (uri, flavors[n]); + + /* skip the file if the thumbnail already exists */ + if (g_file_query_exists (output_file, NULL)) + { + g_object_unref (output_file); + continue; + } + + size = tumbler_thumbnail_flavor_get_size (flavors[n]); + + /* try to load the pixbuf from the file */ + pixbuf = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (input_stream), + size, size, TRUE, NULL, &err); + + /* propagate error if loading failed */ + if (err != NULL) + { + g_propagate_error (error, err); + g_object_unref (input_stream); + g_object_unref (output_file); + return FALSE; + } + + /* try to reset the stream */ + if (!g_seekable_seek (G_SEEKABLE (input_stream), 0, G_SEEK_SET, NULL, &err)) + { + g_propagate_error (error, err); + g_object_unref (input_stream); + g_object_unref (output_file); + g_object_unref (pixbuf); + return FALSE; + } + + /* apply optional orientation */ + pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); + + /* try to create and open the file to write the thumbnail to */ + output_stream = tumbler_thumbnail_create_and_open_file (output_file, &err); + g_object_unref (output_file); + + /* propagate error if preparing for writing failed */ + if (err != NULL) + { + g_propagate_error (error, err); + g_object_unref (input_stream); + g_object_unref (pixbuf); + return FALSE; + } + + /* write the pixbuf into the file */ + gdk_pixbuf_save_to_stream (pixbuf, G_OUTPUT_STREAM (output_stream), "png", NULL, &err, + NULL); + g_object_unref (output_stream); + + /* propagate error if writing failed */ + if (err != NULL) + { + g_propagate_error (error, err); + g_object_unref (input_stream); + g_object_unref (pixbuf); + return FALSE; + } + + /* destroy the pixbuf */ + g_object_unref (pixbuf); + } return TRUE; } diff --git a/tumblerd/tumbler-service.c b/tumblerd/tumbler-service.c index eaca835..881c130 100644 --- a/tumblerd/tumbler-service.c +++ b/tumblerd/tumbler-service.c @@ -77,6 +77,7 @@ static void tumbler_service_set_property (GObject *object, const GValue *value, GParamSpec *pspec); static void tumbler_service_scheduler_error (TumblerScheduler *scheduler, + guint handle, const GStrv failed_uris, gint error_code, const gchar *message, @@ -321,12 +322,13 @@ tumbler_service_set_property (GObject *object, static void tumbler_service_scheduler_error (TumblerScheduler *scheduler, + guint handle, const GStrv failed_uris, gint error_code, const gchar *message, TumblerService *service) { - g_signal_emit (service, tumbler_service_signals[SIGNAL_ERROR], 0, failed_uris, + g_signal_emit (service, tumbler_service_signals[SIGNAL_ERROR], 0, handle, failed_uris, error_code, message); } diff --git a/tumblerd/tumbler-thumbnailer.c b/tumblerd/tumbler-thumbnailer.c index f8dcdd8..b3cf92e 100644 --- a/tumblerd/tumbler-thumbnailer.c +++ b/tumblerd/tumbler-thumbnailer.c @@ -114,7 +114,7 @@ tumbler_thumbnailer_class_init (TumblerThumbnailerIface *klass) NULL, tumbler_marshal_VOID__STRING_INT_STRING, G_TYPE_NONE, - 1, + 3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); |