glib/demo/main.c | 9 +----- glib/poppler-document.cc | 47 ++++++++++++++++++++++++++++++++++++ glib/poppler-document.h | 4 +++ glib/reference/poppler-sections.txt | 1 4 files changed, 54 insertions(+), 7 deletions(-)
New commits: commit ff2c251dbaef9b964af48f51ebb517626ac3145c Author: Carlos Garcia Campos <[email protected]> Date: Sun May 13 20:13:32 2012 +0200 glib-demo: Use poppler_document_new_from_gfile to load the given uri diff --git a/glib/demo/main.c b/glib/demo/main.c index f52c5b8..d8ed142 100644 --- a/glib/demo/main.c +++ b/glib/demo/main.c @@ -293,7 +293,6 @@ gint main (gint argc, gchar **argv) GtkWidget *treeview; GtkTreeSelection *selection; GFile *file; - gchar *uri; GTimer *timer; GError *error = NULL; GtkAccelGroup *gtk_accel; @@ -313,10 +312,9 @@ gint main (gint argc, gchar **argv) gtk_init (&argc, &argv); file = g_file_new_for_commandline_arg (argv[1]); - uri = g_file_get_uri (file); timer = g_timer_new (); - document = poppler_document_new_from_file (uri, NULL, &error); + document = poppler_document_new_from_gfile (file, NULL, NULL, &error); g_timer_stop (timer); if (error) { while (g_error_matches (error, POPPLER_ERROR, POPPLER_ERROR_ENCRYPTED)) { @@ -327,7 +325,6 @@ gint main (gint argc, gchar **argv) if (gtk_dialog_run (dialog) != GTK_RESPONSE_OK) { g_print ("Error: no password provided\n"); g_object_unref (file); - g_free (uri); return 1; } @@ -336,7 +333,7 @@ gint main (gint argc, gchar **argv) password = g_object_get_data (G_OBJECT (dialog), "pgd-password"); g_timer_start (timer); - document = poppler_document_new_from_file (uri, password, &error); + document = poppler_document_new_from_gfile (file, password, NULL, &error); g_timer_stop (timer); gtk_widget_destroy (GTK_WIDGET (dialog)); @@ -346,14 +343,12 @@ gint main (gint argc, gchar **argv) g_print ("Error: %s\n", error->message); g_error_free (error); g_object_unref (file); - g_free (uri); return 1; } } g_object_unref (file); - g_free (uri); g_print ("Document successfully loaded in %.4f seconds\n", g_timer_elapsed (timer, NULL)); commit a7629331ab4ba5b256213af1f1b2954a49953c34 Author: Carlos Garcia Campos <[email protected]> Date: Sun May 13 20:13:03 2012 +0200 glib: Add poppler_document_new_from_gfile diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index cba440b..d404fcd 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -312,6 +312,52 @@ poppler_document_new_from_stream (GInputStream *stream, return _poppler_document_new_from_pdfdoc (newDoc, error); } +/** + * poppler_document_new_from_gfile: + * @file: a #GFile to load + * @password: (allow-none): password to unlock the file with, or %NULL + * @cancellable: (allow-none): a #GCancellable, or %NULL + * @error: (allow-none): Return location for an error, or %NULL + * + * Creates a new #PopplerDocument reading the PDF contents from @file. + * Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR + * domains. + * + * Returns: (transfer full): a new #PopplerDocument, or %NULL + * + * Since: 0.22 + */ +PopplerDocument * +poppler_document_new_from_gfile (GFile *file, + const char *password, + GCancellable *cancellable, + GError **error) +{ + PopplerDocument *document; + GFileInputStream *stream; + + g_return_val_if_fail(G_IS_FILE(file), NULL); + + if (g_file_is_native(file)) { + gchar *uri; + + uri = g_file_get_uri(file); + document = poppler_document_new_from_file(uri, password, error); + g_free(uri); + + return document; + } + + stream = g_file_read(file, cancellable, error); + if (!stream) + return NULL; + + document = poppler_document_new_from_stream(G_INPUT_STREAM(stream), -1, password, cancellable, error); + g_object_unref(stream); + + return document; +} + static gboolean handle_save_error (int err_code, GError **error) diff --git a/glib/poppler-document.h b/glib/poppler-document.h index 7ac6672..a34e88c 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -178,6 +178,10 @@ PopplerDocument *poppler_document_new_from_stream (GInputStream *str const char *password, GCancellable *cancellable, GError **error); +PopplerDocument *poppler_document_new_from_gfile (GFile *file, + const char *password, + GCancellable *cancellable, + GError **error); gboolean poppler_document_save (PopplerDocument *document, const char *uri, GError **error); diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 8573051..6efef6a 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -116,6 +116,7 @@ PopplerPermissions poppler_document_new_from_file poppler_document_new_from_data poppler_document_new_from_stream +poppler_document_new_from_gfile poppler_document_save poppler_document_save_a_copy poppler_document_get_id commit 95277b1f481e274ab0ce22ffb44b40437bffa3c8 Author: Carlos Garcia Campos <[email protected]> Date: Sun May 13 20:11:12 2012 +0200 glib Add missing cancellable param in poppler_document_new_from_stream doc diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index 98500b8..cba440b 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -259,6 +259,7 @@ stream_is_memory_buffer_or_local_file (GInputStream *stream) * @stream: a #GInputStream to read from * @length: the stream length, or -1 if not known * @password: (allow-none): password to unlock the file with, or %NULL + * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: (allow-none): Return location for an error, or %NULL * * Creates a new #PopplerDocument reading the PDF contents from @stream. _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
