1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2005, Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "ev-document-factory.h"
27 /* The various document type backends: */
28 #include "ev-poppler.h"
29 #include "pixbuf-document.h"
30 #include "tiff-document.h"
31 #include "ps-document.h"
33 #include "dvi-document.h"
36 #include "djvu-document.h"
41 typedef struct _EvDocumentType EvDocumentType;
42 struct _EvDocumentType
44 const char *mime_type;
46 GType (*document_type_factory_callback)();
49 const EvDocumentType document_types[] = {
51 {"application/pdf", EV_BACKEND_PDF, pdf_document_get_type},
54 {"application/postscript", EV_BACKEND_PS, ps_document_get_type},
55 {"application/x-gzpostscript", EV_BACKEND_PS, ps_document_get_type},
56 {"image/x-eps", EV_BACKEND_PS, ps_document_get_type},
60 {"image/tiff", EV_BACKEND_TIFF, tiff_document_get_type},
65 {"image/vnd.djvu", EV_BACKEND_DJVU, djvu_document_get_type},
70 {"application/x-dvi", EV_BACKEND_DVI, dvi_document_get_type},
74 /* Would be nice to have this in gdk-pixbuf */
76 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
78 GSList *formats, *list;
79 gboolean retval = FALSE;
81 formats = gdk_pixbuf_get_formats ();
85 GdkPixbufFormat *format = list->data;
89 if (gdk_pixbuf_format_is_disabled (format))
92 mime_types = gdk_pixbuf_format_get_mime_types (format);
94 for (i = 0; mime_types[i] != NULL; i++) {
95 if (strcmp (mime_types[i], mime_type) == 0) {
107 g_slist_free (formats);
114 ev_document_type_get_from_mime (const char *mime_type)
118 g_return_val_if_fail (mime_type, G_TYPE_INVALID);
120 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
121 if (strcmp (mime_type, document_types[i].mime_type) == 0) {
122 g_assert (document_types[i].document_type_factory_callback != NULL);
123 return document_types[i].document_type_factory_callback();
127 if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
128 return pixbuf_document_get_type ();
132 return G_TYPE_INVALID;
136 ev_document_factory_get_document (const char *mime_type)
138 GType type = G_TYPE_INVALID;
140 type = ev_document_type_get_from_mime (mime_type);
142 if (type != G_TYPE_INVALID) {
143 return g_object_new (type, NULL);
150 ev_document_factory_get_backend (EvDocument *document)
154 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
155 GType type = document_types[i].document_type_factory_callback ();
156 if (type == G_TYPE_FROM_INSTANCE (document)) {
157 return document_types[i].backend;
161 g_assert_not_reached ();
167 ev_document_factory_get_mime_types (EvBackend backend)
172 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
173 if (document_types[i].backend == backend) {
174 types = g_list_append (types, g_strdup (document_types[i].mime_type));
182 ev_document_factory_get_all_mime_types (void)
187 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
188 types = g_list_append (types, g_strdup (document_types[i].mime_type));