From f332d42bc834d6a7b0ec58bb8e073e63bc619f63 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 18 Apr 2005 20:37:04 +0000 Subject: New files, handling the mapping from mimetypes to backends 2005-04-18 David Malcolm * shell/ev-document-types.h: * shell/ev-document-types.c: New files, handling the mapping from mimetypes to backends * shell/ev-window.c: * thumbnailer/evince-thumbnailer.c: Use the ev-document-types code * shell/Makefile.am: Added new convenience library libevbackendfactory_la, containing the new mimetype->backend logic; moved the backends into it. * thumbnailer/Makefile.am: Make the thumbnailer link with the libevbackend.la convenience library, rather than having a duplicate of the backend logic here. --- (limited to 'thumbnailer') diff --git a/thumbnailer/Makefile.am b/thumbnailer/Makefile.am index c74910e..81575eb 100644 --- a/thumbnailer/Makefile.am +++ b/thumbnailer/Makefile.am @@ -7,6 +7,7 @@ INCLUDES= \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/pdf \ -I$(top_srcdir)/backend \ + -I$(top_srcdir)/shell \ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ -DGNOMEICONDIR=\""$(datadir)/pixmaps"\" \ $(THUMBNAILER_CFLAGS) \ @@ -19,11 +20,10 @@ evince_thumbnailer_SOURCES= \ evince-thumbnailer.c $(NULL) -evince_thumbnailer_LDADD= \ - $(THUMBNAILER_LIBS) \ +evince_thumbnailer_LDADD= \ + $(THUMBNAILER_LIBS) \ $(top_builddir)/lib/libev.la \ - $(top_builddir)/pdf/libpdfdocument.la \ - $(top_builddir)/backend/libevbackend.la \ + $(top_builddir)/shell/libevbackendfactory.la \ $(NULL) pixmapdir = $(pkgdatadir) diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index d31e70f..f9930bb 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -16,14 +16,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include - #include #include #include #include #include +#include #include #include @@ -37,16 +36,18 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) char *mime_type; GError *error = NULL; GdkPixbuf *pixbuf; + GType document_type; mime_type = gnome_vfs_get_mime_type (uri); if (mime_type == NULL) return FALSE; - if (!strcmp (mime_type, "application/pdf")) - document = g_object_new (PDF_TYPE_DOCUMENT, NULL); - else + document_type = ev_document_type_lookup (mime_type); + if (document_type==G_TYPE_INVALID) return FALSE; + document = g_object_new (document_type, NULL); + if (!ev_document_load (document, uri, &error)) { if (error->domain == EV_DOCUMENT_ERROR && error->code == EV_DOCUMENT_ERROR_ENCRYPTED) { @@ -56,30 +57,44 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) return FALSE; } + if (!EV_IS_DOCUMENT_THUMBNAILS (document)) { + return FALSE; + } + pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), 1, size, FALSE); if (pixbuf != NULL) { - GdkPixbuf *pdflogo; - - pdflogo = gdk_pixbuf_new_from_file (DATADIR"/pdf-icon.png", NULL); - if (pdflogo != NULL) { - int delta_height, delta_width; - - delta_width = gdk_pixbuf_get_width (pixbuf) - - gdk_pixbuf_get_width (pdflogo); - delta_height = gdk_pixbuf_get_height (pixbuf) - - gdk_pixbuf_get_height (pdflogo); - - gdk_pixbuf_composite (pdflogo, pixbuf, - delta_width, delta_height, - gdk_pixbuf_get_width (pdflogo), - gdk_pixbuf_get_height (pdflogo), - delta_width, delta_height, - 1, 1, - GDK_INTERP_NEAREST, 100); - - gdk_pixbuf_unref (pdflogo); + const char *overlaid_icon_name = NULL; + + if (strcmp(mime_type,"application/pdf")==0) { + overlaid_icon_name = "pdf-icon.png"; + } + + if (overlaid_icon_name) { + GdkPixbuf *overlaid_pixbuf; + + gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", DATADIR, overlaid_icon_name); + 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); + + gdk_pixbuf_unref (overlaid_pixbuf); + } } if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) { gdk_pixbuf_unref (pixbuf); -- cgit v0.9.1