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-types.h"
27 /* The various document type backends: */
28 #include "ev-poppler.h"
29 #include "pixbuf-document.h"
30 #include "ps-document.h"
32 #include "dvi-document.h"
35 #include "djvu-document.h"
40 typedef struct _EvDocumentType EvDocumentType;
41 struct _EvDocumentType
43 const char *mime_type;
44 GType (*document_type_factory_callback)();
47 const EvDocumentType document_types[] = {
49 {"application/pdf", pdf_document_get_type},
52 {"application/postscript", ps_document_get_type},
53 {"application/x-gzpostscript", ps_document_get_type},
54 {"image/x-eps", ps_document_get_type},
58 {"image/vnd.djvu", djvu_document_get_type},
63 {"application/x-dvi", dvi_document_get_type},
67 /* Would be nice to have this in gdk-pixbuf */
69 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
71 GSList *formats, *list;
72 gboolean retval = FALSE;
74 formats = gdk_pixbuf_get_formats ();
78 GdkPixbufFormat *format = list->data;
82 if (gdk_pixbuf_format_is_disabled (format))
85 mime_types = gdk_pixbuf_format_get_mime_types (format);
87 for (i = 0; mime_types[i] != NULL; i++) {
88 if (strcmp (mime_types[i], mime_type) == 0) {
100 g_slist_free (formats);
106 ev_document_type_lookup (const char *mime_type)
110 g_return_val_if_fail (mime_type, G_TYPE_INVALID);
112 for (i=0;i<G_N_ELEMENTS (document_types);i++) {
113 if (0==strcmp(mime_type, document_types[i].mime_type)) {
114 g_assert (document_types[i].document_type_factory_callback!=NULL);
115 return document_types[i].document_type_factory_callback();
119 if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
120 return pixbuf_document_get_type ();
123 return G_TYPE_INVALID;