[Pkg-mozext-commits] [gcontactsync] 01/10: Issue #80: Throttle photo downloads
David Prévot
taffit at moszumanska.debian.org
Fri Jun 19 16:29:43 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository gcontactsync.
commit 4a69fb85a9779df62660611c3a3584383fdf3d79
Author: Josh Geenen <joshgeenen at gmail.com>
Date: Sun Jun 7 20:56:40 2015 -0500
Issue #80: Throttle photo downloads
---
src/content/ContactConverter.js | 44 +--------------------
src/content/Sync.js | 66 +++++++++++++++++++++++++++++---
src/content/TBContact.js | 40 +++++++++++++++++--
src/locale/en-US/gcontactsync.properties | 1 +
4 files changed, 99 insertions(+), 52 deletions(-)
diff --git a/src/content/ContactConverter.js b/src/content/ContactConverter.js
index 7566ac9..b3a51e4 100644
--- a/src/content/ContactConverter.js
+++ b/src/content/ContactConverter.js
@@ -596,49 +596,7 @@ com.gContactSync.ContactConverter = {
*/
savePhotoFromGContact: function ContactConvert_savePhotoFromGContact(aTBContact, aGContact) {
- var info = aGContact.getPhotoInfo();
-
- // If the contact has a photo then save it to a local file and update
- // the related attributes
- // Thunderbird requires two copies of each photo. A permanent copy must
- // be kept outside of the Photos directory. Each time a contact is edited
- // Thunderbird will re-copy the original photo to the Photos directory and
- // delete the old copy.
-
- if (!info || !info.etag) {
-
- // If the contact doesn't have a photo then clear the related attributes
- aTBContact.setValue("PhotoName", "");
- aTBContact.setValue("PhotoType", "");
- aTBContact.setValue("PhotoURI", "");
- aTBContact.setValue("PhotoEtag", "");
-
- } else if (info.etag === aTBContact.getValue("PhotoEtag")) {
-
- com.gContactSync.LOGGER.VERBOSE_LOG(" * Photo is already up-to-date");
-
- } else {
-
- var file = aGContact.writePhoto(com.gContactSync.Sync.mCurrentAuthToken);
-
- if (!file) {
-
- com.gContactSync.LOGGER.LOG_WARNING("Failed to write contact photo");
-
- } else {
-
- com.gContactSync.LOGGER.VERBOSE_LOG("Wrote photo...name: " + file.leafName);
- com.gContactSync.copyPhotoToPhotosDir(file);
- aTBContact.setValue("PhotoName", file.leafName);
- aTBContact.setValue("PhotoType", "file");
- aTBContact.setValue("PhotoURI",
- Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .newFileURI(file)
- .spec);
- aTBContact.setValue("PhotoEtag", info.etag);
- }
- }
+ aTBContact.updatePhoto(aGContact.getPhotoInfo());
},
/**
* Check if the given string is null, of length 0, or consists only of spaces
diff --git a/src/content/Sync.js b/src/content/Sync.js
index 00f75a4..3e8b278 100644
--- a/src/content/Sync.js
+++ b/src/content/Sync.js
@@ -49,6 +49,8 @@ com.gContactSync.Sync = {
mContactsToAdd: [],
/** Contacts whose photos need to be written */
mContactsToUploadPhoto: [],
+ /** Contacts whose photos need to be downloaded */
+ mContactsToDownloadPhoto: [],
/** Contacts to update */
mContactsToUpdate: [],
/** Groups to delete */
@@ -446,6 +448,7 @@ com.gContactSync.Sync = {
}
com.gContactSync.Sync.mContactsToAdd = [];
com.gContactSync.Sync.mContactsToUploadPhoto = [];
+ com.gContactSync.Sync.mContactsToDownloadPhoto = [];
com.gContactSync.Sync.mContactsToDelete = [];
com.gContactSync.Sync.mContactsToUpdate = [];
var gContact,
@@ -540,9 +543,15 @@ com.gContactSync.Sync = {
} else if (event.data.mType === "newTBContact") {
var newCard = ab.newContact();
com.gContactSync.ContactConverter.makeCard(gContacts[event.data.mID], newCard);
+ if (newCard.mUpdatePhoto) {
+ this.mContactsToDownloadPhoto.push({abCard: newCard, gContact: gContacts[event.data.mID]});
+ }
} else if (event.data.mType === "updateTBCard") {
var tbContact = abCards[event.data.mTBCardIndex];
com.gContactSync.ContactConverter.makeCard(gContacts[tbContact.getID()], tbContact);
+ if (tbContact.mUpdatePhoto) {
+ this.mContactsToDownloadPhoto.push({abCard: tbContact, gContact: gContacts[tbContact.getID()]});
+ }
} else if (event.data.mType === "done") {
for (var i in event.data.mCurrentSummary) {
@@ -817,7 +826,7 @@ com.gContactSync.Sync = {
},
/**
* Uploads new and updated photos to Google.
- * Calls com.gContactSync.Sync.syncNextUser() when done.
+ * Calls com.gContactSync.Sync.processDownloadPhotoQueue() when done.
*/
processUpdatePhotoQueue: function Sync_processUpdatePhotoQueue() {
@@ -827,6 +836,31 @@ com.gContactSync.Sync = {
(com.gContactSync.Sync.mContactsToUploadPhoto.length === 0) ||
(ab.mPrefs.readOnly === "true")) {
+ com.gContactSync.LOGGER.LOG("***Download contact photos from Google***");
+ com.gContactSync.Sync.processDownloadPhotoQueue();
+ return;
+ }
+
+ com.gContactSync.Overlay.setStatusBarText(com.gContactSync.StringBundle.getStr("uploadingPhotos") + " " +
+ com.gContactSync.Sync.mContactsToUploadPhoto.length + " " +
+ com.gContactSync.StringBundle.getStr("remaining"));
+ var obj = com.gContactSync.Sync.mContactsToUploadPhoto.shift();
+ com.gContactSync.LOGGER.LOG("\n" + obj.abCard.getName());
+ obj.gContact.uploadPhoto(obj.uri);
+ com.gContactSync.Sync.delayedProcessQueue(com.gContactSync.Sync.processUpdatePhotoQueue);
+ },
+ /**
+ * Downloads new photos from Google.
+ * Calls com.gContactSync.Sync.syncNextUser() when done.
+ */
+ processDownloadPhotoQueue: function Sync_processDownloadPhotoQueue() {
+
+ var ab = com.gContactSync.Sync.mCurrentAb;
+
+ if (!com.gContactSync.Sync.mContactsToDownloadPhoto ||
+ (com.gContactSync.Sync.mContactsToDownloadPhoto.length === 0) ||
+ (ab.mPrefs.readOnly === "true")) {
+
if (com.gContactSync.Sync.mAddressBooks[com.gContactSync.Sync.mIndex]) {
var delay = com.gContactSync.Preferences.mSyncPrefs.accountDelay.value;
com.gContactSync.LOGGER.LOG("**About to wait " + delay +
@@ -839,13 +873,33 @@ com.gContactSync.Sync = {
return;
}
- com.gContactSync.Overlay.setStatusBarText(com.gContactSync.StringBundle.getStr("uploadingPhotos") + " " +
- com.gContactSync.Sync.mContactsToAdd.length + " " +
+ com.gContactSync.Overlay.setStatusBarText(com.gContactSync.StringBundle.getStr("downloadingPhotos") + " " +
+ com.gContactSync.Sync.mContactsToDownloadPhoto.length + " " +
com.gContactSync.StringBundle.getStr("remaining"));
- var obj = com.gContactSync.Sync.mContactsToUploadPhoto.shift();
+
+ var obj = com.gContactSync.Sync.mContactsToDownloadPhoto.shift();
com.gContactSync.LOGGER.LOG("\n" + obj.abCard.getName());
- obj.gContact.uploadPhoto(obj.uri);
- com.gContactSync.Sync.delayedProcessQueue(com.gContactSync.Sync.processUpdatePhotoQueue);
+ var file = obj.gContact.writePhoto(com.gContactSync.Sync.mCurrentAuthToken);
+
+ if (!file) {
+
+ com.gContactSync.LOGGER.LOG_WARNING("Failed to write contact photo");
+
+ } else {
+
+ com.gContactSync.LOGGER.VERBOSE_LOG("Wrote photo...name: " + file.leafName);
+ com.gContactSync.copyPhotoToPhotosDir(file);
+ obj.abCard.setValue("PhotoName", file.leafName);
+ obj.abCard.setValue("PhotoType", "file");
+ obj.abCard.setValue("PhotoURI",
+ Components.classes["@mozilla.org/network/io-service;1"]
+ .getService(Components.interfaces.nsIIOService)
+ .newFileURI(file)
+ .spec);
+ obj.abCard.update();
+ }
+
+ com.gContactSync.Sync.delayedProcessQueue(com.gContactSync.Sync.processDownloadPhotoQueue);
},
/**
* Syncs all contact groups with mailing lists.
diff --git a/src/content/TBContact.js b/src/content/TBContact.js
index d82d3db..3fa9e9f 100644
--- a/src/content/TBContact.js
+++ b/src/content/TBContact.js
@@ -15,7 +15,7 @@
*
* The Initial Developer of the Original Code is
* Josh Geenen <gcontactsync at pirules.org>.
- * Portions created by the Initial Developer are Copyright (C) 2009-2014
+ * Portions created by the Initial Developer are Copyright (C) 2009-2015
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
@@ -34,9 +34,9 @@
*
* ***** END LICENSE BLOCK ***** */
-if (!com) var com = {}; // A generic wrapper variable
+if (!com) {var com = {};} // A generic wrapper variable
// A wrapper for all GCS functions and variables
-if (!com.gContactSync) com.gContactSync = {};
+if (!com.gContactSync) {com.gContactSync = {};}
/**
* Makes a new TBContact object that has functions to get and set various values
@@ -61,6 +61,7 @@ com.gContactSync.TBContact = function gCS_TBContact(aCard, aDirectory) {
this.mAddressBook = aDirectory;
this.mContact = aCard;
this.mPostbox = this.mContact.setAdditionalEmailAddresses;
+ this.mUpdatePhoto = false;
};
com.gContactSync.TBContact.prototype = {
@@ -191,5 +192,38 @@ com.gContactSync.TBContact.prototype = {
if (primaryEmail)
return primaryEmail;
return this.getID();
+ },
+ /**
+ * Updates the photo for this contact from the given photo info.
+ *
+ * @param aInfo {Object} Photo information.
+ */
+ updatePhoto: function TBContact_updatePhoto(aInfo) {
+
+ // If the contact has a photo then save it to a local file and update
+ // the related attributes
+ // Thunderbird requires two copies of each photo. A permanent copy must
+ // be kept outside of the Photos directory. Each time a contact is edited
+ // Thunderbird will re-copy the original photo to the Photos directory and
+ // delete the old copy.
+
+ if (!aInfo || !aInfo.etag) {
+
+ // If the contact doesn't have a photo then clear the related attributes
+ this.setValue("PhotoName", "");
+ this.setValue("PhotoType", "");
+ this.setValue("PhotoURI", "");
+ this.setValue("PhotoEtag", "");
+
+ } else if (aInfo.etag === this.getValue("PhotoEtag")) {
+
+ com.gContactSync.LOGGER.VERBOSE_LOG(" * Photo is already up-to-date");
+
+ } else {
+
+ com.gContactSync.LOGGER.VERBOSE_LOG(" * Photo will be downloaded");
+ this.setValue("PhotoEtag", aInfo.etag);
+ this.mUpdatePhoto = true;
+ }
}
};
diff --git a/src/locale/en-US/gcontactsync.properties b/src/locale/en-US/gcontactsync.properties
index df02d59..c7cc742 100644
--- a/src/locale/en-US/gcontactsync.properties
+++ b/src/locale/en-US/gcontactsync.properties
@@ -21,6 +21,7 @@ deleting=Deleting contacts from Google:
updating=Updating contacts from Google:
adding=Adding contacts to Google:
uploadingPhotos=Uploading photos to Google:
+downloadingPhotos=Downloading photos from Google:
remaining=remaining.
pleaseAuth=Please login before trying to sync contacts.
offlineStatusText=Unable to sync contacts while offline.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/gcontactsync.git
More information about the Pkg-mozext-commits
mailing list