[Pkg-mozext-commits] [gcontactsync] 48/88: Issue #27: Added support for synchronizing anniversaries.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 18 20:52:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository gcontactsync.
commit ca1059f3d523c54e5352c3125ff69df651dbc7af
Author: Josh Geenen <joshgeenen at gmail.com>
Date: Mon May 26 15:33:31 2014 -0500
Issue #27: Added support for synchronizing anniversaries.
---
src/content/ContactConverter.js | 41 ++++++++++++++++++++++++++++++--
src/content/GContact.js | 17 +++++++++++++
src/content/gdata.js | 6 ++++-
src/defaults/preferences/gContactSync.js | 20 ++++++++--------
4 files changed, 71 insertions(+), 13 deletions(-)
diff --git a/src/content/ContactConverter.js b/src/content/ContactConverter.js
index 01fe791..4278cfd 100644
--- a/src/content/ContactConverter.js
+++ b/src/content/ContactConverter.js
@@ -261,6 +261,25 @@ com.gContactSync.ContactConverter = {
com.gContactSync.LOGGER.VERBOSE_LOG(" * Birthday: " + birthdayVal);
aGContact.setValue("birthday", 0, null, birthdayVal);
+ var anniversaryDay = parseInt(aTBContact.getValue("AnniversaryDay"), 10);
+ var anniversaryMonth = (isNaN(anniversaryDay) || anniversaryDay > 31) ?
+ null :
+ parseInt(aTBContact.getValue("AnniversaryMonth"), 10);
+ var anniversaryYear = (isNaN(anniversaryMonth) || anniversaryMonth > 13) ?
+ null :
+ parseInt(aTBContact.getValue("AnniversaryYear"), 10);
+ anniversaryDay = String(anniversaryDay);
+ anniversaryMonth = String(anniversaryMonth);
+ while (anniversaryDay.length < 2) {
+ anniversaryDay = "0" + anniversaryDay;
+ }
+ while (anniversaryMonth.length < 2) {
+ anniversaryMonth = "0" + anniversaryMonth;
+ }
+ var anniversaryVal = anniversaryYear ? anniversaryYear + "-" + anniversaryMonth + "-" + anniversaryDay : null;
+ com.gContactSync.LOGGER.VERBOSE_LOG(" * Anniversary: " + anniversaryVal);
+ aGContact.setValue("event", 0, "anniversary", anniversaryVal);
+
// set the extended properties
aGContact.removeExtendedProperties();
arr = com.gContactSync.Preferences.mExtendedProperties;
@@ -272,7 +291,7 @@ com.gContactSync.ContactConverter = {
value = this.checkValue(aTBContact.getValue(arr[i]));
aGContact.setExtendedProperty(arr[i], value);
}
- else {
+ else if (arr[i] != "") {
com.gContactSync.LOGGER.LOG_WARNING("Found a duplicate extended property: " +
arr[i]);
}
@@ -392,7 +411,7 @@ com.gContactSync.ContactConverter = {
}
// Get the birthday info
- var bday = aGContact.getValue("birthday", 0, com.gContactSync.gdata.contacts.types.UNTYPED),
+ var bday = aGContact.getValue("birthday", 0),
year = null,
month = null,
day = null;
@@ -420,6 +439,24 @@ com.gContactSync.ContactConverter = {
aTBContact.setValue("BirthMonth", month);
aTBContact.setValue("BirthDay", day);
+ // Anniversary
+ var anniversary = aGContact.getValue("event", 0, "anniversary");
+ var anniversaryYear = null, anniversaryMonth = null, anniversaryDay = null;
+ if (anniversary && anniversary.value) {
+ com.gContactSync.LOGGER.VERBOSE_LOG(" * Found an anniversary value of " + anniversary.value);
+ var anniversaryArray = anniversary.value.split("-");
+ if (anniversaryArray.length === 3) {
+ anniversaryYear = anniversaryArray[0];
+ anniversaryMonth = anniversaryArray[1];
+ anniversaryDay = anniversaryArray[2];
+ } else {
+ com.gContactSync.LOGGER.LOG_WARNING("Invalid anniversary value", anniversary.value);
+ }
+ }
+ aTBContact.setValue("AnniversaryYear", anniversaryYear);
+ aTBContact.setValue("AnniversaryMonth", anniversaryMonth);
+ aTBContact.setValue("AnniversaryDay", anniversaryDay);
+
if (com.gContactSync.Preferences.mSyncPrefs.getPhotos.value) {
var info = aGContact.getPhotoInfo();
// If the contact has a photo then save it to a local file and update
diff --git a/src/content/GContact.js b/src/content/GContact.js
index 8b0afeb..6521c87 100644
--- a/src/content/GContact.js
+++ b/src/content/GContact.js
@@ -190,6 +190,11 @@ com.gContactSync.GContact.prototype = {
if (arr[i].childNodes[0])
return new com.gContactSync.Property(arr[i].childNodes[0].nodeValue);
return null;
+ case com.gContactSync.gdata.contacts.types.EVENT:
+ if (arr[i].childNodes[0]) {
+ return new com.gContactSync.Property(arr[i].childNodes[0].getAttribute("startTime"));
+ }
+ return null;
default:
com.gContactSync.LOGGER.LOG_WARNING("Error - invalid contact type passed to the " +
"getElementValue method." +
@@ -473,6 +478,18 @@ com.gContactSync.GContact.prototype = {
this.xml.appendChild(elem);
}
break;
+ case com.gContactSync.gdata.contacts.types.EVENT:
+ var eventElem = this.mCurrentElement;
+ if (!eventElem) {
+ eventElem = document.createElementNS(com.gContactSync.gdata.namespaces.GCONTACT.url, "event");
+ eventElem.setAttribute("rel", aType);
+ parentElem.appendChild(document.createElementNS(com.gContactSync.gdata.namespaces.GD.url, "when"));
+ }
+ // TODO - support xs:dateTime
+ // TODO - support endTime attribute
+ eventElem.firstChild.setAttribute("startTime", aValue);
+ if (!this.mCurrentElement) { this.xml.appendChild(eventElem.parentNode); }
+ break;
default:
com.gContactSync.LOGGER.LOG_WARNING("Invalid aType parameter sent to the setElementValue"
+ "method" + com.gContactSync.StringBundle.getStr("pleaseReport"));
diff --git a/src/content/gdata.js b/src/content/gdata.js
index 07c9b84..e7d2f1b 100644
--- a/src/content/gdata.js
+++ b/src/content/gdata.js
@@ -170,7 +170,9 @@ com.gContactSync.gdata = {
TYPED_WITH_ATTR: 1,
UNTYPED: 2,
/** The type is stored in the element's parent */
- PARENT_TYPED: 3
+ PARENT_TYPED: 3,
+ /** gContact:event */
+ EVENT: 4
},
/** The prefix for rel attributes */
rel: "http://schemas.google.com/g/2005",
@@ -185,6 +187,7 @@ com.gContactSync.gdata = {
typedWithChild = this.types.TYPED_WITH_CHILD,
typedWithAttr = this.types.TYPED_WITH_ATTR,
parentTyped = this.types.PARENT_TYPED,
+ eventType = this.types.EVENT,
gd = com.gContactSync.gdata.namespaces.GD,
atom = com.gContactSync.gdata.namespaces.ATOM,
gcontact = com.gContactSync.gdata.namespaces.GCONTACT;
@@ -230,6 +233,7 @@ com.gContactSync.gdata = {
this.region = new GElement(parentTyped, "region", gd);
this.postcode = new GElement(parentTyped, "postcode", gd);
this.country = new GElement(parentTyped, "country", gd);
+ this.event = new GElement(eventType, "event", gcontact);
},
/**
* Updates the given element's type by setting the rel or label attribute
diff --git a/src/defaults/preferences/gContactSync.js b/src/defaults/preferences/gContactSync.js
index f07364c..3496fe5 100644
--- a/src/defaults/preferences/gContactSync.js
+++ b/src/defaults/preferences/gContactSync.js
@@ -93,16 +93,16 @@ pref("extensions.gContactSync.httpRequestTimeout", 0);
// Delay between HTTP requests to mitigate 503 errors.
pref("extensions.gContactSync.httpRequestDelay", 120);
// extended properties to sync
-pref("extensions.gContactSync.extended1", "PreferMailFormat");
-pref("extensions.gContactSync.extended2", "AllowRemoteContent");
-pref("extensions.gContactSync.extended3", "AnniversaryYear");
-pref("extensions.gContactSync.extended4", "AnniversaryMonth");
-pref("extensions.gContactSync.extended5", "AnniversaryDay");
-pref("extensions.gContactSync.extended6", "PopularityIndex");
-pref("extensions.gContactSync.extended7", "Custom1");
-pref("extensions.gContactSync.extended8", "Custom2");
-pref("extensions.gContactSync.extended9", "Custom3");
-pref("extensions.gContactSync.extended10", "Custom4");
+pref("extensions.gContactSync.extended1", "Custom1");
+pref("extensions.gContactSync.extended2", "Custom2");
+pref("extensions.gContactSync.extended3", "Custom3");
+pref("extensions.gContactSync.extended4", "Custom4");
+pref("extensions.gContactSync.extended5", "");
+pref("extensions.gContactSync.extended6", "");
+pref("extensions.gContactSync.extended7", "");
+pref("extensions.gContactSync.extended8", "");
+pref("extensions.gContactSync.extended9", "");
+pref("extensions.gContactSync.extended10", "");
pref("extensions.gContactSync.syncExtended", true);
pref("extensions.gContactSync.faqURL", "http://www.pirules.org/addons/gcontactsync/faq.php");
pref("extensions.gContactSync.forumURL", "http://www.pirules.org/forum/");
--
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