[gnome-documents/gnome-3-24] 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-24] documents: Add a generic load implementation to DocCommon
- Date: Mon, 24 Apr 2017 12:43:34 +0000 (UTC)
commit 672748a04d9781a25e251c3a7d9f6196b4acb165
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 ff7f11b..328ff03 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -405,8 +405,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() {
@@ -964,40 +994,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) {
@@ -1206,40 +1202,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;
},
@@ -1372,40 +1334,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]