[gnome-documents/gnome-3-22] documents: Add a generic load implementation to DocCommon
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/gnome-3-22] documents: Add a generic load implementation to DocCommon
- Date: Wed, 7 Jun 2017 14:45:32 +0000 (UTC)
commit fad4cd4779fb431ebb8166a48deae784be7dd0fa
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Apr 7 18:08:17 2017 +0200
documents: Add a generic load implementation to DocCommon
All the remote document types have the exact same load implementation.
Instead of keeping multiple copies of that code, it's better to share
it via the base class. In theory, we can use the same code for
LocalDocument too, but we already have a trivial implementation that
avoids some needless I/O so it's better to retain it.
https://bugzilla.gnome.org/show_bug.cgi?id=781032
src/documents.js | 136 +++++++++++++-----------------------------------------
1 files changed, 32 insertions(+), 104 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 8430161..7fd95b4 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -399,8 +399,38 @@ const DocCommon = new Lang.Class({
throw(new Error('DocCommon implementations must override downloadImpl'));
},
- load: function() {
- log('Error: DocCommon implementations must override load');
+ load: function(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() {
@@ -961,40 +991,6 @@ const GoogleDocument = new Lang.Class({
}))
},
- load: function(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);
- }));
- }));
- },
-
createThumbnail: function(callback) {
this.createGDataEntry(null, Lang.bind(this,
function(entry, service, exception) {
@@ -1205,40 +1201,6 @@ const OwncloudDocument = new Lang.Class({
}));
},
- load: function(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() {
return false;
},
@@ -1371,40 +1333,6 @@ const SkydriveDocument = new Lang.Class({
}));
},
- load: function(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);
- }));
- }));
- },
-
updateTypeDescription: function() {
let description;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]