use composite calendar for view. Allows to use multiple calendars.

bug 286455, r=stuart,vlad
This commit is contained in:
mvl%exedo.nl 2005-03-21 17:55:24 +00:00
Родитель a8561d3e66
Коммит f5f502297a
9 изменённых файлов: 77 добавлений и 37 удалений

Просмотреть файл

@ -74,32 +74,24 @@ calCompositeCalendar.prototype = {
mCalendars: Array(),
mDefaultCalendar: null,
addCalendar: function (aServer, aType) {
addCalendar: function (aCalendar) {
// check if the calendar already exists
for (cal in this.mCalendars) {
if (cal.uri == aServer) {
if (cal.uri == aCalendar.uri) {
// throw exception if calendar already exists?
return;
}
}
// construct a new calendar
var cid = "@mozilla.org/calendar/calendar;1?type=" + aType;
var cal = Components.classes[cid].createInstance(Components.interfaces.calICalendar);
this.mCalendars.push(aCalendar);
cal.uri = aServer;
this.mCalendars.push(cal);
this.observeCalendarAdded(cal);
this.observeCalendarAdded(aCalendar);
// if we have no default calendar, we need one here
if (this.mDefaultCalendar == null) {
this.mDefaultCalendar = cal;
this.observeDefaultCalendarChanged(cal);
this.mDefaultCalendar = aCalendar;
this.observeDefaultCalendarChanged(aCalendar);
}
return cal;
},
removeCalendar: function (aServer) {
@ -234,7 +226,7 @@ calCompositeCalendar.prototype = {
getItems: function (aItemFilter, aCount, aRangeStart, aRangeEnd, aListener) {
var cmpListener = new calCompositeGetListenerHelper(this.mCalendars.length, aListener, aCount);
for (cal in this.mCalendars) {
cal.getItems (aItemFilter, aCount, aRangeEnd, aRangeEnd, aListener);
this.mCalendars[cal].getItems (aItemFilter, aCount, aRangeStart, aRangeEnd, cmpListener);
}
},
@ -254,7 +246,7 @@ calCompositeCalendar.prototype = {
observeDefaultCalendarChanged: function (aCalendar) {
for (obs in this.mCompositeObservers)
obs.onDefaultCalendarChanged (aCalendar);
},
}
};
// composite listener helper
@ -328,9 +320,9 @@ calCompositeGetListenerHelper.prototype = {
}
// send GetResults to the real listener
this.mRealListener (aCalendar, aStatus, aItemType, aDetail, aCount, aItems);
this.mRealListener.onGetResult (aCalendar, aStatus, aItemType, aDetail, aCount, aItems);
this.mItemsReceived += aCount;
},
}
};

Просмотреть файл

@ -125,6 +125,7 @@ calICSCalendar.prototype = {
{
// XXX ?? Is this ok?
this.mItems = new Array();
this.observeOnStartBatch();
var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
@ -176,6 +177,9 @@ calICSCalendar.prototype = {
}
//} catch(e) { dump(e+"\n");}
this.observeOnEndBatch();
this.addObserver(this.mObserver, calICalendar.ITEM_FILTER_TYPE_ALL);
this.observeOnLoad();
},
@ -269,6 +273,16 @@ calICSCalendar.prototype = {
this.mObservers[i].observer.onError (aErrNo, aMessage);
},
observeOnStartBatch: function () {
for (var i = 0; i < this.mObservers.length; i++)
this.mObservers[i].observer.onStartBatch ();
},
observeOnEndBatch: function () {
for (var i = 0; i < this.mObservers.length; i++)
this.mObservers[i].observer.onEndBatch ();
},
// nsIInterfaceRequestor impl
getInterface: function(iid, instance) {
if (iid.equals(Components.interfaces.nsIAuthPrompt)) {

Просмотреть файл

@ -727,6 +727,22 @@ function getCalendar()
}
}
var gDisplayComposite;
function getDisplayComposite()
{
if (!gDisplayComposite) {
gDisplayComposite = Components.classes["@mozilla.org/calendar/calendar;1?type=composite"]
.createInstance(Components.interfaces.calICompositeCalendar);
var calMgr = getCalendarManager();
var calList = calMgr.getCalendars({});
for (i in calList) {
gDisplayComposite.addCalendar(calList[i]);
}
}
return gDisplayComposite;
}
function isEvent(aObject)
{
return aObject instanceof Components.interfaces.calIEvent;

Просмотреть файл

@ -148,14 +148,33 @@ function CalendarWindow( )
var savedThis = this;
var calendarObserver = {
onStartBatch: function() { },
onEndBatch: function() { },
onLoad: function() { },
onAddItem: function(aItem) { calendarWindow.currentView.refreshEvents(); },
onModifyItem: function(aNewItem, aOldItem) { calendarWindow.currentView.refreshEvents(); },
onDeleteItem: function(aDeletedItem) { calendarWindow.currentView.refreshEvents(); },
mInBatch: false,
onStartBatch: function() {
this.mInBatch = true;
},
onEndBatch: function() {
this.mInBatch = false;
calendarWindow.currentView.refreshEvents();
},
onLoad: function() {
if (!this.mInBatch)
refreshEventTree();
},
onAddItem: function(aItem) {
if (!this.mInBatch)
calendarWindow.currentView.refreshEvents();
},
onModifyItem: function(aNewItem, aOldItem) {
if (!this.mInBatch)
calendarWindow.currentView.refreshEvents();
},
onDeleteItem: function(aDeletedItem) {
if (!this.mInBatch)
calendarWindow.currentView.refreshEvents();
},
onAlarm: function(aAlarmItem) {},
onError: function(aErrNo, aMessage) { }
onError: function(aMessage) {}
}
var calendar = getCalendar();
calendar.addObserver(calendarObserver, calendar.ITEM_FILTER_TYPE_ALL);

Просмотреть файл

@ -131,7 +131,7 @@ DayView.prototype.refreshEvents = function()
}
};
var ccalendar = getCalendar(); // XXX Should get the composite calendar here
var ccalendar = getDisplayComposite();
dump("Fetching events from " + this.displayStartDate.toString() + " to " + this.displayEndDate.toString() + "\n");

Просмотреть файл

@ -241,7 +241,7 @@ MonthView.prototype.refreshEvents = function()
}
};
var ccalendar = getCalendar(); // XXX Should get the composite calendar here
var ccalendar = getDisplayComposite();
dump("Fetching events from " + startDate.toString() + " to " + endDate.toString() + "\n");
@ -251,6 +251,10 @@ MonthView.prototype.refreshEvents = function()
MonthView.prototype.createEventBoxInternal = function(itemOccurrence, startDate, endDate)
{
dayBoxItem = this.dayBoxItemArray[this.indexOfDate(startDate.jsDate)];
if (!dayBoxItem)
return;
var calEvent = itemOccurrence.item.QueryInterface(Components.interfaces.calIEvent);
// Make a box item to hold the event
@ -301,7 +305,6 @@ MonthView.prototype.createEventBoxInternal = function(itemOccurrence, startDate,
eventBox.appendChild(eventBoxText);
// XXX need to look at the number of children here and determine what we're supposed to do
dayBoxItem = this.dayBoxItemArray[this.indexOfDate(startDate.jsDate)];
dayBoxItem.appendChild(eventBox);
/*
@ -572,7 +575,7 @@ MonthView.prototype.refreshDisplay = function()
var lastDateCol = (firstDateCol + lastDayOfMonth - 1) % 7;
this.firstDateOfView = new Date( newYear, newMonth, 1 - firstDateCol, 0, 0, 0 );
this.lastDateOfView = new Date( newYear, newMonth, 42 - firstDateCol, 23, 59, 59 );
this.lastDateOfView = new Date( newYear, newMonth, 42 - firstDateCol, 0, 0, 0 );
// hide or unhide columns for days off
for(var day = 0; day < 7; day++) {

Просмотреть файл

@ -256,7 +256,7 @@ MultiweekView.prototype.refreshEvents = function multiweekView_refreshEvents( )
}
};
var ccalendar = getCalendar();
var ccalendar = getDisplayComposite();
ccalendar.getItems(ccalendar.ITEM_FILTER_TYPE_EVENT | ccalendar.ITEM_FILTER_CLASS_OCCURRENCES,
0, jsDateToDateTime(startDate), jsDateToDateTime(endDate),

Просмотреть файл

@ -133,10 +133,6 @@ function selectSelectedEventsInTree( EventsToSelect )
* display up to date when the calendar event data is changed
*/
/*function unifinderObserver() {
}*/
var unifinderObserver = {
mInBatch: false,
@ -187,8 +183,8 @@ function prepareCalendarUnifinder( )
// set up our calendar event observer
var ccalendar=getCalendar();
ccalendar.addObserver(unifinderObserver,ccalendar.ITEM_FILTER_TYPE_EVENT);
var ccalendar = getDisplayComposite();
ccalendar.addObserver(unifinderObserver, ccalendar.ITEM_FILTER_TYPE_EVENT);
refreshEventTree(); //Display something upon first load. onLoad doesn't work properly for observers
}

Просмотреть файл

@ -154,7 +154,7 @@ WeekView.prototype.refreshEvents = function()
}
};
var ccalendar = getCalendar(); // XXX Should get the composite calendar here
var ccalendar = getDisplayComposite();
debug("Fetching events from " + this.displayStartDate.toString() + " to " + this.displayEndDate.toString() + "\n");