# HG changeset patch # User Paul Boddie # Date 1411863212 -7200 # Node ID c711fd637f8594605e1627bce9c8616f02e96dde # Parent 13a18bb26c90a92af1f8e8933d7fd9fe70941a08 Added interval propagation similar to that used by the CalDAV provider. diff -r 13a18bb26c90 -r c711fd637f85 modules/fburl.js --- a/modules/fburl.js Sun Sep 28 01:52:12 2014 +0200 +++ b/modules/fburl.js Sun Sep 28 02:13:32 2014 +0200 @@ -5,6 +5,7 @@ const Cu = Components.utils; Cu.import("resource://calendar/modules/calUtils.jsm"); +Cu.import("resource://calendar/modules/calIteratorUtils.jsm"); Cu.import("resource:///modules/mailServices.js"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); @@ -24,7 +25,8 @@ this._error = null; this._listener = null; this._url = null; - this._fb = null; + this._calId = null; + this._periods = null; }; fburl.fbUrlProvider.prototype = { @@ -32,16 +34,10 @@ getFreeBusyIntervals: function (aCalId, aRangeStart, aRangeEnd, aBusyTypes, aListener) { - var start = this.cal.createDateTime("20140923T100000Z"); - var end = this.cal.createDateTime("20140923T120000Z"); - - var periods = []; - var interval = new this.cal.FreeBusyInterval( - aCalId, - calIFreeBusyInterval.BUSY, // fbType - start, end); - periods.push(interval); - aListener.onResult(null, periods); + this._listener = aListener; + this._calId = aCalId; + this._periods = null; + this.startSearch(aCalId); }, getLDAPAddressBooks: function () { @@ -119,7 +115,58 @@ var channel = service.newChannelFromURI(service.newURI(this._url, null, null)); stream.init(channel.open()); - this._fb = parser.parseICS(stream.read(-1), null).getFirstSubcomponent("VFREEBUSY"); + var resource = parser.parseICS(stream.read(-1), null); + + // Obtain the free/busy periods. + + this._periods = []; + var fbTypeMap = {}; + + fbTypeMap["FREE"] = calIFreeBusyInterval.FREE; + fbTypeMap["BUSY"] = calIFreeBusyInterval.BUSY; + fbTypeMap["BUSY-UNAVAILABLE"] = calIFreeBusyInterval.BUSY_UNAVAILABLE; + fbTypeMap["BUSY-TENTATIVE"] = calIFreeBusyInterval.BUSY_TENTATIVE; + + // Iterate over components in the response. + + for (var comp in cal.ical.calendarComponentIterator(resource)) { + + // Iterate over free/busy properties. + + for (var fbProp in cal.ical.propertyIterator(comp, "FREEBUSY")) { + + // Assign the stated type or busy otherwise. + + var fbType = fbProp.getParameter("FBTYPE"); + + if (fbType) { + fbType = fbTypeMap[fbType]; + } else { + fbType = calIFreeBusyInterval.BUSY; + } + + var parts = fbProp.value.split("/"); + var begin = cal.createDateTime(parts[0]); + var end; + + // Support durations. + + if (parts[1].charAt(0) == "P") { + end = begin.clone(); + end.addDuration(cal.createDuration(parts[1])); + + // Support plain datetimes. + + } else { + end = cal.createDateTime(parts[1]); + } + + interval = new cal.FreeBusyInterval(this._calId, fbType, begin, end); + this._periods.push(interval); + } + } + + this._listener.onResult(null, this._periods); }, QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsIAbDirSearchListener])