Ok, I see that it would be helpful, if you knew what my AddOn (TbSync) is doing. It is a sync provider for Exchange Active Sync (EAS), it can sync contacts, calendars and I plan to add tasks and email sync as well.
The general concept is, that the user is not adding an EAS-calendar to lightning and an EAS-adressbook to the TB-adressbook, but that he just adds an EAS account to Thunderbird. This is done via a stand-alone TbSync Account Manager.
https://raw.githubusercontent.com/jobisoft/TbSync/master/screenshots/TbSync_005.png
The TbSync Account Manager lists all available folders for a given account and the user may subscribe to one or more folders and the AddOn will create local addressbooks / calendars as needed and fill them with the elements found on the server.
Local changes are logged via Observers (onItemAdd, onItemDelete, ...) and are added to a changelog and next time the user syncs, those changes will be send to the server. Lightning does not know anything about this sync.
As you can see, there is actually no need for a custom calendar provider. The only thing I want is to have a way, to init a TbSync-sync-process (which has nothing to do with lightning), if the user clicks on the Lightning-Sync button.
In my first post I wrote, that the calendar is only updated during load, that is not correct of course, but I did not want to make the introduction to complicated. The calendar gets updates everytime the user hits the sync button in the TbSync account Manager, or if autosync is enabled.
I was now able to get my custom provider running, it was missing the line with the XPCOMUtils.generateNSGetFactory. So this is my minimal provider now:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://calendar/modules/calProviderUtils.jsm");
Components.utils.import("resource://calendar/modules/calUtils.jsm");
/**
* calTbSyncCalendar
* This implements the calICalendar interface adapted to the TbSync Provider.
*
* @class
* @constructor
*/
function calTbSyncCalendar() {
this.initProviderBase();
}
var calTbSyncCalendarClassID = Components.ID("{7eb8f992-3956-4607-95ac-b860ebd51f5a}");
var calTbSyncCalendarInterfaces = [
Components.interfaces.calICalendar,
Components.interfaces.calIChangeLog
];
calTbSyncCalendar.prototype = {
// Inherit from calProviderBase for the the nice helpers
__proto__: cal.ProviderBase.prototype,
classID: calTbSyncCalendarClassID,
QueryInterface: XPCOMUtils.generateQI(calTbSyncCalendarInterfaces),
classInfo: XPCOMUtils.generateCI({
classDescription: "TbSync Calendar Provider",
contractID: "@
mozilla.org/calendar/calendar;1?type=TbSync",
classID: calTbSyncCalendarClassID,
interfaces: calTbSyncCalendarInterfaces
}),
/*
* Implement calICalendar
*
* The following code is heavily inspired by the google calendar provider.
* See
http://mxr.mozilla.org/mozilla1.8/source/calendar/providers/gdata/
*/
get type() {
return "TbSync";
},
get providerID() {
return "{7eb8f992-3956-4607-95ac-b860ebd51f5a}";
},
getProperty: function cTBS_getProperty(aName) {
switch (aName) {
case "cache.enabled":
case "cache.always":
return true;
};
return this.__proto__.__proto__.getProperty.apply(this, arguments);
},
setProperty: function cTBS_setProperty(aName, aValue) {
return this.__proto__.__proto__.setProperty.apply(this, arguments);
},
get canRefresh() {
return true;
},
adoptItem: function cTBS_adoptItem(aItem, aListener) {
this.mOfflineStorage.addItem.apply(this.mOfflineStorage, arguments);
},
addItem: function cTBS_addItem(aItem, aListener) {
this.mOfflineStorage.adoptItem.apply(this.mOfflineStorage, arguments);
},
modifyItem: function cTBS_modifyItem(aNewItem, aOldItem, aListener) {
this.mOfflineStorage.modifyItem.apply(this.mOfflineStorage, arguments);
},
deleteItem: function cTBS_deleteItem(aItem, aListener) {
this.mOfflineStorage.deleteItem.apply(this.mOfflineStorage, arguments);
},
getItem: function cTBS_getItem(aId, aListener) {
this.mOfflineStorage.getItem.apply(this.mOfflineStorage, arguments);
},
getItems: function cTBS_getItems(aItemFilter, aCount, aRangeStart, aRangeEnd, aListener) {
this.mOfflineStorage.getItems.apply(this.mOfflineStorage, arguments);
},
refresh: function cTBS_refresh() {
Components.classes["@
mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage("[TbSync] REFRESH REQUEST");
// tell observers to reload everything
this.mObservers.notify("onLoad", [this]);
},
/**
* Implement calIChangeLog
*/
get offlineStorage() { return this.mOfflineStorage; },
set offlineStorage(val) {
this.mOfflineStorage = val;
return val;
},
replayChangesOn: function(aListener) {
},
};
if (XPCOMUtils.generateNSGetFactory) {
var NSGetFactory = XPCOMUtils.generateNSGetFactory([calTbSyncCalendar]);
}
I have absolutely no idea, what replayChangesOn is needed for and what I need to put in there. He complains, if I do not include it. Running with this provider will show all events twice in the calendar list until I switch to another calendar and back. So something is still wrong/missing.
What is cache.enabled and cache.always actually doing?
Thanks for your time,
John