1.1 --- a/modules/fburl.js Sun Sep 28 01:52:12 2014 +0200
1.2 +++ b/modules/fburl.js Sun Sep 28 02:13:32 2014 +0200
1.3 @@ -5,6 +5,7 @@
1.4 const Cu = Components.utils;
1.5
1.6 Cu.import("resource://calendar/modules/calUtils.jsm");
1.7 +Cu.import("resource://calendar/modules/calIteratorUtils.jsm");
1.8 Cu.import("resource:///modules/mailServices.js");
1.9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
1.10
1.11 @@ -24,7 +25,8 @@
1.12 this._error = null;
1.13 this._listener = null;
1.14 this._url = null;
1.15 - this._fb = null;
1.16 + this._calId = null;
1.17 + this._periods = null;
1.18 };
1.19
1.20 fburl.fbUrlProvider.prototype = {
1.21 @@ -32,16 +34,10 @@
1.22
1.23 getFreeBusyIntervals: function (aCalId, aRangeStart, aRangeEnd, aBusyTypes, aListener) {
1.24
1.25 - var start = this.cal.createDateTime("20140923T100000Z");
1.26 - var end = this.cal.createDateTime("20140923T120000Z");
1.27 -
1.28 - var periods = [];
1.29 - var interval = new this.cal.FreeBusyInterval(
1.30 - aCalId,
1.31 - calIFreeBusyInterval.BUSY, // fbType
1.32 - start, end);
1.33 - periods.push(interval);
1.34 - aListener.onResult(null, periods);
1.35 + this._listener = aListener;
1.36 + this._calId = aCalId;
1.37 + this._periods = null;
1.38 + this.startSearch(aCalId);
1.39 },
1.40
1.41 getLDAPAddressBooks: function () {
1.42 @@ -119,7 +115,58 @@
1.43 var channel = service.newChannelFromURI(service.newURI(this._url, null, null));
1.44
1.45 stream.init(channel.open());
1.46 - this._fb = parser.parseICS(stream.read(-1), null).getFirstSubcomponent("VFREEBUSY");
1.47 + var resource = parser.parseICS(stream.read(-1), null);
1.48 +
1.49 + // Obtain the free/busy periods.
1.50 +
1.51 + this._periods = [];
1.52 + var fbTypeMap = {};
1.53 +
1.54 + fbTypeMap["FREE"] = calIFreeBusyInterval.FREE;
1.55 + fbTypeMap["BUSY"] = calIFreeBusyInterval.BUSY;
1.56 + fbTypeMap["BUSY-UNAVAILABLE"] = calIFreeBusyInterval.BUSY_UNAVAILABLE;
1.57 + fbTypeMap["BUSY-TENTATIVE"] = calIFreeBusyInterval.BUSY_TENTATIVE;
1.58 +
1.59 + // Iterate over components in the response.
1.60 +
1.61 + for (var comp in cal.ical.calendarComponentIterator(resource)) {
1.62 +
1.63 + // Iterate over free/busy properties.
1.64 +
1.65 + for (var fbProp in cal.ical.propertyIterator(comp, "FREEBUSY")) {
1.66 +
1.67 + // Assign the stated type or busy otherwise.
1.68 +
1.69 + var fbType = fbProp.getParameter("FBTYPE");
1.70 +
1.71 + if (fbType) {
1.72 + fbType = fbTypeMap[fbType];
1.73 + } else {
1.74 + fbType = calIFreeBusyInterval.BUSY;
1.75 + }
1.76 +
1.77 + var parts = fbProp.value.split("/");
1.78 + var begin = cal.createDateTime(parts[0]);
1.79 + var end;
1.80 +
1.81 + // Support durations.
1.82 +
1.83 + if (parts[1].charAt(0) == "P") {
1.84 + end = begin.clone();
1.85 + end.addDuration(cal.createDuration(parts[1]));
1.86 +
1.87 + // Support plain datetimes.
1.88 +
1.89 + } else {
1.90 + end = cal.createDateTime(parts[1]);
1.91 + }
1.92 +
1.93 + interval = new cal.FreeBusyInterval(this._calId, fbType, begin, end);
1.94 + this._periods.push(interval);
1.95 + }
1.96 + }
1.97 +
1.98 + this._listener.onResult(null, this._periods);
1.99 },
1.100
1.101 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsIAbDirSearchListener])