diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-01-24 04:03:19 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-01-24 05:48:13 +0100 |
commit | 788485d81eefcd43f0a66cf4cc664f8bde4423f5 (patch) | |
tree | 8c005e62f5ba11c8834e62334d40301515b137b4 /fiv-view.c | |
parent | 991e74b99bbf344effe456f71c544a284f7afe14 (diff) | |
download | fiv-788485d81eefcd43f0a66cf4cc664f8bde4423f5.tar.gz fiv-788485d81eefcd43f0a66cf4cc664f8bde4423f5.tar.xz fiv-788485d81eefcd43f0a66cf4cc664f8bde4423f5.zip |
Redirect warnings to the info bar
And speed up thumbnailing of animated images while at it.
Also, fix thumbnailing SVGs with external links.
Diffstat (limited to 'fiv-view.c')
-rw-r--r-- | fiv-view.c | 52 |
1 files changed, 31 insertions, 21 deletions
@@ -1160,6 +1160,34 @@ fiv_view_init(FivView *self) // --- Public interface -------------------------------------------------------- +static cairo_surface_t * +open_without_swapping_in(FivView *self, const gchar *uri) +{ + FivIoOpenContext ctx = { + .uri = uri, + .screen_profile = self->enable_cms ? self->screen_cms_profile : NULL, + .screen_dpi = 96, // TODO(p): Try to retrieve it from the screen. + .enhance = self->enhance, + .warnings = g_ptr_array_new_with_free_func(g_free), + }; + + GError *error = NULL; + cairo_surface_t *surface = fiv_io_open(&ctx, &error); + if (error) { + g_ptr_array_add(ctx.warnings, g_strdup(error->message)); + g_error_free(error); + } + + g_clear_pointer(&self->messages, g_free); + if (ctx.warnings->len) { + g_ptr_array_add(ctx.warnings, NULL); + self->messages = g_strjoinv("\n", (gchar **) ctx.warnings->pdata); + } + + g_ptr_array_free(ctx.warnings, TRUE); + return surface; +} + // TODO(p): Progressive picture loading, or at least async/cancellable. gboolean fiv_view_set_uri(FivView *self, const gchar *uri) @@ -1172,16 +1200,8 @@ fiv_view_set_uri(FivView *self, const gchar *uri) G_OBJECT(self), view_properties[PROP_ENHANCE]); } - GError *error = NULL; - cairo_surface_t *surface = fiv_io_open( - uri, self->enable_cms ? self->screen_cms_profile : NULL, FALSE, &error); - - g_clear_pointer(&self->messages, g_free); + cairo_surface_t *surface = open_without_swapping_in(self, uri); g_clear_pointer(&self->image, cairo_surface_destroy); - if (error) { - self->messages = g_strdup(error->message); - g_error_free(error); - } self->frame = self->page = NULL; self->image = surface; @@ -1220,19 +1240,9 @@ frame_step(FivView *self, int step) static gboolean reload(FivView *self) { - GError *error = NULL; - cairo_surface_t *surface = fiv_io_open(self->uri, - self->enable_cms ? self->screen_cms_profile : NULL, self->enhance, - &error); - - g_clear_pointer(&self->messages, g_free); - if (error) { - self->messages = g_strdup(error->message); - g_error_free(error); - } - + cairo_surface_t *surface = open_without_swapping_in(self, self->uri); g_object_notify_by_pspec(G_OBJECT(self), view_properties[PROP_MESSAGES]); - if (error) + if (!surface) return FALSE; g_clear_pointer(&self->image, cairo_surface_destroy); |