[gnome-documents] documents: Add a generic load implementation to DocCommon
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] documents: Add a generic load implementation to DocCommon
- Date: Thu, 13 Apr 2017 06:38:05 +0000 (UTC)
commit 8fe668d10fff512fad1618dd8f29bfd1f254a814
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 6a7d123..9a67d57 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -407,8 +407,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() {
@@ -975,40 +1005,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) {
@@ -1226,40 +1222,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;
},
@@ -1392,40 +1354,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]