]> www.fi.muni.cz Git - evince.git/blob - shell/ev-document-types.c
2d64594ddd9247e8033d43b95b559d949e786dc6
[evince.git] / shell / ev-document-types.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  *  Copyright (C) 2005, Red Hat, Inc. 
4  *
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)
8  *  any later version.
9  *
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.
14  *
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.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-document-types.h"
26
27 /* The various document type backends: */
28 #include "ev-poppler.h"
29 #include "pixbuf-document.h"
30 #include "ps-document.h"
31 #ifdef ENABLE_DVI
32 #include "dvi-document.h"
33 #endif
34 #ifdef ENABLE_DJVU
35 #include "djvu-document.h"
36 #endif
37
38 #include <string.h>
39
40 typedef struct _EvDocumentType EvDocumentType;
41 struct _EvDocumentType
42 {
43         const char *mime_type;
44         GType (*document_type_factory_callback)();
45 };
46
47 const EvDocumentType document_types[] = {
48         /* PDF: */
49         {"application/pdf",            pdf_document_get_type},
50
51         /* Postscript: */
52         {"application/postscript",     ps_document_get_type},
53         {"application/x-gzpostscript", ps_document_get_type},
54         {"image/x-eps",                ps_document_get_type},
55
56 #ifdef ENABLE_DJVU
57         /* djvu: */
58         {"image/vnd.djvu",             djvu_document_get_type},
59 #endif          
60
61 #ifdef ENABLE_DVI
62         /* dvi: */
63         {"application/x-dvi",          dvi_document_get_type},
64 #endif
65 };
66
67 /* Would be nice to have this in gdk-pixbuf */
68 static gboolean
69 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
70 {
71         GSList *formats, *list;
72         gboolean retval = FALSE;
73
74         formats = gdk_pixbuf_get_formats ();
75
76         list = formats;
77         while (list) {
78                 GdkPixbufFormat *format = list->data;
79                 int i;
80                 gchar **mime_types;
81
82                 if (gdk_pixbuf_format_is_disabled (format))
83                         continue;
84
85                 mime_types = gdk_pixbuf_format_get_mime_types (format);
86
87                 for (i = 0; mime_types[i] != NULL; i++) {
88                         if (strcmp (mime_types[i], mime_type) == 0) {
89                                 retval = TRUE;
90                                 break;
91                         }
92                 }
93
94                 if (retval)
95                         break;
96
97                 list = list->next;
98         }
99
100         g_slist_free (formats);
101
102         return retval;
103 }
104
105 GType
106 ev_document_type_lookup (const char *mime_type)
107 {
108         int i;
109
110         g_return_val_if_fail (mime_type, G_TYPE_INVALID);
111
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();
116                 }
117         }
118
119         if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
120                 return pixbuf_document_get_type ();
121         }
122
123         return G_TYPE_INVALID;
124 }