[evince/wip/bug654832: 4/18] Revert "libdocument: Simplify ev_document_factory_get_document()"
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/bug654832: 4/18] Revert "libdocument: Simplify ev_document_factory_get_document()"
- Date: Wed, 9 May 2012 17:52:23 +0000 (UTC)
commit bd252cd277f6462acaedeeb3d60a8c68e4c9899d
Author: Christian Persch <chpe gnome org>
Date: Wed May 9 17:50:24 2012 +0200
Revert "libdocument: Simplify ev_document_factory_get_document()"
This reverts commit a082045890434e716c82a1580bc5f28112ef7d9c.
libdocument/ev-document-factory.c | 137 +++++++++++++++++++------------------
1 files changed, 71 insertions(+), 66 deletions(-)
---
diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c
index 3f679e8..1f1eb0d 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -135,11 +135,21 @@ free_uncompressed_uri (gchar *uri_unc)
g_free (uri_unc);
}
-/* Try to get and load the document from a file, dealing with errors
- * differently depending on whether we are using slow or fast mime detection.
+/**
+ * ev_document_factory_get_document:
+ * @uri: an URI
+ * @error: a #GError location to store an error, or %NULL
+ *
+ * Creates a #EvDocument for the document at @uri; or, if no backend handling
+ * the document's type is found, or an error occurred on opening the document,
+ * returns %NULL and fills in @error.
+ * If the document is encrypted, it is returned but also @error is set to
+ * %EV_DOCUMENT_ERROR_ENCRYPTED.
+ *
+ * Returns: a new #EvDocument, or %NULL.
*/
-static EvDocument *
-ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
+EvDocument *
+ev_document_factory_get_document (const char *uri, GError **error)
{
EvDocument *document;
int result;
@@ -147,20 +157,50 @@ ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
gchar *uri_unc = NULL;
GError *err = NULL;
- document = get_document_from_uri (uri, fast, &compression, &err);
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ document = get_document_from_uri (uri, TRUE, &compression, &err);
g_assert (document != NULL || err != NULL);
- if (document == NULL) {
- if (fast) {
- /* Try again with slow mime detection */
- g_clear_error (&err);
- } else {
- /* This should have worked, and is usually the second try,
- * so set an error for the caller. */
- g_assert (err != NULL);
+ if (document != NULL) {
+ uri_unc = ev_file_uncompress (uri, compression, &err);
+ if (uri_unc) {
+ g_object_set_data_full (G_OBJECT (document),
+ "uri-uncompressed",
+ uri_unc,
+ (GDestroyNotify) free_uncompressed_uri);
+ } else if (err != NULL) {
+ /* Error uncompressing file */
+ g_object_unref (document);
g_propagate_error (error, err);
+ return NULL;
}
-
+
+ result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
+
+ if (result == FALSE || err) {
+ if (err &&
+ g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
+ g_propagate_error (error, err);
+ return document;
+ }
+ /* else fall through to slow mime code section below */
+ } else {
+ return document;
+ }
+
+ g_object_unref (document);
+ document = NULL;
+ }
+
+ /* Try again with slow mime detection */
+ g_clear_error (&err);
+ uri_unc = NULL;
+
+ document = get_document_from_uri (uri, FALSE, &compression, &err);
+ if (document == NULL) {
+ g_assert (err != NULL);
+ g_propagate_error (error, err);
return NULL;
}
@@ -172,68 +212,33 @@ ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
(GDestroyNotify) free_uncompressed_uri);
} else if (err != NULL) {
/* Error uncompressing file */
- g_object_unref (document);
g_propagate_error (error, err);
+ g_object_unref (document);
return NULL;
}
-
+
result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
- if (result)
- return document;
-
- if (err) {
- if (g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
+ if (result == FALSE) {
+ if (err == NULL) {
+ /* FIXME: this really should not happen; the backend should
+ * always return a meaningful error.
+ */
+ g_set_error_literal (&err,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Unknown MIME Type"));
+ } else if (g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
g_propagate_error (error, err);
return document;
-
- /* else fall through to slow mime code detection. */
}
- } else if (!fast) {
- /* FIXME: this really should not happen; the backend should
- * always return a meaningful error.
- */
- g_set_error_literal (&err,
- EV_DOCUMENT_ERROR,
- EV_DOCUMENT_ERROR_INVALID,
- _("Unknown MIME Type"));
- g_propagate_error (error, err);
-
- /* else fall through to slow mime code detection. */
- }
-
- g_object_unref (document);
- return NULL;
-}
-
-/**
- * ev_document_factory_get_document:
- * @uri: an URI
- * @error: a #GError location to store an error, or %NULL
- *
- * Creates a #EvDocument for the document at @uri; or, if no backend handling
- * the document's type is found, or an error occurred on opening the document,
- * returns %NULL and fills in @error.
- * If the document is encrypted, it is returned but also @error is set to
- * %EV_DOCUMENT_ERROR_ENCRYPTED.
- *
- * Returns: a new #EvDocument, or %NULL.
- */
-EvDocument *
-ev_document_factory_get_document (const char *uri, GError **error)
-{
- EvDocument *document;
-
- g_return_val_if_fail (uri != NULL, NULL);
-
- document = ev_document_factory_load_uri (uri, TRUE, error);
- if (document)
- return document;
+ g_object_unref (document);
+ document = NULL;
- /* Try again with slow mime detection */
- g_clear_error (error); /* Though this should always be NULL here. */
- document = ev_document_factory_load_uri (uri, FALSE, error);
+ g_propagate_error (error, err);
+ }
+
return document;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]