From: Marco Pesenti Gritti Date: Tue, 5 Jul 2005 15:31:17 +0000 (+0000) Subject: Rework document types managing to avoid code duplication and actually X-Git-Tag: EVINCE_0_3_3~166 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=4684716c489657edf098565eb54bdf86bad1b45c;p=evince.git Rework document types managing to avoid code duplication and actually 2005-07-05 Marco Pesenti Gritti * backend/Makefile.am: * backend/ev-document-factory.c: (mime_type_supported_by_gdk_pixbuf), (ev_document_type_get_from_mime), (ev_document_factory_get_document), (ev_document_factory_get_backend), (ev_document_factory_get_mime_types), (ev_document_factory_get_all_mime_types): * backend/ev-document-factory.h: * shell/Makefile.am: * shell/ev-document-types.c: (get_document_from_uri), (ev_document_types_get_document), (file_filter_add_mime_list_and_free), (ev_document_types_add_filters): * shell/ev-document-types.h: * shell/ev-job-xfer.c: (ev_job_xfer_run): * shell/ev-properties-dialog.c: (ev_properties_dialog_set_document): * shell/ev-window.c: (ev_window_cmd_file_open), (ev_window_cmd_save_as): * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): Rework document types managing to avoid code duplication and actually abstract from backend implementations. Also provide a minimal factory api that can be used by thumbnailer/properties. --- diff --git a/ChangeLog b/ChangeLog index a6ee79c7..b954d0dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2005-07-05 Marco Pesenti Gritti + + * backend/Makefile.am: + * backend/ev-document-factory.c: + (mime_type_supported_by_gdk_pixbuf), + (ev_document_type_get_from_mime), + (ev_document_factory_get_document), + (ev_document_factory_get_backend), + (ev_document_factory_get_mime_types), + (ev_document_factory_get_all_mime_types): + * backend/ev-document-factory.h: + * shell/Makefile.am: + * shell/ev-document-types.c: (get_document_from_uri), + (ev_document_types_get_document), + (file_filter_add_mime_list_and_free), + (ev_document_types_add_filters): + * shell/ev-document-types.h: + * shell/ev-job-xfer.c: (ev_job_xfer_run): + * shell/ev-properties-dialog.c: + (ev_properties_dialog_set_document): + * shell/ev-window.c: (ev_window_cmd_file_open), + (ev_window_cmd_save_as): + * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): + + Rework document types managing to avoid code duplication + and actually abstract from backend implementations. + Also provide a minimal factory api that can be used by + thumbnailer/properties. + 2005-07-05 Christian Persch * properties/ev-properties-view.c: (ev_properties_view_set_info): diff --git a/backend/Makefile.am b/backend/Makefile.am index 8ce117d5..35971869 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -3,6 +3,12 @@ NULL= INCLUDES= \ -DEVINCE_UIDIR=\"$(pkgdatadir)\" \ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ + -I$(top_srcdir)/pdf \ + -I$(top_srcdir)/pixbuf \ + -I$(top_srcdir)/tiff \ + -I$(top_srcdir)/ps \ + -I$(top_srcdir)/djvu \ + -I$(top_srcdir)/dvi \ $(SHELL_CFLAGS) \ $(EVINCE_DISABLE_DEPRECATED) \ $(NULL) @@ -17,6 +23,8 @@ libevbackend_la_SOURCES= \ ev-link.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 \ diff --git a/backend/ev-document-factory.c b/backend/ev-document-factory.c new file mode 100644 index 00000000..251ede3f --- /dev/null +++ b/backend/ev-document-factory.c @@ -0,0 +1,191 @@ +/* -*- 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-factory.h" + +/* The various document type backends: */ +#include "ev-poppler.h" +#include "pixbuf-document.h" +#include "tiff-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; + EvBackend backend; + GType (*document_type_factory_callback)(); +}; + +const EvDocumentType document_types[] = { + /* PDF: */ + {"application/pdf", EV_BACKEND_PDF, pdf_document_get_type}, + + /* Postscript: */ + {"application/postscript", EV_BACKEND_PS, ps_document_get_type}, + {"application/x-gzpostscript", EV_BACKEND_PS, ps_document_get_type}, + {"image/x-eps", EV_BACKEND_PS, ps_document_get_type}, + +#ifdef ENABLE_TIFF + /* Tiff: */ + {"image/tiff", EV_BACKEND_TIFF, tiff_document_get_type}, +#endif + +#ifdef ENABLE_DJVU + /* djvu: */ + {"image/vnd.djvu", EV_BACKEND_DJVU, djvu_document_get_type}, +#endif + +#ifdef ENABLE_DVI + /* dvi: */ + {"application/x-dvi", EV_BACKEND_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; +} + + +static GType +ev_document_type_get_from_mime (const char *mime_type) +{ + int i; + + g_return_val_if_fail (mime_type, G_TYPE_INVALID); + + 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); + return document_types[i].document_type_factory_callback(); + } + } + + if (mime_type_supported_by_gdk_pixbuf (mime_type)) { + return pixbuf_document_get_type (); + } + + return G_TYPE_INVALID; +} + +EvDocument * +ev_document_factory_get_document (const char *mime_type) +{ + GType type = G_TYPE_INVALID; + + type = ev_document_type_get_from_mime (mime_type); + + if (type != G_TYPE_NONE) { + return g_object_new (type, NULL); + } + + return NULL; +} + +EvBackend +ev_document_factory_get_backend (EvDocument *document) +{ + int i; + + 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; + } + } + + g_assert_not_reached (); + + return 0; +} + +GList * +ev_document_factory_get_mime_types (EvBackend backend) +{ + GList *types = NULL; + int i; + + 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; +} + +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)); + } + + return types; +} diff --git a/backend/ev-document-factory.h b/backend/ev-document-factory.h new file mode 100644 index 00000000..56be46d5 --- /dev/null +++ b/backend/ev-document-factory.h @@ -0,0 +1,44 @@ +/* -*- 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. + * + */ + +#ifndef EV_DOCUMENT_FACTORY_H +#define EV_DOCUMENT_FACTORY_H + +#include "ev-document.h" + +G_BEGIN_DECLS + +typedef enum { + EV_BACKEND_PDF, + EV_BACKEND_PS, + EV_BACKEND_TIFF, + EV_BACKEND_PIXBUF, + EV_BACKEND_DJVU, + EV_BACKEND_DVI +} EvBackend; + +EvDocument *ev_document_factory_get_document (const char *mime_type); +EvBackend ev_document_factory_get_backend (EvDocument *document); +GList *ev_document_factory_get_mime_types (EvBackend backend); +GList *ev_document_factory_get_all_mime_types (void); + +G_END_DECLS + +#endif diff --git a/shell/Makefile.am b/shell/Makefile.am index e4010a93..7dc939ff 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -8,13 +8,7 @@ INCLUDES= \ -I$(top_srcdir)/cut-n-paste/zoom-control/ \ -I$(top_srcdir)/cut-n-paste/toolbar-editor/ \ -I$(top_srcdir)/backend \ - -I$(top_srcdir)/pdf \ - -I$(top_srcdir)/pixbuf \ -I$(top_srcdir)/properties \ - -I$(top_srcdir)/tiff \ - -I$(top_srcdir)/ps \ - -I$(top_srcdir)/djvu \ - -I$(top_srcdir)/dvi \ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ -DGNOMEICONDIR=\""$(datadir)/pixmaps"\" \ $(SHELL_CFLAGS) \ diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index 724412fb..d2078c52 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -23,18 +23,7 @@ #endif #include "ev-document-types.h" - -/* The various document type backends: */ -#include "ev-poppler.h" -#include "pixbuf-document.h" -#include "tiff-document.h" -#include "ps-document.h" -#ifdef ENABLE_DVI -#include "dvi-document.h" -#endif -#ifdef ENABLE_DJVU -#include "djvu-document.h" -#endif +#include "ev-document-factory.h" #include #include @@ -43,116 +32,13 @@ #include #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_TIFF - /* Tiff: */ - {"image/tiff", tiff_document_get_type}, -#endif - -#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; -} - - -static GType -ev_document_type_from_from_mime (const char *mime_type) -{ - int i; - - g_return_val_if_fail (mime_type, G_TYPE_INVALID); - - 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); - return document_types[i].document_type_factory_callback(); - } - } - - if (mime_type_supported_by_gdk_pixbuf (mime_type)) { - return pixbuf_document_get_type (); - } - - return G_TYPE_INVALID; -} - -/** - * ev_document_type_get_type: - * @uri: String with uri - * @slow: Do we need to check slow gnome-vfs mime type - * @mime_type: If we've found handled type, the mime_type string is returned here. - * @error: Information about error occured - * - * Return value: G_TYPE_INVALID on error, G_TYPE_NONE when we are not sure about - * mime type, and type of EvDocument implementation when we've found document. - **/ -static GType -ev_document_type_get_type (const char *uri, gboolean slow, gchar **mime_type, GError **error) +static EvDocument * +get_document_from_uri (const char *uri, gboolean slow, gchar **mime_type, GError **error) { + EvDocument *document; GnomeVFSFileInfo *info; GnomeVFSResult result; - GType type = G_TYPE_INVALID; - info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE | @@ -164,7 +50,7 @@ ev_document_type_get_type (const char *uri, gboolean slow, gchar **mime_type, GE 0, gnome_vfs_result_to_string (result)); gnome_vfs_file_info_unref (info); - return G_TYPE_INVALID; + return NULL; } if (info->mime_type == NULL) { @@ -173,195 +59,129 @@ ev_document_type_get_type (const char *uri, gboolean slow, gchar **mime_type, GE 0, _("Unknown MIME Type")); gnome_vfs_file_info_unref (info); - return slow ? G_TYPE_INVALID : G_TYPE_NONE; + return NULL; } - type = ev_document_type_from_from_mime (info->mime_type); + document = ev_document_factory_get_document (info->mime_type); - if (type == G_TYPE_INVALID) { + if (document == NULL) { g_set_error (error, EV_DOCUMENT_ERROR, 0, _("Unhandled MIME type: '%s'"), info->mime_type); gnome_vfs_file_info_unref (info); - return slow ? G_TYPE_INVALID : G_TYPE_NONE; + return NULL; } if (mime_type != NULL) { *mime_type = g_strdup (info->mime_type); } + gnome_vfs_file_info_unref (info); - return type; + return document; } -GType -ev_document_type_lookup (const char *uri, gchar **mime_type, GError **error) +EvDocument * +ev_document_types_get_document (const char *uri, gchar **mime_type, GError **error) { - GType type = G_TYPE_INVALID; + EvDocument *document; - type = ev_document_type_get_type (uri, FALSE, mime_type, error); + document = get_document_from_uri (uri, FALSE, mime_type, error); - if (type != G_TYPE_NONE) - return type; + if (document != NULL) { + return document; + } if (error) { g_error_free (*error); *error = NULL; } - type = ev_document_type_get_type (uri, TRUE, mime_type, error); + document = get_document_from_uri (uri, TRUE, mime_type, error); - return type; + return document; } -void -ev_document_types_add_filters (GtkWidget *chooser) +static void +file_filter_add_mime_list_and_free (GtkFileFilter *filter, GList *mime_types) { - GtkFileFilter *documents_filter; - GtkFileFilter *pdf_filter; - GtkFileFilter *ps_filter; - GtkFileFilter *pixbuf_filter; - GtkFileFilter *all_filter; -#ifdef ENABLE_DJVU - GtkFileFilter *djvu_filter; -#endif -#ifdef ENABLE_DVI - GtkFileFilter *dvi_filter; -#endif - - documents_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (documents_filter, - _("All Documents")); - gtk_file_filter_add_mime_type (documents_filter, "application/postscript"); - gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript"); - gtk_file_filter_add_mime_type (documents_filter, "image/x-eps"); - gtk_file_filter_add_mime_type (documents_filter, "application/pdf"); -#ifdef ENABLE_DVI - gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi"); -#endif - gtk_file_filter_add_pixbuf_formats (documents_filter); -#ifdef ENABLE_DJVU - gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu"); -#endif - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter); + GList *l; - ps_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (ps_filter, _("PostScript Documents")); - gtk_file_filter_add_mime_type (ps_filter, "application/postscript"); - gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript"); - gtk_file_filter_add_mime_type (ps_filter, "image/x-eps"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter); - - pdf_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (pdf_filter, _("PDF Documents")); - gtk_file_filter_add_mime_type (pdf_filter, "application/pdf"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter); - -#ifdef ENABLE_DVI - dvi_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (dvi_filter, _("DVI Documents")); - gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter); -#endif - - pixbuf_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (pixbuf_filter, _("Images")); - gtk_file_filter_add_pixbuf_formats (pixbuf_filter); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter); - -#ifdef ENABLE_DJVU - djvu_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (djvu_filter, _("Djvu Documents")); - gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter); -#endif - - all_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (all_filter, _("All Files")); - gtk_file_filter_add_pattern (all_filter, "*"); + for (l = mime_types; l != NULL; l = l->next) { + gtk_file_filter_add_mime_type (filter, l->data); + } - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), documents_filter); + g_list_foreach (mime_types, (GFunc)g_free, NULL); + g_list_free (mime_types); } void -ev_document_types_add_filters_for_type (GtkWidget *chooser, GType type) +ev_document_types_add_filters (GtkWidget *chooser, EvDocument *document) { - GtkFileFilter *documents_filter; - GtkFileFilter *pdf_filter; - GtkFileFilter *ps_filter; - GtkFileFilter *pixbuf_filter; - GtkFileFilter *all_filter; -#ifdef ENABLE_DJVU - GtkFileFilter *djvu_filter; -#endif -#ifdef ENABLE_DVI - GtkFileFilter *dvi_filter; -#endif + EvBackend backend = 0; + GList *mime_types; + GtkFileFilter *filter; GtkFileFilter *default_filter; - documents_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (documents_filter, - _("All Documents")); - gtk_file_filter_add_mime_type (documents_filter, "application/postscript"); - gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript"); - gtk_file_filter_add_mime_type (documents_filter, "image/x-eps"); - gtk_file_filter_add_mime_type (documents_filter, "application/pdf"); -#ifdef ENABLE_DVI - gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi"); -#endif - gtk_file_filter_add_pixbuf_formats (documents_filter); -#ifdef ENABLE_DJVU - gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu"); -#endif - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter); + if (document != NULL) { + backend = ev_document_factory_get_backend (document); + } + + default_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); + gtk_file_filter_add_pixbuf_formats (filter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + + 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); + } + + 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); + } + + if (document == NULL || backend == EV_BACKEND_PIXBUF) { + default_filter = filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Images")); + gtk_file_filter_add_pixbuf_formats (filter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + } - if (type == PS_TYPE_DOCUMENT) { - ps_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (ps_filter, _("PostScript Documents")); - gtk_file_filter_add_mime_type (ps_filter, "application/postscript"); - gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript"); - gtk_file_filter_add_mime_type (ps_filter, "image/x-eps"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter); - default_filter = ps_filter; - } else if (type == PDF_TYPE_DOCUMENT) { - pdf_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (pdf_filter, _("PDF Documents")); - gtk_file_filter_add_mime_type (pdf_filter, "application/pdf"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter); - default_filter = pdf_filter; #ifdef ENABLE_DVI - } else if (type == DVI_TYPE_DOCUMENT) { - dvi_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (dvi_filter, _("DVI Documents")); - gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter); - default_filter = dvi_filter; + 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 - } else if (type == PIXBUF_TYPE_DOCUMENT) { - pixbuf_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (pixbuf_filter, _("Images")); - gtk_file_filter_add_pixbuf_formats (pixbuf_filter); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter); - default_filter = pixbuf_filter; + #ifdef ENABLE_DJVU - } else if (type == DJVU_TYPE_DOCUMENT) { - djvu_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (djvu_filter, _("Djvu Documents")); - gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter); - default_filter = djvu_filter; -#endif - } else { - default_filter = documents_filter; + 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 - all_filter = gtk_file_filter_new (); - gtk_file_filter_set_name (all_filter, _("All Files")); - gtk_file_filter_add_pattern (all_filter, "*"); + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("All Files")); + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), default_filter); } - diff --git a/shell/ev-document-types.h b/shell/ev-document-types.h index b5d75ddc..1d8b0dfb 100644 --- a/shell/ev-document-types.h +++ b/shell/ev-document-types.h @@ -26,12 +26,11 @@ G_BEGIN_DECLS -GType ev_document_type_lookup (const char *uri, - gchar **mime_type, - GError **error); - -void ev_document_types_add_filters (GtkWidget *chooser); -void ev_document_types_add_filters_for_type (GtkWidget *chooser, GType type); +EvDocument *ev_document_types_get_document (const char *uri, + gchar **mime_type, + GError **error); +void ev_document_types_add_filters (GtkWidget *chooser, + EvDocument *document); G_END_DECLS diff --git a/shell/ev-job-xfer.c b/shell/ev-job-xfer.c index 49f674e5..28e7a91a 100644 --- a/shell/ev-job-xfer.c +++ b/shell/ev-job-xfer.c @@ -90,7 +90,7 @@ ev_job_xfer_new (const gchar *uri) void ev_job_xfer_run (EvJobXfer *job) { - GType document_type; + EvDocument *document; GError *error = NULL; GnomeVFSURI *source_uri; GnomeVFSURI *target_uri; @@ -102,10 +102,10 @@ ev_job_xfer_run (EvJobXfer *job) job->error = NULL; } - document_type = ev_document_type_lookup (job->uri, NULL, &error); + document = ev_document_types_get_document (job->uri, NULL, &error); - if (document_type != G_TYPE_INVALID) { - EV_JOB (job)->document = g_object_new (document_type, NULL); + if (document != NULL) { + EV_JOB (job)->document = document; } else { job->error = error; EV_JOB (job)->finished = TRUE; diff --git a/shell/ev-properties-dialog.c b/shell/ev-properties-dialog.c index c34bb826..220728e6 100644 --- a/shell/ev-properties-dialog.c +++ b/shell/ev-properties-dialog.c @@ -106,7 +106,8 @@ ev_properties_dialog_set_document (EvPropertiesDialog *properties, gtk_widget_show (properties->fonts_page); } - ev_properties_fonts_set_document (EV_PROPERTIES_FONTS (properties->fonts_page), document); + ev_properties_fonts_set_document + (EV_PROPERTIES_FONTS (properties->fonts_page), document); } } diff --git a/shell/ev-window.c b/shell/ev-window.c index 854079b5..c61515be 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -977,7 +977,7 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window) folder); } - ev_document_types_add_filters (chooser); + ev_document_types_add_filters (chooser, NULL); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE); @@ -1146,7 +1146,7 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window) NULL); gtk_window_set_modal (GTK_WINDOW (fc), TRUE); - ev_document_types_add_filters_for_type (fc, G_TYPE_FROM_INSTANCE (ev_window->priv->document)); + ev_document_types_add_filters (fc, ev_window->priv->document); gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK); if (folder) { diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index c4a02cb6..9c672463 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -35,15 +35,12 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) EvDocument *document = NULL; GError *error = NULL; GdkPixbuf *pixbuf; - GType document_type; char *mime_type = NULL; - document_type = ev_document_type_lookup (uri, &mime_type, &error); - if (document_type == G_TYPE_INVALID || error != NULL) + document = ev_document_types_get_document (uri, &mime_type, &error); + if (document == NULL) 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) {