зеркало из https://github.com/mozilla/pjs.git
Merged in recent changes to calMemoryCalendar (not part of the build)
This commit is contained in:
Родитель
a6571d75f6
Коммит
36e2f26f69
|
@ -22,6 +22,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||||
* Dan Mosedale <dan.mosedale@oracle.com>
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
|
* Mike Shaver <mike.x.shaver@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* 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
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -43,23 +44,31 @@
|
||||||
|
|
||||||
function calDavCalendar() {
|
function calDavCalendar() {
|
||||||
this.wrappedJSObject = this;
|
this.wrappedJSObject = this;
|
||||||
|
this.mObservers = { };
|
||||||
|
this.mItems = { };
|
||||||
}
|
}
|
||||||
|
|
||||||
calDavCalendar.prototype = {
|
function makeOccurrence(item, start, end)
|
||||||
//
|
{
|
||||||
// private members
|
var occ = Components.classes["@mozilla.org/calendar/item-occurrence;1"].
|
||||||
//
|
createInstance(calIItemOccurrence);
|
||||||
mObservers: Array(),
|
// XXX poor form
|
||||||
mItems: Array(),
|
occ.wrappedJSObject.item = item;
|
||||||
mUri: "",
|
occ.wrappedJSObject.occurrenceStartDate = item.startDate;
|
||||||
|
occ.wrappedJSObject.occurrenceEndDate = item.endDate;
|
||||||
|
return occ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// END_OF_TIME needs to be the max value a PRTime can be
|
||||||
|
const END_OF_TIME = 0x7fffffffffffffff;
|
||||||
|
|
||||||
|
calDavCalendar.prototype = {
|
||||||
//
|
//
|
||||||
// nsISupports interface
|
// nsISupports interface
|
||||||
//
|
//
|
||||||
QueryInterface: function (aIID) {
|
QueryInterface: function (aIID) {
|
||||||
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
||||||
!aIID.equals(Components.interfaces.calICalendar))
|
!aIID.equals(Components.interfaces.calICalendar)) {
|
||||||
{
|
|
||||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +80,9 @@ calDavCalendar.prototype = {
|
||||||
//
|
//
|
||||||
|
|
||||||
// attribute nsIURI uri;
|
// attribute nsIURI uri;
|
||||||
get uri() { return mURI },
|
mUri: null,
|
||||||
set uri(aURI) { mURI = aURI; },
|
get uri() { return this.mUri },
|
||||||
|
set uri(aUri) { this.mUri = aUri; },
|
||||||
|
|
||||||
// attribute boolean suppressAlarms;
|
// attribute boolean suppressAlarms;
|
||||||
get suppressAlarms() { return false; },
|
get suppressAlarms() { return false; },
|
||||||
|
@ -103,13 +113,14 @@ calDavCalendar.prototype = {
|
||||||
|
|
||||||
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
|
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
|
||||||
addItem: function (aItem, aListener) {
|
addItem: function (aItem, aListener) {
|
||||||
if (aItem.id == null) {
|
if (aItem.id == null)
|
||||||
aItem.id = "uuid:" + (new Date()).getTime();
|
aItem.id = "uuid:" + (new Date()).getTime();
|
||||||
}
|
|
||||||
if (this.mItems[aItem.id] != null) {
|
if (this.mItems[aItem.id] != null) {
|
||||||
// is this an error?
|
// is this an error?
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_ERROR_FAILURE,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_ERROR_FAILURE,
|
||||||
aListener.ADD,
|
aListener.ADD,
|
||||||
aItem.id,
|
aItem.id,
|
||||||
"ID already eists for addItem");
|
"ID already eists for addItem");
|
||||||
|
@ -123,7 +134,8 @@ calDavCalendar.prototype = {
|
||||||
|
|
||||||
// notify the listener
|
// notify the listener
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_OK,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
aListener.ADD,
|
aListener.ADD,
|
||||||
aItem.id,
|
aItem.id,
|
||||||
aItem);
|
aItem);
|
||||||
|
@ -132,11 +144,11 @@ calDavCalendar.prototype = {
|
||||||
// void modifyItem( in calIItemBase aItem, in calIOperationListener aListener );
|
// void modifyItem( in calIItemBase aItem, in calIOperationListener aListener );
|
||||||
modifyItem: function (aItem, aListener) {
|
modifyItem: function (aItem, aListener) {
|
||||||
if (aItem.id == null ||
|
if (aItem.id == null ||
|
||||||
this.mItems[aItem.id] == null)
|
this.mItems[aItem.id] == null) {
|
||||||
{
|
|
||||||
// this is definitely an error
|
// this is definitely an error
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_ERROR_FAILURE,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_ERROR_FAILURE,
|
||||||
aListener.MODIFY,
|
aListener.MODIFY,
|
||||||
aItem.id,
|
aItem.id,
|
||||||
"ID for modifyItem doesn't exist or is null");
|
"ID for modifyItem doesn't exist or is null");
|
||||||
|
@ -151,7 +163,8 @@ calDavCalendar.prototype = {
|
||||||
this.observeModifyItem(modifiedItem, aItem);
|
this.observeModifyItem(modifiedItem, aItem);
|
||||||
|
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_OK,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
aListener.MODIFY,
|
aListener.MODIFY,
|
||||||
aItem.id,
|
aItem.id,
|
||||||
aItem);
|
aItem);
|
||||||
|
@ -160,10 +173,10 @@ calDavCalendar.prototype = {
|
||||||
// void deleteItem( in string id, in calIOperationListener aListener );
|
// void deleteItem( in string id, in calIOperationListener aListener );
|
||||||
deleteItem: function (aId, aListener) {
|
deleteItem: function (aId, aListener) {
|
||||||
if (aId == null ||
|
if (aId == null ||
|
||||||
this.mItems[aId] == null)
|
this.mItems[aId] == null) {
|
||||||
{
|
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_ERROR_FAILURE,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_ERROR_FAILURE,
|
||||||
aListener.DELETE,
|
aListener.DELETE,
|
||||||
aId,
|
aId,
|
||||||
"ID doesn't exist for deleteItem");
|
"ID doesn't exist for deleteItem");
|
||||||
|
@ -177,7 +190,8 @@ calDavCalendar.prototype = {
|
||||||
observeDeleteItem(deletedItem);
|
observeDeleteItem(deletedItem);
|
||||||
|
|
||||||
if (aListener)
|
if (aListener)
|
||||||
aListener.onOperationComplete (Components.results.NS_OK,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
aListener.DELETE,
|
aListener.DELETE,
|
||||||
aId,
|
aId,
|
||||||
null);
|
null);
|
||||||
|
@ -190,9 +204,9 @@ calDavCalendar.prototype = {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (aId == null ||
|
if (aId == null ||
|
||||||
this.mItems[aId] == null)
|
this.mItems[aId] == null) {
|
||||||
{
|
aListener.onOperationComplete(this,
|
||||||
aListener.onOperationComplete(Components.results.NS_ERROR_FAILURE,
|
Components.results.NS_ERROR_FAILURE,
|
||||||
aListener.GET,
|
aListener.GET,
|
||||||
null,
|
null,
|
||||||
"IID doesn't exist for getItem");
|
"IID doesn't exist for getItem");
|
||||||
|
@ -207,18 +221,21 @@ calDavCalendar.prototype = {
|
||||||
} else if (item.QueryInterface(Components.interfaces.calITodo)) {
|
} else if (item.QueryInterface(Components.interfaces.calITodo)) {
|
||||||
iid = Components.interfaces.calITodo;
|
iid = Components.interfaces.calITodo;
|
||||||
} else {
|
} else {
|
||||||
aListener.onOperationComplete (Components.results.NS_ERROR_FAILURE,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_ERROR_FAILURE,
|
||||||
aListener.GET,
|
aListener.GET,
|
||||||
aId,
|
aId,
|
||||||
"Can't deduce item type based on QI");
|
"Can't deduce item type based on QI");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
aListener.onGetResult (Components.results.NS_OK,
|
aListener.onGetResult (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
iid,
|
iid,
|
||||||
null, 1, [item]);
|
null, 1, [item]);
|
||||||
|
|
||||||
aListener.onOperationComplete (Components.results.NS_OK,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
aListener.GET,
|
aListener.GET,
|
||||||
aId,
|
aId,
|
||||||
null);
|
null);
|
||||||
|
@ -242,8 +259,7 @@ calDavCalendar.prototype = {
|
||||||
|
|
||||||
var itemsFound = Array();
|
var itemsFound = Array();
|
||||||
var startTime = 0;
|
var startTime = 0;
|
||||||
// endTime needs to be the max value a PRTime can be
|
var endTime = END_OF_TIME;
|
||||||
var endTime = 0x7fffffffffffffff;
|
|
||||||
if (aRangeStart)
|
if (aRangeStart)
|
||||||
startTime = aRangeStart.utcTime;
|
startTime = aRangeStart.utcTime;
|
||||||
if (aRangeEnd)
|
if (aRangeEnd)
|
||||||
|
@ -272,7 +288,7 @@ calDavCalendar.prototype = {
|
||||||
|
|
||||||
// completed?
|
// completed?
|
||||||
var itemCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_YES) != 0);
|
var itemCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_YES) != 0);
|
||||||
var itemNotCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_YES) != 0);
|
var itemNotCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_NO) != 0);
|
||||||
|
|
||||||
// return occurrences?
|
// return occurrences?
|
||||||
var itemReturnOccurrences = ((aItemFilter & calICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0);
|
var itemReturnOccurrences = ((aItemFilter & calICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0);
|
||||||
|
@ -280,71 +296,60 @@ calDavCalendar.prototype = {
|
||||||
// if aCount != 0, we don't attempt to sort anything, and
|
// if aCount != 0, we don't attempt to sort anything, and
|
||||||
// instead return the first aCount items that match.
|
// instead return the first aCount items that match.
|
||||||
|
|
||||||
for (var i = 0; i < this.mItems.length; i++) {
|
for (var i in this.mItems) {
|
||||||
var item = this.mItems[i];
|
var item = this.mItems[i];
|
||||||
var itemtoadd = null;
|
var itemtoadd = null;
|
||||||
|
if (itemTypeFilter && !(item instanceof itemTypeFilter))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (itemTypeFilter)
|
var itemStartTime = 0;
|
||||||
item = item.QueryInterface(itemTypeFilter);
|
var itemEndTime = 0;
|
||||||
|
|
||||||
if (item) {
|
var tmpitem = item;
|
||||||
var itemStartTime = 0;
|
if (item instanceof calIEvent) {
|
||||||
var itemEndTime = 0;
|
tmpitem = item.QueryInterface(calIEvent);
|
||||||
|
itemStartTime = item.startDate.utcTime || 0
|
||||||
var tmpitem = item;
|
itemEndTime = item.endDate.utcTime || END_OF_TIME;
|
||||||
if ((tmpitem = item.QueryInterface(calIEvent)) != null)
|
|
||||||
{
|
if (itemReturnOccurrences)
|
||||||
itemStartTime = tmpitem.startDate.utcTime;
|
itemtoadd = makeOccurrence(item, item.startDate, item.endDate);
|
||||||
itemEndTime = tmpitem.endDate.utcTime;
|
} else if (item instanceof calITodo) {
|
||||||
|
// if it's a todo, also filter based on completeness
|
||||||
if (itemReturnOccurrences) {
|
if (item.percentComplete == 100 && !itemCompletedFilter)
|
||||||
itemtoadd = Components.classes["@mozilla.org/calendar/item-occurrence;1"].createInstance(calIItemOccurrence);
|
|
||||||
itemtoadd.wrappedJSObject.item = item;
|
|
||||||
itemtoadd.wrappedJSObject.occurrenceStartDate = tmpitem.startDate;
|
|
||||||
itemtoadd.wrappedJSObject.occurrenceEndDate = tmpitem.endDate;
|
|
||||||
}
|
|
||||||
} else if ((tmpitem = item.QueryInterface(calITodo)) != null)
|
|
||||||
{
|
|
||||||
// if it's a todo, also filter based on completeness
|
|
||||||
if (tmpitem.percentComplete == 100 && !itemCompletedFilter)
|
|
||||||
continue;
|
|
||||||
else if (tmpitem.percentComplete < 100 && !itemNotCompletedFilter)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
itemStartTime = tmpitem.entryTime.utcTime;
|
|
||||||
itemEndTime = tmpitem.entryTime.utcTime;
|
|
||||||
|
|
||||||
if (itemReturnOccurrences) {
|
|
||||||
itemtoadd = Components.classes["@mozilla.org/calendar/item-occurrence;1"].createInstance(calIItemOccurrence);
|
|
||||||
itemtoadd.wrappedJSObject.item = item;
|
|
||||||
itemtoadd.wrappedJSObject.occurrenceStartDate = tmpitem.entryTime;
|
|
||||||
itemtoadd.wrappedJSObject.occurrenceEndDate = tmpitem.entryTime;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// XXX unknown item type, wth do we do?
|
|
||||||
continue;
|
continue;
|
||||||
}
|
else if (item.percentComplete < 100 && !itemNotCompletedFilter)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
itemEndTime = itemStartTime = item.entryTime.utcTime || 0;
|
||||||
|
|
||||||
|
if (itemReturnOccurrences)
|
||||||
|
itemtoadd = makeOccurrence(item, item.entryTime, item.entryTime);
|
||||||
|
} else {
|
||||||
|
// XXX unknown item type, wth do we do?
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// determine whether any endpoint falls within the range
|
// determine whether any endpoint falls within the range
|
||||||
if (itemStartTime <= endTime && itemEndTime >= startTime) {
|
if (itemStartTime <= endTime && itemEndTime >= startTime) {
|
||||||
if (itemtoadd == null)
|
if (itemtoadd == null)
|
||||||
itemtoadd = item;
|
itemtoadd = item;
|
||||||
|
|
||||||
itemsFound.push(itemtoadd);
|
itemsFound.push(itemtoadd);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aCount && itemsFound.length >= aCount)
|
if (aCount && itemsFound.length >= aCount)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
aListener.onGetResult (Components.results.NS_OK,
|
aListener.onGetResult (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
itemReturnOccurrences ? calIItemOccurrence : itemTypeFilter,
|
itemReturnOccurrences ? calIItemOccurrence : itemTypeFilter,
|
||||||
null,
|
null,
|
||||||
itemsFound.length,
|
itemsFound.length,
|
||||||
itemsFound);
|
itemsFound);
|
||||||
|
|
||||||
aListener.onOperationComplete (Components.results.NS_OK,
|
aListener.onOperationComplete (this,
|
||||||
|
Components.results.NS_OK,
|
||||||
aListener.GET,
|
aListener.GET,
|
||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
|
@ -384,7 +389,7 @@ calDavCalendar.prototype = {
|
||||||
|
|
||||||
var calDavCalendarModule = {
|
var calDavCalendarModule = {
|
||||||
mCID: Components.ID("{a35fc6ea-3d92-11d9-89f9-00045ace3b8d}"),
|
mCID: Components.ID("{a35fc6ea-3d92-11d9-89f9-00045ace3b8d}"),
|
||||||
mContractID: "@mozilla.org/calendar/calendar;1&type=caldav",
|
mContractID: "@mozilla.org/calendar/calendar;1?type=caldav",
|
||||||
|
|
||||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче