2004-11-24 02:40:06 +03:00
|
|
|
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Oracle Corporation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Oracle Corporation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
//
|
|
|
|
// calCompositeCalendar.js
|
|
|
|
//
|
|
|
|
|
|
|
|
const calIOperationListener = Components.interfaces.calIOperationListener;
|
|
|
|
|
2005-04-19 10:49:50 +04:00
|
|
|
function calCompositeCalendarObserverHelper (compCalendar) {
|
|
|
|
this.compCalendar = compCalendar;
|
2007-09-17 13:14:59 +04:00
|
|
|
this.pendingLoads = {};
|
2005-04-19 10:49:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
calCompositeCalendarObserverHelper.prototype = {
|
2007-09-17 13:14:59 +04:00
|
|
|
pendingLoads: null,
|
2005-04-19 10:49:50 +04:00
|
|
|
|
|
|
|
onStartBatch: function() {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onStartBatch");
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onEndBatch: function() {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onEndBatch");
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
2007-06-11 13:27:26 +04:00
|
|
|
onLoad: function(calendar) {
|
2007-09-17 13:14:59 +04:00
|
|
|
// avoid unnecessary onLoad events:
|
|
|
|
if (this.pendingLoads[calendar.id]) {
|
|
|
|
// don't forward if caused by composite:
|
|
|
|
delete this.pendingLoads[calendar.id];
|
|
|
|
} else {
|
2007-07-31 11:45:38 +04:00
|
|
|
// any refreshed dependent calendar logically refreshes
|
|
|
|
// this composite calendar, thus we send out an onLoad
|
|
|
|
// for this composite calendar:
|
|
|
|
this.compCalendar.mObservers.notify("onLoad", [this.compCalendar]);
|
|
|
|
}
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onAddItem: function(aItem) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onAddItem", arguments);
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onModifyItem: function(aNewItem, aOldItem) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onModifyItem", arguments);
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteItem: function(aDeletedItem) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onDeleteItem", arguments);
|
2005-04-19 10:49:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onError: function(aErrNo, aMessage) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.compCalendar.mObservers.notify("onError", arguments);
|
2007-10-29 17:49:40 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onPropertyChanged: function(aCalendar, aName, aValue, aOldValue) {
|
|
|
|
this.compCalendar.mObservers.notify("onPropertyChanged", arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPropertyDeleting: function(aCalendar, aName) {
|
|
|
|
this.compCalendar.mObservers.notify("onPropertyDeleting", arguments);
|
2005-04-19 10:49:50 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
function calCompositeCalendar () {
|
2005-04-19 11:18:18 +04:00
|
|
|
this.mObserverHelper = new calCompositeCalendarObserverHelper(this);
|
2004-11-24 02:40:06 +03:00
|
|
|
this.wrappedJSObject = this;
|
2006-08-01 07:13:49 +04:00
|
|
|
|
|
|
|
this.mCalendars = new Array();
|
2007-09-22 22:26:57 +04:00
|
|
|
this.mCompositeObservers = new calListenerBag(Components.interfaces.calICompositeObserver);
|
|
|
|
this.mObservers = new calListenerBag(Components.interfaces.calIObserver);
|
2006-08-01 07:13:49 +04:00
|
|
|
this.mDefaultCalendar = null;
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
calCompositeCalendar.prototype = {
|
|
|
|
//
|
|
|
|
// private members
|
|
|
|
//
|
|
|
|
mDefaultCalendar: null,
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports interface
|
|
|
|
//
|
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
2006-09-06 05:42:08 +04:00
|
|
|
!aIID.equals(Components.interfaces.calICalendarProvider) &&
|
2004-11-24 02:40:06 +03:00
|
|
|
!aIID.equals(Components.interfaces.calICalendar) &&
|
|
|
|
!aIID.equals(Components.interfaces.calICompositeCalendar))
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2006-09-06 05:42:08 +04:00
|
|
|
//
|
|
|
|
// calICalendarProvider interface
|
|
|
|
//
|
|
|
|
get prefChromeOverlay() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get displayName() {
|
|
|
|
return calGetString("calendar", "compositeName");
|
|
|
|
},
|
|
|
|
|
|
|
|
createCalendar: function comp_createCal() {
|
|
|
|
throw NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteCalendar: function comp_deleteCal(cal, listener) {
|
|
|
|
// You shouldn't be able to delete from the composite calendar.
|
|
|
|
throw NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
//
|
|
|
|
// calICompositeCalendar interface
|
|
|
|
//
|
|
|
|
|
2006-08-01 07:13:49 +04:00
|
|
|
mCalendars: null,
|
2004-11-24 02:40:06 +03:00
|
|
|
mDefaultCalendar: null,
|
2005-05-03 04:20:14 +04:00
|
|
|
mPrefPrefix: null,
|
|
|
|
mDefaultPref: null,
|
|
|
|
mActivePref: null,
|
|
|
|
|
|
|
|
set prefPrefix (aPrefPrefix) {
|
|
|
|
if (this.mPrefPrefix) {
|
|
|
|
this.mCalendars.forEach(this.removeCalendar, this);
|
|
|
|
}
|
|
|
|
this.mPrefPrefix = aPrefPrefix;
|
|
|
|
this.mActivePref = aPrefPrefix + "-in-composite";
|
|
|
|
this.mDefaultPref = aPrefPrefix + "-default";
|
2006-07-21 04:36:38 +04:00
|
|
|
var mgr = getCalendarManager();
|
2005-05-03 04:20:14 +04:00
|
|
|
var cals = mgr.getCalendars({});
|
|
|
|
|
|
|
|
cals.forEach(function (c) {
|
2007-10-29 17:49:40 +03:00
|
|
|
if (c.getProperty(this.mActivePref))
|
2005-05-03 04:20:14 +04:00
|
|
|
this.addCalendar(c);
|
2007-10-29 17:49:40 +03:00
|
|
|
if (c.getProperty(this.mDefaultPref))
|
2005-05-03 04:20:14 +04:00
|
|
|
this.setDefaultCalendar(c, false);
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
get prefPrefix () {
|
|
|
|
return this.mPrefPrefix;
|
|
|
|
},
|
2004-11-24 02:40:06 +03:00
|
|
|
|
2005-03-21 20:55:24 +03:00
|
|
|
addCalendar: function (aCalendar) {
|
2004-11-24 02:40:06 +03:00
|
|
|
// check if the calendar already exists
|
2005-04-09 00:57:34 +04:00
|
|
|
for each (cal in this.mCalendars) {
|
|
|
|
if (aCalendar.uri.equals(cal.uri)) {
|
2004-11-24 02:40:06 +03:00
|
|
|
// throw exception if calendar already exists?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-19 10:49:50 +04:00
|
|
|
// add our observer helper
|
|
|
|
aCalendar.addObserver(this.mObserverHelper);
|
|
|
|
|
2005-03-21 20:55:24 +03:00
|
|
|
this.mCalendars.push(aCalendar);
|
2005-05-03 04:20:14 +04:00
|
|
|
if (this.mPrefPrefix) {
|
2007-10-29 17:49:40 +03:00
|
|
|
aCalendar.setProperty(this.mActivePref, true);
|
2005-05-03 04:20:14 +04:00
|
|
|
}
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.notify("onCalendarAdded", [aCalendar]);
|
2004-11-24 02:40:06 +03:00
|
|
|
|
|
|
|
// if we have no default calendar, we need one here
|
2005-05-03 04:20:14 +04:00
|
|
|
if (this.mDefaultCalendar == null)
|
|
|
|
this.setDefaultCalendar(aCalendar, false);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
removeCalendar: function (aServer) {
|
|
|
|
var newCalendars = Array();
|
|
|
|
var calToRemove = null;
|
2005-04-09 00:57:34 +04:00
|
|
|
for each (cal in this.mCalendars) {
|
|
|
|
if (!aServer.equals(cal.uri))
|
2004-11-24 02:40:06 +03:00
|
|
|
newCalendars.push(cal);
|
|
|
|
else
|
|
|
|
calToRemove = cal;
|
|
|
|
}
|
|
|
|
|
2005-04-19 10:49:50 +04:00
|
|
|
if (calToRemove) {
|
|
|
|
this.mCalendars = newCalendars;
|
2005-05-03 04:20:14 +04:00
|
|
|
if (this.mPrefPrefix) {
|
2007-10-29 17:49:40 +03:00
|
|
|
calToRemove.deleteProperty(this.mActivePref);
|
|
|
|
calToRemove.deleteProperty(this.mDefaultPref);
|
2005-05-03 04:20:14 +04:00
|
|
|
}
|
2005-04-19 10:49:50 +04:00
|
|
|
calToRemove.removeObserver(this.mObserverHelper);
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.notify("onCalendarRemoved", [calToRemove]);
|
2005-04-19 10:49:50 +04:00
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getCalendar: function (aServer) {
|
2005-04-09 00:57:34 +04:00
|
|
|
for each (cal in this.mCalendars) {
|
|
|
|
if (aServer.equals(cal.uri))
|
2004-11-24 02:40:06 +03:00
|
|
|
return cal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get calendars() {
|
|
|
|
// return a nsISimpleEnumerator of this array. This sucks.
|
2005-05-03 04:20:14 +04:00
|
|
|
// XXX make this an array, like the calendar manager?
|
2004-11-24 02:40:06 +03:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get defaultCalendar() {
|
|
|
|
return this.mDefaultCalendar;
|
|
|
|
},
|
|
|
|
|
2005-05-03 04:20:14 +04:00
|
|
|
setDefaultCalendar: function (cal, usePref) {
|
2006-08-08 20:55:17 +04:00
|
|
|
// don't do anything if the passed calendar is the default calendar!
|
|
|
|
if (this.mDefaultCalendar && cal && this.mDefaultCalendar.uri.equals(cal.uri))
|
2005-05-03 04:20:14 +04:00
|
|
|
return;
|
|
|
|
if (usePref && this.mPrefPrefix) {
|
2006-04-01 01:19:02 +04:00
|
|
|
if (this.mDefaultCalendar) {
|
2007-10-29 17:49:40 +03:00
|
|
|
this.mDefaultCalendar.deleteProperty(this.mDefaultPref);
|
2006-04-01 01:19:02 +04:00
|
|
|
}
|
2006-08-08 20:55:17 +04:00
|
|
|
// if not null set the new calendar as default in the preferences
|
|
|
|
if (cal) {
|
2007-10-29 17:49:40 +03:00
|
|
|
cal.setProperty(this.mDefaultPref, true);
|
2006-08-08 20:55:17 +04:00
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
2005-05-03 04:20:14 +04:00
|
|
|
this.mDefaultCalendar = cal;
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.notify("onDefaultCalendarChanged", [cal]);
|
2005-05-03 04:20:14 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set defaultCalendar(v) {
|
|
|
|
this.setDefaultCalendar(v, true);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// calICalendar interface
|
|
|
|
//
|
|
|
|
// Write operations here are forwarded to either the item's
|
|
|
|
// parent calendar, or to the default calendar if one is set.
|
|
|
|
// Get operations are sent to each calendar.
|
|
|
|
//
|
|
|
|
|
2007-03-09 22:02:08 +03:00
|
|
|
get id() {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
set id(id) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2007-11-21 11:26:03 +03:00
|
|
|
get superCalendar() {
|
|
|
|
// There shouldn't be a superCalendar for the composite
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
set superCalendar(val) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
// this could, at some point, return some kind of URI identifying
|
|
|
|
// all the child calendars, thus letting us create nifty calendar
|
|
|
|
// trees.
|
|
|
|
get uri() {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
set uri(v) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2005-10-21 20:51:13 +04:00
|
|
|
get readOnly() {
|
2005-10-23 22:49:58 +04:00
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 20:51:13 +04:00
|
|
|
},
|
|
|
|
set readOnly(bool) {
|
2005-10-23 22:49:58 +04:00
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 20:51:13 +04:00
|
|
|
},
|
|
|
|
|
2006-06-12 23:51:19 +04:00
|
|
|
get canRefresh() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2007-10-29 17:49:40 +03:00
|
|
|
get name() {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
set name(v) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "composite";
|
|
|
|
},
|
|
|
|
|
|
|
|
getProperty: function(aName) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
setProperty: function(aName, aValue) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
deleteProperty: function(aName) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2005-04-15 22:51:47 +04:00
|
|
|
// void addObserver( in calIObserver observer );
|
2006-08-01 07:13:49 +04:00
|
|
|
mCompositeObservers: null,
|
|
|
|
mObservers: null,
|
2005-04-19 10:49:50 +04:00
|
|
|
addObserver: function (aObserver) {
|
2007-09-22 22:26:57 +04:00
|
|
|
if (aObserver instanceof Components.interfaces.calICompositeObserver) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.add(aObserver);
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mObservers.add(aObserver);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void removeObserver( in calIObserver observer );
|
|
|
|
removeObserver: function (aObserver) {
|
2007-09-22 22:26:57 +04:00
|
|
|
if (aObserver instanceof Components.interfaces.calICompositeObserver) {
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.remove(aObserver);
|
|
|
|
}
|
|
|
|
this.mObservers.remove(aObserver);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
2005-07-25 23:17:09 +04:00
|
|
|
refresh: function() {
|
2007-09-17 13:14:59 +04:00
|
|
|
for each (cal in this.mCalendars) {
|
|
|
|
try {
|
|
|
|
if (cal.canRefresh) {
|
|
|
|
this.mObserverHelper.pendingLoads[cal.id] = true;
|
|
|
|
cal.refresh();
|
2007-09-14 16:08:49 +04:00
|
|
|
}
|
2007-09-17 13:14:59 +04:00
|
|
|
} catch (e) {
|
|
|
|
ASSERT(false, e);
|
|
|
|
delete this.mObserverHelper.pendingLoads[cal.id];
|
2007-07-31 11:45:38 +04:00
|
|
|
}
|
2005-07-25 23:17:09 +04:00
|
|
|
}
|
2007-09-17 13:14:59 +04:00
|
|
|
// send out a single onLoad for this composite calendar,
|
|
|
|
// although e.g. the ics provider will trigger another
|
|
|
|
// onLoad asynchronously; we cannot rely on every calendar
|
|
|
|
// sending an onLoad:
|
|
|
|
this.mObservers.notify("onLoad", [this]);
|
2005-07-25 23:17:09 +04:00
|
|
|
},
|
|
|
|
|
2005-06-10 03:24:45 +04:00
|
|
|
// void modifyItem( in calIItemBase aNewItem, in calIItemBase aOldItem, in calIOperationListener aListener );
|
|
|
|
modifyItem: function (aNewItem, aOldItem, aListener) {
|
|
|
|
if (aNewItem.calendar == null) {
|
2004-11-24 02:40:06 +03:00
|
|
|
// XXX Can't modify item with NULL parent
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-09-14 16:08:49 +04:00
|
|
|
return aNewItem.calendar.modifyItem(aNewItem, aOldItem, aListener);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void deleteItem( in string id, in calIOperationListener aListener );
|
|
|
|
deleteItem: function (aItem, aListener) {
|
2005-06-04 00:46:36 +04:00
|
|
|
if (aItem.calendar == null) {
|
2004-11-24 02:40:06 +03:00
|
|
|
// XXX Can't delete item with NULL parent
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-09-14 16:08:49 +04:00
|
|
|
return aItem.calendar.deleteItem(aItem, aListener);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
addItem: function (aItem, aListener) {
|
2007-09-14 16:08:49 +04:00
|
|
|
return this.mDefaultCalendar.addItem(aItem, aListener);
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void getItem( in string aId, in calIOperationListener aListener );
|
|
|
|
getItem: function (aId, aListener) {
|
|
|
|
var cmpListener = new calCompositeGetListenerHelper(this.mCalendars.length, aListener);
|
2005-04-09 00:57:34 +04:00
|
|
|
for each (cal in this.mCalendars) {
|
2007-09-14 16:08:49 +04:00
|
|
|
try {
|
|
|
|
cmpListener.opGroup.add(cal.getItem(aId, cmpListener));
|
|
|
|
} catch (exc) {
|
|
|
|
ASSERT(false, exc);
|
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
2007-09-14 16:08:49 +04:00
|
|
|
return cmpListener.opGroup;
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void getItems( in unsigned long aItemFilter, in unsigned long aCount,
|
|
|
|
// in calIDateTime aRangeStart, in calIDateTime aRangeEnd,
|
|
|
|
// in calIOperationListener aListener );
|
|
|
|
getItems: function (aItemFilter, aCount, aRangeStart, aRangeEnd, aListener) {
|
2005-11-07 20:55:05 +03:00
|
|
|
// If there are no calendars, then we just call onOperationComplete
|
|
|
|
if (this.mCalendars.length == 0) {
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
|
|
|
calIOperationListener.GET,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
var cmpListener = new calCompositeGetListenerHelper(this.mCalendars.length, aListener, aCount);
|
|
|
|
for (cal in this.mCalendars) {
|
2007-09-14 16:08:49 +04:00
|
|
|
try {
|
|
|
|
cmpListener.opGroup.add(
|
|
|
|
this.mCalendars[cal].getItems(
|
|
|
|
aItemFilter, aCount, aRangeStart, aRangeEnd, cmpListener));
|
|
|
|
} catch (exc) {
|
|
|
|
ASSERT(false, exc);
|
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
2007-09-14 16:08:49 +04:00
|
|
|
return cmpListener.opGroup;
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
2005-10-29 00:13:53 +04:00
|
|
|
startBatch: function ()
|
|
|
|
{
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.notify("onStartBatch");
|
2005-10-29 00:13:53 +04:00
|
|
|
},
|
|
|
|
endBatch: function ()
|
|
|
|
{
|
2007-07-31 11:45:38 +04:00
|
|
|
this.mCompositeObservers.notify("onEndBatch");
|
2005-05-28 00:37:44 +04:00
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// composite listener helper
|
|
|
|
function calCompositeGetListenerHelper(aNumQueries, aRealListener, aMaxItems) {
|
|
|
|
this.wrappedJSObject = this;
|
|
|
|
this.mNumQueries = aNumQueries;
|
|
|
|
this.mRealListener = aRealListener;
|
|
|
|
this.mMaxItems = aMaxItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
calCompositeGetListenerHelper.prototype = {
|
|
|
|
mNumQueries: 0,
|
|
|
|
mRealListener: null,
|
2007-09-14 16:08:49 +04:00
|
|
|
mOpGroup: null,
|
2004-11-24 02:40:06 +03:00
|
|
|
mReceivedCompletes: 0,
|
|
|
|
mFinished: false,
|
|
|
|
mMaxItems: 0,
|
|
|
|
mItemsReceived: 0,
|
|
|
|
|
2007-09-14 16:08:49 +04:00
|
|
|
get opGroup() {
|
|
|
|
if (!this.mOpGroup) {
|
|
|
|
var this_ = this;
|
|
|
|
function cancelFunc() { // operation group has been cancelled
|
|
|
|
var listener = this_.mRealListener;
|
|
|
|
this_.mRealListener = null;
|
|
|
|
if (listener) {
|
|
|
|
listener.onOperationComplete(
|
|
|
|
this_, Components.interfaces.calIErrors.OPERATION_CANCELLED,
|
|
|
|
calIOperationListener.GET, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mOpGroup = new calOperationGroup(cancelFunc);
|
|
|
|
}
|
|
|
|
return this.mOpGroup;
|
|
|
|
},
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
|
|
|
!aIID.equals(Components.interfaces.calIOperationListener))
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
onOperationComplete: function (aCalendar, aStatus, aOperationType, aId, aDetail) {
|
2007-09-14 16:08:49 +04:00
|
|
|
if (!this.mRealListener) {
|
|
|
|
// has been cancelled, ignore any providers firing on this...
|
|
|
|
return;
|
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
if (this.mFinished) {
|
|
|
|
dump ("+++ calCompositeGetListenerHelper.onOperationComplete: called with mFinished == true!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Components.isSuccessCode(aStatus)) {
|
|
|
|
// proxy this to a onGetResult
|
|
|
|
// XXX - do we want to give the real calendar? or this?
|
2005-05-26 02:43:42 +04:00
|
|
|
// XXX - get rid of iid param
|
|
|
|
this.mRealListener.onGetResult (aCalendar, aStatus,
|
|
|
|
Components.interfaces.nsISupports,
|
|
|
|
aDetail, 0, []);
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.mReceivedCompletes++;
|
|
|
|
|
|
|
|
if (this.mReceivedCompletes == this.mNumQueries) {
|
|
|
|
// we're done here.
|
2007-11-02 18:52:44 +03:00
|
|
|
this.mFinished = true;
|
|
|
|
this.opGroup.notifyCompleted();
|
2004-11-24 02:40:06 +03:00
|
|
|
this.mRealListener.onOperationComplete (this,
|
2007-09-14 16:08:49 +04:00
|
|
|
aStatus,
|
2004-11-24 02:40:06 +03:00
|
|
|
calIOperationListener.GET,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onGetResult: function (aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
|
2007-09-14 16:08:49 +04:00
|
|
|
if (!this.mRealListener) {
|
|
|
|
// has been cancelled, ignore any providers firing on this...
|
|
|
|
return;
|
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
if (this.mFinished) {
|
|
|
|
dump ("+++ calCompositeGetListenerHelper.onGetResult: called with mFinished == true!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore if we have a max and we're past it
|
|
|
|
if (this.mMaxItems && this.mItemsReceived >= this.mMaxItems)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Components.isSuccessCode(aStatus) &&
|
|
|
|
this.mMaxItems &&
|
|
|
|
((this.mItemsReceived + aCount) > this.mMaxItems))
|
|
|
|
{
|
|
|
|
// this will blow past the limit
|
|
|
|
aCount = this.mMaxItems - this.mItemsReceived;
|
2007-12-15 22:07:09 +03:00
|
|
|
aItems = aItems.slice(0, aCount);
|
2004-11-24 02:40:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// send GetResults to the real listener
|
2005-03-21 20:55:24 +03:00
|
|
|
this.mRealListener.onGetResult (aCalendar, aStatus, aItemType, aDetail, aCount, aItems);
|
2004-11-24 02:40:06 +03:00
|
|
|
this.mItemsReceived += aCount;
|
2005-03-21 20:55:24 +03:00
|
|
|
}
|
2004-11-24 02:40:06 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-10-29 18:51:48 +03:00
|
|
|
// nsIFactory
|
|
|
|
const calCompositeCalendarFactory = {
|
|
|
|
createInstance: function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return (new calCompositeCalendar()).QueryInterface(iid);
|
|
|
|
}
|
|
|
|
};
|
2004-11-24 02:40:06 +03:00
|
|
|
|
|
|
|
/****
|
|
|
|
**** module registration
|
|
|
|
****/
|
|
|
|
|
|
|
|
var calCompositeCalendarModule = {
|
|
|
|
mCID: Components.ID("{aeff788d-63b0-4996-91fb-40a7654c6224}"),
|
|
|
|
mContractID: "@mozilla.org/calendar/calendar;1?type=composite",
|
2006-07-21 04:36:38 +04:00
|
|
|
|
|
|
|
mUtilsLoaded: false,
|
|
|
|
loadUtils: function compositeLoadUtils() {
|
|
|
|
if (this.mUtilsLoaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
|
|
|
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
|
|
|
|
2006-07-27 18:10:31 +04:00
|
|
|
const iosvcContractID = "@mozilla.org/network/io-service;1";
|
|
|
|
const iosvcIID = Components.interfaces.nsIIOService;
|
2006-07-21 04:36:38 +04:00
|
|
|
|
|
|
|
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
|
|
|
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
|
|
|
|
2006-07-27 18:10:31 +04:00
|
|
|
// Note that unintuitively, __LOCATION__.parent == .
|
|
|
|
// We expect to find utils in ./../js
|
|
|
|
var appdir = __LOCATION__.parent.parent;
|
|
|
|
appdir.append("js");
|
2006-07-21 04:36:38 +04:00
|
|
|
var scriptName = "calUtils.js";
|
|
|
|
|
|
|
|
var f = appdir.clone();
|
|
|
|
f.append(scriptName);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var fileurl = iosvc.newFileURI(f);
|
|
|
|
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
|
|
|
} catch (e) {
|
|
|
|
dump("Error while loading " + fileurl.spec + "\n");
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mUtilsLoaded = true;
|
|
|
|
},
|
2004-11-24 02:40:06 +03:00
|
|
|
|
|
|
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
compMgr.registerFactoryLocation(this.mCID,
|
|
|
|
"Calendar composite provider",
|
|
|
|
this.mContractID,
|
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
},
|
|
|
|
|
|
|
|
getClassObject: function (compMgr, cid, iid) {
|
|
|
|
if (!cid.equals(this.mCID))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2006-07-21 04:36:38 +04:00
|
|
|
this.loadUtils();
|
|
|
|
|
2007-10-29 18:51:48 +03:00
|
|
|
return calCompositeCalendarFactory;
|
2004-11-24 02:40:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
canUnload: function(compMgr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return calCompositeCalendarModule;
|
|
|
|
}
|