From f6ce926719943751cf65cacde7fae050593eb2d6 Mon Sep 17 00:00:00 2001 From: Perberos Date: Wed, 9 Nov 2011 18:17:43 -0300 Subject: inicial --- thumbnailer/Makefile.am | 83 ++++++ thumbnailer/evince-thumbnailer-comics.schemas.in | 106 ++++++++ thumbnailer/evince-thumbnailer-djvu.schemas.in | 30 +++ thumbnailer/evince-thumbnailer-dvi.schemas.in | 83 ++++++ thumbnailer/evince-thumbnailer-ps.schemas.in | 154 +++++++++++ thumbnailer/evince-thumbnailer.c | 309 +++++++++++++++++++++++ thumbnailer/evince-thumbnailer.schemas.in | 80 ++++++ 7 files changed, 845 insertions(+) create mode 100644 thumbnailer/Makefile.am create mode 100644 thumbnailer/evince-thumbnailer-comics.schemas.in create mode 100644 thumbnailer/evince-thumbnailer-djvu.schemas.in create mode 100644 thumbnailer/evince-thumbnailer-dvi.schemas.in create mode 100644 thumbnailer/evince-thumbnailer-ps.schemas.in create mode 100644 thumbnailer/evince-thumbnailer.c create mode 100644 thumbnailer/evince-thumbnailer.schemas.in (limited to 'thumbnailer') diff --git a/thumbnailer/Makefile.am b/thumbnailer/Makefile.am new file mode 100644 index 00000000..bc5a3314 --- /dev/null +++ b/thumbnailer/Makefile.am @@ -0,0 +1,83 @@ + +bin_PROGRAMS = evince-thumbnailer + +evince_thumbnailer_SOURCES = \ + evince-thumbnailer.c + +evince_thumbnailer_CPPFLAGS = \ + -DEVINCEDATADIR=\"$(pkgdatadir)\" \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + -DMATELOCALEDIR=\"$(datadir)/locale\" \ + -DMATEICONDIR=\""$(datadir)/pixmaps"\" \ + $(AM_CPPFLAGS) + +evince_thumbnailer_CFLAGS = \ + $(FRONTEND_CFLAGS) \ + $(DISABLE_DEPRECATED) \ + $(WARN_CFLAGS) \ + $(AM_CFLAGS) + +evince_thumbnailer_LDFLAGS = $(AM_LDFLAGS) + +if PLATFORM_WIN32 +evince_thumbnailer_LDFLAGS += -mwindows +endif + +evince_thumbnailer_LDADD = \ + $(top_builddir)/libdocument/libevdocument.la \ + $(FRONTEND_LIBS) + +schema_files = \ + evince-thumbnailer-dvi.schemas.in \ + evince-thumbnailer-djvu.schemas.in \ + evince-thumbnailer-comics.schemas.in \ + evince-thumbnailer-ps.schemas.in \ + evince-thumbnailer.schemas.in + +if WITH_MATECONF + +@INTLTOOL_SCHEMAS_RULE@ + +schema_DATA = + +if ENABLE_PDF +schema_DATA += evince-thumbnailer.schemas +endif + +if ENABLE_PS +schema_DATA += evince-thumbnailer-ps.schemas +endif + +if ENABLE_DJVU +schema_DATA += evince-thumbnailer-djvu.schemas +endif + +if ENABLE_DVI +schema_DATA += evince-thumbnailer-dvi.schemas +endif + +if ENABLE_COMICS +schema_DATA += evince-thumbnailer-comics.schemas +endif + +schemadir = $(MATECONF_SCHEMA_FILE_DIR) + +install-data-local: +if MATECONF_SCHEMAS_INSTALL + if test -z "$(DESTDIR)" ; then \ + for p in $(schema_DATA) ; do \ + MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(top_builddir)/thumbnailer/$$p >&1 > /dev/null; \ + done \ + fi +endif + +endif # WITH_MATECONF + +EXTRA_DIST = \ + $(schema_files) + +DISTCLEANFILES = \ + $(schema_DATA) + +-include $(top_srcdir)/git.mk diff --git a/thumbnailer/evince-thumbnailer-comics.schemas.in b/thumbnailer/evince-thumbnailer-comics.schemas.in new file mode 100644 index 00000000..2f00a802 --- /dev/null +++ b/thumbnailer/evince-thumbnailer-comics.schemas.in @@ -0,0 +1,106 @@ + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbz/enable + /desktop/mate/thumbnailers/application@x-cbz/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbz/command + /desktop/mate/thumbnailers/application@x-cbz/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbr/enable + /desktop/mate/thumbnailers/application@x-cbr/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbr/command + /desktop/mate/thumbnailers/application@x-cbr/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cb7/enable + /desktop/mate/thumbnailers/application@x-cb7/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cb7/command + /desktop/mate/thumbnailers/application@x-cb7/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbt/enable + /desktop/mate/thumbnailers/application@x-cbt/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-cbt/command + /desktop/mate/thumbnailers/application@x-cbt/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + diff --git a/thumbnailer/evince-thumbnailer-djvu.schemas.in b/thumbnailer/evince-thumbnailer-djvu.schemas.in new file mode 100644 index 00000000..4ea35272 --- /dev/null +++ b/thumbnailer/evince-thumbnailer-djvu.schemas.in @@ -0,0 +1,30 @@ + + + + + /schemas/desktop/mate/thumbnailers/image@vnd.djvu/enable + /desktop/mate/thumbnailers/image@vnd.djvu/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/image@vnd.djvu/command + /desktop/mate/thumbnailers/image@vnd.djvu/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + diff --git a/thumbnailer/evince-thumbnailer-dvi.schemas.in b/thumbnailer/evince-thumbnailer-dvi.schemas.in new file mode 100644 index 00000000..eab49a61 --- /dev/null +++ b/thumbnailer/evince-thumbnailer-dvi.schemas.in @@ -0,0 +1,83 @@ + + + + + /schemas/desktop/mate/thumbnailers/application@x-dvi/enable + /desktop/mate/thumbnailers/application@x-dvi/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-dvi/command + /desktop/mate/thumbnailers/application@x-dvi/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzdvi/enable + /desktop/mate/thumbnailers/application@x-gzdvi/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzdvi/command + /desktop/mate/thumbnailers/application@x-gzdvi/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzdvi/enable + /desktop/mate/thumbnailers/application@x-bzdvi/enable + evince + bool + true + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzdvi/command + /desktop/mate/thumbnailers/application@x-bzdvi/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + diff --git a/thumbnailer/evince-thumbnailer-ps.schemas.in b/thumbnailer/evince-thumbnailer-ps.schemas.in new file mode 100644 index 00000000..6866ef5a --- /dev/null +++ b/thumbnailer/evince-thumbnailer-ps.schemas.in @@ -0,0 +1,154 @@ + + + + + /schemas/desktop/mate/thumbnailers/application@postscript/enable + /desktop/mate/thumbnailers/application@postscript/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/application@postscript/command + /desktop/mate/thumbnailers/application@postscript/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzpostscript/enable + /desktop/mate/thumbnailers/application@x-bzpostscript/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzpostscript/command + /desktop/mate/thumbnailers/application@x-bzpostscript/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzpostscript/enable + /desktop/mate/thumbnailers/application@x-gzpostscript/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzpostscript/command + /desktop/mate/thumbnailers/application@x-gzpostscript/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-eps/enable + /desktop/mate/thumbnailers/image@x-eps/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-eps/command + /desktop/mate/thumbnailers/image@x-eps/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-bzeps/enable + /desktop/mate/thumbnailers/image@x-bzeps/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-bzeps/command + /desktop/mate/thumbnailers/image@x-bzeps/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-gzeps/enable + /desktop/mate/thumbnailers/image@x-gzeps/enable + evince + bool + true + + + + + + + + /schemas/desktop/mate/thumbnailers/image@x-gzeps/command + /desktop/mate/thumbnailers/image@x-gzeps/command + evince + string + evince-thumbnailer -s %s %u %o + + + + + + + + diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c new file mode 100644 index 00000000..23ad92b0 --- /dev/null +++ b/thumbnailer/evince-thumbnailer.c @@ -0,0 +1,309 @@ +/* + Copyright (C) 2005 Fernando Herrera + + 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. +*/ + +#include + +#include + +#include + +#include +#include + +#ifdef G_OS_WIN32 +#include +#include +#if !(_WIN32_WINNT >= 0x0500) +#error "_WIN32_WINNT must be defined >= 0x0500" +#endif +#include +#endif + +#define THUMBNAIL_SIZE 128 + +static gint size = THUMBNAIL_SIZE; +static const gchar **file_arguments; + +static const GOptionEntry goption_options[] = { + { "size", 's', 0, G_OPTION_ARG_INT, &size, NULL, "SIZE" }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, " " }, + { NULL } +}; + +struct AsyncData { + EvDocument *document; + const gchar *output; + gint size; + gboolean success; +}; + +static void +delete_temp_file (GFile *file) +{ + ev_tmp_file_unlink (file); + g_object_unref (file); +} + +static EvDocument * +evince_thumbnailer_get_document (GFile *file) +{ + EvDocument *document = NULL; + gchar *uri; + GFile *tmp_file = NULL; + GError *error = NULL; + + if (!g_file_is_native (file)) { + gchar *base_name, *template; + + base_name = g_file_get_basename (file); + template = g_strdup_printf ("document.XXXXXX-%s", base_name); + g_free (base_name); + + tmp_file = ev_mkstemp_file (template, &error); + g_free (template); + if (!tmp_file) { + g_printerr ("Error loading remote document: %s\n", error->message); + g_error_free (error); + + return NULL; + } + + g_file_copy (file, tmp_file, G_FILE_COPY_OVERWRITE, + NULL, NULL, NULL, &error); + if (error) { + g_printerr ("Error loading remote document: %s\n", error->message); + g_error_free (error); + g_object_unref (tmp_file); + + return NULL; + } + uri = g_file_get_uri (tmp_file); + } else { + uri = g_file_get_uri (file); + } + + document = ev_document_factory_get_document (uri, &error); + if (tmp_file) { + if (document) { + g_object_weak_ref (G_OBJECT (document), + (GWeakNotify)delete_temp_file, + tmp_file); + } else { + ev_tmp_file_unlink (tmp_file); + g_object_unref (tmp_file); + } + } + g_free (uri); + if (error) { + if (error->domain == EV_DOCUMENT_ERROR && + error->code == EV_DOCUMENT_ERROR_ENCRYPTED) { + /* FIXME: Create a thumb for cryp docs */ + g_error_free (error); + return NULL; + } + g_printerr ("Error loading document: %s\n", error->message); + g_error_free (error); + return NULL; + } + + return document; +} + +static gboolean +evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int size) +{ + EvRenderContext *rc; + double width, height; + GdkPixbuf *pixbuf; + EvPage *page; + + page = ev_document_get_page (document, 0); + + ev_document_get_page_size (document, 0, &width, &height); + + rc = ev_render_context_new (page, 0, size / width); + pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), + rc, FALSE); + g_object_unref (rc); + g_object_unref (page); + + if (pixbuf != NULL) { + const char *overlaid_icon_name = NULL; + + if (overlaid_icon_name) { + GdkPixbuf *overlaid_pixbuf; + +#ifdef G_OS_WIN32 + gchar *dir = g_win32_get_package_installation_directory_of_module (NULL); + gchar *overlaid_icon_path = g_build_filename (dir, "share", "evince", overlaid_icon_name, NULL); + g_free (dir); +#else + gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", EVINCEDATADIR, overlaid_icon_name); +#endif + overlaid_pixbuf = gdk_pixbuf_new_from_file (overlaid_icon_path, NULL); + g_free (overlaid_icon_path); + if (overlaid_pixbuf != NULL) { + int delta_height, delta_width; + + delta_width = gdk_pixbuf_get_width (pixbuf) - + gdk_pixbuf_get_width (overlaid_pixbuf); + delta_height = gdk_pixbuf_get_height (pixbuf) - + gdk_pixbuf_get_height (overlaid_pixbuf); + + gdk_pixbuf_composite (overlaid_pixbuf, pixbuf, + delta_width, delta_height, + gdk_pixbuf_get_width (overlaid_pixbuf), + gdk_pixbuf_get_height (overlaid_pixbuf), + delta_width, delta_height, + 1, 1, + GDK_INTERP_NEAREST, 100); + + g_object_unref (overlaid_pixbuf); + } + } + + if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) { + g_object_unref (pixbuf); + return TRUE; + } + + g_object_unref (pixbuf); + } + + return FALSE; +} + +static gpointer +evince_thumbnail_pngenc_get_async (struct AsyncData *data) +{ + ev_document_doc_mutex_lock (); + data->success = evince_thumbnail_pngenc_get (data->document, + data->output, + data->size); + ev_document_doc_mutex_unlock (); + + g_idle_add ((GSourceFunc)gtk_main_quit, NULL); + + return NULL; +} + +static void +print_usage (GOptionContext *context) +{ + gchar *help; + + help = g_option_context_get_help (context, TRUE, NULL); + g_print ("%s", help); + g_free (help); +} + +int +main (int argc, char *argv[]) +{ + EvDocument *document; + GOptionContext *context; + const char *input; + const char *output; + GFile *file; + GError *error = NULL; + + context = g_option_context_new ("- MATE Document Thumbnailer"); + g_option_context_add_main_entries (context, goption_options, NULL); + + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_printerr ("%s\n", error->message); + g_error_free (error); + print_usage (context); + g_option_context_free (context); + + return -1; + } + + input = file_arguments ? file_arguments[0] : NULL; + output = input ? file_arguments[1] : NULL; + if (!input || !output) { + print_usage (context); + g_option_context_free (context); + + return -1; + } + + g_option_context_free (context); + + if (size < 1) { + g_print ("Size cannot be smaller than 1 pixel\n"); + return -1; + } + + input = file_arguments[0]; + output = file_arguments[1]; + + g_type_init (); + + if (!g_thread_supported ()) + g_thread_init (NULL); + + if (!ev_init ()) + return -1; + + file = g_file_new_for_commandline_arg (input); + document = evince_thumbnailer_get_document (file); + g_object_unref (file); + + if (!document) { + ev_shutdown (); + return -2; + } + + if (!EV_IS_DOCUMENT_THUMBNAILS (document)) { + g_object_unref (document); + ev_shutdown (); + return -2; + } + + if (EV_IS_ASYNC_RENDERER (document)) { + struct AsyncData data; + + gtk_init (&argc, &argv); + + data.document = document; + data.output = output; + data.size = size; + + g_thread_create ((GThreadFunc) evince_thumbnail_pngenc_get_async, + &data, FALSE, NULL); + + gtk_main (); + + g_object_unref (document); + ev_shutdown (); + + return data.success ? 0 : -2; + } + + if (!evince_thumbnail_pngenc_get (document, output, size)) { + g_object_unref (document); + ev_shutdown (); + return -2; + } + + g_object_unref (document); + ev_shutdown (); + + return 0; +} diff --git a/thumbnailer/evince-thumbnailer.schemas.in b/thumbnailer/evince-thumbnailer.schemas.in new file mode 100644 index 00000000..6dafb8f0 --- /dev/null +++ b/thumbnailer/evince-thumbnailer.schemas.in @@ -0,0 +1,80 @@ + + + + + /schemas/desktop/mate/thumbnailers/application@pdf/enable + /desktop/mate/thumbnailers/application@pdf/enable + evince + bool + true + + Enable thumbnailing of PDF Documents + Boolean options available: true enables thumbnailing and false disables the creation of new thumbnails + + + + + + /schemas/desktop/mate/thumbnailers/application@pdf/command + /desktop/mate/thumbnailers/application@pdf/command + evince + string + evince-thumbnailer -s %s %u %o + + Thumbnail command for PDF Documents + Valid command plus arguments for the PDF Document thumbnailer. See Caja thumbnailer documentation for more information. + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzpdf/enable + /desktop/mate/thumbnailers/application@x-bzpdf/enable + evince + bool + true + + Enable thumbnailing of PDF Documents + Boolean options available: true enables thumbnailing and false disables the creation of new thumbnails + + + + + + /schemas/desktop/mate/thumbnailers/application@x-bzpdf/command + /desktop/mate/thumbnailers/application@x-bzpdf/command + evince + string + evince-thumbnailer -s %s %u %o + + Thumbnail command for PDF Documents + Valid command plus arguments for the PDF Document thumbnailer. See Caja thumbnailer documentation for more information. + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzpdf/enable + /desktop/mate/thumbnailers/application@x-gzpdf/enable + evince + bool + true + + Enable thumbnailing of PDF Documents + Boolean options available: true enables thumbnailing and false disables the creation of new thumbnails + + + + + + /schemas/desktop/mate/thumbnailers/application@x-gzpdf/command + /desktop/mate/thumbnailers/application@x-gzpdf/command + evince + string + evince-thumbnailer -s %s %u %o + + Thumbnail command for PDF Documents + Valid command plus arguments for the PDF Document thumbnailer. See Caja thumbnailer documentation for more information. + + + + + -- cgit v1.2.1