From bce52566ee6d4e618521e019ca3bec2bf1927524 Mon Sep 17 00:00:00 2001 From: "mvl%exedo.nl" Date: Thu, 5 May 2005 20:59:53 +0000 Subject: [PATCH] the ics provider should return the right calendar to the listeners. bug 293053, r=vladimir --- calendar/providers/ics/calICSCalendar.js | 5 ++- .../providers/memory/calMemoryCalendar.js | 37 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/calendar/providers/ics/calICSCalendar.js b/calendar/providers/ics/calICSCalendar.js index 095af610901e..4b5ab38f7655 100644 --- a/calendar/providers/ics/calICSCalendar.js +++ b/calendar/providers/ics/calICSCalendar.js @@ -95,6 +95,7 @@ calICSCalendar.prototype = { this.mObserver = new calICSObserver(this); this.mMemoryCalendar.addObserver(this.mObserver); + this.mMemoryCalendar.wrappedJSObject.calendarToReturn = this; }, get name() { @@ -109,6 +110,7 @@ calICSCalendar.prototype = { mUri: null, get uri() { return this.mUri }, set uri(aUri) { + this.mMemoryCalendar.uri = aUri; // Lock other changes to the item list. this.locked = true; // set to prevent writing after loading, without any changes @@ -142,7 +144,8 @@ calICSCalendar.prototype = { // Create a new calendar, to get rid of all the old events this.mMemoryCalendar = Components.classes["@mozilla.org/calendar/calendar;1?type=memory"] .createInstance(Components.interfaces.calICalendar); - // And don't forget to add our observer + this.mMemoryCalendar.uri = this.mUri; + this.mMemoryCalendar.wrappedJSObject.calendarToReturn = this; this.mMemoryCalendar.addObserver(this.mObserver); this.mObserver.onStartBatch(); diff --git a/calendar/providers/memory/calMemoryCalendar.js b/calendar/providers/memory/calMemoryCalendar.js index ca23e4ed637b..799aa941cec1 100644 --- a/calendar/providers/memory/calMemoryCalendar.js +++ b/calendar/providers/memory/calMemoryCalendar.js @@ -55,6 +55,7 @@ function getCalendarManager() function calMemoryCalendar() { this.wrappedJSObject = this; + this.calendarToReturn = this, this.initMemoryCalendar(); } @@ -74,6 +75,10 @@ const START_OF_TIME = -0x7fffffffffffffff; const END_OF_TIME = 0x7fffffffffffffff; calMemoryCalendar.prototype = { + // This will be returned from getItems as the calendar. The ics + // calendar overwrites this. + calendarToReturn: null, + // // nsISupports interface // @@ -142,7 +147,7 @@ calMemoryCalendar.prototype = { if (aItem.id == null) { if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.ADD, aItem.id, @@ -153,7 +158,7 @@ calMemoryCalendar.prototype = { if (this.mItems[aItem.id] != null) { // is this an error? if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.ADD, aItem.id, @@ -169,7 +174,7 @@ calMemoryCalendar.prototype = { // notify the listener if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_OK, aListener.ADD, newItem.id, @@ -185,7 +190,7 @@ calMemoryCalendar.prototype = { { // this is definitely an error if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.MODIFY, aItem.id, @@ -197,7 +202,7 @@ calMemoryCalendar.prototype = { if (oldItem.generation != aItem.generation) { if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.MODIFY, aItem.id, @@ -211,7 +216,7 @@ calMemoryCalendar.prototype = { this.mItems[newItem.id] = newItem; if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_OK, aListener.MODIFY, newItem.id, @@ -224,7 +229,7 @@ calMemoryCalendar.prototype = { deleteItem: function (aItem, aListener) { if (aItem.id == null || this.mItems[aItem.id] == null) { if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.DELETE, aItem.id, @@ -235,7 +240,7 @@ calMemoryCalendar.prototype = { var oldItem = this.mItems[aItem.id]; if (oldItem.generation != aItem.generation) { if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.DELETE, aItem.id, @@ -246,7 +251,7 @@ calMemoryCalendar.prototype = { delete this.mItems[aItem.id]; if (aListener) - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_OK, aListener.DELETE, aItem.id, @@ -262,7 +267,7 @@ calMemoryCalendar.prototype = { if (aId == null || this.mItems[aId] == null) { - aListener.onOperationComplete(this, + aListener.onOperationComplete(this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.GET, null, @@ -278,7 +283,7 @@ calMemoryCalendar.prototype = { } else if (item instanceof Components.interfaces.calITodo) { iid = Components.interfaces.calITodo; } else { - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.GET, aId, @@ -286,12 +291,12 @@ calMemoryCalendar.prototype = { return; } - aListener.onGetResult (this, + aListener.onGetResult (this.calendarToReturn, Components.results.NS_OK, iid, null, 1, [item]); - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_OK, aListener.GET, aId, @@ -332,7 +337,7 @@ calMemoryCalendar.prototype = { var wantTodos = ((aItemFilter & calICalendar.ITEM_FILTER_TYPE_TODO) != 0); if(!wantEvents && !wantTodos) { // bail. - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_ERROR_FAILURE, aListener.GET, null, @@ -414,14 +419,14 @@ calMemoryCalendar.prototype = { break; } - aListener.onGetResult (this, + aListener.onGetResult (this.calendarToReturn, Components.results.NS_OK, typeIID, null, itemsFound.length, itemsFound); - aListener.onOperationComplete (this, + aListener.onOperationComplete (this.calendarToReturn, Components.results.NS_OK, aListener.GET, null,