From 31e16bd8f386dc292e60489d4a17227804bdc2e6 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Fri, 28 Dec 2007 18:13:32 +0000 Subject: Plugin system for backends. Fixes bug #351348. 2007-12-28 Carlos Garcia Campos * configure.ac: * Makefile.am: * po/POTFILES.in: * backend/comics/Makefile.am: * backend/comics/comics-document.[ch]: * backend/comics/comicsdocument.evince-backend.in: * backend/djvu/Makefile.am: * backend/djvu/djvu-document.[ch]: * backend/djvu/djvudocument.evince-backend.in: * backend/dvi/Makefile.am: * backend/dvi/dvi-document.[c]: * backend/dvi/dvidocument.evince-backend.in: * backend/impress/Makefile.am: * backend/impress/impress-document.[ch]: * backend/impress/impressdocument.evince-backend.in: * backend/pdf/Makefile.am: * backend/pdf/ev-poppler.cc: * backend/pdf/ev-poppler.h: * backend/pdf/pdfdocument.evince-backend.in: * backend/pixbuf/Makefile.am: * backend/pixbuf/pixbuf-document.[ch]: * backend/pixbuf/pixbufdocument.evince-backend.in: * backend/ps/Makefile.am: * backend/ps/ev-spectre.[ch]: * backend/ps/ps-document.[ch]: * backend/ps/psdocument.evince-backend.in: * backend/tiff/Makefile.am: * backend/tiff/tiff-document.[ch]: * backend/tiff/tiffdocument.evince-backend.in: * libdocument/Makefile.am: * libdocument/ev-backends-manager.[ch]: * libdocument/ev-module.[ch]: * libdocument/ev-document.h: * libdocument/ev-document-factory.[ch]: (gdk_pixbuf_mime_type_list), (mime_type_supported_by_gdk_pixbuf), (get_compression_from_mime_type), (get_document_from_uri), (ev_document_factory_get_document), (file_filter_add_mime_types), (ev_document_factory_add_filters): * shell/Makefile.am: * shell/ev-window-title.c: (get_filename_from_uri): * shell/main.c: (main): * thumbnailer/Makefile.am: * thumbnailer/evince-thumbnailer.c: (main): Plugin system for backends. Fixes bug #351348. svn path=/trunk/; revision=2786 --- diff --git a/ChangeLog b/ChangeLog index cb0830a..4f40ea2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,51 @@ +2007-12-28 Carlos Garcia Campos + + * configure.ac: + * Makefile.am: + * po/POTFILES.in: + * backend/comics/Makefile.am: + * backend/comics/comics-document.[ch]: + * backend/comics/comicsdocument.evince-backend.in: + * backend/djvu/Makefile.am: + * backend/djvu/djvu-document.[ch]: + * backend/djvu/djvudocument.evince-backend.in: + * backend/dvi/Makefile.am: + * backend/dvi/dvi-document.[c]: + * backend/dvi/dvidocument.evince-backend.in: + * backend/impress/Makefile.am: + * backend/impress/impress-document.[ch]: + * backend/impress/impressdocument.evince-backend.in: + * backend/pdf/Makefile.am: + * backend/pdf/ev-poppler.cc: + * backend/pdf/ev-poppler.h: + * backend/pdf/pdfdocument.evince-backend.in: + * backend/pixbuf/Makefile.am: + * backend/pixbuf/pixbuf-document.[ch]: + * backend/pixbuf/pixbufdocument.evince-backend.in: + * backend/ps/Makefile.am: + * backend/ps/ev-spectre.[ch]: + * backend/ps/ps-document.[ch]: + * backend/ps/psdocument.evince-backend.in: + * backend/tiff/Makefile.am: + * backend/tiff/tiff-document.[ch]: + * backend/tiff/tiffdocument.evince-backend.in: + * libdocument/Makefile.am: + * libdocument/ev-backends-manager.[ch]: + * libdocument/ev-module.[ch]: + * libdocument/ev-document.h: + * libdocument/ev-document-factory.[ch]: + (gdk_pixbuf_mime_type_list), (mime_type_supported_by_gdk_pixbuf), + (get_compression_from_mime_type), (get_document_from_uri), + (ev_document_factory_get_document), (file_filter_add_mime_types), + (ev_document_factory_add_filters): + * shell/Makefile.am: + * shell/ev-window-title.c: (get_filename_from_uri): + * shell/main.c: (main): + * thumbnailer/Makefile.am: + * thumbnailer/evince-thumbnailer.c: (main): + + Plugin system for backends. Fixes bug #351348. + 2007-12-25 Nickolay V. Shmyrev * shell/ev-view-private.h: diff --git a/Makefile.am b/Makefile.am index 14f3b1e..38d8b96 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ SUBDIRS = \ cut-n-paste \ data \ - backend \ libdocument \ + backend \ properties \ shell \ po \ diff --git a/backend/comics/Makefile.am b/backend/comics/Makefile.am index 47332cd..5f2fb89 100644 --- a/backend/comics/Makefile.am +++ b/backend/comics/Makefile.am @@ -1,11 +1,34 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - $(BACKEND_CFLAGS) +backenddir = $(libdir)/evince/backends -noinst_LTLIBRARIES = libcomicsdocument.la +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ + $(LIB_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) + +backend_LTLIBRARIES = libcomicsdocument.la libcomicsdocument_la_SOURCES = \ comics-document.c \ comics-document.h +libcomicsdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libcomicsdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) \ + $(LIB_LIBS) + +backend_in_files = comicsdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) + + diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index b72eef6..8c3b00c 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + #include #include #include @@ -25,6 +27,7 @@ #include "comics-document.h" #include "ev-document-misc.h" #include "ev-document-thumbnails.h" +#include "ev-file-helpers.h" struct _ComicsDocumentClass { @@ -58,11 +61,8 @@ static char** extract_argv (EvDocument *document, gint page); -G_DEFINE_TYPE_WITH_CODE ( - ComicsDocument, comics_document, G_TYPE_OBJECT, +EV_BACKEND_REGISTER_WITH_CODE (ComicsDocument, comics_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - comics_document_document_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, comics_document_document_thumbnails_iface_init); } ); diff --git a/backend/comics/comics-document.h b/backend/comics/comics-document.h index cd5b17b..fdc815c 100644 --- a/backend/comics/comics-document.h +++ b/backend/comics/comics-document.h @@ -29,9 +29,9 @@ G_BEGIN_DECLS typedef struct _ComicsDocument ComicsDocument; -ComicsDocument *comics_document_new (void); +GType comics_document_get_type (void) G_GNUC_CONST; -GType comics_document_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/comics/comicsdocument.evince-backend.in b/backend/comics/comicsdocument.evince-backend.in new file mode 100644 index 0000000..df1a97e --- /dev/null +++ b/backend/comics/comicsdocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=comicsdocument +_TypeDescription=Comic Books +MimeType=application/x-cbr;application/x-cbz; diff --git a/backend/djvu/Makefile.am b/backend/djvu/Makefile.am index fa44bbb..ea5f904 100644 --- a/backend/djvu/Makefile.am +++ b/backend/djvu/Makefile.am @@ -1,22 +1,44 @@ +backenddir = $(libdir)/evince/backends + INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/libdocument \ -DGNOMEICONDIR=\""${prefix}/${DATADIRNAME}/pixmaps"\" \ - $(LIB_CFLAGS) \ - $(DJVU_CFLAGS) + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ + $(DJVU_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) -noinst_LTLIBRARIES = libgtkdjvu.la +backend_LTLIBRARIES = libdjvudocument.la -libgtkdjvu_la_SOURCES = \ - djvu-document.c \ - djvu-document.h \ +libdjvudocument_la_SOURCES = \ + djvu-document.c \ + djvu-document.h \ djvu-document-private.h \ - djvu-links.c \ - djvu-links.h \ - djvu-text.c \ - djvu-text.h \ - djvu-text-page.c \ + djvu-links.c \ + djvu-links.h \ + djvu-text.c \ + djvu-text.h \ + djvu-text-page.c \ djvu-text-page.h +libdjvudocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libdjvudocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) \ + $(DJVU_LIBS) + +backend_in_files = djvudocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) + + diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index 2b9dee7..e16ec6a 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + #include "djvu-document.h" #include "djvu-text.h" #include "djvu-links.h" @@ -27,6 +29,7 @@ #include "ev-document-find.h" #include "ev-document-links.h" #include "ev-selection.h" +#include "ev-file-helpers.h" #include #include @@ -54,10 +57,8 @@ static void djvu_document_find_iface_init (EvDocumentFindIface *iface); static void djvu_document_document_links_iface_init (EvDocumentLinksIface *iface); static void djvu_selection_iface_init (EvSelectionIface *iface); -G_DEFINE_TYPE_WITH_CODE - (DjvuDocument, djvu_document, G_TYPE_OBJECT, +EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, djvu_document_document_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, djvu_document_document_thumbnails_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, djvu_document_file_exporter_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, djvu_document_find_iface_init); @@ -262,7 +263,7 @@ djvu_document_render (EvDocument *document, rowstride = page_width * 4; pixels = (gchar *) g_malloc (page_height * rowstride); - surface = cairo_image_surface_create_for_data (pixels, + surface = cairo_image_surface_create_for_data ((guchar *)pixels, CAIRO_FORMAT_RGB24, page_width, page_height, diff --git a/backend/djvu/djvu-document.h b/backend/djvu/djvu-document.h index 402f476..3a5cd6f 100644 --- a/backend/djvu/djvu-document.h +++ b/backend/djvu/djvu-document.h @@ -29,9 +29,9 @@ G_BEGIN_DECLS typedef struct _DjvuDocument DjvuDocument; -DjvuDocument *djvu_document_new (void); +GType djvu_document_get_type (void) G_GNUC_CONST; -GType djvu_document_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/djvu/djvudocument.evince-backend.in b/backend/djvu/djvudocument.evince-backend.in new file mode 100644 index 0000000..716dabf --- /dev/null +++ b/backend/djvu/djvudocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=djvudocument +_TypeDescription=Djvu Documents +MimeType=image/vnd.djvu diff --git a/backend/dvi/Makefile.am b/backend/dvi/Makefile.am index 10325e0..c65b5e8 100644 --- a/backend/dvi/Makefile.am +++ b/backend/dvi/Makefile.am @@ -1,23 +1,45 @@ SUBDIRS = mdvi-lib -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - -I$(srcdir)/mdvi-lib \ - $(LIB_CFLAGS) \ +backenddir = $(libdir)/evince/backends + +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -I$(srcdir)/mdvi-lib \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ $(SPECTRE_CFLAGS) -noinst_LTLIBRARIES = libgtkdvi.la - -libgtkdvi_la_SOURCES = \ - dvi-document.c \ - dvi-document.h \ - cairo-device.c \ - cairo-device.h \ - fonts.c \ +backend_LTLIBRARIES = libdvidocument.la + +libdvidocument_la_SOURCES = \ + dvi-document.c \ + dvi-document.h \ + cairo-device.c \ + cairo-device.h \ + fonts.c \ fonts.h -libgtkdvi_la_LIBADD = mdvi-lib/libmdvi.la +libdvidocument_la_LIBADD = \ + mdvi-lib/libmdvi.la \ + -lkpathsea \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) \ + $(SPECTRE_LIBS) + +if WITH_TYPE1_FONTS +libdvidocument_la_LIBADD += -lt1 +endif + +backend_in_files = dvidocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c index 73b148b..56a0d92 100644 --- a/backend/dvi/dvi-document.c +++ b/backend/dvi/dvi-document.c @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + #include "dvi-document.h" #include "ev-document-thumbnails.h" #include "ev-document-misc.h" @@ -26,7 +28,6 @@ #include "fonts.h" #include "cairo-device.h" -#include #include GMutex *dvi_context_mutex = NULL; @@ -73,10 +74,8 @@ static void dvi_document_do_color_special (DviContext const char *prefix, const char *arg); -G_DEFINE_TYPE_WITH_CODE - (DviDocument, dvi_document, G_TYPE_OBJECT, - { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, dvi_document_document_iface_init); +EV_BACKEND_REGISTER_WITH_CODE (DviDocument, dvi_document, + { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, dvi_document_document_thumbnails_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, dvi_document_file_exporter_iface_init); }); diff --git a/backend/dvi/dvi-document.h b/backend/dvi/dvi-document.h index d92d474..1f8c260 100644 --- a/backend/dvi/dvi-document.h +++ b/backend/dvi/dvi-document.h @@ -29,9 +29,9 @@ G_BEGIN_DECLS typedef struct _DviDocument DviDocument; -DviDocument *dvi_document_new (void); +GType dvi_document_get_type (void) G_GNUC_CONST; -GType dvi_document_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/dvi/dvidocument.evince-backend.in b/backend/dvi/dvidocument.evince-backend.in new file mode 100644 index 0000000..b43e8df --- /dev/null +++ b/backend/dvi/dvidocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=dvidocument +_TypeDescription=DVI Documents +MimeType=application/x-dvi diff --git a/backend/impress/Makefile.am b/backend/impress/Makefile.am index 526839b..dec003d 100644 --- a/backend/impress/Makefile.am +++ b/backend/impress/Makefile.am @@ -1,10 +1,15 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - $(SHELL_CFLAGS) \ - -DDATADIR=\""$(datadir)"\" +backenddir = $(libdir)/evince/backends -noinst_LTLIBRARIES = libimpressdocument.la +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + -DDATADIR=\""$(datadir)"\" \ + $(BACKEND_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) + +backend_LTLIBRARIES = libimpressdocument.la libimpressdocument_la_SOURCES = \ $(IMPOSTER_SOURCE_FILES) \ @@ -36,3 +41,17 @@ IMPOSTER_RENDER_SOURCE_FILES = \ IMPOSTER_RENDER_INCLUDE_FILES = \ render.h +libimpressdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libimpressdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) + +backend_in_files = impressdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) diff --git a/backend/impress/impress-document.c b/backend/impress/impress-document.c index 74d335a..687972b 100644 --- a/backend/impress/impress-document.c +++ b/backend/impress/impress-document.c @@ -18,6 +18,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + #include #include #include @@ -58,9 +60,8 @@ typedef struct _ImpressDocumentClass ImpressDocumentClass; static void impress_document_document_iface_init (EvDocumentIface *iface); static void impress_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); -G_DEFINE_TYPE_WITH_CODE (ImpressDocument, impress_document, G_TYPE_OBJECT, - { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - impress_document_document_iface_init); +EV_BACKEND_REGISTER_WITH_CODE (ImpressDocument, impress_document, + { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, impress_document_document_thumbnails_iface_init); }); diff --git a/backend/impress/impress-document.h b/backend/impress/impress-document.h index 7698e98..9f84498 100644 --- a/backend/impress/impress-document.h +++ b/backend/impress/impress-document.h @@ -30,8 +30,9 @@ G_BEGIN_DECLS typedef struct _ImpressDocument ImpressDocument; -ImpressDocument *impress_document_new (void); -GType impress_document_get_type (void) G_GNUC_CONST; +GType impress_document_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/impress/impressdocument.evince-backend.in b/backend/impress/impressdocument.evince-backend.in new file mode 100644 index 0000000..61de77a --- /dev/null +++ b/backend/impress/impressdocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=impressdocument +_TypeDescription=Impress Slides +MimeType=application/vnd.sun.xml.impress;application/vnd.oasis.opendocument.presentation; diff --git a/backend/pdf/Makefile.am b/backend/pdf/Makefile.am index 38d0831..4d2e549 100644 --- a/backend/pdf/Makefile.am +++ b/backend/pdf/Makefile.am @@ -1,13 +1,34 @@ +backenddir = $(libdir)/evince/backends + INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ $(BACKEND_CFLAGS) \ $(POPPLER_CFLAGS) \ $(WARN_CXXFLAGS) \ $(DISABLE_DEPRECATED) -noinst_LTLIBRARIES = libpdfdocument.la +backend_LTLIBRARIES = libpdfdocument.la libpdfdocument_la_SOURCES = \ ev-poppler.cc \ ev-poppler.h + +libpdfdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libpdfdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) \ + $(POPPLER_LIBS) \ + $(CAIRO_PDF_LIBS) \ + $(CAIRO_PS_LIBS) + +backend_in_files = pdfdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) \ No newline at end of file diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 690c908..5b03980 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -123,10 +123,8 @@ static EvLink *ev_link_from_action (PdfDocument *pdf_document, static void pdf_document_search_free (PdfDocumentSearch *search); static void pdf_print_context_free (PdfPrintContext *ctx); -G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, - { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - pdf_document_document_iface_init); +EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document, + { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY, pdf_document_security_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, @@ -1975,12 +1973,6 @@ pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface) iface->get_page_duration = pdf_document_get_page_duration; } -PdfDocument * -pdf_document_new (void) -{ - return PDF_DOCUMENT (g_object_new (PDF_TYPE_DOCUMENT, NULL)); -} - /* Forms */ static void pdf_document_get_crop_box (EvDocument *document, diff --git a/backend/pdf/ev-poppler.h b/backend/pdf/ev-poppler.h index 8cc65d1..8f9dcb6 100644 --- a/backend/pdf/ev-poppler.h +++ b/backend/pdf/ev-poppler.h @@ -30,8 +30,9 @@ G_BEGIN_DECLS typedef struct _PdfDocument PdfDocument; typedef struct _PdfDocumentClass PdfDocumentClass; -PdfDocument *pdf_document_new (void); -GType pdf_document_get_type (void) G_GNUC_CONST; +GType pdf_document_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/pdf/pdfdocument.evince-backend.in b/backend/pdf/pdfdocument.evince-backend.in new file mode 100644 index 0000000..476afe3 --- /dev/null +++ b/backend/pdf/pdfdocument.evince-backend.in @@ -0,0 +1,5 @@ +[Evince Backend] +Module=pdfdocument +_TypeDescription=PDF Documents +MimeType=application/pdf;application/x-bzpdf;application/x-gzpdf + diff --git a/backend/pixbuf/Makefile.am b/backend/pixbuf/Makefile.am index b81e1c8..acc23a5 100644 --- a/backend/pixbuf/Makefile.am +++ b/backend/pixbuf/Makefile.am @@ -1,10 +1,30 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - $(BACKEND_CFLAGS) +backenddir = $(libdir)/evince/backends -noinst_LTLIBRARIES = libpixbufdocument.la +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) + +backend_LTLIBRARIES = libpixbufdocument.la libpixbufdocument_la_SOURCES = \ pixbuf-document.c \ pixbuf-document.h + +libpixbufdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libpixbufdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) + +backend_in_files = pixbufdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c index 5f61587..c5810d1 100644 --- a/backend/pixbuf/pixbuf-document.c +++ b/backend/pixbuf/pixbuf-document.c @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "config.h" + #include "pixbuf-document.h" #include "ev-document-thumbnails.h" #include "ev-document-misc.h" @@ -40,12 +42,11 @@ typedef struct _PixbufDocumentClass PixbufDocumentClass; static void pixbuf_document_document_iface_init (EvDocumentIface *iface); static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); -G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT, - { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - pixbuf_document_document_iface_init); +EV_BACKEND_REGISTER_WITH_CODE (PixbufDocument, pixbuf_document, + { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, pixbuf_document_document_thumbnails_iface_init) - }); + }); static gboolean pixbuf_document_load (EvDocument *document, diff --git a/backend/pixbuf/pixbuf-document.h b/backend/pixbuf/pixbuf-document.h index bddf94a..d8a4d43 100644 --- a/backend/pixbuf/pixbuf-document.h +++ b/backend/pixbuf/pixbuf-document.h @@ -29,9 +29,9 @@ G_BEGIN_DECLS typedef struct _PixbufDocument PixbufDocument; -PixbufDocument *pixbuf_document_new (void); +GType pixbuf_document_get_type (void) G_GNUC_CONST; -GType pixbuf_document_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/pixbuf/pixbufdocument.evince-backend.in b/backend/pixbuf/pixbufdocument.evince-backend.in new file mode 100644 index 0000000..9beb526 --- /dev/null +++ b/backend/pixbuf/pixbufdocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=pixbufdocument +_TypeDescription=Images +MimeType=image/*; diff --git a/backend/ps/Makefile.am b/backend/ps/Makefile.am index 921e397..3e46801 100644 --- a/backend/ps/Makefile.am +++ b/backend/ps/Makefile.am @@ -1,15 +1,18 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - $(BACKEND_CFLAGS) \ - $(WARN_CFLAGS) \ +backenddir = $(libdir)/evince/backends + +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ + $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED) if HAVE_SPECTRE INCLUDES += $(SPECTRE_CFLAGS) endif -noinst_LTLIBRARIES = libpsdocument.la +backend_LTLIBRARIES = libpsdocument.la if HAVE_SPECTRE libpsdocument_la_SOURCES = \ @@ -29,3 +32,22 @@ libpsdocument_la_SOURCES = \ gsdefaults.c \ gsdefaults.h endif + +libpsdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libpsdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + $(BACKEND_LIBS) + +if HAVE_SPECTRE +libpsdocument_la_LIBADD += $(SPECTRE_LIBS) +endif + +backend_in_files = psdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) \ No newline at end of file diff --git a/backend/ps/ev-spectre.c b/backend/ps/ev-spectre.c index a16c0a0..82e3ca6 100644 --- a/backend/ps/ev-spectre.c +++ b/backend/ps/ev-spectre.c @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ +#include + #include #include #include @@ -42,10 +44,8 @@ static void ps_document_document_iface_init (EvDocumentIface static void ps_document_file_exporter_iface_init (EvFileExporterIface *iface); static void ps_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); -G_DEFINE_TYPE_WITH_CODE (PSDocument, ps_document, G_TYPE_OBJECT, +EV_BACKEND_REGISTER_WITH_CODE (PSDocument, ps_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - ps_document_document_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, ps_document_document_thumbnails_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, diff --git a/backend/ps/ev-spectre.h b/backend/ps/ev-spectre.h index fb00f9f..f79f6b8 100644 --- a/backend/ps/ev-spectre.h +++ b/backend/ps/ev-spectre.h @@ -39,7 +39,9 @@ G_BEGIN_DECLS typedef struct _PSDocument PSDocument; typedef struct _PSDocumentClass PSDocumentClass; -GType ps_document_get_type (void) G_GNUC_CONST; +GType ps_document_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/ps/ps-document.c b/backend/ps/ps-document.c index 61f07ab..abe8192 100644 --- a/backend/ps/ps-document.c +++ b/backend/ps/ps-document.c @@ -74,10 +74,8 @@ static void ps_interpreter_page_rendered (PSInterpreter GdkPixbuf *pixbuf, PSDocument *ps_document); -G_DEFINE_TYPE_WITH_CODE (PSDocument, ps_document, G_TYPE_OBJECT, +EV_BACKEND_REGISTER_WITH_CODE (PSDocument, ps_document, { - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - ps_document_document_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, ps_document_document_thumbnails_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, diff --git a/backend/ps/ps-document.h b/backend/ps/ps-document.h index fb00f9f..f79f6b8 100644 --- a/backend/ps/ps-document.h +++ b/backend/ps/ps-document.h @@ -39,7 +39,9 @@ G_BEGIN_DECLS typedef struct _PSDocument PSDocument; typedef struct _PSDocumentClass PSDocumentClass; -GType ps_document_get_type (void) G_GNUC_CONST; +GType ps_document_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/ps/psdocument.evince-backend.in b/backend/ps/psdocument.evince-backend.in new file mode 100644 index 0000000..616c66b --- /dev/null +++ b/backend/ps/psdocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=psdocument +_TypeDescription=PostScript Documents +MimeType=application/postscript;application/x-bzpostscript;application/x-gzpostscript;image/x-eps;image/x-bzeps;image/x-gzeps diff --git a/backend/tiff/Makefile.am b/backend/tiff/Makefile.am index f89e9d9..aa7ce72 100644 --- a/backend/tiff/Makefile.am +++ b/backend/tiff/Makefile.am @@ -1,12 +1,32 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/libdocument \ - $(BACKEND_CFLAGS) +backenddir = $(libdir)/evince/backends -noinst_LTLIBRARIES = libtiffdocument.la +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libdocument \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + $(BACKEND_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) + +backend_LTLIBRARIES = libtiffdocument.la libtiffdocument_la_SOURCES = \ tiff-document.c \ tiff-document.h \ tiff2ps.c \ tiff2ps.h + +libtiffdocument_la_LDFLAGS = $(BACKEND_LIBTOOL_FLAGS) +libtiffdocument_la_LIBADD = \ + $(top_builddir)/libdocument/libevbackend.la \ + -ltiff + +backend_in_files = tiffdocument.evince-backend.in + +%.evince-backend: %.evince-backend.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +backend_DATA = $(backend_in_files:.evince-backend.in=.evince-backend) + +EXTRA_DIST = $(backend_DATA) + +CLEANFILES = $(backend_DATA) diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 34275c1..d1473a1 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -20,8 +20,11 @@ /* FIXME: Should probably buffer calls to libtiff with TIFFSetWarningHandler */ +#include "config.h" + #include #include +#include #include "tiffio.h" #include "tiff2ps.h" @@ -29,6 +32,7 @@ #include "ev-document-misc.h" #include "ev-document-thumbnails.h" #include "ev-file-exporter.h" +#include "ev-file-helpers.h" struct _TiffDocumentClass { @@ -52,9 +56,8 @@ static void tiff_document_document_iface_init (EvDocumentIface *iface); static void tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); static void tiff_document_document_file_exporter_iface_init (EvFileExporterIface *iface); -G_DEFINE_TYPE_WITH_CODE (TiffDocument, tiff_document, G_TYPE_OBJECT, - { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - tiff_document_document_iface_init); +EV_BACKEND_REGISTER_WITH_CODE (TiffDocument, tiff_document, + { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, tiff_document_document_thumbnails_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, diff --git a/backend/tiff/tiff-document.h b/backend/tiff/tiff-document.h index bdf0e29..4170cca 100644 --- a/backend/tiff/tiff-document.h +++ b/backend/tiff/tiff-document.h @@ -30,8 +30,8 @@ G_BEGIN_DECLS typedef struct _TiffDocument TiffDocument; -TiffDocument *tiff_document_new (void); -GType tiff_document_get_type (void) G_GNUC_CONST; +GType tiff_document_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT GType register_evince_backend (GTypeModule *module); G_END_DECLS diff --git a/backend/tiff/tiffdocument.evince-backend.in b/backend/tiff/tiffdocument.evince-backend.in new file mode 100644 index 0000000..daaa7fd --- /dev/null +++ b/backend/tiff/tiffdocument.evince-backend.in @@ -0,0 +1,4 @@ +[Evince Backend] +Module=tiffdocument +_TypeDescription=Tiff Documents +MimeType=image/tiff diff --git a/configure.ac b/configure.ac index bf9d378..906c2d1 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,9 @@ AC_PREREQ(2.57) AC_INIT([Evince],[2.21.1],[http://bugzilla.gnome.org/enter_bug.cgi?product=evince],[evince]) AM_INIT_AUTOMAKE([1.9 dist-bzip2 no-dist-gzip]) +EV_API_VERSION=2.20 +AC_SUBST(EV_API_VERSION) + AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE @@ -35,7 +38,7 @@ AM_GLIB_GNU_GETTEXT dnl Check dependencies -# LIB_CFLAGS for helpers and generic widgets. (lib, cut-and-paste) +# LIB_CFLAGS for helpers and generic widgets. (libdocument, cut-and-paste) # BACKEND_CFLAGS for backend implementations. # FRONTEND_CFLAGS for frontend implementations. (properties, thumbnailer) # FRONTEND_LIBS @@ -54,11 +57,14 @@ LIBXML_REQUIRED=2.5.0 GTK_PRINT_REQUIRED=2.10.0 -PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED) -PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0) +PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED gnome-vfs-2.0) +PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED) PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED libglade-2.0 gnome-vfs-2.0) PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gnome-vfs-2.0 libglade-2.0 gconf-2.0 gnome-keyring-1 >= $KEYRING_REQUIRED) +BACKEND_LIBTOOL_FLAGS="-module -avoid-version" +AC_SUBST(BACKEND_LIBTOOL_FLAGS) + AC_ARG_WITH(libgnome, AC_HELP_STRING([--without-libgnome],[disable the use of libgnome]), [case "${withval}" in @@ -152,8 +158,7 @@ LIB_LIBS="$LIB_LIBS $GNOME_LIBS" AC_SUBST(LIB_CFLAGS) AC_SUBST(LIB_LIBS) -BACKEND_CFLAGS="$BACKEND_CFLAGS $GNOME_CFLAGS -DGDK_MULTIHEAD_SAFE -DGTK_MULTIHEAD_SAFE" -BACKEND_LIBS="$BACKEND_LIBS $GNOME_LIBS" +BACKEND_CFLAGS="$BACKEND_CFLAGS -DGDK_MULTIHEAD_SAFE -DGTK_MULTIHEAD_SAFE" AC_SUBST(BACKEND_CFLAGS) AC_SUBST(BACKEND_LIBS) @@ -231,12 +236,11 @@ if test "x$enable_pdf" = "xyes"; then if test "x$enable_pdf" = "xyes"; then AC_DEFINE([ENABLE_PDF], [1], [Enable pdf support.]) - FRONTEND_LIBS="$FRONTEND_LIBS $POPPLER_LIBS" SHELL_LIBS="$SHELL_LIBS $POPPLER_LIBS" SHELL_CFLAGS="$SHELL_CFLAGS $POPPLER_CFLAGS" evince_save_LIBS=$LIBS - LIBS="$LIBS $FRONTEND_LIBS" + LIBS="$LIBS $POPPLER_LIBS" AC_CHECK_FUNCS(poppler_page_render) AC_CHECK_FUNCS(poppler_page_render_for_printing) LIBS=$evince_save_LIBS @@ -274,9 +278,6 @@ if test x$enable_ps = xyes; then AC_DEFINE([ENABLE_PS], [1], [Enable support for PostScript files.]) if test "x$have_spectre" = "xyes"; then - FRONTEND_LIBS="$FRONTEND_LIBS $SPECTRE_LIBS" - SHELL_LIBS="$SHELL_LIBS $SPECTRE_LIBS" - SHELL_CFLAGS="$SHELL_CFLAGS $SPECTRE_CFLAGS" ps_backend="(libspectre)" else dnl check for GS version @@ -312,8 +313,6 @@ if test "x$enable_tiff" = "xyes"; then fi if test "x$enable_tiff" = "xyes"; then AC_DEFINE([ENABLE_TIFF], [1], [Enable multipage tiff support.]) - FRONTEND_LIBS="$FRONTEND_LIBS -ltiff" - SHELL_LIBS="$SHELL_LIBS -ltiff" else AC_MSG_WARN("Tiff support is disabled since tiff library version 3.6 or newer not found") fi diff --git a/libdocument/Makefile.am b/libdocument/Makefile.am index f96d019..d6e0c56 100644 --- a/libdocument/Makefile.am +++ b/libdocument/Makefile.am @@ -1,109 +1,77 @@ -INCLUDES= \ - -DEVINCE_UIDIR=\"$(pkgdatadir)\" \ - -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ - -I$(top_srcdir)/backend/pdf \ - -I$(top_srcdir)/backend/pixbuf \ - -I$(top_srcdir)/backend/tiff \ - -I$(top_srcdir)/backend/ps \ - -I$(top_srcdir)/backend/djvu \ - -I$(top_srcdir)/backend/dvi \ - -I$(top_srcdir)/backend/impress \ - -I$(top_srcdir)/backend/comics \ - $(BACKEND_CFLAGS) \ - $(WARN_CFLAGS) \ +INCLUDES= \ + -DEVINCE_UIDIR=\"$(pkgdatadir)\" \ + -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + -DEV_BACKENDSDIR=\"$(libdir)/evince/backends\" \ + $(LIB_CFLAGS) \ + $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED) -noinst_LTLIBRARIES = libevbackend.la +lib_LTLIBRARIES = libevbackend.la + +libevbackend_la_LDFLAGS = -export-dynamic +libevbackend_la_LIBADD = $(LIB_LIBS) + +NOINST_H_FILES = \ + ev-backend-marshalers.h \ + ev-backends-manager.h \ + ev-document-factory.h \ + ev-module.h + +INST_H_FILES = \ + ev-async-renderer.h \ + ev-attachment.h \ + ev-document-find.h \ + ev-document-fonts.h \ + ev-document-forms.h \ + ev-document.h \ + ev-document-images.h \ + ev-document-info.h \ + ev-document-links.h \ + ev-document-misc.h \ + ev-document-security.h \ + ev-document-thumbnails.h \ + ev-document-transition.h \ + ev-file-exporter.h \ + ev-file-helpers.h \ + ev-form-field.h \ + ev-image.h \ + ev-link-action.h \ + ev-link-dest.h \ + ev-link.h \ + ev-render-context.h \ + ev-selection.h + +headerdir = $(prefix)/include/evince-@EV_API_VERSION@/evince +header_DATA = $(INST_H_FILES) libevbackend_la_SOURCES= \ ev-async-renderer.c \ - ev-async-renderer.h \ ev-attachment.c \ - ev-attachment.h \ + ev-backends-manager.c \ ev-backend-marshal.c \ ev-link.c \ - ev-link.h \ ev-link-action.c \ - ev-link-action.h \ ev-link-dest.c \ - ev-link-dest.h \ ev-image.c \ - ev-image.h \ ev-document.c \ - ev-document.h \ ev-document-factory.c \ - ev-document-factory.h \ ev-document-thumbnails.c \ - ev-document-thumbnails.h \ ev-document-fonts.c \ - ev-document-fonts.h \ ev-document-links.c \ - ev-document-links.h \ ev-document-images.c \ - ev-document-images.h \ ev-document-security.c \ - ev-document-security.h \ ev-document-find.c \ - ev-document-find.h \ - ev-document-info.h \ - ev-document-transition.h \ ev-document-transition.c \ - ev-document-forms.h \ ev-document-forms.c \ - ev-form-field.h \ ev-form-field.c \ ev-file-exporter.c \ - ev-file-exporter.h \ ev-file-helpers.c \ - ev-file-helpers.h \ - ev-render-context.h \ + ev-module.c \ ev-render-context.c \ - ev-selection.h \ ev-selection.c \ - ev-document-misc.h \ - ev-document-misc.c - -libevbackend_la_LIBADD = - -if ENABLE_PDF -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/pdf/libpdfdocument.la -endif - -if ENABLE_PS -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/ps/libpsdocument.la -endif - -if ENABLE_PIXBUF -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/pixbuf/libpixbufdocument.la -endif - -if ENABLE_DJVU -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/djvu/libgtkdjvu.la -endif - -if ENABLE_TIFF -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/tiff/libtiffdocument.la -endif - -if ENABLE_DVI -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/dvi/libgtkdvi.la -endif - -if ENABLE_COMICS -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/comics/libcomicsdocument.la -endif - -if ENABLE_IMPRESS -libevbackend_la_LIBADD += \ - $(top_builddir)/backend/impress/libimpressdocument.la -endif + ev-document-misc.c \ + $(NOINST_H_FILES) \ + $(INST_H_FILES) BUILT_SOURCES= \ ev-backend-marshalers.h \ @@ -119,8 +87,5 @@ ev-backend-marshalers.c: ev-backend-marshalers.list ev-backend-marshal.c: ev-backend-marshalers.h ev-backend-marshalers.c -noinst_HEADERS = \ - ev-backend-marshalers.h - EXTRA_DIST= \ ev-backend-marshalers.list diff --git a/libdocument/ev-backends-manager.c b/libdocument/ev-backends-manager.c new file mode 100644 index 0000000..0f501a1 --- /dev/null +++ b/libdocument/ev-backends-manager.c @@ -0,0 +1,291 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2007 Carlos Garcia Campos + * + * Evince 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. + * + * Evince 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. + */ + +#include + +#include + +#include "ev-module.h" +#include "ev-backends-manager.h" + +static GList *ev_backends_list = NULL; + +typedef struct _EvBackendInfo EvBackendInfo; +struct _EvBackendInfo { + gchar *module_name; + GTypeModule *module; + + GType type_id; + + gchar *type_desc; + gchar **mime_types; +}; + +#define EV_BACKENDS_GROUP "Evince Backend" +#define EV_BACKENDS_EXTENSION ".evince-backend" + +static void +ev_backend_info_free (EvBackendInfo *info) +{ + g_free (info->module_name); + g_free (info->type_desc); + g_strfreev (info->mime_types); + g_free (info); +} + +static EvBackendInfo * +ev_backends_manager_load_backend (const gchar *file) +{ + EvBackendInfo *info; + GKeyFile *backend_file = NULL; + GError *error = NULL; + + backend_file = g_key_file_new (); + if (!g_key_file_load_from_file (backend_file, file, G_KEY_FILE_NONE, &error)) { + g_warning ("Error opening backend file %s: %s", + file, error->message); + g_error_free (error); + g_key_file_free (backend_file); + + return NULL; + } + + info = g_new0 (EvBackendInfo, 1); + info->module_name = g_key_file_get_string (backend_file, EV_BACKENDS_GROUP, + "Module", NULL); + if (!info->module_name) { + g_warning ("Bad evince backend file %s: Could not find 'Module'", + file); + ev_backend_info_free (info); + g_key_file_free (backend_file); + + return NULL; + } + + info->type_desc = g_key_file_get_locale_string (backend_file, EV_BACKENDS_GROUP, + "TypeDescription", NULL, NULL); + if (!info->type_desc) { + g_warning ("Bad evince backend file %s: Could not find 'TypeDescription'", + file); + ev_backend_info_free (info); + g_key_file_free (backend_file); + + return NULL; + } + + info->mime_types = g_key_file_get_string_list (backend_file, EV_BACKENDS_GROUP, + "MimeType", NULL, NULL); + if (!info->mime_types) { + g_warning ("Bad evince backend file %s: Could not find 'MimeType'", + file); + ev_backend_info_free (info); + g_key_file_free (backend_file); + + return NULL; + } + + g_key_file_free (backend_file); + + return info; +} + +static gboolean +ev_backends_manager_load (void) +{ + GDir *dir; + const gchar *dirent; + GError *error = NULL; + + dir = g_dir_open (EV_BACKENDSDIR, 0, &error); + if (!dir) { + g_warning (error->message); + g_error_free (error); + + return FALSE; + } + + while ((dirent = g_dir_read_name (dir))) { + EvBackendInfo *info; + gchar *file; + + if (!g_str_has_suffix (dirent, EV_BACKENDS_EXTENSION)) + continue; + + file = g_build_filename (EV_BACKENDSDIR, dirent, NULL); + info = ev_backends_manager_load_backend (file); + g_free (file); + + if (!info) + continue; + + ev_backends_list = g_list_prepend (ev_backends_list, info); + } + + return TRUE; +} + +gboolean +ev_backends_manager_init (void) +{ + if (ev_backends_list) + return FALSE; + + return ev_backends_manager_load (); +} + +void +ev_backends_manager_shutdown (void) +{ + g_list_foreach (ev_backends_list, (GFunc)ev_backend_info_free, NULL); + g_list_free (ev_backends_list); + ev_backends_list = NULL; +} + +static EvBackendInfo * +ev_backends_manager_get_backend_info (const gchar *mime_type) +{ + GList *l; + + for (l = ev_backends_list; l; l = g_list_next (l)) { + EvBackendInfo *info; + gint i = 0; + const char *mime; + + info = (EvBackendInfo *)l->data; + + while ((mime = info->mime_types[i++])) { + if (g_ascii_strcasecmp (mime, mime_type) == 0) + return info; + } + } + + return NULL; +} + +EvDocument * +ev_backends_manager_get_document (const gchar *mime_type) +{ + EvDocument *document; + EvBackendInfo *info; + + info = ev_backends_manager_get_backend_info (mime_type); + if (!info) + return NULL; + + if (!info->module) { + gchar *path; + + path = g_module_build_path (EV_BACKENDSDIR, info->module_name); + info->module = G_TYPE_MODULE (ev_module_new (path)); + g_free (path); + } + + if (!g_type_module_use (info->module)) { + g_warning ("Cannot load backend '%s' since file '%s' cannot be read.", + info->module_name, + ev_module_get_path (EV_MODULE (info->module))); + g_object_unref (G_OBJECT (info->module)); + info->module = NULL; + + return NULL; + } + + document = EV_DOCUMENT (ev_module_new_object (EV_MODULE (info->module))); + g_type_module_unuse (info->module); + + return document; +} + +static EvBackendInfo * +get_document_backend_info (EvDocument *document) +{ + GList *l; + + for (l = ev_backends_list; l; l = g_list_next (l)) { + EvBackendInfo *info; + GType type_id; + + info = (EvBackendInfo *)l->data; + + if (!info->module) + continue; + + type_id = ev_module_get_object_type (EV_MODULE (info->module)); + + if (G_TYPE_CHECK_INSTANCE_TYPE (document, type_id)) { + return info; + } + } + + return NULL; +} + +const gchar * +ev_backends_manager_get_document_module_name (EvDocument *document) +{ + EvBackendInfo *info; + + info = get_document_backend_info (document); + return info ? info->module_name : NULL; +} + +static EvTypeInfo * +ev_type_info_new (const gchar *desc, const gchar **mime_types) +{ + EvTypeInfo *info; + + info = g_new (EvTypeInfo, 1); + + info->desc = desc; + info->mime_types = mime_types; + + return info; +} + +EvTypeInfo * +ev_backends_manager_get_document_type_info (EvDocument *document) +{ + EvBackendInfo *info; + + info = get_document_backend_info (document); + return info ? + ev_type_info_new (info->type_desc, + (const gchar **)info->mime_types) + : NULL; +} + +GList * +ev_backends_manager_get_all_types_info (void) +{ + GList *l; + GList *retval = NULL; + + for (l = ev_backends_list; l; l = g_list_next (l)) { + EvBackendInfo *info; + EvTypeInfo *type_info; + + info = (EvBackendInfo *)l->data; + + type_info = ev_type_info_new (info->type_desc, + (const gchar **)info->mime_types); + retval = g_list_prepend (retval, type_info); + } + + return retval; +} diff --git a/libdocument/ev-backends-manager.h b/libdocument/ev-backends-manager.h new file mode 100644 index 0000000..a78d6f8 --- /dev/null +++ b/libdocument/ev-backends-manager.h @@ -0,0 +1,44 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2007 Carlos Garcia Campos + * + * Evince 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. + * + * Evince 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. + */ + +#ifndef EV_BACKENDS_MANAGER +#define EV_BACKENDS_MANAGER + +#include + +#include "ev-document.h" + +G_BEGIN_DECLS + +typedef struct _EvTypeInfo { + const gchar *desc; + const gchar **mime_types; +} EvTypeInfo; + +gboolean ev_backends_manager_init (void); +void ev_backends_manager_shutdown (void); + +EvDocument *ev_backends_manager_get_document (const gchar *mime_type); +const gchar *ev_backends_manager_get_document_module_name (EvDocument *document); +EvTypeInfo *ev_backends_manager_get_document_type_info (EvDocument *document); +GList *ev_backends_manager_get_all_types_info (void); + +G_END_DECLS + +#endif /* EV_BACKENDS_MANAGER */ diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c index b500fdf..21e0b4a 100644 --- a/libdocument/ev-document-factory.c +++ b/libdocument/ev-document-factory.c @@ -22,34 +22,6 @@ #include "config.h" #endif -#include "ev-document-factory.h" - -/* The various document type backends: */ -#ifdef ENABLE_PDF -#include "ev-poppler.h" -#endif -#ifdef ENABLE_PS -#include "ps-document.h" -#endif -#ifdef ENABLE_TIFF -#include "tiff-document.h" -#endif -#ifdef ENABLE_DVI -#include "dvi-document.h" -#endif -#ifdef ENABLE_PIXBUF -#include "pixbuf-document.h" -#endif -#ifdef ENABLE_DJVU -#include "djvu-document.h" -#endif -#ifdef ENABLE_COMICS -#include "comics-document.h" -#endif -#ifdef ENABLE_IMPRESS -#include "impress-document.h" -#endif - #include #include #include @@ -58,87 +30,27 @@ #include #include +#include "ev-backends-manager.h" +#include "ev-document-factory.h" #include "ev-file-helpers.h" -typedef struct _EvDocumentType EvDocumentType; -struct _EvDocumentType { - const char *mime_type; - EvCompressionType compression; - EvBackend backend; - GType (*document_type_factory_callback)(); -}; - -const EvDocumentType document_types[] = { -#ifdef ENABLE_PDF - /* PDF: */ - {"application/pdf", EV_COMPRESSION_NONE, EV_BACKEND_PDF, pdf_document_get_type}, - {"application/x-bzpdf", EV_COMPRESSION_BZIP2, EV_BACKEND_PDF, pdf_document_get_type}, - {"application/x-gzpdf", EV_COMPRESSION_GZIP, EV_BACKEND_PDF, pdf_document_get_type}, -#endif - -#ifdef ENABLE_PS - /* Postscript: */ - {"application/postscript", EV_COMPRESSION_NONE, EV_BACKEND_PS, ps_document_get_type}, - {"application/x-bzpostscript", EV_COMPRESSION_BZIP2, EV_BACKEND_PS, ps_document_get_type}, - {"application/x-gzpostscript", EV_COMPRESSION_GZIP, EV_BACKEND_PS, ps_document_get_type}, - {"image/x-eps", EV_COMPRESSION_NONE, EV_BACKEND_PS, ps_document_get_type}, - {"image/x-bzeps", EV_COMPRESSION_BZIP2, EV_BACKEND_PS, ps_document_get_type}, - {"image/x-gzeps", EV_COMPRESSION_GZIP, EV_BACKEND_PS, ps_document_get_type}, -#endif - -#ifdef ENABLE_TIFF - /* Tiff: */ - {"image/tiff", EV_COMPRESSION_NONE, EV_BACKEND_TIFF, tiff_document_get_type}, -#endif - -#ifdef ENABLE_DJVU - /* djvu: */ - {"image/vnd.djvu", EV_COMPRESSION_NONE, EV_BACKEND_DJVU, djvu_document_get_type}, -#endif - -#ifdef ENABLE_DVI - /* dvi: */ - {"application/x-dvi", EV_COMPRESSION_NONE, EV_BACKEND_DVI, dvi_document_get_type}, -#endif - -#ifdef ENABLE_COMICS - /* cbr/cbz: */ - {"application/x-cbr", EV_COMPRESSION_NONE, EV_BACKEND_COMICS, comics_document_get_type}, - {"application/x-cbz", EV_COMPRESSION_NONE, EV_BACKEND_COMICS, comics_document_get_type}, -#endif - -#ifdef ENABLE_IMPRESS - /* Impress slides: */ - {"application/vnd.sun.xml.impress", EV_COMPRESSION_NONE, EV_BACKEND_IMPRESS, impress_document_get_type}, - {"application/vnd.oasis.opendocument.presentation", EV_COMPRESSION_NONE, EV_BACKEND_IMPRESS, impress_document_get_type}, -#endif - -}; - #ifdef ENABLE_PIXBUF - static GList* gdk_pixbuf_mime_type_list () { GSList *formats, *list; - GList *result; + GList *result = NULL; formats = gdk_pixbuf_get_formats (); - result = NULL; - for (list = formats; list != NULL; list = list->next) { GdkPixbufFormat *format = list->data; - int i; - gchar **mime_types; + 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++) { - result = g_list_append (result, mime_types[i]); - } + result = g_list_prepend (result, mime_types); } g_slist_free (formats); @@ -152,110 +64,45 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) GList *mime_types; GList *list; gboolean retval = FALSE; - + mime_types = gdk_pixbuf_mime_type_list (); for (list = mime_types; list; list = list->next) { - if (strcmp ((char *)list->data, mime_type) == 0) { - retval = TRUE; - break; + gchar **mtypes = (gchar **)list->data; + const gchar *mtype; + gint i = 0; + + while ((mtype = mtypes[i++])) { + if (strcmp (mtype, mime_type) == 0) { + retval = TRUE; + break; + } } } - - g_list_foreach (mime_types, (GFunc)g_free, NULL); + + g_list_foreach (mime_types, (GFunc)g_strfreev, NULL); g_list_free (mime_types); return retval; } -#endif +#endif /* ENABLE_PIXBUF */ -static EvDocument * -ev_document_factory_get_from_mime (const gchar *mime_type, - EvCompressionType *compression) +static EvCompressionType +get_compression_from_mime_type (const gchar *mime_type) { - int i; - GType type = G_TYPE_INVALID; - EvDocument *document = NULL; + gchar type[3]; + gchar *p; - *compression = EV_COMPRESSION_NONE; - - for (i = 0; i < G_N_ELEMENTS (document_types); i++) { - if (strcmp (mime_type, document_types[i].mime_type) == 0) { - g_assert (document_types[i].document_type_factory_callback != NULL); - type = document_types[i].document_type_factory_callback (); - *compression = document_types[i].compression; - break; - } - } -#ifdef ENABLE_PIXBUF - if (type == G_TYPE_INVALID && mime_type_supported_by_gdk_pixbuf (mime_type)) { - type = pixbuf_document_get_type (); - } -#endif - - if (type != G_TYPE_INVALID) { - document = g_object_new (type, NULL); - } - - return document; -} - -EvBackend -ev_document_factory_get_backend (EvDocument *document) -{ - int i; + if (!(p = g_strrstr (mime_type, "/"))) + return EV_COMPRESSION_NONE; - for (i = 0; i < G_N_ELEMENTS (document_types); i++) { - GType type = document_types[i].document_type_factory_callback (); - if (type == G_TYPE_FROM_INSTANCE (document)) { - return document_types[i].backend; - } + if (sscanf (++p, "x-%2s%*s", type) == 1) { + if (g_ascii_strcasecmp (type, "gz") == 0) + return EV_COMPRESSION_GZIP; + else if (g_ascii_strcasecmp (type, "bz") == 0) + return EV_COMPRESSION_BZIP2; } -#ifdef ENABLE_PIXBUF - if (G_TYPE_FROM_INSTANCE (document) == pixbuf_document_get_type ()) - return EV_BACKEND_PIXBUF; -#endif - g_assert_not_reached (); - - return 0; -} - -static GList * -ev_document_factory_get_mime_types (EvBackend backend) -{ - GList *types = NULL; - int i; - -#ifdef ENABLE_PIXBUF - if (backend == EV_BACKEND_PIXBUF) { - return gdk_pixbuf_mime_type_list (); - } -#endif - - for (i = 0; i < G_N_ELEMENTS (document_types); i++) { - if (document_types[i].backend == backend) { - types = g_list_append (types, g_strdup (document_types[i].mime_type)); - } - } - - return types; -} - -static GList * -ev_document_factory_get_all_mime_types (void) -{ - GList *types = NULL; - int i; - - for (i = 0; i < G_N_ELEMENTS (document_types); i++) { - types = g_list_append (types, g_strdup (document_types[i].mime_type)); - } - -#ifdef ENABLE_PIXBUF - types = g_list_concat (types, gdk_pixbuf_mime_type_list ()); -#endif - - return types; + return EV_COMPRESSION_NONE; } static EvDocument * @@ -293,8 +140,15 @@ get_document_from_uri (const char *uri, return NULL; } - document = ev_document_factory_get_from_mime (info->mime_type, compression); - +#ifdef ENABLE_PIXBUF + if (mime_type_supported_by_gdk_pixbuf (info->mime_type)) { + document = ev_backends_manager_get_document ("image/*"); + } else + document = ev_backends_manager_get_document (info->mime_type); +#else + document = ev_backends_manager_get_document (info->mime_type); +#endif /* ENABLE_PIXBUF */ + if (document == NULL) { g_set_error (error, EV_DOCUMENT_ERROR, @@ -304,6 +158,8 @@ get_document_from_uri (const char *uri, return NULL; } + *compression = get_compression_from_mime_type (info->mime_type); + gnome_vfs_file_info_unref (info); return document; @@ -410,106 +266,76 @@ ev_document_factory_get_document (const char *uri, GError **error) } static void -file_filter_add_mime_list_and_free (GtkFileFilter *filter, GList *mime_types) +file_filter_add_mime_types (EvTypeInfo *info, GtkFileFilter *filter) { - GList *l; + const gchar *mime_type; + gint i = 0; - for (l = mime_types; l != NULL; l = l->next) { - gtk_file_filter_add_mime_type (filter, l->data); - } +#ifdef ENABLE_PIXBUF + if (g_ascii_strcasecmp (info->mime_types[0], "image/*") == 0) { + GList *pixbuf_types, *l; + + pixbuf_types = gdk_pixbuf_mime_type_list (); + for (l = pixbuf_types; l; l = g_list_next (l)) { + gchar **mime_types = (gchar **)l->data; + gint j = 0; + + while ((mime_type = mime_types[j++])) + gtk_file_filter_add_mime_type (filter, mime_type); + + g_strfreev (mime_types); + } + g_list_free (pixbuf_types); - g_list_foreach (mime_types, (GFunc)g_free, NULL); - g_list_free (mime_types); + return; + } +#endif /* ENABLE_PIXBUF */ + + while ((mime_type = info->mime_types[i++])) + gtk_file_filter_add_mime_type (filter, mime_type); } void ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document) { - EvBackend backend = 0; - GList *mime_types; + GList *all_types; GtkFileFilter *filter; GtkFileFilter *default_filter; GtkFileFilter *document_filter; - if (document != NULL) { - backend = ev_document_factory_get_backend (document); - } - + all_types = ev_backends_manager_get_all_types_info (); + default_filter = document_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Documents")); - mime_types = ev_document_factory_get_all_mime_types (); - file_filter_add_mime_list_and_free (filter, mime_types); + g_list_foreach (all_types, (GFunc)file_filter_add_mime_types, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); -#ifdef ENABLE_PS - if (document == NULL || backend == EV_BACKEND_PS) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("PostScript Documents")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_PS); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif - -#ifdef ENABLE_PDF - if (document == NULL || backend == EV_BACKEND_PDF) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("PDF Documents")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_PDF); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif + if (document) { + EvTypeInfo *info; -#ifdef ENABLE_PIXBUF - if (document == NULL || backend == EV_BACKEND_PIXBUF) { + info = ev_backends_manager_get_document_type_info (document); default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Images")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_PIXBUF); - file_filter_add_mime_list_and_free (filter, mime_types); + gtk_file_filter_set_name (filter, info->desc); + file_filter_add_mime_types (info, filter); + g_free (info); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif + } else { + GList *l; -#ifdef ENABLE_DVI - if (document == NULL || backend == EV_BACKEND_DVI) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("DVI Documents")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_DVI); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif + for (l = all_types; l; l = g_list_next (l)){ + EvTypeInfo *info; -#ifdef ENABLE_DJVU - if (document == NULL || backend == EV_BACKEND_DJVU) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Djvu Documents")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_DJVU); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif + info = (EvTypeInfo *)l->data; -#ifdef ENABLE_COMICS - if (document == NULL || backend == EV_BACKEND_COMICS) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Comic Books")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_COMICS); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + default_filter = filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, info->desc); + file_filter_add_mime_types (info, filter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + } } -#endif -#ifdef ENABLE_IMPRESS - if (document == NULL || backend == EV_BACKEND_IMPRESS) { - default_filter = filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Impress Slides")); - mime_types = ev_document_factory_get_mime_types (EV_BACKEND_IMPRESS); - file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - } -#endif + g_list_foreach (all_types, (GFunc)g_free, NULL); + g_list_free (all_types); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Files")); diff --git a/libdocument/ev-document-factory.h b/libdocument/ev-document-factory.h index 886be69..55c59e4 100644 --- a/libdocument/ev-document-factory.h +++ b/libdocument/ev-document-factory.h @@ -26,19 +26,7 @@ G_BEGIN_DECLS -typedef enum { - EV_BACKEND_PDF, - EV_BACKEND_PS, - EV_BACKEND_TIFF, - EV_BACKEND_PIXBUF, - EV_BACKEND_DJVU, - EV_BACKEND_DVI, - EV_BACKEND_COMICS, - EV_BACKEND_IMPRESS -} EvBackend; - EvDocument* ev_document_factory_get_document (const char *uri, GError **error); -EvBackend ev_document_factory_get_backend (EvDocument *document); void ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document); G_END_DECLS diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h index 4f83553..6e7232b 100644 --- a/libdocument/ev-document.h +++ b/libdocument/ev-document.h @@ -123,8 +123,74 @@ GList *ev_document_get_attachments (EvDocument *document); cairo_surface_t *ev_document_render (EvDocument *document, EvRenderContext *rc); -gint ev_rect_cmp (EvRectangle *a, - EvRectangle *b); +gint ev_rect_cmp (EvRectangle *a, + EvRectangle *b); + +/* + * Utility macro used to register backends + * + * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) + */ +#define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \ + \ +static GType g_define_type_id = 0; \ + \ +GType \ +backend_name##_get_type (void) \ +{ \ + return g_define_type_id; \ +} \ + \ +static void backend_name##_init (BackendName *self); \ +static void backend_name##_class_init (BackendName##Class *klass); \ +static gpointer backend_name##_parent_class = NULL; \ +static void backend_name##_class_intern_init (gpointer klass) \ +{ \ + backend_name##_parent_class = g_type_class_peek_parent (klass); \ + backend_name##_class_init ((BackendName##Class *) klass); \ +} \ + \ +G_MODULE_EXPORT GType \ +register_evince_backend (GTypeModule *module) \ +{ \ + static const GTypeInfo our_info = { \ + sizeof (BackendName##Class), \ + NULL, /* base_init */ \ + NULL, /* base_finalize */ \ + (GClassInitFunc) backend_name##_class_intern_init, \ + NULL, \ + NULL, /* class_data */ \ + sizeof (BackendName), \ + 0, /* n_preallocs */ \ + (GInstanceInitFunc) backend_name##_init \ + }; \ + \ + /* Initialise the i18n stuff */ \ + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \ + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \ + \ + g_define_type_id = g_type_module_register_type (module, \ + G_TYPE_OBJECT, \ + #BackendName, \ + &our_info, \ + (GTypeFlags)0); \ + \ + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, \ + backend_name##_document_iface_init); \ + \ + CODE \ + \ + return g_define_type_id; \ +} + +/* + * Utility macro used to register backend + * + * use: EV_BACKEND_REGISTER(BackendName, backend_name) + */ +#define EV_BACKEND_REGISTER(BackendName, backend_name) \ + EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;) + G_END_DECLS #endif /* EV_DOCUMENT_H */ diff --git a/libdocument/ev-module.c b/libdocument/ev-module.c new file mode 100644 index 0000000..f2aebe7 --- /dev/null +++ b/libdocument/ev-module.c @@ -0,0 +1,190 @@ +/* + * ev-module.c + * This file is part of Evince + * + * Copyright (C) 2005 - Paolo Maggi + * + * 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., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* This is a modified version of ephy-module.c from Epiphany source code. + * Here the original copyright assignment: + * + * Copyright (C) 2003 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + */ + +/* + * Modified by the gedit Team, 2005. See the AUTHORS file for a + * list of people on the gedit Team. + * See the ChangeLog files for a list of changes. + * + * $Id: gedit-module.c 5367 2006-12-17 14:29:49Z pborelli $ + */ + +/* Modified by evince team */ + +#include "config.h" + +#include "ev-module.h" + +#include + +typedef struct _EvModuleClass EvModuleClass; + +struct _EvModuleClass { + GTypeModuleClass parent_class; +}; + +struct _EvModule { + GTypeModule parent_instance; + + GModule *library; + + gchar *path; + GType type; +}; + +typedef GType (*EvModuleRegisterFunc) (GTypeModule *); + +static void ev_module_init (EvModule *action); +static void ev_module_class_init (EvModuleClass *class); + +G_DEFINE_TYPE (EvModule, ev_module, G_TYPE_TYPE_MODULE) + +static gboolean +ev_module_load (GTypeModule *gmodule) +{ + EvModule *module = EV_MODULE (gmodule); + EvModuleRegisterFunc register_func; + + module->library = g_module_open (module->path, 0); + + if (!module->library) { + g_warning (g_module_error ()); + + return FALSE; + } + + /* extract symbols from the lib */ + if (!g_module_symbol (module->library, "register_evince_backend", + (void *) ®ister_func)) { + g_warning (g_module_error ()); + g_module_close (module->library); + + return FALSE; + } + + /* symbol can still be NULL even though g_module_symbol + * returned TRUE */ + if (!register_func) { + g_warning ("Symbol 'register_evince_backend' should not be NULL"); + g_module_close (module->library); + + return FALSE; + } + + module->type = register_func (gmodule); + + if (module->type == 0) { + g_warning ("Invalid evince backend contained by module %s", module->path); + + return FALSE; + } + + return TRUE; +} + +static void +ev_module_unload (GTypeModule *gmodule) +{ + EvModule *module = EV_MODULE (gmodule); + + g_module_close (module->library); + + module->library = NULL; + module->type = 0; +} + +const gchar * +ev_module_get_path (EvModule *module) +{ + g_return_val_if_fail (EV_IS_MODULE (module), NULL); + + return module->path; +} + +GObject * +ev_module_new_object (EvModule *module) +{ + g_return_val_if_fail (EV_IS_MODULE (module), NULL); + + if (module->type == 0) + return NULL; + + return g_object_new (module->type, NULL); +} + +GType +ev_module_get_object_type (EvModule *module) +{ + g_return_val_if_fail (EV_IS_MODULE (module), 0); + + return module->type; +} + +static void +ev_module_init (EvModule *module) +{ +} + +static void +ev_module_finalize (GObject *object) +{ + EvModule *module = EV_MODULE (object); + + g_free (module->path); + + G_OBJECT_CLASS (ev_module_parent_class)->finalize (object); +} + +static void +ev_module_class_init (EvModuleClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class); + + object_class->finalize = ev_module_finalize; + + module_class->load = ev_module_load; + module_class->unload = ev_module_unload; +} + +EvModule * +ev_module_new (const gchar *path) +{ + EvModule *result; + + g_return_val_if_fail (path != NULL && path[0] != '\0', NULL); + + result = g_object_new (EV_TYPE_MODULE, NULL); + + g_type_module_set_name (G_TYPE_MODULE (result), path); + result->path = g_strdup (path); + + return result; +} diff --git a/libdocument/ev-module.h b/libdocument/ev-module.h new file mode 100644 index 0000000..4239cb1 --- /dev/null +++ b/libdocument/ev-module.h @@ -0,0 +1,69 @@ +/* + * ev-module.h + * This file is part of Evince + * + * Copyright (C) 2005 - Paolo Maggi + * + * 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., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* This is a modified version of gedit-module.h from Epiphany source code. + * Here the original copyright assignment: + * + * Copyright (C) 2003 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + */ + +/* + * Modified by the gedit Team, 2005. See the AUTHORS file for a + * list of people on the gedit Team. + * See the ChangeLog files for a list of changes. + * + * $Id: gedit-module.h 5263 2006-10-08 14:26:02Z pborelli $ + */ + +/* Modified by Evince Team */ + +#ifndef EV_MODULE_H +#define EV_MODULE_H + +#include + +G_BEGIN_DECLS + +#define EV_TYPE_MODULE (ev_module_get_type ()) +#define EV_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_MODULE, EvModule)) +#define EV_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_MODULE, EvModuleClass)) +#define EV_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_MODULE)) +#define EV_IS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EV_TYPE_MODULE)) +#define EV_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_MODULE, EvModuleClass)) + +typedef struct _EvModule EvModule; + +GType ev_module_get_type (void) G_GNUC_CONST; + +EvModule *ev_module_new (const gchar *path); + +const gchar *ev_module_get_path (EvModule *module); + +GObject *ev_module_new_object (EvModule *module); + +GType ev_module_get_object_type (EvModule *module); + +G_END_DECLS + +#endif /* EV_MODULE_H */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 93e5efb..e29511c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -2,14 +2,20 @@ # Please keep this file sorted alphabetically. [encoding: UTF-8] backend/comics/comics-document.c +backend/comics/comicsdocument.evince-backend.in backend/djvu/djvu-document.c +backend/djvu/djvudocument.evince-backend.in backend/dvi/dvi-document.c +backend/dvi/dvidocument.evince-backend.in backend/pdf/ev-poppler.cc +backend/pdf/pdfdocument.evince-backend.in +backend/impress/impress-document.c +backend/impress/impressdocument.evince-backend.in backend/impress/zip.c backend/ps/gsdefaults.c backend/ps/ps-document.c backend/ps/ps-interpreter.c -backend/impress/impress-document.c +backend/ps/psdocument.evince-backend.in libdocument/ev-attachment.c libdocument/ev-document-factory.c cut-n-paste/toolbar-editor/egg-editable-toolbar.c diff --git a/shell/Makefile.am b/shell/Makefile.am index 973882b..a4e8d1e 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -102,18 +102,6 @@ evince_LDADD= \ $(SHELL_LIBS) \ $(GNOME_PRINT_LIBS) -if ENABLE_DJVU -evince_LDADD += $(DJVU_LIBS) -endif - -if ENABLE_DVI -evince_LDADD += -lkpathsea -endif - -if WITH_TYPE1_FONTS -evince_LDADD += -lt1 -endif - BUILT_SOURCES = ev-marshal.h ev-marshal.c if ENABLE_DBUS diff --git a/shell/ev-window-title.c b/shell/ev-window-title.c index 3a7d908..ac1be65 100644 --- a/shell/ev-window-title.c +++ b/shell/ev-window-title.c @@ -18,15 +18,19 @@ */ #include "ev-window-title.h" -#include "ev-document-factory.h" +#include "ev-backends-manager.h" #include #include +/* Known backends (for bad extensions fix) */ +#define EV_BACKEND_PS "psdocument" +#define EV_BACKEND_PDF "pdfdocument" + typedef struct { - EvBackend backend; - const char *ext; + const gchar *backend; + const gchar *ext; } BadExtensionEntry; struct _EvWindowTitle @@ -74,12 +78,13 @@ get_filename_from_uri (const char *uri) Let's show the filename in this case */ static void ev_window_title_sanitize_extension (EvWindowTitle *window_title, char **title) { - EvBackend backend; + const gchar *backend; int i; - backend = ev_document_factory_get_backend (window_title->document); + backend = ev_backends_manager_get_document_module_name (window_title->document); + for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) { - if (bad_extensions[i].backend == backend && + if (g_ascii_strcasecmp (bad_extensions[i].backend, backend) == 0 && g_str_has_suffix (*title, bad_extensions[i].ext)) { char *new_title; char *filename = get_filename_from_uri (window_title->uri); diff --git a/shell/main.c b/shell/main.c index b7362e0..e4c2d1b 100644 --- a/shell/main.c +++ b/shell/main.c @@ -45,6 +45,7 @@ #include "ev-stock-icons.h" #include "ev-job-queue.h" #include "ev-file-helpers.h" +#include "ev-backends-manager.h" static gchar *ev_page_label; static gchar *ev_find_string; @@ -379,6 +380,8 @@ main (int argc, char *argv[]) gnome_authentication_manager_init (); #endif + ev_backends_manager_init (); + if (enable_metadata) { ev_metadata_manager_init (); } @@ -408,6 +411,8 @@ main (int argc, char *argv[]) ev_metadata_manager_shutdown (); } + ev_backends_manager_shutdown (); + #if WITH_GNOME g_object_unref (program); #endif diff --git a/thumbnailer/Makefile.am b/thumbnailer/Makefile.am index 25868e9..0d34109 100644 --- a/thumbnailer/Makefile.am +++ b/thumbnailer/Makefile.am @@ -19,18 +19,6 @@ evince_thumbnailer_LDADD= \ $(FRONTEND_LIBS) \ $(DJVU_LIBS) -if ENABLE_DJVU -evince_thumbnailer_LDADD += $(DJVU_LIBS) -endif - -if ENABLE_DVI -evince_thumbnailer_LDADD += -lkpathsea -endif - -if WITH_TYPE1_FONTS -evince_thumbnailer_LDADD += -lt1 -endif - schema_files = \ evince-thumbnailer-dvi.schemas.in \ evince-thumbnailer-djvu.schemas.in \ diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index f76b9c4..d550674 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -163,16 +164,21 @@ main (int argc, char *argv[]) gnome_vfs_init (); + ev_backends_manager_init (); + uri = gnome_vfs_make_uri_from_shell_arg (input); document = evince_thumbnailer_get_document (uri); g_free (uri); - if (!document) + if (!document) { + ev_backends_manager_shutdown (); return -2; + } if (!EV_IS_DOCUMENT_THUMBNAILS (document)) { g_object_unref (document); - return FALSE; + ev_backends_manager_shutdown (); + return -2; } if (EV_IS_ASYNC_RENDERER (document)) { @@ -190,16 +196,19 @@ main (int argc, char *argv[]) gtk_main (); g_object_unref (document); + ev_backends_manager_shutdown (); return data.success ? 0 : -2; } if (!evince_thumbnail_pngenc_get (document, output, size)) { g_object_unref (document); + ev_backends_manager_shutdown (); return -2; } g_object_unref (document); + ev_backends_manager_shutdown (); return 0; } -- cgit v0.9.1