From f332d42bc834d6a7b0ec58bb8e073e63bc619f63 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 18 Apr 2005 20:37:04 +0000 Subject: [PATCH] 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. --- ChangeLog | 18 +++++ shell/Makefile.am | 45 +++++++---- shell/ev-document-types.c | 124 +++++++++++++++++++++++++++++++ shell/ev-document-types.h | 32 ++++++++ shell/ev-window.c | 101 +++---------------------- thumbnailer/Makefile.am | 8 +- thumbnailer/evince-thumbnailer.c | 65 +++++++++------- 7 files changed, 256 insertions(+), 137 deletions(-) create mode 100644 shell/ev-document-types.c create mode 100644 shell/ev-document-types.h diff --git a/ChangeLog b/ChangeLog index c917278e..58f6f661 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +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. + 2005-04-18 Paolo Borelli * shell/ev-stock-icons.c: constify some vars. diff --git a/shell/Makefile.am b/shell/Makefile.am index 629e89d3..95dcf833 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -18,6 +18,34 @@ INCLUDES= \ $(NULL) bin_PROGRAMS=evince +noinst_LTLIBRARIES = libevbackendfactory.la + +libevbackendfactory_la_SOURCES= \ + ev-document-types.c \ + ev-document-types.h + +libevbackendfactory_la_LIBADD = \ + $(top_builddir)/pdf/libpdfdocument.la \ + $(top_builddir)/pixbuf/libpixbufdocument.la \ + $(top_builddir)/ps/libgtkgs.la \ + $(top_builddir)/backend/libevbackend.la \ + $(NULL) + +if ENABLE_DJVU +libevbackendfactory_la_LIBADD += \ + $(top_builddir)/djvu/libgtkdjvu.la \ + $(NULL) +endif + +if ENABLE_DVI +libevbackendfactory_la_LIBADD += \ + $(top_builddir)/dvi/libgtkdvi.la \ + $(NULL) +endif + +if WITH_TYPE1_FONTS +libevbackendfactory_la_LIBADD += -lt1lib +endif evince_SOURCES= \ dummy.cc \ @@ -58,23 +86,8 @@ evince_LDADD= \ $(SHELL_LIBS) \ $(top_builddir)/cut-n-paste/recent-files/librecent.la \ $(top_builddir)/lib/libev.la \ - $(top_builddir)/pdf/libpdfdocument.la \ - $(top_builddir)/pixbuf/libpixbufdocument.la \ - $(top_builddir)/ps/libgtkgs.la \ - $(top_builddir)/backend/libevbackend.la \ - $(NULL) - -if ENABLE_DJVU -evince_LDADD += \ - $(top_builddir)/djvu/libgtkdjvu.la \ + libevbackendfactory.la \ $(NULL) -endif - -if ENABLE_DVI -evince_LDADD += \ - $(top_builddir)/dvi/libgtkdvi.la \ - $(NULL) -endif BUILT_SOURCES = ev-marshal.h ev-marshal.c diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c new file mode 100644 index 00000000..cc7734f1 --- /dev/null +++ b/shell/ev-document-types.c @@ -0,0 +1,124 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ +/* + * Copyright (C) 2005, Red Hat, Inc. + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "ev-document-types.h" + +/* The various document type backends: */ +#include "ev-poppler.h" +#include "pixbuf-document.h" +#include "ps-document.h" +#ifdef ENABLE_DVI +#include "dvi-document.h" +#endif +#ifdef ENABLE_DJVU +#include "djvu-document.h" +#endif + +#include + +typedef struct _EvDocumentType EvDocumentType; +struct _EvDocumentType +{ + const char *mime_type; + GType (*document_type_factory_callback)(); +}; + +const EvDocumentType document_types[] = { + /* PDF: */ + {"application/pdf", pdf_document_get_type}, + + /* Postscript: */ + {"application/postscript", ps_document_get_type}, + {"application/x-gzpostscript", ps_document_get_type}, + {"image/x-eps", ps_document_get_type}, + +#ifdef ENABLE_DJVU + /* djvu: */ + {"image/vnd.djvu", djvu_document_get_type), +#endif + +#ifdef ENABLE_DVI + /* dvi: */ + {"application/x-dvi", dvi_document_get_type}, +#endif +}; + +/* Would be nice to have this in gdk-pixbuf */ +static gboolean +mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) +{ + GSList *formats, *list; + gboolean retval = FALSE; + + formats = gdk_pixbuf_get_formats (); + + list = formats; + while (list) { + GdkPixbufFormat *format = list->data; + int i; + gchar **mime_types; + + if (gdk_pixbuf_format_is_disabled (format)) + continue; + + mime_types = gdk_pixbuf_format_get_mime_types (format); + + for (i = 0; mime_types[i] != NULL; i++) { + if (strcmp (mime_types[i], mime_type) == 0) { + retval = TRUE; + break; + } + } + + if (retval) + break; + + list = list->next; + } + + g_slist_free (formats); + + return retval; +} + +GType +ev_document_type_lookup (const char *mime_type) +{ + int i; + + g_return_val_if_fail (mime_type, G_TYPE_INVALID); + + for (i=0;i #include #include @@ -398,44 +389,6 @@ unable_to_load (EvWindow *ev_window, gtk_widget_destroy (dialog); } -/* Would be nice to have this in gdk-pixbuf */ -static gboolean -mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) -{ - GSList *formats, *list; - gboolean retval = FALSE; - - formats = gdk_pixbuf_get_formats (); - - list = formats; - while (list) { - GdkPixbufFormat *format = list->data; - int i; - gchar **mime_types; - - if (gdk_pixbuf_format_is_disabled (format)) - continue; - - mime_types = gdk_pixbuf_format_get_mime_types (format); - - for (i = 0; mime_types[i] != NULL; i++) { - if (strcmp (mime_types[i], mime_type) == 0) { - retval = TRUE; - break; - } - } - - if (retval) - break; - - list = list->next; - } - - g_slist_free (formats); - - return retval; -} - static void update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window) { @@ -709,33 +662,6 @@ start_loading_document (EvWindow *ev_window, return FALSE; } -static gboolean -is_file_supported (const gchar *mime_type) -{ - static const char * const supported_types [] = { - "application/pdf", - "application/postscript", - "application/x-dvi", - "image/vnd.djvu", - "application/x-gzpostscript", - "image/x-eps", - NULL - }; - gint i; - - g_return_val_if_fail (mime_type != NULL, FALSE); - - if (mime_type_supported_by_gdk_pixbuf (mime_type)) - return TRUE; - - for (i = 0; supported_types[i] != NULL; i++) { - if (g_ascii_strcasecmp (mime_type, supported_types[i]) == 0) - return TRUE; - } - - return FALSE; -} - void ev_window_open (EvWindow *ev_window, const char *uri) { @@ -749,22 +675,13 @@ ev_window_open (EvWindow *ev_window, const char *uri) if (mime_type == NULL) document = NULL; - else if (!strcmp (mime_type, "application/pdf")) - document = g_object_new (PDF_TYPE_DOCUMENT, NULL); - else if (!strcmp (mime_type, "application/postscript") || - !strcmp (mime_type, "application/x-gzpostscript") || - !strcmp (mime_type, "image/x-eps")) - document = g_object_new (PS_TYPE_DOCUMENT, NULL); -#ifdef ENABLE_DJVU - else if (!strcmp (mime_type, "image/vnd.djvu")) - document = g_object_new (DJVU_TYPE_DOCUMENT, NULL); -#endif - else if (mime_type_supported_by_gdk_pixbuf (mime_type)) - document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL); -#ifdef ENABLE_DVI - else if (!strcmp (mime_type, "application/x-dvi")) - document = g_object_new (DVI_TYPE_DOCUMENT, NULL); -#endif + else { + GType document_type = ev_document_type_lookup (mime_type); + + if (document_type!=G_TYPE_INVALID) { + document = g_object_new (document_type, NULL); + } + } if (document) { start_loading_document (ev_window, document, uri); @@ -797,7 +714,7 @@ ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list) uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE); mime_type = gnome_vfs_get_mime_type (uri); - if (is_file_supported (mime_type)) { + if (ev_document_type_lookup (mime_type)!=G_TYPE_INVALID) { if (ev_window_is_empty (EV_WINDOW (ev_window))) { ev_window_open (ev_window, uri); diff --git a/thumbnailer/Makefile.am b/thumbnailer/Makefile.am index c74910eb..81575ebe 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 d31e70f7..f9930bbf 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); -- 2.43.5