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"
39 #include "comics-document.h"
44 typedef struct _EvDocumentType EvDocumentType;
45 struct _EvDocumentType
47 const char *mime_type;
49 GType (*document_type_factory_callback)();
52 const EvDocumentType document_types[] = {
54 {"application/pdf", EV_BACKEND_PDF, pdf_document_get_type},
57 {"application/postscript", EV_BACKEND_PS, ps_document_get_type},
58 {"application/x-gzpostscript", EV_BACKEND_PS, ps_document_get_type},
59 {"image/x-eps", EV_BACKEND_PS, ps_document_get_type},
63 {"image/tiff", EV_BACKEND_TIFF, tiff_document_get_type},
68 {"image/vnd.djvu", EV_BACKEND_DJVU, djvu_document_get_type},
73 {"application/x-dvi", EV_BACKEND_DVI, dvi_document_get_type},
78 {"application/cbr", EV_BACKEND_COMICS, comics_document_get_type},
79 {"application/cbz", EV_BACKEND_COMICS, comics_document_get_type},
84 /* Would be nice to have this in gdk-pixbuf */
86 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
88 GSList *formats, *list;
89 gboolean retval = FALSE;
91 formats = gdk_pixbuf_get_formats ();
95 GdkPixbufFormat *format = list->data;
99 if (gdk_pixbuf_format_is_disabled (format))
102 mime_types = gdk_pixbuf_format_get_mime_types (format);
104 for (i = 0; mime_types[i] != NULL; i++) {
105 if (strcmp (mime_types[i], mime_type) == 0) {
117 g_slist_free (formats);
124 ev_document_type_get_from_mime (const char *mime_type)
128 g_return_val_if_fail (mime_type, G_TYPE_INVALID);
130 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
131 if (strcmp (mime_type, document_types[i].mime_type) == 0) {
132 g_assert (document_types[i].document_type_factory_callback != NULL);
133 return document_types[i].document_type_factory_callback();
137 if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
138 return pixbuf_document_get_type ();
142 return G_TYPE_INVALID;
146 ev_document_factory_get_document (const char *mime_type)
148 GType type = G_TYPE_INVALID;
150 type = ev_document_type_get_from_mime (mime_type);
152 if (type != G_TYPE_INVALID) {
153 return g_object_new (type, NULL);
160 ev_document_factory_get_backend (EvDocument *document)
164 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
165 GType type = document_types[i].document_type_factory_callback ();
166 if (type == G_TYPE_FROM_INSTANCE (document)) {
167 return document_types[i].backend;
171 g_assert_not_reached ();
177 ev_document_factory_get_mime_types (EvBackend backend)
182 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
183 if (document_types[i].backend == backend) {
184 types = g_list_append (types, g_strdup (document_types[i].mime_type));
192 ev_document_factory_get_all_mime_types (void)
197 for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
198 types = g_list_append (types, g_strdup (document_types[i].mime_type));