[gnome-documents/gnome-3-22] documents, pdf-loader: Reduce the reliance on GdPdfLoader for ownCloud
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/gnome-3-22] documents, pdf-loader: Reduce the reliance on GdPdfLoader for ownCloud
- Date: Wed, 7 Jun 2017 14:45:17 +0000 (UTC)
commit 80138570ae12a3a4e4008427cc995caebf522bc7
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Apr 7 13:21:27 2017 +0200
documents, pdf-loader: Reduce the reliance on GdPdfLoader for ownCloud
As a positive side-effect this restores the caching for ODFs and
OOXMLs from ownCloud.
https://bugzilla.gnome.org/show_bug.cgi?id=781032
src/documents.js | 93 +++++++++++++++++++++++++++-
src/lib/gd-pdf-loader.c | 157 +----------------------------------------------
2 files changed, 94 insertions(+), 156 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 1c9fd6b..8430161 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1124,7 +1124,17 @@ const OwncloudDocument = new Lang.Class({
populateFromCursor: function(cursor) {
this.parent(cursor);
- this.uriToLoad = this.uri;
+
+ let localDir = GLib.build_filenamev([GLib.get_user_cache_dir(), "gnome-documents", "owncloud"]);
+
+ let identifierHash = this.identifier.substring(OWNCLOUD_PREFIX.length);
+ let filenameStripped = GdPrivate.filename_strip_extension(this.filename);
+ let extension = this.filename.substring(filenameStripped.length);
+ let localFilename = identifierHash + extension;
+
+ let localPath = GLib.build_filenamev([localDir, localFilename]);
+ let localFile = Gio.File.new_for_path(localPath);
+ this.uriToLoad = localFile.get_uri();
},
createThumbnail: function(callback) {
@@ -1146,8 +1156,87 @@ const OwncloudDocument = new Lang.Class({
this.typeDescription = description;
},
+ downloadImpl: function(localFile, cancellable, callback) {
+ let remoteFile = Gio.File.new_for_uri(this.uri);
+ remoteFile.read_async(GLib.PRIORITY_DEFAULT, cancellable, Lang.bind(this,
+ function(object, res) {
+ let inputStream;
+
+ try {
+ inputStream = object.read_finish(res);
+ } catch (e) {
+ callback(false, e);
+ return;
+ }
+
+ localFile.replace_async(null,
+ false,
+ Gio.FileCreateFlags.PRIVATE,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ let outputStream;
+
+ try {
+ outputStream = object.replace_finish(res);
+ } catch (e) {
+ callback(false, e);
+ return;
+ }
+
+ outputStream.splice_async(inputStream,
+ Gio.OutputStreamSpliceFlags.CLOSE_SOURCE |
+ Gio.OutputStreamSpliceFlags.CLOSE_TARGET,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ try {
+ object.splice_finish(res);
+ } catch (e) {
+ callback(false, e);
+ return;
+ }
+
+ callback(false, null);
+ }));
+ }));
+ }));
+ },
+
load: function(passwd, cancellable, callback) {
- this.loadLocal(passwd, cancellable, callback);
+ this.download(true, cancellable, Lang.bind(this,
+ function(fromCache, error) {
+ if (error) {
+ callback(this, null, error);
+ return;
+ }
+
+ this.loadLocal(passwd, cancellable, Lang.bind(this,
+ function(doc, docModel, error) {
+ if (error) {
+ if (fromCache &&
+ !error.matches(EvDocument.DocumentError,
EvDocument.DocumentError.ENCRYPTED)) {
+ this.download(false, cancellable, Lang.bind(this,
+ function(fromCache, error) {
+ if (error) {
+ callback(this, null, error);
+ return;
+ }
+
+ this.loadLocal(passwd, cancellable, callback);
+ }));
+ } else {
+ callback(this, null, error);
+ }
+
+ return;
+ }
+
+ callback(this, docModel, null);
+ }));
+ }));
},
canEdit: function() {
diff --git a/src/lib/gd-pdf-loader.c b/src/lib/gd-pdf-loader.c
index dbde195..3e7752a 100644
--- a/src/lib/gd-pdf-loader.c
+++ b/src/lib/gd-pdf-loader.c
@@ -721,167 +721,16 @@ pdf_load_job_from_regular_file (PdfLoadJob *job)
}
static void
-remote_file_copy_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- PdfLoadJob *job = user_data;
- GError *error = NULL;
- char *uri;
-
- g_file_copy_finish (G_FILE (source), res, &error);
- if (error != NULL) {
- pdf_load_job_complete_error (job, error);
- return;
- }
-
- pdf_load_job_cache_set_attributes (job);
-}
-
-static void
-pdf_load_job_remote_refresh_cache (PdfLoadJob *job)
-{
- GFile *remote_file;
-
- remote_file = g_file_new_for_uri (job->uri);
- g_file_copy_async (remote_file,
- job->download_file,
- G_FILE_COPY_OVERWRITE,
- G_PRIORITY_DEFAULT,
- job->cancellable,
- NULL,
- NULL,
- remote_file_copy_cb,
- job);
-
- g_object_unref (remote_file);
-}
-
-static void
-remote_cache_query_info_ready_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- PdfLoadJob *job = user_data;
- GError *error = NULL;
- GFileInfo *info;
-
- info = g_file_query_info_finish (G_FILE (source), res, &error);
-
- if (error != NULL) {
- /* create/invalidate cache */
- pdf_load_job_remote_refresh_cache (job);
- g_error_free (error);
-
- return;
- }
-
- job->pdf_cache_mtime =
- g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- g_object_unref (info);
-
- if (job->original_file_mtime != job->pdf_cache_mtime) {
- pdf_load_job_remote_refresh_cache (job);
- } else {
- job->from_old_cache = TRUE;
-
- /* load the cached file */
- pdf_load_job_from_pdf (job);
- }
-}
-
-static void
-remote_query_info_ready_cb (GObject *obj,
- GAsyncResult *res,
- gpointer user_data)
-{
- PdfLoadJob *job = user_data;
- GError *error = NULL;
- GFile *pdf_file;
- GFileInfo *info;
- const gchar *content_type;
- gchar *tmp_name;
- gchar *tmp_path;
-
- info = g_file_query_info_finish (G_FILE (obj),
- res, &error);
-
- if (error != NULL) {
- pdf_load_job_complete_error (job, error);
- return;
- }
-
- job->original_file_mtime =
- g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-
- tmp_name = g_strdup_printf ("gnome-documents-%u.pdf", g_str_hash (job->uri));
- tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL);
- job->pdf_path =
- g_build_filename (tmp_path, tmp_name, NULL);
- g_mkdir_with_parents (tmp_path, 0700);
-
- content_type = g_file_info_get_content_type (info);
-
- if (!content_type_is_native (content_type)) {
- GFileIOStream *iostream;
-
- job->download_file = g_file_new_tmp (NULL, &iostream, &error);
- if (error != NULL) {
- pdf_load_job_complete_error (job, error);
- return;
- }
-
- /* We don't need the iostream. */
- g_io_stream_close (G_IO_STREAM (iostream), NULL, NULL);
- } else {
- job->download_file = g_file_new_for_path (job->pdf_path);
- }
-
- pdf_file = g_file_new_for_path (job->pdf_path);
-
- g_file_query_info_async (pdf_file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- job->cancellable,
- remote_cache_query_info_ready_cb,
- job);
-
- g_free (tmp_name);
- g_free (tmp_path);
- g_object_unref (pdf_file);
- g_object_unref (info);
-}
-
-static void
-pdf_load_job_from_remote_file (PdfLoadJob *job)
-{
- GFile *remote_file;
-
- remote_file = g_file_new_for_uri (job->uri);
- g_file_query_info_async (remote_file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- job->cancellable,
- remote_query_info_ready_cb,
- job);
-
- g_object_unref (remote_file);
-}
-
-static void
pdf_load_job_from_uri (PdfLoadJob *job)
{
GFile *file;
file = g_file_new_for_uri (job->uri);
+
if (!g_file_is_native (file))
- pdf_load_job_from_remote_file (job);
- else
- pdf_load_job_from_regular_file (job);
+ g_assert_not_reached ();
+ pdf_load_job_from_regular_file (job);
g_object_unref (file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]