From 33b10be852e41bcde731f9eb95907f120a63e141 Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Sat, 4 Apr 2015 17:28:00 +0200 Subject: [PATCH] Fixes #9659: Add comicbook thumbnailer plugin Adds a plugin to generate thumbnails from comicbook archives (.cbr, .cbz, .cbt, .cb7). Uses libarchive to extract the first image from the comicbook archive and displays that as the thumbnail. --- README | 1 + acinclude.m4 | 21 ++ configure.ac | 7 + plugins/Makefile.am | 1 + plugins/comicbook-thumbnailer/Makefile.am | 64 +++++ .../comicbook-thumbnailer-plugin.c | 94 +++++++ .../comicbook-thumbnailer-provider.c | 142 ++++++++++ .../comicbook-thumbnailer-provider.h | 44 +++ .../comicbook-thumbnailer.c | 253 ++++++++++++++++++ .../comicbook-thumbnailer.h | 44 +++ 10 files changed, 671 insertions(+) create mode 100644 plugins/comicbook-thumbnailer/Makefile.am create mode 100644 plugins/comicbook-thumbnailer/comicbook-thumbnailer-plugin.c create mode 100644 plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.c create mode 100644 plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.h create mode 100644 plugins/comicbook-thumbnailer/comicbook-thumbnailer.c create mode 100644 plugins/comicbook-thumbnailer/comicbook-thumbnailer.h diff --git a/README b/README index 06eedef..ab39f07 100644 --- a/README +++ b/README @@ -32,6 +32,7 @@ Tumbler can optionally use the following packages: * FreeType 2.x (for a font thumbnailer plugin) * libpng >= 1.2.0 (for the Thumbnail Managing Standard storage backend, gdk-pixbuf-2.0 is also required for this) + * libarchive (for a comicbook thumbnailer plugin) Installation diff --git a/acinclude.m4 b/acinclude.m4 index 596917b..b735113 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -256,6 +256,27 @@ AC_MSG_RESULT([$ac_tumbler_cover_thumbnailer]) +dnl TUMBLER_COMICBOOK_THUMBNAILER() +dnl +dnl Check whether to build and install the Comicbook Archive thumbnailer plugin. +dnl +AC_DEFUN([TUMBLER_COMICBOOK_THUMBNAILER], +[ +AC_ARG_ENABLE([comicbook-thumbnailer], [AC_HELP_STRING([--disable-comicbook-thumbnailer], [Don't build the Comicbook Archive thumbnailer plugin])], + [ac_tumbler_comicbook_thumbnailer=$enableval], [ac_tumbler_comicbook_thumbnailer=yes]) +if test x"$ac_tumbler_comicbook_thumbnailer" = x"yes"; then + dnl Check for gdk-pixbuf + PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.14], + [ac_tumbler_comicbook_thumbnailer=no]) +fi + +AC_MSG_CHECKING([whether to build the Comicbook Archive thumbnailer plugin]) +AM_CONDITIONAL([TUMBLER_COMICBOOK_THUMBNAILER], [test x"$ac_tumbler_comicbook_thumbnailer" = x"yes"]) +AC_MSG_RESULT([$ac_tumbler_comicbook_thumbnailer]) +]) + + + dnl TUMBLER_XDG_CACHE() dnl dnl Check whether to build and install the freedesktop.org cache plugin. diff --git a/configure.ac b/configure.ac index 9f8befd..bc661f0 100644 --- a/configure.ac +++ b/configure.ac @@ -153,6 +153,7 @@ dnl ************************* dnl *** Check for plugins *** dnl ************************* TUMBLER_COVER_THUMBNAILER() +TUMBLER_COMICBOOK_THUMBNAILER() TUMBLER_FONT_THUMBNAILER() TUMBLER_JPEG_THUMBNAILER() TUMBLER_PIXBUF_THUMBNAILER() @@ -188,6 +189,7 @@ docs/reference/tumbler/Makefile docs/reference/tumbler/version.xml plugins/Makefile plugins/cover-thumbnailer/Makefile +plugins/comicbook-thumbnailer/Makefile plugins/font-thumbnailer/Makefile plugins/gst-thumbnailer/Makefile plugins/jpeg-thumbnailer/Makefile @@ -225,6 +227,11 @@ echo " * Cover thumbnailer plugin: yes" else echo " * Cover thumbnailer plugin: no" fi +if test x"$ac_tumbler_comicbook_thumbnailer" = x"yes"; then +echo " * Comicbook Archive thumbnailer plugin: yes" +else +echo " * Comicbook Archive thumbnailer plugin: no" +fi if test x"$ac_tumbler_font_thumbnailer" = x"yes"; then echo " * FreeType font thumbnailer plugin: yes" else diff --git a/plugins/Makefile.am b/plugins/Makefile.am index f2b5307..56aa127 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -19,6 +19,7 @@ SUBDIRS = \ cover-thumbnailer \ + comicbook-thumbnailer \ font-thumbnailer \ gst-thumbnailer \ jpeg-thumbnailer \ diff --git a/plugins/comicbook-thumbnailer/Makefile.am b/plugins/comicbook-thumbnailer/Makefile.am new file mode 100644 index 0000000..a6a453e --- /dev/null +++ b/plugins/comicbook-thumbnailer/Makefile.am @@ -0,0 +1,64 @@ +# vi:set ts=8 sw=8 noet ai nocindent: +# - +# Copyright (c) 2012 Nick Schermer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + +if TUMBLER_COMICBOOK_THUMBNAILER + +tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins +tumbler_plugin_LTLIBRARIES = \ + tumbler-comicbook-thumbnailer.la + +tumbler_comicbook_thumbnailer_la_SOURCES = \ + comicbook-thumbnailer-plugin.c \ + comicbook-thumbnailer-provider.c \ + comicbook-thumbnailer-provider.h \ + comicbook-thumbnailer.c \ + comicbook-thumbnailer.h + +tumbler_comicbook_thumbnailer_la_CFLAGS = \ + -I$(top_builddir) \ + -I$(top_builddir)/plugins \ + -I$(top_srcdir) \ + -I$(top_srcdir)/plugins \ + -DG_LOG_DOMAIN=\"tumbler-comicbook-thumbnailer\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(GDK_PIXBUF_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(LIBARCHIVE_CFLAGS) \ + $(PLATFORM_CFLAGS) \ + $(PLATFORM_CPPFLAGS) + +tumbler_comicbook_thumbnailer_la_LDFLAGS = \ + -avoid-version \ + -export-dynamic \ + -module \ + $(PLATFORM_LDFLAGS) + +tumbler_comicbook_thumbnailer_la_LIBADD = \ + $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la \ + $(GDK_PIXBUF_LIBS) \ + $(GIO_LIBS) \ + $(GLIB_LIBS) \ + $(CURL_LIBS) \ + -lm + +tumbler_comicbook_thumbnailer_la_DEPENDENCIES = \ + $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la + +endif diff --git a/plugins/comicbook-thumbnailer/comicbook-thumbnailer-plugin.c b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-plugin.c new file mode 100644 index 0000000..a9d303a --- /dev/null +++ b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-plugin.c @@ -0,0 +1,94 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann + * Copyright (c) 2011 Nick Schermer + * Copyright (c) 2019 Peter Maatman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include + +#include +#include + + + +G_MODULE_EXPORT void tumbler_plugin_initialize (TumblerProviderPlugin *plugin); +G_MODULE_EXPORT void tumbler_plugin_shutdown (void); +G_MODULE_EXPORT void tumbler_plugin_get_types (const GType **types, + gint *n_types); + + + +static GType type_list[1]; + + + +void +tumbler_plugin_initialize (TumblerProviderPlugin *plugin) +{ + const gchar *mismatch; + + /* verify that the tumbler versions are compatible */ + mismatch = tumbler_check_version (TUMBLER_MAJOR_VERSION, + TUMBLER_MINOR_VERSION, + TUMBLER_MICRO_VERSION); + if (G_UNLIKELY (mismatch != NULL)) + { + g_warning (_("Version mismatch: %s"), mismatch); + return; + } + +#ifdef DEBUG + g_print ("Initializing the Tumbler Comicbook Thumbnailer plugin\n"); +#endif + + /* register the types provided by this plugin */ + comicbook_thumbnailer_register (plugin); + comicbook_thumbnailer_provider_register (plugin); + + /* set up the plugin provider type list */ + type_list[0] = TYPE_COMICBOOK_THUMBNAILER_PROVIDER; +} + + + +void +tumbler_plugin_shutdown (void) +{ +#ifdef DEBUG + g_print ("Shutting down the Tumbler Comicbook Thumbnailer plugin\n"); +#endif +} + + + +void +tumbler_plugin_get_types (const GType **types, + gint *n_types) +{ + *types = type_list; + *n_types = G_N_ELEMENTS (type_list); +} diff --git a/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.c b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.c new file mode 100644 index 0000000..2903ec3 --- /dev/null +++ b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.c @@ -0,0 +1,142 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2012 Nick Schermer + * Copyright (c) 2019 Peter Maatman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +#include +#include + + + +static void comicbook_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface); +static GList *comicbook_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider); +static void comicbook_thumbnailer_provider_finalize (GObject *object); + + + +struct _ComicbookThumbnailerProviderClass +{ + GObjectClass __parent__; +}; + +struct _ComicbookThumbnailerProvider +{ + GObject __parent__; +}; + + + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (ComicbookThumbnailerProvider, + comicbook_thumbnailer_provider, + G_TYPE_OBJECT, + 0, + TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER, + comicbook_thumbnailer_provider_thumbnailer_provider_init)); + + + +void +comicbook_thumbnailer_provider_register (TumblerProviderPlugin *plugin) +{ + comicbook_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin)); +} + + + +static void +comicbook_thumbnailer_provider_class_init (ComicbookThumbnailerProviderClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = comicbook_thumbnailer_provider_finalize; +} + + + +static void +comicbook_thumbnailer_provider_class_finalize (ComicbookThumbnailerProviderClass *klass) +{ +} + + + +static void +comicbook_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface) +{ + iface->get_thumbnailers = comicbook_thumbnailer_provider_get_thumbnailers; +} + + + +static void +comicbook_thumbnailer_provider_init (ComicbookThumbnailerProvider *provider) +{ +} + + + +static void +comicbook_thumbnailer_provider_finalize (GObject *object) +{ + (*G_OBJECT_CLASS (comicbook_thumbnailer_provider_parent_class)->finalize) (object); +} + + + +static GList * +comicbook_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider) +{ + ComicbookThumbnailer *thumbnailer; + GList *thumbnailers = NULL; + GStrv uri_schemes; + static const gchar *mime_types[] = + { + "application/x-cbr", + NULL + }; + + /* determine the URI schemes supported by GIO */ + uri_schemes = tumbler_util_get_supported_uri_schemes (); + + /* create the pixbuf thumbnailer */ + thumbnailer = g_object_new (TYPE_COMICBOOK_THUMBNAILER, + "uri-schemes", uri_schemes, + "mime-types", mime_types, + NULL); + + /* add the thumbnailer to the list */ + thumbnailers = g_list_append (thumbnailers, thumbnailer); + + /* free URI schemes */ + g_strfreev (uri_schemes); + + return thumbnailers; +} diff --git a/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.h b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.h new file mode 100644 index 0000000..73ad0a9 --- /dev/null +++ b/plugins/comicbook-thumbnailer/comicbook-thumbnailer-provider.h @@ -0,0 +1,44 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann + * Copyright (c) 2019 Peter Maatman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __COMICBOOK_THUMBNAILER_PROVIDER_H__ +#define __COMICBOOK_THUMBNAILER_PROVIDER_H__ + +#include + +G_BEGIN_DECLS + +#define TYPE_COMICBOOK_THUMBNAILER_PROVIDER (comicbook_thumbnailer_provider_get_type ()) +#define COMICBOOK_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMICBOOK_THUMBNAILER_PROVIDER, ComicbookThumbnailerProvider)) +#define COMICBOOK_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COMICBOOK_THUMBNAILER_PROVIDER, ComicbookThumbnailerProviderClass)) +#define IS_COMICBOOK_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMICBOOK_THUMBNAILER_PROVIDER)) +#define IS_COMICBOOK_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COMICBOOK_THUMBNAILER_PROVIDER) +#define COMICBOOK_THUMBNAILER_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_COMICBOOK_THUMBNAILER_PROVIDER, ComicbookThumbnailerProviderClass)) + +typedef struct _ComicbookThumbnailerProviderClass ComicbookThumbnailerProviderClass; +typedef struct _ComicbookThumbnailerProvider ComicbookThumbnailerProvider; + +GType comicbook_thumbnailer_provider_get_type (void) G_GNUC_CONST; +void comicbook_thumbnailer_provider_register (TumblerProviderPlugin *plugin); + +G_END_DECLS + +#endif /* !__COMICBOOK_THUMBNAILER_PROVIDER_H__ */ diff --git a/plugins/comicbook-thumbnailer/comicbook-thumbnailer.c b/plugins/comicbook-thumbnailer/comicbook-thumbnailer.c new file mode 100644 index 0000000..ea87a3b --- /dev/null +++ b/plugins/comicbook-thumbnailer/comicbook-thumbnailer.c @@ -0,0 +1,253 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann + * Copyright (c) 2011 Tam Merlant + * Copyright (c) 2019 Peter Maatman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +#include "comicbook-thumbnailer.h" + +static void comicbook_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info); + + + +struct _ComicbookThumbnailerClass +{ + TumblerAbstractThumbnailerClass __parent__; +}; + +struct _ComicbookThumbnailer +{ + TumblerAbstractThumbnailer __parent__; +}; + + + +G_DEFINE_DYNAMIC_TYPE (ComicbookThumbnailer, + comicbook_thumbnailer, + TUMBLER_TYPE_ABSTRACT_THUMBNAILER); + + + +void +comicbook_thumbnailer_register (TumblerProviderPlugin *plugin) +{ + comicbook_thumbnailer_register_type (G_TYPE_MODULE (plugin)); +} + + + +static void +comicbook_thumbnailer_class_init (ComicbookThumbnailerClass *klass) +{ + TumblerAbstractThumbnailerClass *abstractthumbnailer_class; + + abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass); + abstractthumbnailer_class->create = comicbook_thumbnailer_create; +} + + + +static void +comicbook_thumbnailer_class_finalize (ComicbookThumbnailerClass *klass) +{ +} + + + +static void +comicbook_thumbnailer_init (ComicbookThumbnailer *thumbnailer) +{ +} + + + + +static GInputStream * +comicbook_thumbnailer_read_archive_first_file_to_stream(GFile *file) +{ + struct archive *a; + struct archive_entry *entry; + gint r; + int size; + void *buf = NULL; + + a = archive_read_new (); + archive_read_support_format_rar (a); + archive_read_support_format_zip (a); + archive_read_support_format_7zip (a); + archive_read_support_format_tar (a); + + // FIXME: what should the blocksize be? 10240 was used in the untar example in libarchive + if ((r = archive_read_open_filename (a, g_file_get_path(file), 10240))) { + return NULL; + } + + r = archive_read_next_header (a, &entry); + + if (r == ARCHIVE_EOF || r != ARCHIVE_OK) + return NULL; + + size = archive_entry_size(entry); + archive_entry_free (entry); + + archive_read_data(a, buf, size); + + archive_read_close(a); + archive_read_free (a); + + return g_memory_input_stream_new_from_data(buf, size, NULL); +} + + +static GdkPixbuf* +comicbook_thumbnailer_get_cover(TumblerAbstractThumbnailer *thumbnailer, + GFile *file) +{ + GdkPixbuf* pixbuf; + GError *error; + + GInputStream *stream = comicbook_thumbnailer_read_archive_first_file_to_stream (file); + + pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error); + if (pixbuf == NULL) + { + g_signal_emit_by_name (thumbnailer, "error", "", error->code, error->message); + g_error_free (error); + } + + return pixbuf; +} + + +static void +comicbook_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info) +{ + TumblerThumbnailFlavor *flavor; + TumblerImageData data; + TumblerThumbnail *thumbnail; + const gchar *uri; + gchar *path; + GdkPixbuf *pixbuf = NULL; + GError *error = NULL; + GFile *file; + gint height; + gint width; + GdkPixbuf *scaled; + + g_return_if_fail (IS_COMICBOOK_THUMBNAILER (thumbnailer)); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + g_return_if_fail (TUMBLER_IS_FILE_INFO (info)); + + /* do nothing if cancelled */ + if (g_cancellable_is_cancelled (cancellable)) + return; + + uri = tumbler_file_info_get_uri (info); + file = g_file_new_for_uri (uri); + + thumbnail = tumbler_file_info_get_thumbnail (info); + g_assert (thumbnail != NULL); + + /* get destination size */ + flavor = tumbler_thumbnail_get_flavor (thumbnail); + g_assert (flavor != NULL); + tumbler_thumbnail_flavor_get_size (flavor, &width, &height); + g_object_unref (flavor); + + /* only handle local files */ + path = g_file_get_path (file); + if (path != NULL && g_path_is_absolute (path)) + { + pixbuf = comicbook_thumbnailer_get_cover(thumbnailer, file); + + if (pixbuf == NULL) + { + g_set_error_literal (&error, TUMBLER_ERROR, TUMBLER_ERROR_NO_CONTENT, + _("Thumbnail could not be inferred from file contents")); + } + } + else + { + g_set_error_literal (&error, TUMBLER_ERROR, TUMBLER_ERROR_UNSUPPORTED, + _("Only local files are supported")); + } + + g_free (path); + g_object_unref (file); + + if (pixbuf != NULL) + { + scaled = scale_pixbuf (pixbuf, width, height); + g_object_unref (pixbuf); + pixbuf = scaled; + + data.data = gdk_pixbuf_get_pixels (pixbuf); + data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); + data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf); + data.width = gdk_pixbuf_get_width (pixbuf); + data.height = gdk_pixbuf_get_height (pixbuf); + data.rowstride = gdk_pixbuf_get_rowstride (pixbuf); + data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf); + + tumbler_thumbnail_save_image_data (thumbnail, &data, + tumbler_file_info_get_mtime (info), + NULL, &error); + } + + if (error != NULL) + { + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + } + else + { + g_signal_emit_by_name (thumbnailer, "ready", uri); + g_object_unref (pixbuf); + } + + g_object_unref (thumbnail); +} diff --git a/plugins/comicbook-thumbnailer/comicbook-thumbnailer.h b/plugins/comicbook-thumbnailer/comicbook-thumbnailer.h new file mode 100644 index 0000000..64fa3c5 --- /dev/null +++ b/plugins/comicbook-thumbnailer/comicbook-thumbnailer.h @@ -0,0 +1,44 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2012 Nick Schermer + * Copyright (c) 2019 Peter Maatman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __COMICBOOK_THUMBNAILER_H__ +#define __COMICBOOK_THUMBNAILER_H__ + +#include + +G_BEGIN_DECLS + +#define TYPE_COMICBOOK_THUMBNAILER (comicbook_thumbnailer_get_type ()) +#define COMICBOOK_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMICBOOK_THUMBNAILER, ComicbookThumbnailer)) +#define COMICBOOK_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COMICBOOK_THUMBNAILER, ComicbookThumbnailerClass)) +#define IS_COMICBOOK_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMICBOOK_THUMBNAILER)) +#define IS_COMICBOOK_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COMICBOOK_THUMBNAILER) +#define COMICBOOK_THUMBNAILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_COMICBOOK_THUMBNAILER, ComicbookThumbnailerClass)) + +typedef struct _ComicbookThumbnailerClass ComicbookThumbnailerClass; +typedef struct _ComicbookThumbnailer ComicbookThumbnailer; + +GType comicbook_thumbnailer_get_type (void) G_GNUC_CONST; +void comicbook_thumbnailer_register (TumblerProviderPlugin *plugin); + +G_END_DECLS + +#endif /* !__COMICBOOK_THUMBNAILER_H__ */ -- 2.24.0