summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGaël Bonithon <gael@xfce.org>2021-12-12 19:03:45 +0100
committerGaël Bonithon <gael@xfce.org>2021-12-12 19:26:39 +0100
commit1de05df20d52fb45e3c06e1d5ff36984341cb55d (patch)
tree1166e5aa73db78fb01e81c60391467b9c4d14b3e /plugins
parent88dd43a1026d8a0c56dd1ccf3babf6f8ac275ebb (diff)
downloadtumbler-1de05df20d52fb45e3c06e1d5ff36984341cb55d.tar.gz
desktop-thumbnailer: Fix error handling
Pass the GError to all sub-functions of `load_thumbnail()` so that * `pixbuf == NULL` <=> `error != NULL` <=> Tumbler emits the "error" signal * `pixbuf != NULL` <=> `error == NULL` <=> Tumbler emits the "ready" signal (if there is no error afterwards when saving the thumbnail to disk)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer.c b/plugins/desktop-thumbnailer/desktop-thumbnailer.c
index 47f9248..8e4418f 100644
--- a/plugins/desktop-thumbnailer/desktop-thumbnailer.c
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer.c
@@ -196,28 +196,23 @@ static GdkPixbuf *
desktop_thumbnailer_get_pixbuf (GInputStream *stream,
int dest_width,
int dest_height,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GError **error)
{
GdkPixbuf *source;
gdouble hratio;
gdouble wratio;
gint source_width;
gint source_height;
- GError *error = NULL;
- source = gdk_pixbuf_new_from_stream (stream, cancellable, &error);
-
- if (!source)
- {
- g_clear_error (&error);
- return NULL;
- }
+ source = gdk_pixbuf_new_from_stream (stream, cancellable, error);
+ if (source == NULL)
+ return NULL;
/* determine the source pixbuf dimensions */
source_width = gdk_pixbuf_get_width (source);
source_height = gdk_pixbuf_get_height (source);
-
/* return the same pixbuf if no scaling is required */
if (source_width <= dest_width && source_height <= dest_height)
return source;
@@ -236,7 +231,6 @@ desktop_thumbnailer_get_pixbuf (GInputStream *stream,
return gdk_pixbuf_scale_simple (source,
MAX (dest_width, 1), MAX (dest_height, 1),
GDK_INTERP_BILINEAR);
-
}
@@ -305,7 +299,8 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer,
const gchar *path,
gint width,
gint height,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GError **error)
{
GFileIOStream *stream;
GFile *tmpfile;
@@ -317,11 +312,10 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer,
gint size;
gchar *working_directory = NULL;
GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
g_object_get (G_OBJECT (thumbnailer), "exec", &exec, NULL);
- tmpfile = g_file_new_tmp ("tumbler-XXXXXXX.png", &stream, NULL);
+ tmpfile = g_file_new_tmp ("tumbler-XXXXXX.png", &stream, error);
if ( G_LIKELY (tmpfile) )
{
@@ -336,27 +330,27 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer,
tmpfilepath,
&cmd_argc,
&cmd_argv,
- &error);
+ error);
if (G_LIKELY (res))
{
working_directory = g_path_get_dirname (path);
-
res = g_spawn_sync (working_directory,
cmd_argv, NULL,
G_SPAWN_SEARCH_PATH,
NULL, NULL,
NULL, NULL,
NULL,
- &error);
+ error);
if (G_LIKELY (res))
{
pixbuf = desktop_thumbnailer_get_pixbuf (g_io_stream_get_input_stream(G_IO_STREAM(stream)),
width,
height,
- cancellable);
+ cancellable,
+ error);
g_unlink (tmpfilepath);
}
@@ -364,10 +358,8 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer,
g_strfreev (cmd_argv);
}
else
- {
- g_warning (_("Malformed command line \"%s\": %s"), exec, error->message);
- g_clear_error (&error);
- }
+ g_warning (_("Malformed command line \"%s\": %s"), exec, (*error)->message);
+
g_free (tmpfilepath);
g_object_unref (tmpfile);
g_object_unref (stream);
@@ -418,7 +410,8 @@ desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
tumbler_thumbnail_flavor_get_size (flavor, &width, &height);
- pixbuf = desktop_thumbnailer_load_thumbnail (DESKTOP_THUMBNAILER(thumbnailer), uri, path, width, height, cancellable);
+ pixbuf = desktop_thumbnailer_load_thumbnail (DESKTOP_THUMBNAILER(thumbnailer),
+ uri, path, width, height, cancellable, &error);
if (pixbuf != NULL)
{