]> www.fi.muni.cz Git - evince.git/commitdiff
Rework document types managing to avoid code duplication and actually
authorMarco Pesenti Gritti <mpg@redhat.com>
Tue, 5 Jul 2005 15:31:17 +0000 (15:31 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Tue, 5 Jul 2005 15:31:17 +0000 (15:31 +0000)
2005-07-05  Marco Pesenti Gritti  <mpg@redhat.com>

        * 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.

ChangeLog
backend/Makefile.am
backend/ev-document-factory.c [new file with mode: 0644]
backend/ev-document-factory.h [new file with mode: 0644]
shell/Makefile.am
shell/ev-document-types.c
shell/ev-document-types.h
shell/ev-job-xfer.c
shell/ev-properties-dialog.c
shell/ev-window.c
thumbnailer/evince-thumbnailer.c

index a6ee79c7c79761d00cb67b08137f83216440c120..b954d0dcf51c75953da7262f91157de39a27fa25 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2005-07-05  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * 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  <chpe@cvs.gnome.org>
 
        * properties/ev-properties-view.c: (ev_properties_view_set_info):
index 8ce117d52d1c8b396642090d7e7c21c34b1cfa0b..35971869909957fcb384fff0d4f6ef74d409d92d 100644 (file)
@@ -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 (file)
index 0000000..251ede3
--- /dev/null
@@ -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 <string.h>
+
+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 (file)
index 0000000..56be46d
--- /dev/null
@@ -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
index e4010a93d776b7dc68172192b7d25ad2f860175f..7dc939ff98e603a0fcac1b64f15c51b2fa88881c 100644 (file)
@@ -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)                                 \
index 724412fb968e2e808bae1b8fcbae83e4270ea288..d2078c52311fe591423ff6d919be316b1d5efbc8 100644 (file)
 #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 <string.h>
 #include <glib/gi18n.h>
 #include <libgnomevfs/gnome-vfs-ops.h>
 #include <gtk/gtkfilechooserdialog.h>
 
-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);
 }
-
index b5d75ddce4803654f0f4f8af9c216649ffe2649a..1d8b0dfbe49399c50a934a949375619fb4657c43 100644 (file)
 
 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
 
index 49f674e53f2ebdbeec8b9c6840426aec05c70bef..28e7a91a472ff725948e9019c540ce01120a1884 100644 (file)
@@ -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;
index c34bb826840392ed970ce4b66643df032cb181f9..220728e6d3a1ca45b68e43ee18310f90c04eb123 100644 (file)
@@ -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);
        }
 }
 
index 854079b573e0888cfbb9a4c2929daeafce1adf06..c61515be7e381a0a592744786fbaa6978d7c1e43 100644 (file)
@@ -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) {
index c4a02cb6b7193c31374a6c03fae05e520265a9d8..9c672463bd6106a8e007493b340f1b7dd462d2fb 100644 (file)
@@ -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) {