[gnome-documents/wip/rishi/onedrive: 5/8] documents: Let everybody provide their own download implementation
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/rishi/onedrive: 5/8] documents: Let everybody provide their own download implementation
- Date: Fri, 31 Mar 2017 15:37:56 +0000 (UTC)
commit de67ade3bbd4df7326b8a901566a6c5aa90a3cad
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Mar 30 18:18:16 2017 +0200
documents: Let everybody provide their own download implementation
This is meant to reduce our reliance on GdPdfLoader for loading remote
documents. We can open ODFs and OOXMLs in LOKDocView, so we don't need
to convert everything to PDFs. In the future, remote sub-classes will
provider their own implementation to download a document, and this will
help unify the loading across the various sub-classes.
https://bugzilla.gnome.org/show_bug.cgi?id=774937
src/documents.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 7359dcf..9244506 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -365,6 +365,70 @@ const DocCommon = new Lang.Class({
}
},
+ download: function(useCache, cancellable, callback) {
+ let localFile = Gio.File.new_for_uri(this.uriToLoad);
+ let localPath = localFile.get_path();
+ let localDir = GLib.path_get_dirname(localPath);
+ GLib.mkdir_with_parents(localDir, 448);
+
+ if (!useCache) {
+ this.downloadImpl(localFile, cancellable, callback);
+ return;
+ }
+
+ localFile.query_info_async(Gio.FILE_ATTRIBUTE_TIME_MODIFIED,
+ Gio.FileQueryInfoFlags.NONE,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ let info;
+
+ try {
+ info = object.query_info_finish(res);
+ } catch (e) {
+ this.downloadImpl(localFile, cancellable, callback);
+ return;
+ }
+
+ let cacheMtime = info.get_attribute_uint64(Gio.FILE_ATTRIBUTE_TIME_MODIFIED);
+ cacheMtime /= 1000000;
+
+ if (this.mtime == cacheMtime) {
+ callback(true, null);
+ return;
+ }
+
+ this.downloadImpl(localFile, cancellable, callback);
+ }));
+ },
+
+ downloadImpl: function(localFile, cancellable, callback) {
+ throw(new Error('DocCommon implementations must override downloadImpl'));
+ },
+
+ setCacheAttributes: function(localFile, cancellable, callback) {
+ let info = new Gio.FileInfo();
+ let cacheMtime = this.mtime * 1000000;
+ info.set_attribute_uint64(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, cacheMtime);
+ localFile.set_attributes_async(info,
+ Gio.FileQueryInfoFlags.NONE,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ try {
+ object.set_attributes_finish(res);
+ } catch (e) {
+ logError(e,
+ 'Cannot set mtime on the cache file; cache will not be valid after the file has
' +
+ 'been viewed.');
+ }
+
+ callback();
+ }));
+ },
+
load: function() {
log('Error: DocCommon implementations must override load');
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]