2004-11-10 21:25:38 +00: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 ***** */
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// calMemoryCalendar.js
|
|
|
|
//
|
|
|
|
|
|
|
|
function calMemoryCalendar() {
|
2004-11-10 21:25:38 +00:00
|
|
|
this.wrappedJSObject = this;
|
2004-12-14 03:34:59 +00:00
|
|
|
this.mObservers = Array();
|
2004-11-25 16:55:31 +00:00
|
|
|
this.mItems = { };
|
2004-11-07 23:48:13 +00:00
|
|
|
}
|
|
|
|
|
2004-11-25 16:55:31 +00:00
|
|
|
function makeOccurrence(item, start, end)
|
|
|
|
{
|
|
|
|
var occ = Components.classes["@mozilla.org/calendar/item-occurrence;1"].
|
2004-12-14 00:53:45 +00:00
|
|
|
createInstance(Components.interfaces.calIItemOccurrence);
|
2004-11-25 16:55:31 +00:00
|
|
|
// XXX poor form
|
|
|
|
occ.wrappedJSObject.item = item;
|
2004-12-14 00:53:45 +00:00
|
|
|
occ.wrappedJSObject.occurrenceStartDate = start;
|
|
|
|
occ.wrappedJSObject.occurrenceEndDate = end;
|
2004-11-25 16:55:31 +00:00
|
|
|
return occ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// END_OF_TIME needs to be the max value a PRTime can be
|
|
|
|
const END_OF_TIME = 0x7fffffffffffffff;
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-11-25 16:55:31 +00:00
|
|
|
calMemoryCalendar.prototype = {
|
2004-11-07 23:48:13 +00:00
|
|
|
//
|
|
|
|
// nsISupports interface
|
|
|
|
//
|
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
2004-11-25 16:55:31 +00:00
|
|
|
!aIID.equals(Components.interfaces.calICalendar)) {
|
2004-11-07 23:48:13 +00:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsICalendar interface
|
|
|
|
//
|
|
|
|
|
|
|
|
// attribute nsIURI uri;
|
2004-11-23 23:40:06 +00:00
|
|
|
mUri: null,
|
|
|
|
get uri() { return this.mUri; },
|
|
|
|
set uri(aURI) { this.mUri = aURI; },
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
// attribute boolean suppressAlarms;
|
|
|
|
get suppressAlarms() { return false; },
|
|
|
|
set suppressAlarms(aSuppressAlarms) { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
|
|
|
|
|
|
|
// void addObserver( in calIObserver observer, in unsigned long aItemFilter );
|
|
|
|
addObserver: function (aObserver, aItemFilter) {
|
|
|
|
for (var i = 0; i < this.mObservers.length; i++) {
|
|
|
|
if (this.mObservers[i].observer == aObserver &&
|
|
|
|
this.mObservers[i].filter == aItemFilter)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mObservers.push( {observer: aObserver, filter: aItemFilter} );
|
|
|
|
},
|
|
|
|
|
|
|
|
// void removeObserver( in calIObserver observer );
|
|
|
|
removeObserver: function (aObserver) {
|
|
|
|
var newObservers = Array();
|
|
|
|
for (var i = 0; i < this.mObservers.length; i++) {
|
|
|
|
if (this.mObservers[i].observer != aObserver)
|
|
|
|
newObservers.push(mObservers[i]);
|
|
|
|
}
|
|
|
|
this.mObservers = newObservers;
|
|
|
|
},
|
|
|
|
|
|
|
|
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
addItem: function (aItem, aListener) {
|
2004-12-08 22:48:30 +00:00
|
|
|
if (aItem.id == null && aItem.isMutable)
|
2004-11-19 01:01:40 +00:00
|
|
|
aItem.id = "uuid:" + (new Date()).getTime();
|
2004-11-25 16:55:31 +00:00
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
if (aItem.id == null) {
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.ADD,
|
|
|
|
aItem.id,
|
|
|
|
"Can't set ID on non-mutable item to addItem");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-07 23:48:13 +00:00
|
|
|
if (this.mItems[aItem.id] != null) {
|
|
|
|
// is this an error?
|
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.ADD,
|
2004-11-23 01:37:43 +00:00
|
|
|
aItem.id,
|
2004-12-08 22:48:30 +00:00
|
|
|
"ID already exists for addItem");
|
2004-11-07 23:48:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
var newItem = aItem.clone();
|
|
|
|
newItem.parent = this;
|
|
|
|
newItem.generation = 1;
|
|
|
|
newItem.makeImmutable();
|
|
|
|
this.mItems[newItem.id] = newItem;
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
// notify the listener
|
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.ADD,
|
2004-12-08 22:48:30 +00:00
|
|
|
newItem.id,
|
|
|
|
newItem);
|
|
|
|
// notify observers
|
|
|
|
this.observeAddItem(newItem);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// void modifyItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
modifyItem: function (aItem, aListener) {
|
|
|
|
if (aItem.id == null ||
|
2004-12-11 00:38:10 +00:00
|
|
|
this.mItems[aItem.id] == null)
|
2004-12-08 22:48:30 +00:00
|
|
|
{
|
2004-11-07 23:48:13 +00:00
|
|
|
// this is definitely an error
|
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.MODIFY,
|
2004-11-23 01:37:43 +00:00
|
|
|
aItem.id,
|
2004-12-08 22:48:30 +00:00
|
|
|
"ID for modifyItem doesn't exist, is null, or is from different calendar");
|
2004-11-07 23:48:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
var oldItem = this.mItems[aItem.id];
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
if (oldItem.generation != aItem.generation) {
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.MODIFY,
|
|
|
|
aItem.id,
|
|
|
|
"generation mismatch in modifyItem");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var newItem = aItem.clone();
|
|
|
|
newItem.generation += 1;
|
|
|
|
newItem.makeImmutable();
|
|
|
|
this.mItems[newItem.id] = newItem;
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.MODIFY,
|
2004-12-08 22:48:30 +00:00
|
|
|
newItem.id,
|
|
|
|
newItem);
|
|
|
|
// notify observers
|
|
|
|
this.observeModifyItem(oldItem, newItem);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
// void deleteItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
deleteItem: function (aItem, aListener) {
|
2004-12-11 00:38:10 +00:00
|
|
|
if (aItem.id == null || this.mItems[aItem.id] == null) {
|
2004-11-07 23:48:13 +00:00
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.DELETE,
|
2004-11-23 01:37:43 +00:00
|
|
|
aId,
|
2004-12-08 22:48:30 +00:00
|
|
|
"ID is null or is from different calendar in deleteItem");
|
2004-11-07 23:48:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
var oldItem = this.mItems[aItem.id];
|
|
|
|
if (oldItem.generation != aItem.generation) {
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.DELETE,
|
|
|
|
aId,
|
|
|
|
"generation mismatch in deleteItem");
|
|
|
|
return;
|
|
|
|
}
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-12-08 22:48:30 +00:00
|
|
|
delete this.mItems[aItem.id];
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
if (aListener)
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-07 23:48:13 +00:00
|
|
|
aListener.DELETE,
|
2004-11-23 01:37:43 +00:00
|
|
|
aId,
|
2004-11-07 23:48:13 +00:00
|
|
|
null);
|
2004-12-08 22:48:30 +00:00
|
|
|
// notify observers
|
|
|
|
observeDeleteItem(oldItem);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// void getItem( in string id, in calIOperationListener aListener );
|
|
|
|
getItem: function (aId, aListener) {
|
2004-11-19 01:01:40 +00:00
|
|
|
if (!aListener)
|
|
|
|
return;
|
|
|
|
|
2004-11-07 23:48:13 +00:00
|
|
|
if (aId == null ||
|
2004-11-25 16:55:31 +00:00
|
|
|
this.mItems[aId] == null) {
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete(this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-23 01:37:43 +00:00
|
|
|
aListener.GET,
|
|
|
|
null,
|
|
|
|
"IID doesn't exist for getItem");
|
2004-11-07 23:48:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-19 01:01:40 +00:00
|
|
|
var item = this.mItems[aId];
|
|
|
|
var iid = null;
|
|
|
|
|
|
|
|
if (item.QueryInterface(Components.interfaces.calIEvent)) {
|
|
|
|
iid = Components.interfaces.calIEvent;
|
|
|
|
} else if (item.QueryInterface(Components.interfaces.calITodo)) {
|
|
|
|
iid = Components.interfaces.calITodo;
|
|
|
|
} else {
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-23 01:37:43 +00:00
|
|
|
aListener.GET,
|
|
|
|
aId,
|
|
|
|
"Can't deduce item type based on QI");
|
2004-11-19 01:01:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onGetResult (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-23 01:37:43 +00:00
|
|
|
iid,
|
|
|
|
null, 1, [item]);
|
|
|
|
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-23 01:37:43 +00:00
|
|
|
aListener.GET,
|
|
|
|
aId,
|
|
|
|
null);
|
|
|
|
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
2004-11-23 01:37:43 +00:00
|
|
|
// void getItems( in unsigned long aItemFilter, in unsigned long aCount,
|
|
|
|
// in calIDateTime aRangeStart, in calIDateTime aRangeEnd,
|
2004-11-07 23:48:13 +00:00
|
|
|
// in calIOperationListener aListener );
|
2004-11-23 01:37:43 +00:00
|
|
|
getItems: function (aItemFilter, aCount,
|
2004-11-07 23:48:13 +00:00
|
|
|
aRangeStart, aRangeEnd, aListener)
|
|
|
|
{
|
2004-11-23 01:37:43 +00:00
|
|
|
if (!aListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const calICalendar = Components.interfaces.calICalendar;
|
|
|
|
const calIItemBase = Components.interfaces.calIItemBase;
|
|
|
|
const calIEvent = Components.interfaces.calIEvent;
|
|
|
|
const calITodo = Components.interfaces.calITodo;
|
|
|
|
const calIItemOccurrence = Components.interfaces.calIItemOccurrence;
|
2004-12-11 00:38:10 +00:00
|
|
|
const calIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
var itemsFound = Array();
|
|
|
|
var startTime = 0;
|
2004-11-25 16:55:31 +00:00
|
|
|
var endTime = END_OF_TIME;
|
2004-11-07 23:48:13 +00:00
|
|
|
if (aRangeStart)
|
2004-12-10 01:43:25 +00:00
|
|
|
startTime = aRangeStart.nativeTime;
|
2004-11-07 23:48:13 +00:00
|
|
|
if (aRangeEnd)
|
2004-12-10 01:43:25 +00:00
|
|
|
endTime = aRangeEnd.nativeTime;
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-11-23 01:37:43 +00:00
|
|
|
//
|
|
|
|
// filters
|
|
|
|
//
|
|
|
|
|
|
|
|
// item base type
|
|
|
|
var itemTypeFilter = null;
|
|
|
|
if (aItemFilter & calICalendar.ITEM_FILTER_TYPE_ALL)
|
|
|
|
itemTypeFilter = calIItemBase;
|
|
|
|
else if (aItemFilter & calICalendar.ITEM_FILTER_TYPE_EVENT)
|
|
|
|
itemTypeFilter = calIEvent;
|
|
|
|
else if (aItemFilter & calICalendar.ITEM_FILTER_TYPE_TODO)
|
|
|
|
itemTypeFilter = calITodo;
|
|
|
|
else {
|
|
|
|
// bail.
|
|
|
|
aListener.onOperationComplete (Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.GET,
|
|
|
|
null,
|
|
|
|
"Bad aItemFilter passed to getItems");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// completed?
|
|
|
|
var itemCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_YES) != 0);
|
2004-11-25 16:55:31 +00:00
|
|
|
var itemNotCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_NO) != 0);
|
2004-11-23 01:37:43 +00:00
|
|
|
|
|
|
|
// return occurrences?
|
|
|
|
var itemReturnOccurrences = ((aItemFilter & calICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0);
|
|
|
|
|
|
|
|
// if aCount != 0, we don't attempt to sort anything, and
|
|
|
|
// instead return the first aCount items that match.
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-11-25 16:55:31 +00:00
|
|
|
for (var i in this.mItems) {
|
2004-11-07 23:48:13 +00:00
|
|
|
var item = this.mItems[i];
|
2004-11-23 01:37:43 +00:00
|
|
|
var itemtoadd = null;
|
2004-11-25 16:55:31 +00:00
|
|
|
if (itemTypeFilter && !(item instanceof itemTypeFilter))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var itemStartTime = 0;
|
|
|
|
var itemEndTime = 0;
|
2004-12-11 00:38:10 +00:00
|
|
|
|
2004-11-25 16:55:31 +00:00
|
|
|
var tmpitem = item;
|
|
|
|
if (item instanceof calIEvent) {
|
|
|
|
tmpitem = item.QueryInterface(calIEvent);
|
2004-12-10 01:43:25 +00:00
|
|
|
itemStartTime = item.startDate.nativeTime || 0;
|
|
|
|
itemEndTime = item.endDate.nativeTime || END_OF_TIME;
|
2004-11-25 16:55:31 +00:00
|
|
|
} else if (item instanceof calITodo) {
|
|
|
|
// if it's a todo, also filter based on completeness
|
|
|
|
if (item.percentComplete == 100 && !itemCompletedFilter)
|
2004-11-07 23:48:13 +00:00
|
|
|
continue;
|
2004-11-25 16:55:31 +00:00
|
|
|
else if (item.percentComplete < 100 && !itemNotCompletedFilter)
|
|
|
|
continue;
|
2004-12-11 00:38:10 +00:00
|
|
|
|
2004-12-10 01:43:25 +00:00
|
|
|
itemEndTime = itemStartTime = item.entryTime.nativeTime || 0;
|
2004-11-25 16:55:31 +00:00
|
|
|
} else {
|
|
|
|
// XXX unknown item type, wth do we do?
|
|
|
|
continue;
|
|
|
|
}
|
2004-11-07 23:48:13 +00:00
|
|
|
|
2004-12-11 00:38:10 +00:00
|
|
|
if (itemStartTime <= endTime) {
|
|
|
|
// figure out if there are recurrences here we care about
|
|
|
|
if (itemReturnOccurrences && item.recurrenceInfo &&
|
|
|
|
item.recurrenceInfo.recurType != calIRecurrenceInfo.CAL_RECUR_INVALID)
|
|
|
|
{
|
|
|
|
// there might be some recurrences here that we need to handle
|
2004-12-14 03:34:59 +00:00
|
|
|
var recs = item.recurrenceInfo.getOccurrencesBetween (item, aRangeStart, aRangeEnd, {});
|
2004-12-11 00:38:10 +00:00
|
|
|
for (var i = 0; i < recs.length; i++) {
|
|
|
|
itemsFound.push(recs[i]);
|
|
|
|
}
|
|
|
|
} else if (itemEndTime >= startTime) {
|
|
|
|
// no occurrences
|
|
|
|
if (itemReturnOccurrences)
|
2004-12-14 00:49:54 +00:00
|
|
|
itemtoadd = makeOccurrence(item, item.startDate, item.endDate);
|
2004-12-11 00:38:10 +00:00
|
|
|
else
|
|
|
|
itemtoadd = item;
|
|
|
|
itemsFound.push(itemtoadd);
|
|
|
|
}
|
2004-11-07 23:48:13 +00:00
|
|
|
}
|
2004-11-23 01:37:43 +00:00
|
|
|
|
|
|
|
if (aCount && itemsFound.length >= aCount)
|
|
|
|
break;
|
2004-11-07 23:48:13 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onGetResult (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-23 01:37:43 +00:00
|
|
|
itemReturnOccurrences ? calIItemOccurrence : itemTypeFilter,
|
|
|
|
null,
|
|
|
|
itemsFound.length,
|
|
|
|
itemsFound);
|
|
|
|
|
2004-11-23 23:40:06 +00:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-23 01:37:43 +00:00
|
|
|
aListener.GET,
|
|
|
|
null,
|
|
|
|
null);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// Helper functions
|
|
|
|
//
|
|
|
|
observeBatchChange: function (aNewBatchMode) {
|
|
|
|
for (var i = 0; i < this.mObservers.length; i++) {
|
|
|
|
if (aNewBatchMode)
|
2004-12-14 03:34:59 +00:00
|
|
|
this.mObservers[i].observer.onStartBatch ();
|
2004-11-07 23:48:13 +00:00
|
|
|
else
|
2004-12-14 03:34:59 +00:00
|
|
|
this.mObservers[i].observer.onEndBatch ();
|
2004-11-07 23:48:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
observeAddItem: function (aItem) {
|
2004-12-14 03:34:59 +00:00
|
|
|
for (var i = 0; i < this.mObservers.length; i++) {
|
|
|
|
this.mObservers[i].observer.onAddItem (aItem);
|
|
|
|
}
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
observeModifyItem: function (aOldItem, aNewItem) {
|
|
|
|
for (var i = 0; i < this.mObservers.length; i++)
|
2004-12-14 03:34:59 +00:00
|
|
|
this.mObservers[i].observer.onModifyItem (aOldItem, aNewItem);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
observeDeleteItem: function (aDeletedItem) {
|
|
|
|
for (var i = 0; i < this.mObservers.length; i++)
|
2004-12-14 03:34:59 +00:00
|
|
|
this.mObservers[i].observer.onDeleteItem (aDeletedItem);
|
2004-11-07 23:48:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
**** module registration
|
|
|
|
****/
|
|
|
|
|
2004-11-10 21:25:38 +00:00
|
|
|
var calMemoryCalendarModule = {
|
2004-11-07 23:48:13 +00:00
|
|
|
mCID: Components.ID("{bda0dd7f-0a2f-4fcf-ba08-5517e6fbf133}"),
|
2004-11-23 23:40:06 +00:00
|
|
|
mContractID: "@mozilla.org/calendar/calendar;1?type=memory",
|
2004-11-07 23:48:13 +00:00
|
|
|
|
|
|
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
compMgr.registerFactoryLocation(this.mCID,
|
|
|
|
"Calendar in-memory back-end",
|
|
|
|
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;
|
|
|
|
|
|
|
|
return this.mFactory;
|
|
|
|
},
|
|
|
|
|
|
|
|
mFactory: {
|
|
|
|
createInstance: function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
2004-11-10 21:25:38 +00:00
|
|
|
return (new calMemoryCalendar()).QueryInterface(iid);
|
2004-11-07 23:48:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
canUnload: function(compMgr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2004-11-10 21:25:38 +00:00
|
|
|
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return calMemoryCalendarModule;
|
|
|
|
}
|