1.1 --- a/modules/fburl.js Sun Apr 17 21:54:48 2016 +0200
1.2 +++ b/modules/fburl.js Mon Apr 18 16:54:32 2016 +0200
1.3 @@ -25,6 +25,8 @@
1.4 const calIFreeBusyInterval = Ci.calIFreeBusyInterval;
1.5 const calIDateTime = Ci.calIDateTime;
1.6
1.7 +/* Initialise the provider.
1.8 + */
1.9 fburl.fbUrlProvider = function(cal) {
1.10 this.cal = cal;
1.11 this._query = null;
1.12 @@ -38,9 +40,16 @@
1.13 this._periods = null;
1.14 };
1.15
1.16 +/* The free/busy provider for FBURL-specified resources.
1.17 + * This implements the calIFreeBusyProvider interface, returning free/busy
1.18 + * intervals when getFreeBusyIntervals is called.
1.19 + */
1.20 fburl.fbUrlProvider.prototype = {
1.21 classID: Components.ID("{11291d94-b457-4322-bfba-ae9df4b6a3c1}"),
1.22
1.23 + /* Called by the calFreeBusyService, this function performs a search in
1.24 + * LDAP address books and returns any intervals found.
1.25 + */
1.26 getFreeBusyIntervals: function (aCalId, aRangeStart, aRangeEnd, aBusyTypes, aListener) {
1.27
1.28 this._listener = aListener;
1.29 @@ -49,6 +58,9 @@
1.30 this.startSearch(aCalId);
1.31 },
1.32
1.33 + /* Access the address book manager and obtain all LDAP directory address
1.34 + * books.
1.35 + */
1.36 getLDAPAddressBooks: function () {
1.37
1.38 var abManager = Cc["@mozilla.org/abmanager;1"].getService(Ci.nsIAbManager);
1.39 @@ -65,6 +77,9 @@
1.40 return books;
1.41 },
1.42
1.43 + /* Initiate a search, obtaining LDAP address books and querying each one for
1.44 + * an identity having the given primary e-mail address.
1.45 + */
1.46 startSearch: function (aCalId) {
1.47
1.48 var service = Cc["@mozilla.org/network/ldap-service;1"].getService(Ci.nsILDAPService);
1.49 @@ -94,6 +109,8 @@
1.50 }
1.51 },
1.52
1.53 + /* Stop any currently-initiated search.
1.54 + */
1.55 stopSearch: function stopSearch() {
1.56 if (this._context) {
1.57 this._query.stopQuery(this._context);
1.58 @@ -102,11 +119,22 @@
1.59 }
1.60 },
1.61
1.62 + /* Search finished callback.
1.63 + */
1.64 onSearchFinished: function (aResult, aErrorMsg) {
1.65 this._context = null;
1.66 this._error = aErrorMsg;
1.67 },
1.68
1.69 + /* Search success callback, indicating any found address book card. The
1.70 + * supplied card should provide the FBURL property which is then used to
1.71 + * retrieve the referenced free/busy resource.
1.72 + *
1.73 + * Upon retrieval, the resource is parsed using the calICSService and the
1.74 + * free/busy periods obtained. Finally, each period is encapsulated in an
1.75 + * interval object and the collection of such objects presented to the
1.76 + * originally-specified result callback.
1.77 + */
1.78 onSearchFoundCard: function (aCard) {
1.79
1.80 this._result = aCard;
1.81 @@ -181,6 +209,8 @@
1.82 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsIAbDirSearchListener])
1.83 };
1.84
1.85 +/* Provide a way of adding the provider to the free/busy service.
1.86 + */
1.87 fburl.initProvider = function() {
1.88 cal.getFreeBusyService().addProvider(new fburl.fbUrlProvider(cal));
1.89 }