[evince/wip/bug654832: 11/16] libdocument: Add API to load/save EvDocument from GFile



commit 709a21de2810e80fbd404eb780a053ba9d4f473f
Author: Christian Persch <chpe gnome org>
Date:   Sun May 13 19:29:43 2012 +0200

    libdocument: Add API to load/save EvDocument from GFile
    
    Part of bug #654832.

 .../libdocument/libevdocument-sections.txt         |    1 +
 libdocument/ev-document.c                          |   81 ++++++++++++++++++++
 libdocument/ev-document.h                          |   22 +++++-
 3 files changed, 103 insertions(+), 1 deletions(-)
---
diff --git a/help/reference/libdocument/libevdocument-sections.txt b/help/reference/libdocument/libevdocument-sections.txt
index a2457de..c04fc1a 100644
--- a/help/reference/libdocument/libevdocument-sections.txt
+++ b/help/reference/libdocument/libevdocument-sections.txt
@@ -344,6 +344,7 @@ ev_document_get_info
 ev_document_get_backend_info
 ev_document_load
 ev_document_load_stream_sync
+ev_document_load_gfile_sync
 ev_document_save
 ev_document_write_stream_sync
 ev_document_get_n_pages
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index 419b8cb..d393b3f 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -387,6 +387,49 @@ ev_document_load_stream_sync (EvDocument         *document,
 }
 
 /**
+ * ev_document_load_gfile_sync:
+ * @document: a #EvDocument
+ * @file: a #GFile
+ * @flags: flags from #EvDocumentLoadFlags
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @error: (allow-none): a #GError location to store an error, or %NULL
+ *
+ * Loads the document from @stream. See ev_document_load() for more information.
+ *
+ * Returns: %TRUE if loading succeeded, or %FALSE on error with @error filled in
+ *
+ * Since: 3.6
+ */
+gboolean
+ev_document_load_gfile_sync (EvDocument         *document,
+                             GFile              *file,
+                             EvDocumentLoadFlags flags,
+                             GCancellable       *cancellable,
+                             GError            **error)
+{
+        EvDocumentClass *klass;
+
+        g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE);
+        g_return_val_if_fail (G_IS_FILE (file), FALSE);
+        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+        klass = EV_DOCUMENT_GET_CLASS (document);
+        if (!klass->load_gfile_sync) {
+                g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                                     "Backend does not support loading from GFile");
+                return FALSE;
+        }
+
+        if (!klass->load_gfile_sync (document, file, flags, cancellable, error))
+                return FALSE;
+
+        ev_document_setup_cache (document);
+
+        return TRUE;
+}
+
+/**
  * ev_document_save:
  * @document:
  * @uri: the target URI
@@ -444,6 +487,44 @@ ev_document_write_stream_sync (EvDocument          *document,
         return klass->write_stream_sync (document, stream, flags, cancellable, error);
 }
 
+/**
+ * ev_document_write_gfile_sync:
+ * @document: a #EvDocument
+ * @gfile: a #GFile
+ * @flags: flags from #EvDocumentWriteFlags
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @error: (allow-none): a #GError location to store an error, or %NULL
+ *
+ * Writes the document to @gfile. See ev_document_save() for more information.
+ *
+ * Returns: %TRUE if saving succeeded, or %FALSE on error with @error filled in
+ *
+ * Since: 3.6
+ */
+gboolean
+ev_document_write_gfile_sync (EvDocument          *document,
+                              GFile               *file,
+                              EvDocumentWriteFlags flags,
+                              GCancellable        *cancellable,
+                              GError             **error)
+{
+        EvDocumentClass *klass;
+
+        g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE);
+        g_return_val_if_fail (G_IS_FILE (file), FALSE);
+        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+        klass = EV_DOCUMENT_GET_CLASS (document);
+        if (!klass->write_gfile_sync) {
+                g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                                     "Backend does not support saving to GFile");
+                return FALSE;
+        }
+
+        return klass->write_gfile_sync (document, file, flags, cancellable, error);
+}
+
 EvPage *
 ev_document_get_page (EvDocument *document,
 		      gint        index)
diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h
index 4abb7b6..0b2908d 100644
--- a/libdocument/ev-document.h
+++ b/libdocument/ev-document.h
@@ -119,17 +119,27 @@ struct _EvDocumentClass
                                                EvDocumentBackendInfo *info);
         gboolean	  (* support_synctex) (EvDocument      *document);
 
-        /* GIO streams */
+        /* GIO */
         gboolean          (* load_stream_sync)  (EvDocument          *document,
                                                  GInputStream        *stream,
                                                  EvDocumentLoadFlags  flags,
                                                  GCancellable        *cancellable,
                                                  GError             **error);
+        gboolean          (* load_gfile_sync)   (EvDocument          *document,
+                                                 GFile               *file,
+                                                 EvDocumentLoadFlags  flags,
+                                                 GCancellable        *cancellable,
+                                                 GError             **error);
         gboolean          (* write_stream_sync) (EvDocument          *document,
                                                  GOutputStream       *stream,
                                                  EvDocumentWriteFlags flags,
                                                  GCancellable        *cancellable,
                                                  GError             **error);
+        gboolean          (* write_gfile_sync)  (EvDocument          *document,
+                                                 GFile               *file,
+                                                 EvDocumentWriteFlags flags,
+                                                 GCancellable        *cancellable,
+                                                 GError             **error);
 };
 
 GType            ev_document_get_type             (void) G_GNUC_CONST;
@@ -158,6 +168,11 @@ gboolean         ev_document_load_stream_sync     (EvDocument         *document,
                                                    EvDocumentLoadFlags flags,
                                                    GCancellable       *cancellable,
                                                    GError            **error);
+gboolean         ev_document_load_gfile_sync      (EvDocument         *document,
+                                                   GFile              *file,
+                                                   EvDocumentLoadFlags flags,
+                                                   GCancellable       *cancellable,
+                                                   GError            **error);
 gboolean         ev_document_save                 (EvDocument      *document,
 						   const char      *uri,
 						   GError         **error);
@@ -166,6 +181,11 @@ gboolean         ev_document_write_stream_sync    (EvDocument          *document
                                                    EvDocumentWriteFlags flags,
                                                    GCancellable        *cancellable,
                                                    GError             **error);
+gboolean         ev_document_write_gfile_sync     (EvDocument          *document,
+                                                   GFile               *file,
+                                                   EvDocumentWriteFlags flags,
+                                                   GCancellable        *cancellable,
+                                                   GError             **error);
 gint             ev_document_get_n_pages          (EvDocument      *document);
 EvPage          *ev_document_get_page             (EvDocument      *document,
 						   gint             index);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]