[evince] libdocument: Allow passing flags to load functions
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] libdocument: Allow passing flags to load functions
- Date: Sun, 26 Mar 2017 11:04:22 +0000 (UTC)
commit 0ff4254ce1721af7ad934613bb092ca22e182603
Author: Bastien Nocera <hadess hadess net>
Date: Mon Mar 20 18:27:42 2017 +0100
libdocument: Allow passing flags to load functions
https://bugzilla.gnome.org/show_bug.cgi?id=780210
libdocument/ev-document-factory.c | 33 +++++++++++++++++++++++++++---
libdocument/ev-document-factory.h | 3 ++
libdocument/ev-document.c | 39 ++++++++++++++++++++++++++++++++----
libdocument/ev-document.h | 4 +++
4 files changed, 70 insertions(+), 9 deletions(-)
---
diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c
index 766e118..aef1769 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -270,8 +270,9 @@ _ev_document_factory_shutdown (void)
}
/**
- * ev_document_factory_get_document:
+ * ev_document_factory_get_document_full:
* @uri: an URI
+ * @flags: flags from #EvDocumentLoadFlags
* @error: a #GError location to store an error, or %NULL
*
* Creates a #EvDocument for the document at @uri; or, if no backend handling
@@ -283,7 +284,9 @@ _ev_document_factory_shutdown (void)
* Returns: (transfer full): a new #EvDocument, or %NULL
*/
EvDocument *
-ev_document_factory_get_document (const char *uri, GError **error)
+ev_document_factory_get_document_full (const char *uri,
+ EvDocumentLoadFlags flags,
+ GError **error)
{
EvDocument *document;
int result;
@@ -310,7 +313,7 @@ ev_document_factory_get_document (const char *uri, GError **error)
return NULL;
}
- result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
+ result = ev_document_load_full (document, uri_unc ? uri_unc : uri, flags, &err);
if (result == FALSE || err) {
if (err &&
@@ -352,7 +355,8 @@ ev_document_factory_get_document (const char *uri, GError **error)
return NULL;
}
- result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
+ result = ev_document_load_full (document, uri_unc ? uri_unc : uri,
+ EV_DOCUMENT_LOAD_FLAG_NONE, &err);
if (result == FALSE) {
if (err == NULL) {
/* FIXME: this really should not happen; the backend should
@@ -377,6 +381,27 @@ ev_document_factory_get_document (const char *uri, GError **error)
}
/**
+ * 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: (transfer full): a new #EvDocument, or %NULL
+ */
+EvDocument *
+ev_document_factory_get_document (const char *uri, GError **error)
+{
+ return ev_document_factory_get_document_full (uri,
+ EV_DOCUMENT_LOAD_FLAG_NONE,
+ error);
+}
+
+/**
* ev_document_factory_get_document_for_gfile:
* @file: a #GFile
* @flags: flags from #EvDocumentLoadFlags
diff --git a/libdocument/ev-document-factory.h b/libdocument/ev-document-factory.h
index b0e6d23..1ccdb91 100644
--- a/libdocument/ev-document-factory.h
+++ b/libdocument/ev-document-factory.h
@@ -35,6 +35,9 @@ gboolean _ev_document_factory_init (void);
void _ev_document_factory_shutdown (void);
EvDocument* ev_document_factory_get_document (const char *uri, GError **error);
+EvDocument *ev_document_factory_get_document_full (const char *uri,
+ EvDocumentLoadFlags flags,
+ GError **error);
EvDocument* ev_document_factory_get_document_for_gfile (GFile *file,
EvDocumentLoadFlags flags,
GCancellable *cancellable,
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index de0e1fc..6af9a02 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -294,9 +294,10 @@ ev_document_initialize_synctex (EvDocument *document,
}
/**
- * ev_document_load:
+ * ev_document_load_full:
* @document: a #EvDocument
* @uri: the document's URI
+ * @flags: flags from #EvDocumentLoadFlags
* @error: a #GError location to store an error, or %NULL
*
* Loads @document from @uri.
@@ -311,9 +312,10 @@ ev_document_initialize_synctex (EvDocument *document,
* Returns: %TRUE on success, or %FALSE on failure.
*/
gboolean
-ev_document_load (EvDocument *document,
- const char *uri,
- GError **error)
+ev_document_load_full (EvDocument *document,
+ const char *uri,
+ EvDocumentLoadFlags flags,
+ GError **error)
{
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
gboolean retval;
@@ -336,7 +338,8 @@ ev_document_load (EvDocument *document,
} else {
document->priv->info = _ev_document_get_info (document);
document->priv->n_pages = _ev_document_get_n_pages (document);
- ev_document_setup_cache (document);
+ if (!(flags & EV_DOCUMENT_LOAD_FLAG_NO_CACHE))
+ ev_document_setup_cache (document);
document->priv->uri = g_strdup (uri);
document->priv->file_size = _ev_document_get_size (uri);
ev_document_initialize_synctex (document, uri);
@@ -346,6 +349,32 @@ ev_document_load (EvDocument *document,
}
/**
+ * ev_document_load:
+ * @document: a #EvDocument
+ * @uri: the document's URI
+ * @error: a #GError location to store an error, or %NULL
+ *
+ * Loads @document from @uri.
+ *
+ * On failure, %FALSE is returned and @error is filled in.
+ * If the document is encrypted, EV_DEFINE_ERROR_ENCRYPTED is returned.
+ * If the backend cannot load the specific document, EV_DOCUMENT_ERROR_INVALID
+ * is returned. Other errors are possible too, depending on the backend
+ * used to load the document and the URI, e.g. #GIOError, #GFileError, and
+ * #GConvertError.
+ *
+ * Returns: %TRUE on success, or %FALSE on failure.
+ */
+gboolean
+ev_document_load (EvDocument *document,
+ const char *uri,
+ GError **error)
+{
+ return ev_document_load_full (document, uri,
+ EV_DOCUMENT_LOAD_FLAG_NONE, error);
+}
+
+/**
* ev_document_load_stream:
* @document: a #EvDocument
* @stream: a #GInputStream
diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h
index 1b1a827..d1915f5 100644
--- a/libdocument/ev-document.h
+++ b/libdocument/ev-document.h
@@ -154,6 +154,10 @@ gboolean ev_document_get_backend_info (EvDocument *document,
gboolean ev_document_load (EvDocument *document,
const char *uri,
GError **error);
+gboolean ev_document_load_full (EvDocument *document,
+ const char *uri,
+ EvDocumentLoadFlags flags,
+ GError **error);
gboolean ev_document_load_stream (EvDocument *document,
GInputStream *stream,
EvDocumentLoadFlags flags,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]