]> www.fi.muni.cz Git - evince.git/blobdiff - backend/ev-document-factory.c
Fix for the bug 166566 - don't show menubar in fullscreen mode.
[evince.git] / backend / ev-document-factory.c
index 251ede3fc2af00e666007f569af12f36f0443fda..e15f7213750c6831e94fa9cb2847a2f135dfd491 100644 (file)
 #include "ev-poppler.h"
 #include "pixbuf-document.h"
 #include "tiff-document.h"
+#ifdef ENABLE_PS
 #include "ps-document.h"
+#endif
 #ifdef ENABLE_DVI
 #include "dvi-document.h"
 #endif
 #ifdef ENABLE_DJVU
 #include "djvu-document.h"
 #endif
+#ifdef ENABLE_COMICS
+#include "comics-document.h"
+#endif
 
 #include <string.h>
 
@@ -50,10 +55,12 @@ const EvDocumentType document_types[] = {
        /* PDF: */
        {"application/pdf",            EV_BACKEND_PDF,  pdf_document_get_type},
 
+#ifdef ENABLE_PS
        /* 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},
+#endif
 
 #ifdef ENABLE_TIFF
        /* Tiff: */
@@ -69,19 +76,26 @@ const EvDocumentType document_types[] = {
        /* dvi: */
        {"application/x-dvi",          EV_BACKEND_DVI,  dvi_document_get_type},
 #endif
+
+#ifdef ENABLE_COMICS
+       /* cbr/cbz: */
+       {"application/x-cbr",           EV_BACKEND_COMICS,  comics_document_get_type},
+       {"application/x-cbz",           EV_BACKEND_COMICS,  comics_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)
+#ifdef ENABLE_PIXBUF
+
+static GList*
+gdk_pixbuf_mime_type_list ()
 {
        GSList *formats, *list;
-       gboolean retval = FALSE;
+       GList *result;
 
        formats = gdk_pixbuf_get_formats ();
+       result = NULL;
 
-       list = formats;
-       while (list) {
+       for (list = formats; list != NULL; list = list->next) {
                GdkPixbufFormat *format = list->data;
                int i;
                gchar **mime_types;
@@ -92,23 +106,36 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
                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;
-                       }
+                       result = g_list_append (result, mime_types[i]);
                }
+       }
+       g_slist_free (formats);
 
-               if (retval)
-                       break;
+       return result;
+}
 
-               list = list->next;
+/* Would be nice to have this in gdk-pixbuf */
+static gboolean
+mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
+{
+       GList *mime_types;
+       GList *list;
+       gboolean retval = FALSE;
+       
+       mime_types = gdk_pixbuf_mime_type_list ();
+       for (list = mime_types; list; list = list->next) {
+               if (strcmp ((char *)list->data, mime_type) == 0) {
+                       retval = TRUE;
+                       break;
+               }
        }
-
-       g_slist_free (formats);
+       
+       g_list_foreach (mime_types, (GFunc)g_free, NULL);
+       g_list_free (mime_types);
 
        return retval;
 }
-
+#endif
 
 static GType
 ev_document_type_get_from_mime (const char *mime_type)
@@ -123,10 +150,11 @@ ev_document_type_get_from_mime (const char *mime_type)
                        return document_types[i].document_type_factory_callback();
                }
        }
-
+#ifdef ENABLE_PIXBUF
        if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
                return pixbuf_document_get_type ();
        }
+#endif
 
        return G_TYPE_INVALID;
 }
@@ -138,7 +166,7 @@ ev_document_factory_get_document (const char *mime_type)
        
        type = ev_document_type_get_from_mime (mime_type);
 
-       if (type != G_TYPE_NONE) {
+       if (type != G_TYPE_INVALID) {
                return g_object_new (type, NULL);
        }
                
@@ -157,6 +185,10 @@ ev_document_factory_get_backend (EvDocument *document)
                }
        }
 
+#ifdef ENABLE_PIXBUF
+       if (G_TYPE_FROM_INSTANCE (document) == pixbuf_document_get_type ())
+               return EV_BACKEND_PIXBUF;
+#endif
        g_assert_not_reached ();
        
        return 0;
@@ -168,6 +200,12 @@ ev_document_factory_get_mime_types (EvBackend backend)
        GList *types = NULL;
        int i;
        
+#ifdef ENABLE_PIXBUF
+       if (backend == EV_BACKEND_PIXBUF) {
+               return gdk_pixbuf_mime_type_list ();
+       }
+#endif
+       
        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));
@@ -186,6 +224,10 @@ ev_document_factory_get_all_mime_types (void)
        for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
                types = g_list_append (types, g_strdup (document_types[i].mime_type));
        }
+       
+#ifdef ENABLE_PIXBUF
+       types = g_list_concat (types, gdk_pixbuf_mime_type_list ());
+#endif
 
        return types;
 }