X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=backend%2Fev-document-factory.c;h=f524e1a0e0724f0f0e4a3be36527c3e812eea9d2;hb=d47bc2205d248b34dbfcdd349473f54d45d5ec70;hp=c7314ecffe28af832cc38305e10db6690117e3b0;hpb=67a923a1096f1e9765a5d804e4fb9fac39bcfcf2;p=evince.git diff --git a/backend/ev-document-factory.c b/backend/ev-document-factory.c index c7314ecf..f524e1a0 100644 --- a/backend/ev-document-factory.c +++ b/backend/ev-document-factory.c @@ -26,20 +26,28 @@ /* The various document type backends: */ #include "ev-poppler.h" -#include "pixbuf-document.h" -#include "tiff-document.h" + #ifdef ENABLE_PS #include "ps-document.h" #endif +#ifdef ENABLE_TIFF +#include "tiff-document.h" +#endif #ifdef ENABLE_DVI #include "dvi-document.h" #endif +#ifdef ENABLE_PIXBUF +#include "pixbuf-document.h" +#endif #ifdef ENABLE_DJVU #include "djvu-document.h" #endif #ifdef ENABLE_COMICS #include "comics-document.h" #endif +#ifdef ENABLE_IMPRESS +#include "impress-document.h" +#endif #include #include @@ -87,6 +95,13 @@ const EvDocumentType document_types[] = { {"application/x-cbr", EV_BACKEND_COMICS, comics_document_get_type}, {"application/x-cbz", EV_BACKEND_COMICS, comics_document_get_type}, #endif + +#ifdef ENABLE_IMPRESS + /* Impress slides: */ + {"application/vnd.sun.xml.impress", EV_BACKEND_IMPRESS, impress_document_get_type}, + {"application/vnd.oasis.opendocument.presentation", EV_BACKEND_IMPRESS, impress_document_get_type}, +#endif + }; #ifdef ENABLE_PIXBUF @@ -142,7 +157,7 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) } #endif -EvDocument* +static EvDocument* ev_document_factory_get_from_mime (const char *mime_type) { int i; @@ -230,7 +245,7 @@ ev_document_factory_get_all_mime_types (void) } static EvDocument * -get_document_from_uri (const char *uri, gboolean slow, gchar **mime_type, GError **error) +get_document_from_uri (const char *uri, gboolean slow, GError **error) { EvDocument *document = NULL; @@ -259,45 +274,77 @@ get_document_from_uri (const char *uri, gboolean slow, gchar **mime_type, GError gnome_vfs_file_info_unref (info); return NULL; } - + document = ev_document_factory_get_from_mime (info->mime_type); if (document == NULL) { g_set_error (error, EV_DOCUMENT_ERROR, 0, - _("Unhandled MIME type: '%s'"), info->mime_type); + _("Unhandled MIME type: “%s”"), info->mime_type); gnome_vfs_file_info_unref (info); return NULL; } - if (mime_type != NULL) { - *mime_type = g_strdup (info->mime_type); - } - gnome_vfs_file_info_unref (info); return document; } EvDocument * -ev_document_factory_get_document (const char *uri, gchar **mime_type, GError **error) +ev_document_factory_get_document (const char *uri, GError **error) { EvDocument *document; - - document = get_document_from_uri (uri, FALSE, mime_type, error); + int result; - if (document != NULL) { - return document; + document = get_document_from_uri (uri, FALSE, error); + + if (*error == NULL) { + result = ev_document_load (document, uri, error); + + if (result == FALSE || *error) { + if (*error && + (*error)->domain == EV_DOCUMENT_ERROR && + (*error)->code == EV_DOCUMENT_ERROR_ENCRYPTED) + return document; + } else { + return document; + } } - - if (error) { + + /* Try again with slow mime detection */ + if (document) + g_object_unref (document); + document = NULL; + + if (*error) g_error_free (*error); - *error = NULL; + *error = NULL; + + document = get_document_from_uri (uri, TRUE, error); + + if (*error != NULL) { + return NULL; } - document = get_document_from_uri (uri, TRUE, mime_type, error); + result = ev_document_load (document, uri, error); + + if (result == FALSE) { + if (*error == NULL) { + g_set_error (error, + EV_DOCUMENT_ERROR, + 0, + _("Unknown MIME Type")); + } else if ((*error)->domain == EV_DOCUMENT_ERROR && + (*error)->code == EV_DOCUMENT_ERROR_ENCRYPTED) { + return document; + } + if (document) + g_object_unref (document); + document = NULL; + } + return document; } @@ -391,6 +438,16 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document) } #endif +#ifdef ENABLE_IMPRESS + if (document == NULL || backend == EV_BACKEND_IMPRESS) { + default_filter = filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Impress Slides")); + mime_types = ev_document_factory_get_mime_types (EV_BACKEND_IMPRESS); + file_filter_add_mime_list_and_free (filter, mime_types); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + } +#endif + filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_add_pattern (filter, "*");